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