v1.0.0, working script
This commit is contained in:
parent
9291825b01
commit
3e2d080c3d
@ -1,6 +1,6 @@
|
|||||||
#!/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, MILA
|
||||||
#
|
#
|
||||||
# errors
|
# errors
|
||||||
# 1 parameter error
|
# 1 parameter error
|
||||||
@ -11,7 +11,7 @@ set -eu
|
|||||||
|
|
||||||
readonly PROGNAME=`/usr/bin/basename $0`
|
readonly PROGNAME=`/usr/bin/basename $0`
|
||||||
readonly PROGPATH=`echo $0 | sed -e 's,[\\/][^\\/][^\\/]*$,,'`
|
readonly PROGPATH=`echo $0 | sed -e 's,[\\/][^\\/][^\\/]*$,,'`
|
||||||
readonly REVISION="0.0.1-WIP"
|
readonly REVISION="1.0.0"
|
||||||
|
|
||||||
repo=""
|
repo=""
|
||||||
login_old=""
|
login_old=""
|
||||||
@ -23,11 +23,13 @@ dry_run=true
|
|||||||
#
|
#
|
||||||
print_help()
|
print_help()
|
||||||
{
|
{
|
||||||
|
echo "--- $PROGNAME $REVISION"
|
||||||
cat << "EOF"
|
cat << "EOF"
|
||||||
PURPOSE
|
PURPOSE
|
||||||
- Migrate assignments for Gitea-Issues after a Gitea2Gitea-Migration
|
- Migrate assignments for Gitea-Issues after a Gitea2Gitea-Migration
|
||||||
- issues must have the same ID on both systems
|
- issues must have the same ID on both systems
|
||||||
- users must have the same NAME on both systems
|
- users must have the same NAME on both systems
|
||||||
|
- users must have the right to be assigned on both systems
|
||||||
- example
|
- example
|
||||||
- OLD: https://oldgitea.example.com/my_organisation/my_repository
|
- OLD: https://oldgitea.example.com/my_organisation/my_repository
|
||||||
- NEW: https://newgitea.example.com/my_organisation/my_repository
|
- NEW: https://newgitea.example.com/my_organisation/my_repository
|
||||||
@ -41,12 +43,15 @@ INFORMATION
|
|||||||
- 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
|
- issue-ids are checked; titles are not checked
|
||||||
- assignments in new repo are 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
|
- if your titles include a ¬ character, the script may could behave funny as this is used as separator
|
||||||
|
- Troubleshooting
|
||||||
|
- "Error: could not edit issue:"
|
||||||
|
- please check, if the assigned person(s) have the right to be assigned (are they in the Organisation? Collaborators?)
|
||||||
|
|
||||||
INSTALLATION AND PREPARATION
|
INSTALLATION AND PREPARATION
|
||||||
- install
|
- install
|
||||||
- jq - Command-line JSON processor
|
- jq - Command-line JSON processor - https://github.com/stedolan/jq
|
||||||
- tea: https://gitea.com/gitea/tea
|
- tea - Command line tool to interact with Gitea - https://gitea.com/gitea/tea
|
||||||
- create Gitea tokens for tea
|
- create Gitea tokens for tea
|
||||||
- permissions on the OLD system:
|
- permissions on the OLD system:
|
||||||
- user: read
|
- user: read
|
||||||
@ -74,7 +79,7 @@ error_in_or_out_not_specified()
|
|||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
# @param $1 "command" → the command to check for
|
# @param $1 "command" → the command to check for
|
||||||
checkCommand()
|
checkCommand()
|
||||||
{
|
{
|
||||||
command -v "$1" >/dev/null 2>&1 || { echo >&2 "Command ${1} is required but it's not installed. Aborting."; exit 42; }
|
command -v "$1" >/dev/null 2>&1 || { echo >&2 "Command ${1} is required but it's not installed. Aborting."; exit 42; }
|
||||||
@ -127,6 +132,7 @@ if $dry_run; then echo -e "###\n### DRY RUN - will not change anything\n###"; fi
|
|||||||
checkCommand tea
|
checkCommand tea
|
||||||
checkCommand jq
|
checkCommand jq
|
||||||
checkCommand sort
|
checkCommand sort
|
||||||
|
checkCommand tr
|
||||||
|
|
||||||
# check access and get data
|
# check access and 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\")"
|
||||||
@ -153,10 +159,18 @@ if [[ "$json_new_assignments" != "" ]]; then echo >&2 "NEW repo already contains
|
|||||||
# process data
|
# process data
|
||||||
echo -e "\n# processing data"
|
echo -e "\n# processing data"
|
||||||
while IFS="¬"; read -r index assignees title; do
|
while IFS="¬"; read -r index assignees title; do
|
||||||
assignees=$(echo "$assignees"|tr ' ' ,)
|
assignees=$(echo "$assignees" | tr ' ' ,)
|
||||||
echo "… issue#$index - \"$title\" - assigned to \"$assignees\""
|
issueinfo="… issue#$index - \"$title\" - assigned to \"$assignees\""
|
||||||
|
|
||||||
|
if [[ -n $assignees ]]; then
|
||||||
|
echo "$issueinfo"
|
||||||
|
if [ $dry_run = false ]; then
|
||||||
|
tea issue edit --login "$login_new" --repo "$repo" --add-assignees "$assignees" "$index" >/dev/null
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo "$issueinfo - SKIPPED"
|
||||||
|
fi
|
||||||
|
|
||||||
done< <(echo "$json_old" | jq --raw-output '.[] | "\(.index)¬\(.assignees)¬\(.title)"')
|
done< <(echo "$json_old" | jq --raw-output '.[] | "\(.index)¬\(.assignees)¬\(.title)"')
|
||||||
|
|
||||||
|
|
||||||
exit 0
|
exit 0
|
||||||
${#a[@]}
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user