Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
17f8f66a9b | |||
a3eb327e5b |
@ -11,12 +11,14 @@ 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="1.0.0"
|
readonly REVISION="1.2.0"
|
||||||
|
|
||||||
repo=""
|
repo=""
|
||||||
login_old=""
|
login_old=""
|
||||||
login_new=""
|
login_new=""
|
||||||
dry_run=true
|
dry_run=true
|
||||||
|
wait_time=0.25
|
||||||
|
use_colour=true
|
||||||
|
|
||||||
#
|
#
|
||||||
# FUNCTIONS
|
# FUNCTIONS
|
||||||
@ -43,10 +45,13 @@ 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 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
|
- Troubleshooting
|
||||||
- "Error: could not edit issue:"
|
- "Error: could not edit issue:"
|
||||||
- please check, if the assigned person(s) have the right to be assigned (are they in the Organisation? Collaborators?)
|
- 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
|
INSTALLATION AND PREPARATION
|
||||||
- install
|
- install
|
||||||
@ -64,11 +69,16 @@ INSTALLATION AND PREPARATION
|
|||||||
- 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
|
||||||
|
SWITCHES
|
||||||
-h | --help print this help
|
-h | --help print this help
|
||||||
|
-c | --colour disable colour output
|
||||||
|
--GO stop dry mode
|
||||||
|
|
||||||
|
PARAMETERS
|
||||||
-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
|
||||||
-n | --login_new required, tea-id of your new 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
|
EOF
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -89,7 +99,7 @@ checkCommand()
|
|||||||
# PARAMETERS
|
# PARAMETERS
|
||||||
#
|
#
|
||||||
if [[ "$@" == "" ]] ; then error_in_or_out_not_specified ; fi
|
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}"
|
eval set -- "${TEMP}"
|
||||||
while true ; do
|
while true ; do
|
||||||
case "$1" in
|
case "$1" in
|
||||||
@ -97,6 +107,9 @@ while true ; do
|
|||||||
print_help
|
print_help
|
||||||
exit 0
|
exit 0
|
||||||
;;
|
;;
|
||||||
|
--colour|-c)
|
||||||
|
use_colour=false
|
||||||
|
;;
|
||||||
--repo|-r)
|
--repo|-r)
|
||||||
repo="$2"
|
repo="$2"
|
||||||
shift
|
shift
|
||||||
@ -109,6 +122,10 @@ while true ; do
|
|||||||
login_new="$2"
|
login_new="$2"
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
|
--wait|-w)
|
||||||
|
wait_time="$2"
|
||||||
|
shift
|
||||||
|
;;
|
||||||
--GO)
|
--GO)
|
||||||
dry_run=false
|
dry_run=false
|
||||||
;;
|
;;
|
||||||
@ -126,7 +143,14 @@ 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
|
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
|
# check commands
|
||||||
checkCommand tea
|
checkCommand tea
|
||||||
@ -135,11 +159,11 @@ checkCommand sort
|
|||||||
checkCommand tr
|
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 "# 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_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,assignees,title)
|
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_old_ids=$(echo "$json_old" | jq ".[] | .index" | sort -n)
|
||||||
readonly json_new_ids=$(echo "$json_new" | jq ".[] | .index" | sort -n)
|
readonly json_new_ids=$(echo "$json_new" | jq ".[] | .index" | sort -n)
|
||||||
# check if issues
|
# check if issues
|
||||||
@ -157,20 +181,51 @@ if [[ "$json_new_assignments" != "" ]]; then echo >&2 "NEW repo already contains
|
|||||||
|
|
||||||
|
|
||||||
# process data
|
# process data
|
||||||
echo -e "\n# processing data"
|
echo "# processing data"
|
||||||
while IFS="¬"; read -r index assignees title; do
|
while IFS="¬"; read -r index author assignees; do
|
||||||
assignees=$(echo "$assignees" | tr ' ' ,)
|
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
|
if [[ -n $assignees ]]; then
|
||||||
echo "$issueinfo"
|
|
||||||
if [ $dry_run = false ]; then
|
if [ $dry_run = false ]; then
|
||||||
tea issue edit --login "$login_new" --repo "$repo" --add-assignees "$assignees" "$index" >/dev/null
|
tea issue edit --login "$login_new" --repo "$repo" --add-assignees "$assignees" "$index" >/dev/null
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
t="OK"
|
||||||
|
if [ $use_colour = true ]; then
|
||||||
|
echo -e " → \e[1m\e[48;5;22m$t\e[0m"
|
||||||
|
else
|
||||||
|
echo " → $t"
|
||||||
|
fi
|
||||||
else
|
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
|
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
|
exit 0
|
||||||
|
Reference in New Issue
Block a user