diff --git a/migrate_assignments.sh b/migrate_assignments.sh index 80cd91e..e516354 100755 --- a/migrate_assignments.sh +++ b/migrate_assignments.sh @@ -40,6 +40,7 @@ INFORMATION - this script will check the environment and stops on any error - 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 i used as separator INSTALLATION AND PREPARATION @@ -127,29 +128,33 @@ checkCommand tea checkCommand jq checkCommand sort -# get data +# 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) -# check data +echo -e "\n# running consitency checks" readonly json_old_ids=$(echo "$json_old" | jq ".[] | .index" | sort -n) readonly json_new_ids=$(echo "$json_new" | jq ".[] | .index" | sort -n) -# issues? - -if [[ $json_old_ids == "" || $json_new_ids == "" ]]; then echo >&2 "OLD and/or NEW repo contains no issues. Aborting."; exit 2; fi -# same issues? +# check if issues +if [[ "$json_old_ids" == "" || "$json_new_ids" == "" ]]; then echo >&2 "OLD and/or NEW repo contains no issues. Aborting."; exit 2; fi +# check same issues if [[ "$json_old_ids" != "$json_new_ids" ]]; then echo >&2 "OLD repositories' ids differ from NEW repository. Aborting."; echo >&2 "OLD repositories' ids: $(echo "$json_old_ids" | tr '\n' ,)"; echo >&2 "NEW repositories' ids: $(echo "$json_new_ids" | tr '\n' ,)"; exit 2; fi +# check if NEW.assignments are empty +readonly json_new_assignments=$(echo "$json_new" | jq --join-output ".[] | .assignees" ) +if [[ "$json_new_assignments" != "" ]]; then echo >&2 "NEW repo already contains issues with assignments. Aborting."; exit 2; fi # process data +echo -e "\n# processing data" while IFS="¬"; read -r index assignees title; do - echo "processing issue #${index} - \"${title}\", assigned to \"${assignees}\"" + assignees=$(echo "$assignees"|tr ' ' ,) + echo "… issue#$index - \"$title\" - assigned to \"$assignees\"" done< <(echo "$json_old" | jq --raw-output '.[] | "\(.index)¬\(.assignees)¬\(.title)"')