|
|
|
@ -11,9 +11,10 @@ set -eu
|
|
|
|
|
|
|
|
|
|
readonly PROGNAME=`/usr/bin/basename $0`
|
|
|
|
|
readonly PROGPATH=`echo $0 | sed -e 's,[\\/][^\\/][^\\/]*$,,'`
|
|
|
|
|
readonly REVISION="1.3.0"
|
|
|
|
|
readonly REVISION="1.5.0"
|
|
|
|
|
|
|
|
|
|
repo=""
|
|
|
|
|
repo="" # the OLD repo
|
|
|
|
|
transfer="" # the NEW repo
|
|
|
|
|
login_old=""
|
|
|
|
|
login_new=""
|
|
|
|
|
dry_run=true
|
|
|
|
@ -23,7 +24,7 @@ use_colour=true
|
|
|
|
|
#
|
|
|
|
|
# FUNCTIONS
|
|
|
|
|
#
|
|
|
|
|
print_help()
|
|
|
|
|
print_help ()
|
|
|
|
|
{
|
|
|
|
|
echo "--- $PROGNAME $REVISION"
|
|
|
|
|
cat << "EOF"
|
|
|
|
@ -46,7 +47,6 @@ INFORMATION
|
|
|
|
|
- issue-ids are checked; titles are not checked
|
|
|
|
|
- assignments in new repo are checked
|
|
|
|
|
- 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?)
|
|
|
|
@ -70,19 +70,21 @@ INSTALLATION AND PREPARATION
|
|
|
|
|
|
|
|
|
|
USAGE
|
|
|
|
|
SWITCHES
|
|
|
|
|
-h | --help print this help
|
|
|
|
|
-c | --colour disable colour output
|
|
|
|
|
--GO stop dry mode
|
|
|
|
|
-h | --help print this help
|
|
|
|
|
-c | --colour | --color 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
|
|
|
|
|
-w | --wait wait time in s between issue handling (default 0.25)
|
|
|
|
|
-r | --repo required, i.e. "my_organisation/my_repository"
|
|
|
|
|
-t | --transfer optional, if the new repo has another organisation / name
|
|
|
|
|
if not set transfer is set to "repo"
|
|
|
|
|
-o | --login_old required, tea-id of your old login
|
|
|
|
|
-n | --login_new required, tea-id of your new login
|
|
|
|
|
-w | --wait wait time in s between issue handling (default 0.25)
|
|
|
|
|
EOF
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
error_in_or_out_not_specified()
|
|
|
|
|
error_in_or_out_not_specified ()
|
|
|
|
|
{
|
|
|
|
|
echo -e "Error: --repo, --login_old and --login_new must be specified\n";
|
|
|
|
|
print_help;
|
|
|
|
@ -90,16 +92,43 @@ error_in_or_out_not_specified()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# @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; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# collects all data from the given gitea instance+repo,
|
|
|
|
|
# uses pagination to really get all data (limit may be set by the server)
|
|
|
|
|
# get_all_data_from_gitea "$login_old" "$repo"
|
|
|
|
|
get_all_data_from_gitea ()
|
|
|
|
|
{
|
|
|
|
|
local readonly l="$1"
|
|
|
|
|
local readonly r="$2"
|
|
|
|
|
|
|
|
|
|
local _collect=""
|
|
|
|
|
local _page=1
|
|
|
|
|
while true; do
|
|
|
|
|
# get data from repo and remove [ and ]
|
|
|
|
|
local _tmp=$(tea issues list --output json --login "$l" --repo "$r" --state all --limit 100 --fields index,author,assignees --page $_page | sed 's/\[//g' | sed 's/\]//g')
|
|
|
|
|
if [[ $(echo "[$_tmp]" | jq length) -eq 0 ]]; then
|
|
|
|
|
break
|
|
|
|
|
fi
|
|
|
|
|
if [[ -z "$_collect" ]] then
|
|
|
|
|
_collect="$_tmp"
|
|
|
|
|
else
|
|
|
|
|
_collect="$_collect,$_tmp"
|
|
|
|
|
fi
|
|
|
|
|
_page=$(($_page+1));
|
|
|
|
|
done
|
|
|
|
|
echo "[$_collect]"
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# PARAMETERS
|
|
|
|
|
#
|
|
|
|
|
if [[ "$@" == "" ]] ; then error_in_or_out_not_specified ; fi
|
|
|
|
|
readonly TEMP=$(getopt -o h,r:o:n:w:c --long help,GO,colour,repo:,login_old:,login_new:,wait: -n "${PROGNAME}" -- "$@")
|
|
|
|
|
readonly TEMP=$(getopt -o h,r:t:o:n:w:c --long help,GO,colour,color,repo:,transfer:,login_old:,login_new:,wait: -n "${PROGNAME}" -- "$@")
|
|
|
|
|
eval set -- "${TEMP}"
|
|
|
|
|
while true ; do
|
|
|
|
|
case "$1" in
|
|
|
|
@ -107,13 +136,17 @@ while true ; do
|
|
|
|
|
print_help
|
|
|
|
|
exit 0
|
|
|
|
|
;;
|
|
|
|
|
--colour|-c)
|
|
|
|
|
--colour|--color|-c)
|
|
|
|
|
use_colour=false
|
|
|
|
|
;;
|
|
|
|
|
--repo|-r)
|
|
|
|
|
repo="$2"
|
|
|
|
|
shift
|
|
|
|
|
;;
|
|
|
|
|
--transfer|-t)
|
|
|
|
|
transfer="$2"
|
|
|
|
|
shift
|
|
|
|
|
;;
|
|
|
|
|
--login_old|-o)
|
|
|
|
|
login_old="$2"
|
|
|
|
|
shift
|
|
|
|
@ -137,8 +170,12 @@ while true ; do
|
|
|
|
|
shift
|
|
|
|
|
done
|
|
|
|
|
|
|
|
|
|
if [[ "$transfer" == "" ]]; then
|
|
|
|
|
transfer="$repo"
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# check required
|
|
|
|
|
if [[ -z "$repo" || -z "$login_old" || -z "$login_new" ]] ; then error_in_or_out_not_specified ; fi
|
|
|
|
|
if [[ -z "$repo" || -z "$transfer" || -z "$login_old" || -z "$login_new" ]] ; then error_in_or_out_not_specified ; fi
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# START
|
|
|
|
@ -160,8 +197,9 @@ checkCommand tr
|
|
|
|
|
|
|
|
|
|
# check access and get data
|
|
|
|
|
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)
|
|
|
|
|
|
|
|
|
|
readonly json_old=$(get_all_data_from_gitea "$login_old" "$repo")
|
|
|
|
|
readonly json_new=$(get_all_data_from_gitea "$login_new" "$transfer")
|
|
|
|
|
|
|
|
|
|
echo "# running consistency checks"
|
|
|
|
|
readonly json_old_ids=$(echo "$json_old" | jq ".[] | .index" | sort -n)
|
|
|
|
@ -185,32 +223,26 @@ echo "# processing data"
|
|
|
|
|
while IFS="¬"; read -r index author assignees; do
|
|
|
|
|
assignees=$(echo "$assignees" | tr ' ' ,)
|
|
|
|
|
|
|
|
|
|
echo "… #$index - by \"$author\" assigned to \"$assignees\""
|
|
|
|
|
echo -n "… #$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
|
|
|
|
|
echo "migrator: this issue was created by @$author and will be assigned to '$assignees'" | tea comment --login "$login_new" --repo "$transfer" "$index" >/dev/null
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# assignment
|
|
|
|
|
t="OK"
|
|
|
|
|
if [[ -n $assignees ]]; then
|
|
|
|
|
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"
|
|
|
|
|
tea issue edit --login "$login_new" --repo "$transfer" --add-assignees "$assignees" "$index" >/dev/null
|
|
|
|
|
fi
|
|
|
|
|
else
|
|
|
|
|
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
|
|
|
|
|
t="OK (no assignee)"
|
|
|
|
|
fi
|
|
|
|
|
if [ $use_colour = true ]; then
|
|
|
|
|
echo -e " → \e[1m\e[48;5;22m$t\e[0m"
|
|
|
|
|
else
|
|
|
|
|
echo " → $t"
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
sleep $wait_time
|
|
|
|
|