1 |
On Thu, Aug 3, 2017 at 10:18 AM, Michał Górny <mgorny@g.o> wrote: |
2 |
|
3 |
> Support two new options: --bug (-b) and --closes (-c) to add a plain |
4 |
> 'Bug' reference and a 'Closes' footer for a GitHub pull request. Both |
5 |
> options can be specified multiple times, resulting in multiple footer |
6 |
> tags being written. |
7 |
> |
8 |
> The --bug option accepts either a Gentoo Bugzilla bug number or an URL |
9 |
> to any bug tracker. In the latter case, it performs two trivial |
10 |
> transformations automatically: replaces long 'show_bug.cgi' Bugzilla |
11 |
> URLs with the short 'https://bugs.gentoo.org/NNNNNN', and forces |
12 |
> https:// for a few known services. |
13 |
> |
14 |
> The --closes option accepts either a GitHub Gentoo repository pull |
15 |
> request number or an URL to any pull request (or bug) that uses |
16 |
> the 'Closes' tag. In the latter case, https:// is forced for a few known |
17 |
> services. |
18 |
> --- |
19 |
> repoman/pym/repoman/actions.py | 29 +++++++++++++++++++++++++++++ |
20 |
> repoman/pym/repoman/argparser.py | 16 +++++++++++++++- |
21 |
> 2 files changed, 44 insertions(+), 1 deletion(-) |
22 |
> |
23 |
> diff --git a/repoman/pym/repoman/actions.py b/repoman/pym/repoman/actions. |
24 |
> py |
25 |
> index 00bb5b2ca..869ca7031 100644 |
26 |
> --- a/repoman/pym/repoman/actions.py |
27 |
> +++ b/repoman/pym/repoman/actions.py |
28 |
> @@ -324,6 +324,11 @@ class Actions(object): |
29 |
> return (changes.new, changes.changed, changes.removed, |
30 |
> changes.no_expansion, changes.expansion) |
31 |
> |
32 |
> + long_bugzilla_url_re = re.compile( |
33 |
> + r'https?://bugs\.gentoo\.org/ |
34 |
> show_bug\.cgi\?id=(\d+(#.*)?)') |
35 |
> + http_bugtracker_url_re = re.compile( |
36 |
> + r'http://(bugs\.gentoo\.org|bitbucket\.org|git(hub|lab)\. |
37 |
> com)/') |
38 |
> + |
39 |
> |
40 |
|
41 |
Would you consider using the urlparse module here, instead of regexp? |
42 |
|
43 |
|
44 |
> def get_commit_footer(self): |
45 |
> portage_version = getattr(portage, "VERSION", None) |
46 |
> gpg_key = self.repoman_settings.get("PORTAGE_GPG_KEY", "") |
47 |
> @@ -345,6 +350,30 @@ class Actions(object): |
48 |
> |
49 |
> # Common part of commit footer |
50 |
> commit_footer = "\n" |
51 |
> + for bug in self.options.bug: |
52 |
> + # case 1: pure number NNNNNN |
53 |
> + if bug.isdigit(): |
54 |
> + bug = 'https://bugs.gentoo.org/%s' % |
55 |
> (bug, ) |
56 |
> + else: |
57 |
> + # case 2: long Gentoo bugzilla URL to |
58 |
> shorten |
59 |
> + m = self.long_bugzilla_url_re.match(bug) |
60 |
> + if m is not None: |
61 |
> + bug = 'https://bugs.gentoo.org/%s' |
62 |
> % (m.group(1), ) |
63 |
> + # case 3: bug tracker w/ http -> https |
64 |
> + m = self.http_bugtracker_url_re.match(bug) |
65 |
> + if m is not None: |
66 |
> + bug = bug.replace('http', 'https', |
67 |
> 1) |
68 |
> + commit_footer += "Bug: %s\n" % (bug, ) |
69 |
> + for closes in self.options.closes: |
70 |
> + # case 1: pure number NNNN |
71 |
> + if closes.isdigit(): |
72 |
> + closes = 'https://github.com/gentoo/ |
73 |
> gentoo/pull/%s' % (closes, ) |
74 |
> + else: |
75 |
> + # case 2: bug tracker w/ http -> https |
76 |
> + m = self.http_bugtracker_url_re. |
77 |
> match(closes) |
78 |
> + if m is not None: |
79 |
> + closes = closes.replace('http', |
80 |
> 'https', 1) |
81 |
> + commit_footer += "Closes: %s\n" % (closes, ) |
82 |
> if dco_sob: |
83 |
> commit_footer += "Signed-off-by: %s\n" % (dco_sob, |
84 |
> ) |
85 |
> |
86 |
> diff --git a/repoman/pym/repoman/argparser.py b/repoman/pym/repoman/ |
87 |
> argparser.py |
88 |
> index 2d56a87e6..f32972288 100644 |
89 |
> --- a/repoman/pym/repoman/argparser.py |
90 |
> +++ b/repoman/pym/repoman/argparser.py |
91 |
> @@ -1,5 +1,5 @@ |
92 |
> # repoman: Argument parser |
93 |
> -# Copyright 2007-2014 Gentoo Foundation |
94 |
> +# Copyright 2007-2017 Gentoo Foundation |
95 |
> # Distributed under the terms of the GNU General Public License v2 |
96 |
> |
97 |
> """This module contains functions used in Repoman to parse CLI |
98 |
> arguments.""" |
99 |
> @@ -58,6 +58,20 @@ def parse_args(argv, qahelp, repoman_default_opts): |
100 |
> help='Request a confirmation before commiting') |
101 |
> |
102 |
> parser.add_argument( |
103 |
> + '-b', '--bug', dest='bug', action='append', |
104 |
> metavar='<BUG-NO|BUG-URL>', |
105 |
> + default=[], |
106 |
> + help=( |
107 |
> + 'Mention a Gentoo or upstream bug in the commit |
108 |
> footer; ' |
109 |
> + 'takes either Gentoo bug number or full bug URL')) |
110 |
> + |
111 |
> + parser.add_argument( |
112 |
> + '-c', '--closes', dest='closes', action='append', |
113 |
> metavar='<PR-NO|PR-URL>', |
114 |
> + default=[], |
115 |
> + help=( |
116 |
> + 'Adds a Closes footer to close GitHub pull request |
117 |
> (or compatible); ' |
118 |
> + 'takes either GitHub PR number or full PR URL')) |
119 |
> + |
120 |
> + parser.add_argument( |
121 |
> '-m', '--commitmsg', dest='commitmsg', |
122 |
> help='specify a commit message on the command line') |
123 |
> |
124 |
> -- |
125 |
> 2.13.4 |
126 |
> |
127 |
> |
128 |
> |