2 Commits
1.0.0 ... 1.2.0

View File

@ -11,12 +11,14 @@ set -eu
readonly PROGNAME=`/usr/bin/basename $0`
readonly PROGPATH=`echo $0 | sed -e 's,[\\/][^\\/][^\\/]*$,,'`
readonly REVISION="1.0.0"
readonly REVISION="1.2.0"
repo=""
login_old=""
login_new=""
dry_run=true
wait_time=0.25
use_colour=true
#
# FUNCTIONS
@ -43,10 +45,13 @@ INFORMATION
- this script will check the OLD and NEW repository for inconsistencies
- issue-ids are checked; titles are not checked
- assignments in new repo are checked
- if your titles include a ¬ character, the script may could behave funny as this is used as separator
- the --wait time slows down the script to reduce e-mail-sending-speed
- the title is not fetched due to complications with tea and "quotes"
- 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?)
- "Error: The target couldn't be found."
- please check, if the --repo is the same for OLD and NEW
INSTALLATION AND PREPARATION
- install
@ -64,11 +69,16 @@ INSTALLATION AND PREPARATION
- tea login add --name NEW --url https://newgitea.example.com --token 123459789123456789
USAGE
SWITCHES
-h | --help print this help
-c | --colour disable colour output
--GO stop dry mode
PARAMETERS
-r | --repo required, i.e. "my_organisation/my_repository"
-o | --login_old required, tea-id of your old login
-n | --login_new required, tea-id of your new login
--GO stop dry mode
-w | --wait wait time in s between issue handling (default 0.25)
EOF
}
@ -89,7 +99,7 @@ checkCommand()
# PARAMETERS
#
if [[ "$@" == "" ]] ; then error_in_or_out_not_specified ; fi
readonly 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:w:c --long help,GO,colour,repo:,login_old:,login_new:,wait: -n "${PROGNAME}" -- "$@")
eval set -- "${TEMP}"
while true ; do
case "$1" in
@ -97,6 +107,9 @@ while true ; do
print_help
exit 0
;;
--colour|-c)
use_colour=false
;;
--repo|-r)
repo="$2"
shift
@ -109,6 +122,10 @@ while true ; do
login_new="$2"
shift
;;
--wait|-w)
wait_time="$2"
shift
;;
--GO)
dry_run=false
;;
@ -126,7 +143,14 @@ 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
if $dry_run; then
t="###\n### DRY RUN - will not change anything\n###"
if [ $use_colour = true ]; then
echo -e "\e[1m\e[38;5;214m$t\e[0m"
else
echo -e "$t"
fi
fi
# check commands
checkCommand tea
@ -135,11 +159,11 @@ checkCommand sort
checkCommand tr
# check access and get data
echo -e "\n# checking access to OLD (\"$login_old\") and NEW (\"$login_new\")"
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)
echo "# checking access to OLD (\"$login_old\") and NEW (\"$login_new\")"
readonly json_old=$(tea issues list --output json --login "$login_old" --repo "$repo" --state all --fields index,author,assignees)
readonly json_new=$(tea issues list --output json --login "$login_new" --repo "$repo" --state all --fields index,author,assignees)
echo -e "\n# running consitency checks"
echo "# running consistency checks"
readonly json_old_ids=$(echo "$json_old" | jq ".[] | .index" | sort -n)
readonly json_new_ids=$(echo "$json_new" | jq ".[] | .index" | sort -n)
# check if issues
@ -157,20 +181,51 @@ if [[ "$json_new_assignments" != "" ]]; then echo >&2 "NEW repo already contains
# process data
echo -e "\n# processing data"
while IFS="¬"; read -r index assignees title; do
echo "# processing data"
while IFS="¬"; read -r index author assignees; do
assignees=$(echo "$assignees" | tr ' ' ,)
issueinfo="… issue#$index - \"$title\" - assigned to \"$assignees\""
echo "… #$index - by \"$author\" assigned to \"$assignees\""
# comment for the original author
if [ $dry_run = false ]; then
echo "migrator: this issue was created by @$author and will be assigned to '$assignees'" | tea comment --login "$login_new" --repo "$repo" "$index" >/dev/null
fi
# assignment
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
t="OK"
if [ $use_colour = true ]; then
echo -e " → \e[1m\e[48;5;22m$t\e[0m"
else
echo "$t"
fi
else
echo "$issueinfo - SKIPPED"
t="INFO: added comment, no assignee"
if [ $use_colour = true ]; then
echo -e " → \e[1m\e[48;5;172m$t\e[0m"
else
echo -e "$t"
fi
fi
done< <(echo "$json_old" | jq --raw-output '.[] | "\(.index)¬\(.assignees)¬\(.title)"')
sleep $wait_time
done< <(echo "$json_old" | jq --raw-output '.[] | "\(.index)¬\(.author)¬\(.assignees)"')
if $dry_run; then
t="###\n### DRY RUN - nothing changed\n###"
if [ $use_colour = true ]; then
echo -e "\e[1m\e[38;5;214m$t\e[0m"
else
echo -e "$t"
fi
fi
echo "# done"
exit 0