WIP++, doc, errors
This commit is contained in:
parent
dda2e04862
commit
0892c257aa
@ -1,6 +1,12 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
# Migrate assignments for Gitea-Issues after a Gitea2Gitea-Migration
|
# Migrate assignments for Gitea-Issues after a Gitea2Gitea-Migration
|
||||||
# 2024 Benjamin Winter
|
# 2024 Benjamin Winter
|
||||||
|
#
|
||||||
|
# errors
|
||||||
|
# 1 parameter error
|
||||||
|
# 2 repository-check error
|
||||||
|
# 5 internal error
|
||||||
|
# 42 command cannot be found
|
||||||
set -eu
|
set -eu
|
||||||
|
|
||||||
readonly PROGNAME=`/usr/bin/basename $0`
|
readonly PROGNAME=`/usr/bin/basename $0`
|
||||||
@ -15,7 +21,6 @@ dry_run=true
|
|||||||
#
|
#
|
||||||
# FUNCTIONS
|
# FUNCTIONS
|
||||||
#
|
#
|
||||||
|
|
||||||
print_help()
|
print_help()
|
||||||
{
|
{
|
||||||
cat << "EOF"
|
cat << "EOF"
|
||||||
@ -34,6 +39,7 @@ INFORMATION
|
|||||||
- this script will start in DRY MODE by default - see --GO parameter
|
- 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 environment and stops on any error
|
||||||
- this script will check the OLD and NEW repository for inconsistencies
|
- 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
|
- if your titles include a ¬ character, the script may could behave funny as this i used as separator
|
||||||
|
|
||||||
INSTALLATION AND PREPARATION
|
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 OLD --url https://oldgitea.example.com --token 123456789123456789
|
||||||
- tea login add --name NEW --url https://newgitea.example.com --token 123459789123456789
|
- tea login add --name NEW --url https://newgitea.example.com --token 123459789123456789
|
||||||
|
|
||||||
USAGE
|
USAGE
|
||||||
-h | --help print this help
|
-h | --help print this help
|
||||||
-r | --repo required, i.e. "my_organisation/my_repository"
|
-r | --repo required, i.e. "my_organisation/my_repository"
|
||||||
-o | --login_old required, tea-id of your old login
|
-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";
|
echo -e "Error: --repo, --login_old and --login_new must be specified\n";
|
||||||
print_help;
|
print_help;
|
||||||
exit 2
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
# @param $1 "command" → the command to check for
|
# @param $1 "command" → the command to check for
|
||||||
@ -77,7 +83,7 @@ checkCommand()
|
|||||||
# PARAMETERS
|
# PARAMETERS
|
||||||
#
|
#
|
||||||
if [[ "$@" == "" ]] ; then error_in_or_out_not_specified ; fi
|
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}"
|
eval set -- "${TEMP}"
|
||||||
while true ; do
|
while true ; do
|
||||||
case "$1" in
|
case "$1" in
|
||||||
@ -119,20 +125,25 @@ if $dry_run; then echo -e "###\n### DRY RUN - will not change anything\n###"; fi
|
|||||||
# check commands
|
# check commands
|
||||||
checkCommand tea
|
checkCommand tea
|
||||||
checkCommand jq
|
checkCommand jq
|
||||||
|
checkCommand sort
|
||||||
|
|
||||||
# get data
|
# get data
|
||||||
echo -e "\n# checking access to OLD (\"$login_old\") and NEW (\"$login_new\")"
|
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)
|
readonly 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_new=$(tea issues list --output json --login "$login_new" --repo "$repo" --state all --fields index,assignees,title)
|
||||||
|
|
||||||
# check data
|
# check data
|
||||||
readonly json_old_ids=$(echo "$json_old" | jq ".[] | .index")
|
readonly json_old_ids=$(echo "$json_old" | jq ".[] | .index" | sort -n)
|
||||||
readonly json_new_ids=$(echo "$json_new" | jq ".[] | .index")
|
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
|
if [[ "$json_old_ids" != "$json_new_ids" ]]; then
|
||||||
echo >&2 "OLD repositories' ids differ from NEW repository. Aborting.";
|
echo >&2 "OLD repositories' ids differ from NEW repository. Aborting.";
|
||||||
echo >&2 "OLD repositories' ids: $(echo "$json_old_ids" | tr '\n' ,)";
|
echo >&2 "OLD repositories' ids: $(echo "$json_old_ids" | tr '\n' ,)";
|
||||||
echo >&2 "NEW repositories' ids: $(echo "$json_new_ids" | tr '\n' ,)";
|
echo >&2 "NEW repositories' ids: $(echo "$json_new_ids" | tr '\n' ,)";
|
||||||
exit 3;
|
exit 2;
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
@ -143,3 +154,4 @@ done< <(echo "$json_old" | jq --raw-output '.[] | "\(.index)¬\(.assignees)¬\(.
|
|||||||
|
|
||||||
|
|
||||||
exit 0
|
exit 0
|
||||||
|
${#a[@]}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user