Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit dfb65e9

Browse files
committed
feat(issue): add subcommand to move issues between projects
The move command allows users to transfer an issue from one project to another within the Arch Linux packaging group. This is useful when an issue is identified to be more relevant or better handled in a different project. By default, the command operates within the current directory, but users can specify a different package base from which to move the issue. Users must specify the issue ID (IID) and the destination package to which the issue should be moved. A comment message explaining the reason for the move can be provided directly through the command line. Component: pkgctl issue move Signed-off-by: Levente Polyak <[email protected]>
1 parent 4e7ec8b commit dfb65e9

File tree

7 files changed

+289
-0
lines changed

7 files changed

+289
-0
lines changed

contrib/completion/bash/devtools.in

+24
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,7 @@ _pkgctl_issue_cmds=(
450450
close
451451
comment
452452
list
453+
move
453454
reopen
454455
view
455456
)
@@ -523,6 +524,29 @@ _pkgctl_issue_list_args__status_opts() { _devtools_completions_issue_status; }
523524
_pkgctl_issue_list_args__assignee_opts() { :; }
524525
_pkgctl_issue_list_args__author_opts() { :; }
525526

527+
_pkgctl_issue_move_args=(
528+
-p --package
529+
-m --message
530+
-e --edit
531+
-h --help
532+
)
533+
534+
_pkgctl_issue_move_opts() {
535+
local subcommand args
536+
subcommand=(repo switch)
537+
args=$(__pkgctl_word_count_after_subcommand "${subcommand[@]}")
538+
539+
if (( args == 0 )); then
540+
:
541+
elif (( args >= 1 )); then
542+
_devtools_completions_all_packages
543+
fi
544+
}
545+
_pkgctl_issue_move_args__package_opts() { _devtools_completions_all_packages; }
546+
_pkgctl_issue_move_args_p_opts() { _pkgctl_issue_move_args__package_opts; }
547+
_pkgctl_issue_move_args__message_opts() { :; }
548+
_pkgctl_issue_move_args_m_opts() { _pkgctl_issue_move_args__message_opts; }
549+
526550
_pkgctl_issue_reopen_args=(
527551
-p --package
528552
-m --message

contrib/completion/zsh/_devtools.in

+10
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ _pkgctl_issue_cmds=(
9999
"close[Close an issue]"
100100
"comment[Comment on an issue]"
101101
"list[List project or group issues]"
102+
"move[Move an issue to another project]"
102103
"reopen[Reopen a closed issue]"
103104
"view[Display information about an issue]"
104105
)
@@ -142,6 +143,15 @@ _pkgctl_issue_list_args=(
142143
'*:pkgbase:_devtools_completions_all_packages'
143144
)
144145

146+
_pkgctl_issue_move_args=(
147+
'(-p --package)'{-p,--package}'[Interact with <pkgbase> instead of the current directory]:pkgbase:_devtools_completions_all_packages'
148+
'(-m --message)'{-m,--message}'[Use the provided message as the comment]:message:'
149+
'(-e --edit)'{-e,--edit}'[Edit the comment using an editor]'
150+
'(-h --help)'{-h,--help}'[Display usage]'
151+
"1:issue_iid:"
152+
'1:pkgbase:_devtools_completions_all_packages'
153+
)
154+
145155
_pkgctl_issue_reopen_args=(
146156
'(-p --package)'{-p,--package}'[Interact with <pkgbase> instead of the current directory]:pkgbase:_devtools_completions_all_packages'
147157
'(-m --message)'{-m,--message}'[Use the provided message as the comment]:message:'

doc/man/pkgctl-issue-move.1.asciidoc

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
pkgctl-issue-move(1)
2+
====================
3+
4+
Name
5+
----
6+
pkgctl-issue-move - Move an issue to another project
7+
8+
Synopsis
9+
--------
10+
pkgctl issue move [OPTIONS] [IID] [DESTINATION_PACKAGE]
11+
12+
Description
13+
-----------
14+
15+
The move command allows users to transfer an issue from one project to another
16+
within the Arch Linux packaging group. This is useful when an issue is
17+
identified to be more relevant or better handled in a different project.
18+
19+
By default, the command operates within the current directory, but users can
20+
specify a different package base from which to move the issue.
21+
22+
Users must specify the issue ID (IID) and the destination package to which the
23+
issue should be moved. A comment message explaining the reason for the move can
24+
be provided directly through the command line. For more detailed explanations
25+
or additional context, users have the option to edit the move comment using a
26+
text editor before submitting it.
27+
28+
Options
29+
-------
30+
31+
*-p, --package* 'PKGBASE'::
32+
Move from `PKGBASE` instead of the current directory
33+
34+
*-m, --message* 'MSG'::
35+
Use the provided message as the comment
36+
37+
*-e, --edit*::
38+
Edit the comment using an editor
39+
40+
*-h, --help*::
41+
Show a help text
42+
43+
include::include/footer.asciidoc[]

doc/man/pkgctl-issue.1.asciidoc

+4
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ pkgctl issue comment::
3232
pkgctl issue list::
3333
List project or group issues
3434

35+
pkgctl issue move::
36+
Move an issue to another project
37+
3538
pkgctl issue reopen::
3639
Reopen a closed issue
3740

@@ -44,6 +47,7 @@ See Also
4447
pkgctl-issue-close(1)
4548
pkgctl-issue-comment(1)
4649
pkgctl-issue-list(1)
50+
pkgctl-issue-move(1)
4751
pkgctl-issue-reopen(1)
4852
pkgctl-issue-view(1)
4953

src/lib/api/gitlab.sh

+43
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,25 @@ gitlab_api_search() {
402402
return 0
403403
}
404404

405+
# https://docs.gitlab.com/ee/api/projects.html#get-single-project
406+
gitlab_project() {
407+
local project=$1
408+
local outfile project_path
409+
410+
[[ -z ${WORKDIR:-} ]] && setup_workdir
411+
outfile=$(mktemp --tmpdir="${WORKDIR}" pkgctl-gitlab-api.XXXXXXXXXX)
412+
413+
project_path=$(gitlab_project_name_to_path "${project}")
414+
415+
if ! gitlab_api_call "${outfile}" GET "projects/archlinux%2fpackaging%2fpackages%2f${project_path}/"; then
416+
return 1
417+
fi
418+
419+
cat "${outfile}"
420+
421+
return 0
422+
}
423+
405424
# TODO: parallelize
406425
# https://docs.gitlab.com/ee/api/issues.html#list-project-issues
407426
gitlab_projects_issues_list() {
@@ -541,6 +560,30 @@ gitlab_create_project_issue_note() {
541560
return 0
542561
}
543562

563+
gitlab_project_issue_move() {
564+
local pkgbase=$1
565+
local iid=$2
566+
local to_project_id=$3
567+
local outfile path project_path
568+
569+
[[ -z ${WORKDIR:-} ]] && setup_workdir
570+
outfile=$(mktemp --tmpdir="${WORKDIR}" pkgctl-gitlab-api.XXXXXXXXXX)
571+
572+
project_path=$(gitlab_project_name_to_path "${pkgbase}")
573+
574+
if ! gitlab_api_call "${outfile}" POST "/projects/archlinux%2fpackaging%2fpackages%2f${project_path}/issues/${iid}/move?to_project_id=${to_project_id}"; then
575+
return 1
576+
fi
577+
578+
if ! path=$(jq --raw-output --exit-status '.title' < "${outfile}"); then
579+
msg_error " failed to move issue: $(cat "${outfile}")"
580+
return 1
581+
fi
582+
583+
cat "${outfile}"
584+
return 0
585+
}
586+
544587
gitlab_severity_from_labels() {
545588
local labels=("$@")
546589
local severity="unknown"

src/lib/issue/issue.sh

+9
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ pkgctl_issue_usage() {
2121
close Close an issue
2222
comment Comment on an issue
2323
list List project or group issues
24+
move Move an issue to another project
2425
reopen Reopen a closed issue
2526
view Display information about an issue
2627
@@ -70,6 +71,14 @@ pkgctl_issue() {
7071
pkgctl_issue_comment "$@"
7172
exit 0
7273
;;
74+
move)
75+
_DEVTOOLS_COMMAND+=" $1"
76+
shift
77+
# shellcheck source=src/lib/issue/move.sh
78+
source "${_DEVTOOLS_LIBRARY_DIR}"/lib/issue/move.sh
79+
pkgctl_issue_move "$@"
80+
exit 0
81+
;;
7382
reopen)
7483
_DEVTOOLS_COMMAND+=" $1"
7584
shift

src/lib/issue/move.sh

+156
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
#!/hint/bash
2+
#
3+
# SPDX-License-Identifier: GPL-3.0-or-later
4+
5+
[[ -z ${DEVTOOLS_INCLUDE_ISSUE_MOVE_SH:-} ]] || return 0
6+
DEVTOOLS_INCLUDE_ISSUE_MOVE_SH=1
7+
8+
_DEVTOOLS_LIBRARY_DIR=${_DEVTOOLS_LIBRARY_DIR:-@pkgdatadir@}
9+
10+
# shellcheck source=src/lib/common.sh
11+
source "${_DEVTOOLS_LIBRARY_DIR}"/lib/common.sh
12+
# shellcheck source=src/lib/cache.sh
13+
source "${_DEVTOOLS_LIBRARY_DIR}"/lib/cache.sh
14+
# shellcheck source=src/lib/api/gitlab.sh
15+
source "${_DEVTOOLS_LIBRARY_DIR}"/lib/api/gitlab.sh
16+
17+
set -eo pipefail
18+
19+
20+
pkgctl_issue_move_usage() {
21+
local -r COMMAND=${_DEVTOOLS_COMMAND:-${BASH_SOURCE[0]##*/}}
22+
cat <<- _EOF_
23+
Usage: ${COMMAND} [OPTIONS] [IID] [DESTINATION_PACKAGE]
24+
25+
The move command allows users to transfer an issue from one project to another
26+
within the Arch Linux packaging group. This is useful when an issue is
27+
identified to be more relevant or better handled in a different project.
28+
29+
By default, the command operates within the current directory, but users can
30+
specify a different package base from which to move the issue.
31+
32+
Users must specify the issue ID (IID) and the destination package to which the
33+
issue should be moved. A comment message explaining the reason for the move can
34+
be provided directly through the command line.
35+
36+
OPTIONS
37+
-p, --package PKGBASE Move from <pkgbase> instead of the current directory
38+
-m, --message MSG Use the provided message as the comment
39+
-e, --edit Edit the comment using an editor
40+
-h, --help Show this help text
41+
42+
EXAMPLES
43+
$ ${COMMAND} 42 to-bar
44+
$ ${COMMAND} --package from-foo 42 to-bar
45+
_EOF_
46+
}
47+
48+
pkgctl_issue_move() {
49+
if (( $# < 1 )); then
50+
pkgctl_issue_move_usage
51+
exit 0
52+
fi
53+
54+
local iid=""
55+
local pkgbase=""
56+
local message=""
57+
local edit=0
58+
59+
local to_project_name to_project_id project_path issue_url to_iid result
60+
61+
# option checking
62+
while (( $# )); do
63+
case $1 in
64+
-h|--help)
65+
pkgctl_issue_move_usage
66+
exit 0
67+
;;
68+
-p|--package)
69+
(( $# <= 1 )) && die "missing argument for %s" "$1"
70+
pkgbase=$2
71+
shift 2
72+
;;
73+
-m|--message)
74+
(( $# <= 1 )) && die "missing argument for %s" "$1"
75+
message=$2
76+
shift 2
77+
;;
78+
-e|--edit)
79+
edit=1
80+
shift
81+
;;
82+
-*)
83+
die "invalid argument: %s" "$1"
84+
;;
85+
*)
86+
break
87+
;;
88+
esac
89+
done
90+
91+
if [[ -z ${pkgbase} ]]; then
92+
if ! [[ -f PKGBUILD ]]; then
93+
die "missing --package option or PKGBUILD in current directory"
94+
fi
95+
pkgbase=$(realpath --canonicalize-existing .)
96+
fi
97+
pkgbase=$(basename "${pkgbase}")
98+
99+
if (( $# < 2 )); then
100+
pkgctl_issue_move_usage
101+
exit 1
102+
fi
103+
104+
iid=$1
105+
to_project_name=$(basename "$2")
106+
107+
# spawn editor
108+
if (( edit )); then
109+
msgfile=$(mktemp --tmpdir="${WORKDIR}" pkgctl-issue-note.XXXXXXXXXX.md)
110+
printf "%s\n" "${message}" >> "${msgfile}"
111+
if [[ -n $VISUAL ]]; then
112+
$VISUAL "${msgfile}" || die
113+
elif [[ -n $EDITOR ]]; then
114+
$EDITOR "${msgfile}" || die
115+
else
116+
die "No usable editor found (tried \$VISUAL, \$EDITOR)."
117+
fi
118+
message=$(cat "${msgfile}")
119+
fi
120+
121+
if ! result=$(gitlab_project "${to_project_name}"); then
122+
msg_error "Failed to query target project ${BOLD}${to_project_name}${ALL_OFF}"
123+
exit 1
124+
fi
125+
126+
if ! to_project_id=$(jq --raw-output ".id" <<< "${result}"); then
127+
msg_error "Failed to query project id for ${BOLD}${to_project_name}${ALL_OFF}"
128+
exit 1
129+
fi
130+
131+
# comment on issue
132+
if [[ -n ${message} ]]; then
133+
if ! result=$(gitlab_create_project_issue_note "${pkgbase}" "${iid}" "${message}"); then
134+
msg_error "Failed to comment on issue ${BOLD}#${iid}${ALL_OFF}"
135+
exit 1
136+
fi
137+
msg_success "Commented on issue ${BOLD}#${iid}${ALL_OFF}"
138+
fi
139+
140+
if ! result=$(gitlab_project_issue_move "${pkgbase}" "${iid}" "${to_project_id}"); then
141+
msg_error "Failed to move issue ${BOLD}#${iid}${ALL_OFF} to ${BOLD}${to_project_name}${ALL_OFF}"
142+
exit 1
143+
fi
144+
145+
if ! to_iid=$(jq --raw-output ".iid" <<< "${result}"); then
146+
msg_error "Failed to query issue id for ${BOLD}${to_project_name}${ALL_OFF}"
147+
exit 1
148+
fi
149+
150+
project_path=$(gitlab_project_name_to_path "${to_project_name}")
151+
issue_url="${GIT_PACKAGING_URL_HTTPS}/${project_path}/-/issues/${to_iid}"
152+
153+
msg_success "Moved issue ${BOLD}${pkgbase}${ALL_OFF} ${BOLD}#${iid}${ALL_OFF} to ${BOLD}${to_project_name}${ALL_OFF} ${BOLD}#${to_iid}${ALL_OFF}"
154+
echo
155+
printf "%sView this issue on GitLab: %s%s\n" "${GRAY}" "${issue_url}" "${ALL_OFF}"
156+
}

0 commit comments

Comments
 (0)