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
# Migrate assignments for Gitea-Issues after a Gitea2Gitea-Migration
# 2024 Benjamin Winter
set -eu
readonly PROGNAME=`/usr/bin/basename $0`
@ -18,9 +20,23 @@ print_help()
{
cat << "EOF"
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
- jq - Command-line JSON processor
- 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 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
@ -98,23 +114,32 @@ if [[ -z "$repo" || -z "$login_old" || -z "$login_new" ]] ; then error_in_or_out
#
# START
#
if $dry_run; then echo -e "###\n### DRY RUN - will not change anything\n###"; fi
# check commands
checkCommand tea
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
str=$(tea issues list --output json --login "$login_old" --repo "$repo" --fields index,title,assignees)
while IFS="¬"; read -r index title assignees; do
echo "processing issue #${index} - \"${title}\", assigned to ${assignees}"
done< <(echo "$str" | jq --raw-output '.[] | "\(.index)¬\(.title)¬\(.assignees)"')
# check data
readonly json_old_ids=$(echo "$json_old" | jq ".[] | .index")
readonly json_new_ids=$(echo "$json_new" | jq ".[] | .index")
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;
fi
#tea issues list --output simple --login NEW
#tea issues list --output simple --login NEW --repo eine_tolle_organisation/ein_tolles_repository
# process data
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