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/pym/repoman/actions.py | 29 +++++++++++++++++++++++++++++ |
18 |
repoman/pym/repoman/argparser.py | 16 +++++++++++++++- |
19 |
2 files changed, 44 insertions(+), 1 deletion(-) |
20 |
|
21 |
diff --git a/repoman/pym/repoman/actions.py b/repoman/pym/repoman/actions.py |
22 |
index 00bb5b2ca..869ca7031 100644 |
23 |
--- a/repoman/pym/repoman/actions.py |
24 |
+++ b/repoman/pym/repoman/actions.py |
25 |
@@ -324,6 +324,11 @@ class Actions(object): |
26 |
return (changes.new, changes.changed, changes.removed, |
27 |
changes.no_expansion, changes.expansion) |
28 |
|
29 |
+ long_bugzilla_url_re = re.compile( |
30 |
+ r'https?://bugs\.gentoo\.org/show_bug\.cgi\?id=(\d+(#.*)?)') |
31 |
+ http_bugtracker_url_re = re.compile( |
32 |
+ r'http://(bugs\.gentoo\.org|bitbucket\.org|git(hub|lab)\.com)/') |
33 |
+ |
34 |
def get_commit_footer(self): |
35 |
portage_version = getattr(portage, "VERSION", None) |
36 |
gpg_key = self.repoman_settings.get("PORTAGE_GPG_KEY", "") |
37 |
@@ -345,6 +350,30 @@ class Actions(object): |
38 |
|
39 |
# Common part of commit footer |
40 |
commit_footer = "\n" |
41 |
+ for bug in self.options.bug: |
42 |
+ # case 1: pure number NNNNNN |
43 |
+ if bug.isdigit(): |
44 |
+ bug = 'https://bugs.gentoo.org/%s' % (bug, ) |
45 |
+ else: |
46 |
+ # case 2: long Gentoo bugzilla URL to shorten |
47 |
+ m = self.long_bugzilla_url_re.match(bug) |
48 |
+ if m is not None: |
49 |
+ bug = 'https://bugs.gentoo.org/%s' % (m.group(1), ) |
50 |
+ # case 3: bug tracker w/ http -> https |
51 |
+ m = self.http_bugtracker_url_re.match(bug) |
52 |
+ if m is not None: |
53 |
+ bug = bug.replace('http', 'https', 1) |
54 |
+ commit_footer += "Bug: %s\n" % (bug, ) |
55 |
+ for closes in self.options.closes: |
56 |
+ # case 1: pure number NNNN |
57 |
+ if closes.isdigit(): |
58 |
+ closes = 'https://github.com/gentoo/gentoo/pull/%s' % (closes, ) |
59 |
+ else: |
60 |
+ # case 2: bug tracker w/ http -> https |
61 |
+ m = self.http_bugtracker_url_re.match(closes) |
62 |
+ if m is not None: |
63 |
+ closes = closes.replace('http', 'https', 1) |
64 |
+ commit_footer += "Closes: %s\n" % (closes, ) |
65 |
if dco_sob: |
66 |
commit_footer += "Signed-off-by: %s\n" % (dco_sob, ) |
67 |
|
68 |
diff --git a/repoman/pym/repoman/argparser.py b/repoman/pym/repoman/argparser.py |
69 |
index 2d56a87e6..f32972288 100644 |
70 |
--- a/repoman/pym/repoman/argparser.py |
71 |
+++ b/repoman/pym/repoman/argparser.py |
72 |
@@ -1,5 +1,5 @@ |
73 |
# repoman: Argument parser |
74 |
-# Copyright 2007-2014 Gentoo Foundation |
75 |
+# Copyright 2007-2017 Gentoo Foundation |
76 |
# Distributed under the terms of the GNU General Public License v2 |
77 |
|
78 |
"""This module contains functions used in Repoman to parse CLI arguments.""" |
79 |
@@ -58,6 +58,20 @@ def parse_args(argv, qahelp, repoman_default_opts): |
80 |
help='Request a confirmation before commiting') |
81 |
|
82 |
parser.add_argument( |
83 |
+ '-b', '--bug', dest='bug', action='append', metavar='<BUG-NO|BUG-URL>', |
84 |
+ default=[], |
85 |
+ help=( |
86 |
+ 'Mention a Gentoo or upstream bug in the commit footer; ' |
87 |
+ 'takes either Gentoo bug number or full bug URL')) |
88 |
+ |
89 |
+ parser.add_argument( |
90 |
+ '-c', '--closes', dest='closes', action='append', metavar='<PR-NO|PR-URL>', |
91 |
+ default=[], |
92 |
+ help=( |
93 |
+ 'Adds a Closes footer to close GitHub pull request (or compatible); ' |
94 |
+ 'takes either GitHub PR number or full PR URL')) |
95 |
+ |
96 |
+ parser.add_argument( |
97 |
'-m', '--commitmsg', dest='commitmsg', |
98 |
help='specify a commit message on the command line') |
99 |
|
100 |
-- |
101 |
2.13.4 |