1 |
Support two new options: --bug (-b) and --closes (-c) to add a plain |
2 |
'Bug' reference and a 'Closes' footer for a GitHub pull request. Both |
3 |
options can be specified multiple times, resulting in multiple footer |
4 |
tags being written. |
5 |
|
6 |
The --bug option accepts either a Gentoo Bugzilla bug number or an URL |
7 |
to any bug tracker. In the latter case, it performs two trivial |
8 |
transformations automatically: replaces long 'show_bug.cgi' Bugzilla |
9 |
URLs with the short 'https://bugs.gentoo.org/NNNNNN', and forces |
10 |
https:// for a few known services. |
11 |
|
12 |
The --closes option accepts either a GitHub Gentoo repository pull |
13 |
request number or an URL to any pull request (or bug) that uses |
14 |
the 'Closes' tag. In the latter case, https:// is forced for a few known |
15 |
services. |
16 |
--- |
17 |
repoman/man/repoman.1 | 14 ++++++++++++++ |
18 |
repoman/pym/repoman/actions.py | 42 ++++++++++++++++++++++++++++++++++++++++ |
19 |
repoman/pym/repoman/argparser.py | 16 ++++++++++++++- |
20 |
3 files changed, 71 insertions(+), 1 deletion(-) |
21 |
|
22 |
v4: now with manpage update |
23 |
|
24 |
diff --git a/repoman/man/repoman.1 b/repoman/man/repoman.1 |
25 |
index 4101c283f..a49c72c0d 100644 |
26 |
--- a/repoman/man/repoman.1 |
27 |
+++ b/repoman/man/repoman.1 |
28 |
@@ -21,6 +21,20 @@ BASH. |
29 |
\fB-a\fR, \fB--ask\fR |
30 |
Request a confirmation before commiting |
31 |
.TP |
32 |
+\fB-b\fR, \fB--bug\fR |
33 |
+Include a bug reference in the commit message footer. The argument can |
34 |
+be either a Gentoo bug number or a full bug URL (either Gentoo |
35 |
+or upstream). Gentoo bug URLs are automatically shortened to |
36 |
+the canonical \fBhttps://bugs.gentoo.org/NNNNNN\fR form, and HTTPS |
37 |
+is forced for known bug trackers. |
38 |
+.TP |
39 |
+\fB-c\fR, \fB--closes\fR |
40 |
+Include a \fBCloses\fR tag in the commit message footer that can be used |
41 |
+to close pull requests (and issues) on GitHub and other compatible |
42 |
+services (GitLab, Bitbucket). The argument can be either a PR number for |
43 |
+the gentoo/gentoo GitHub repository or a full PR/bug URL. For bug URLs, |
44 |
+HTTPS is forced automatically for known bug/PR trackers. |
45 |
+.TP |
46 |
\fB\-\-digest=<y|n>\fR |
47 |
Automatically update Manifest digests for modified files. This |
48 |
option triggers a behavior that is very similar to that enabled |
49 |
diff --git a/repoman/pym/repoman/actions.py b/repoman/pym/repoman/actions.py |
50 |
index 00bb5b2ca..2112299c0 100644 |
51 |
--- a/repoman/pym/repoman/actions.py |
52 |
+++ b/repoman/pym/repoman/actions.py |
53 |
@@ -14,6 +14,11 @@ import tempfile |
54 |
import time |
55 |
from itertools import chain |
56 |
|
57 |
+try: |
58 |
+ from urllib.parse import parse_qs, urlsplit, urlunsplit |
59 |
+except ImportError: |
60 |
+ from urlparse import parse_qs, urlsplit, urlunsplit |
61 |
+ |
62 |
from _emerge.UserQuery import UserQuery |
63 |
|
64 |
from repoman._portage import portage |
65 |
@@ -324,6 +329,13 @@ class Actions(object): |
66 |
return (changes.new, changes.changed, changes.removed, |
67 |
changes.no_expansion, changes.expansion) |
68 |
|
69 |
+ https_bugtrackers = frozenset([ |
70 |
+ 'bitbucket.org', |
71 |
+ 'bugs.gentoo.org', |
72 |
+ 'github.com', |
73 |
+ 'gitlab.com', |
74 |
+ ]) |
75 |
+ |
76 |
def get_commit_footer(self): |
77 |
portage_version = getattr(portage, "VERSION", None) |
78 |
gpg_key = self.repoman_settings.get("PORTAGE_GPG_KEY", "") |
79 |
@@ -345,6 +357,36 @@ class Actions(object): |
80 |
|
81 |
# Common part of commit footer |
82 |
commit_footer = "\n" |
83 |
+ for bug in self.options.bug: |
84 |
+ # case 1: pure number NNNNNN |
85 |
+ if bug.isdigit(): |
86 |
+ bug = 'https://bugs.gentoo.org/%s' % (bug, ) |
87 |
+ else: |
88 |
+ purl = urlsplit(bug) |
89 |
+ qs = parse_qs(purl.query) |
90 |
+ # case 2: long Gentoo bugzilla URL to shorten |
91 |
+ if (purl.netloc == 'bugs.gentoo.org' and |
92 |
+ purl.path == '/show_bug.cgi' and |
93 |
+ tuple(qs.keys()) == ('id',)): |
94 |
+ bug = urlunsplit(('https', purl.netloc, |
95 |
+ qs['id'][-1], '', purl.fragment)) |
96 |
+ # case 3: bug tracker w/ http -> https |
97 |
+ elif (purl.scheme == 'http' and |
98 |
+ purl.netloc in self.https_bugtrackers): |
99 |
+ bug = urlunsplit(('https',) + purl[1:]) |
100 |
+ commit_footer += "Bug: %s\n" % (bug, ) |
101 |
+ |
102 |
+ for closes in self.options.closes: |
103 |
+ # case 1: pure number NNNN |
104 |
+ if closes.isdigit(): |
105 |
+ closes = 'https://github.com/gentoo/gentoo/pull/%s' % (closes, ) |
106 |
+ else: |
107 |
+ purl = urlsplit(closes) |
108 |
+ # case 2: bug tracker w/ http -> https |
109 |
+ if purl.netloc in self.https_bugtrackers: |
110 |
+ closes = urlunsplit(('https',) + purl[1:]) |
111 |
+ commit_footer += "Closes: %s\n" % (closes, ) |
112 |
+ |
113 |
if dco_sob: |
114 |
commit_footer += "Signed-off-by: %s\n" % (dco_sob, ) |
115 |
|
116 |
diff --git a/repoman/pym/repoman/argparser.py b/repoman/pym/repoman/argparser.py |
117 |
index 2d56a87e6..f32972288 100644 |
118 |
--- a/repoman/pym/repoman/argparser.py |
119 |
+++ b/repoman/pym/repoman/argparser.py |
120 |
@@ -1,5 +1,5 @@ |
121 |
# repoman: Argument parser |
122 |
-# Copyright 2007-2014 Gentoo Foundation |
123 |
+# Copyright 2007-2017 Gentoo Foundation |
124 |
# Distributed under the terms of the GNU General Public License v2 |
125 |
|
126 |
"""This module contains functions used in Repoman to parse CLI arguments.""" |
127 |
@@ -57,6 +57,20 @@ def parse_args(argv, qahelp, repoman_default_opts): |
128 |
default=False, |
129 |
help='Request a confirmation before commiting') |
130 |
|
131 |
+ parser.add_argument( |
132 |
+ '-b', '--bug', dest='bug', action='append', metavar='<BUG-NO|BUG-URL>', |
133 |
+ default=[], |
134 |
+ help=( |
135 |
+ 'Mention a Gentoo or upstream bug in the commit footer; ' |
136 |
+ 'takes either Gentoo bug number or full bug URL')) |
137 |
+ |
138 |
+ parser.add_argument( |
139 |
+ '-c', '--closes', dest='closes', action='append', metavar='<PR-NO|PR-URL>', |
140 |
+ default=[], |
141 |
+ help=( |
142 |
+ 'Adds a Closes footer to close GitHub pull request (or compatible); ' |
143 |
+ 'takes either GitHub PR number or full PR URL')) |
144 |
+ |
145 |
parser.add_argument( |
146 |
'-m', '--commitmsg', dest='commitmsg', |
147 |
help='specify a commit message on the command line') |
148 |
-- |
149 |
2.14.0 |