From 0892c257aa1ba932c27ad435bff5810552fb6ec9 Mon Sep 17 00:00:00 2001 From: winterb Date: Fri, 23 Feb 2024 14:08:23 +0100 Subject: [PATCH] WIP++, doc, errors --- migrate_assignments.sh | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/migrate_assignments.sh b/migrate_assignments.sh index 1e4e21b..80cd91e 100755 --- a/migrate_assignments.sh +++ b/migrate_assignments.sh @@ -1,6 +1,12 @@ #!/bin/bash # Migrate assignments for Gitea-Issues after a Gitea2Gitea-Migration # 2024 Benjamin Winter +# +# errors +# 1 parameter error +# 2 repository-check error +# 5 internal error +# 42 command cannot be found set -eu readonly PROGNAME=`/usr/bin/basename $0` @@ -15,7 +21,6 @@ dry_run=true # # FUNCTIONS # - print_help() { cat << "EOF" @@ -34,6 +39,7 @@ INFORMATION - this script will start in DRY MODE by default - see --GO parameter - 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 - if your titles include a ¬ character, the script may could behave funny as this i used as separator INSTALLATION AND PREPARATION @@ -51,7 +57,7 @@ INSTALLATION AND PREPARATION - tea login add --name OLD --url https://oldgitea.example.com --token 123456789123456789 - tea login add --name NEW --url https://newgitea.example.com --token 123459789123456789 - USAGE +USAGE -h | --help print this help -r | --repo required, i.e. "my_organisation/my_repository" -o | --login_old required, tea-id of your old login @@ -64,7 +70,7 @@ error_in_or_out_not_specified() { echo -e "Error: --repo, --login_old and --login_new must be specified\n"; print_help; - exit 2 + exit 1 } # @param $1 "command" → the command to check for @@ -77,7 +83,7 @@ checkCommand() # PARAMETERS # if [[ "$@" == "" ]] ; then error_in_or_out_not_specified ; fi -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: --long help,GO,repo:login_old:,login_new: -n "${PROGNAME}" -- "$@") eval set -- "${TEMP}" while true ; do case "$1" in @@ -119,20 +125,25 @@ if $dry_run; then echo -e "###\n### DRY RUN - will not change anything\n###"; fi # check commands checkCommand tea checkCommand jq +checkCommand sort # get data echo -e "\n# checking access to OLD (\"$login_old\") and NEW (\"$login_new\")" -json_old=$(tea issues list --output json --login "$login_old" --repo "$repo" --state all --fields index,assignees,title) -json_new=$(tea issues list --output json --login "$login_new" --repo "$repo" --state all --fields index,assignees,title) +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 -readonly json_old_ids=$(echo "$json_old" | jq ".[] | .index") -readonly json_new_ids=$(echo "$json_new" | jq ".[] | .index") +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? 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 3; + exit 2; fi @@ -143,3 +154,4 @@ done< <(echo "$json_old" | jq --raw-output '.[] | "\(.index)¬\(.assignees)¬\(. exit 0 +${#a[@]}