WIP++; added check functions; also include closed; doc

This commit is contained in:
Benjamin Winter 2024-02-23 12:28:43 +01:00
parent f734790237
commit dda2e04862

View File

@ -1,4 +1,6 @@
#!/bin/bash #!/bin/bash
# Migrate assignments for Gitea-Issues after a Gitea2Gitea-Migration
# 2024 Benjamin Winter
set -eu set -eu
readonly PROGNAME=`/usr/bin/basename $0` readonly PROGNAME=`/usr/bin/basename $0`
@ -18,9 +20,23 @@ print_help()
{ {
cat << "EOF" cat << "EOF"
PURPOSE PURPOSE
this script will start in DRY MODE by default - see --GO parameter - Migrate assignments for Gitea-Issues after a Gitea2Gitea-Migration
- issues must have the same ID on both systems
- users must have the same NAME on both systems
- example
- OLD: https://oldgitea.example.com/my_organisation/my_repository
- NEW: https://newgitea.example.com/my_organisation/my_repository
- Typical Workflow
1. migrate your repository from your OLD Gitea instance to your NEW one
2. use this script to migrate the assignments
INSTALLATION AND PREPERATION 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
- if your titles include a ¬ character, the script may could behave funny as this i used as separator
INSTALLATION AND PREPARATION
- install - install
- jq - Command-line JSON processor - jq - Command-line JSON processor
- tea: https://gitea.com/gitea/tea - tea: https://gitea.com/gitea/tea
@ -35,7 +51,7 @@ INSTALLATION AND PREPERATION
- 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
@ -98,23 +114,32 @@ if [[ -z "$repo" || -z "$login_old" || -z "$login_new" ]] ; then error_in_or_out
# #
# START # START
# #
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
# 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)
if $dry_run; then echo -e "###\n### DRY RUN - will not change anything\n###"; fi # check data
readonly json_old_ids=$(echo "$json_old" | jq ".[] | .index")
str=$(tea issues list --output json --login "$login_old" --repo "$repo" --fields index,title,assignees) readonly json_new_ids=$(echo "$json_new" | jq ".[] | .index")
if [[ "$json_old_ids" != "$json_new_ids" ]]; then
while IFS="¬"; read -r index title assignees; do echo >&2 "OLD repositories' ids differ from NEW repository. Aborting.";
echo "processing issue #${index} - \"${title}\", assigned to ${assignees}" echo >&2 "OLD repositories' ids: $(echo "$json_old_ids" | tr '\n' ,)";
done< <(echo "$str" | jq --raw-output '.[] | "\(.index)¬\(.title)¬\(.assignees)"') echo >&2 "NEW repositories' ids: $(echo "$json_new_ids" | tr '\n' ,)";
exit 3;
fi
#tea issues list --output simple --login NEW # process data
#tea issues list --output simple --login NEW --repo eine_tolle_organisation/ein_tolles_repository while IFS="¬"; read -r index assignees title; do
echo "processing issue #${index} - \"${title}\", assigned to \"${assignees}\""
done< <(echo "$json_old" | jq --raw-output '.[] | "\(.index)¬\(.assignees)¬\(.title)"')
exit 0 exit 0