diff --git a/migrate_assignments.sh b/migrate_assignments.sh index e8652e8..eca6d63 100755 --- a/migrate_assignments.sh +++ b/migrate_assignments.sh @@ -11,12 +11,13 @@ set -eu readonly PROGNAME=`/usr/bin/basename $0` readonly PROGPATH=`echo $0 | sed -e 's,[\\/][^\\/][^\\/]*$,,'` -readonly REVISION="1.0.0" +readonly REVISION="1.1.0" repo="" login_old="" login_new="" dry_run=true +wait_time=0.25 # # FUNCTIONS @@ -43,10 +44,13 @@ INFORMATION - this script will check the OLD and NEW repository for inconsistencies - issue-ids are checked; titles are not checked - assignments in new repo are checked -- if your titles include a ¬ character, the script may could behave funny as this is used as separator +- the --wait time slows down the script to reduce e-mail-sending-speed +- the title is not fetched due to complications with tea and "quotes" - Troubleshooting - "Error: could not edit issue:" - please check, if the assigned person(s) have the right to be assigned (are they in the Organisation? Collaborators?) + - "Error: The target couldn't be found." + - please check, if the --repo is the same for OLD and NEW INSTALLATION AND PREPARATION - install @@ -68,6 +72,7 @@ USAGE -r | --repo required, i.e. "my_organisation/my_repository" -o | --login_old required, tea-id of your old login -n | --login_new required, tea-id of your new login + -w | --wait wait time in s between issue handling (default 0.25) --GO stop dry mode EOF } @@ -89,7 +94,7 @@ checkCommand() # PARAMETERS # if [[ "$@" == "" ]] ; then error_in_or_out_not_specified ; fi -readonly TEMP=$(getopt -o h,r:o:n: --long help,GO,repo:login_old:,login_new: -n "${PROGNAME}" -- "$@") +readonly TEMP=$(getopt -o h,r:o:n:w: --long help,GO,repo:login_old:,login_new:wait: -n "${PROGNAME}" -- "$@") eval set -- "${TEMP}" while true ; do case "$1" in @@ -109,6 +114,10 @@ while true ; do login_new="$2" shift ;; + --wait|-w) + wait_time="$2" + shift + ;; --GO) dry_run=false ;; @@ -135,11 +144,11 @@ checkCommand sort checkCommand tr # check access and get data -echo -e "\n# checking access to OLD (\"$login_old\") and NEW (\"$login_new\")" -readonly json_old=$(tea issues list --output json --login "$login_old" --repo "$repo" --state all --fields index,assignees,title) -readonly json_new=$(tea issues list --output json --login "$login_new" --repo "$repo" --state all --fields index,assignees,title) +echo "# checking access to OLD (\"$login_old\") and NEW (\"$login_new\")" +readonly json_old=$(tea issues list --output json --login "$login_old" --repo "$repo" --state all --fields index,author,assignees) +readonly json_new=$(tea issues list --output json --login "$login_new" --repo "$repo" --state all --fields index,author,assignees) -echo -e "\n# running consitency checks" +echo "# running consistency checks" readonly json_old_ids=$(echo "$json_old" | jq ".[] | .index" | sort -n) readonly json_new_ids=$(echo "$json_new" | jq ".[] | .index" | sort -n) # check if issues @@ -157,20 +166,30 @@ if [[ "$json_new_assignments" != "" ]]; then echo >&2 "NEW repo already contains # process data -echo -e "\n# processing data" -while IFS="¬"; read -r index assignees title; do +echo "# processing data" +while IFS="¬"; read -r index author assignees; do assignees=$(echo "$assignees" | tr ' ' ,) - issueinfo="… issue#$index - \"$title\" - assigned to \"$assignees\"" + echo "… #$index - by \"$author\" assigned to \"$assignees\"" + + # comment for the original author + if [ $dry_run = false ]; then + echo "migrator: this issue was created by @$author and will be assigned to '$assignees'" | tea comment --login "$login_new" --repo "$repo" "$index" >/dev/null + fi + + # assignment if [[ -n $assignees ]]; then - echo "$issueinfo" if [ $dry_run = false ]; then tea issue edit --login "$login_new" --repo "$repo" --add-assignees "$assignees" "$index" >/dev/null fi + echo " → OK" else - echo "$issueinfo - SKIPPED" + echo " → INFO: added comment, no assignee" fi -done< <(echo "$json_old" | jq --raw-output '.[] | "\(.index)¬\(.assignees)¬\(.title)"') + sleep $wait_time +done< <(echo "$json_old" | jq --raw-output '.[] | "\(.index)¬\(.author)¬\(.assignees)"') + +echo "# done" exit 0