Gentoo Archives: gentoo-portage-dev

From: Alec Warner <antarus@g.o>
To: gentoo-portage-dev@l.g.o
Cc: "Michał Górny" <mgorny@g.o>
Subject: Re: [gentoo-portage-dev] [PATCH v2] repoman commit: Support --bug (-b) and --closes (-c) for git footer
Date: Sat, 05 Aug 2017 21:11:10
Message-Id: CAAr7Pr-xnK0d2dea6T5eXxL7HSMkMV5FyjCmnUzvionBi9Mjow@mail.gmail.com
In Reply to: [gentoo-portage-dev] [PATCH v2] repoman commit: Support --bug (-b) and --closes (-c) for git footer by "Michał Górny"
1 On Fri, Aug 4, 2017 at 6:37 PM, 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 > Changes in v2: use urlparse instead of regexps
20 >
21 > ---
22 > repoman/pym/repoman/actions.py | 45 ++++++++++++++++++++++++++++++
23 > ++++++++++
24 > repoman/pym/repoman/argparser.py | 16 +++++++++++++-
25 > 2 files changed, 60 insertions(+), 1 deletion(-)
26 >
27 > diff --git a/repoman/pym/repoman/actions.py b/repoman/pym/repoman/actions.
28 > py
29 > index 00bb5b2ca..8299ed0fe 100644
30 > --- a/repoman/pym/repoman/actions.py
31 > +++ b/repoman/pym/repoman/actions.py
32 > @@ -14,6 +14,11 @@ import tempfile
33 > import time
34 > from itertools import chain
35 >
36 > +try:
37 > + from urllib.parse import parse_qs, urlsplit, urlunsplit
38 > +except ImportError:
39 > + from urlparse import parse_qs, urlsplit, urlunsplit
40 > +
41 > from _emerge.UserQuery import UserQuery
42 >
43 > from repoman._portage import portage
44 > @@ -324,6 +329,13 @@ class Actions(object):
45 > return (changes.new, changes.changed, changes.removed,
46 > changes.no_expansion, changes.expansion)
47 >
48 > + https_bugtrackers = frozenset([
49 > + 'bitbucket.org',
50 > + 'bugs.gentoo.org',
51 > + 'github.com',
52 > + 'gitlab.com',
53 > + ])
54 > +
55 > def get_commit_footer(self):
56 > portage_version = getattr(portage, "VERSION", None)
57 > gpg_key = self.repoman_settings.get("PORTAGE_GPG_KEY", "")
58 > @@ -345,9 +357,42 @@ class Actions(object):
59 >
60 > # Common part of commit footer
61 > commit_footer = "\n"
62 > + for bug in self.options.bug:
63 > + # case 1: pure number NNNNNN
64 > + if bug.isdigit():
65 > + bug = 'https://bugs.gentoo.org/%s' %
66 > (bug, )
67 > + else:
68 > + purl = urlsplit(bug)
69 > + qs = parse_qs(purl.query)
70 > + # case 2: long Gentoo bugzilla URL to
71 > shorten
72 > + if (purl.netloc == 'bugs.gentoo.org' and
73 > + purl.path ==
74 > '/show_bug.cgi' and
75 > + tuple(qs.keys()) ==
76 > ('id',)):
77 > + bug = urlunsplit(('https',
78 > purl.netloc,
79 > + qs['id'][-1], '',
80 > purl.fragment))
81 > + # case 3: bug tracker w/ http -> https
82 > + elif (purl.scheme == 'http' and
83 > + purl.netloc in
84 > self.https_bugtrackers):
85 > + bug = urlunsplit(('https',) +
86 > purl[1:])
87 > + commit_footer += "Bug: %s\n" % (bug, )
88 > +
89 > + for closes in self.options.closes:
90 > + # case 1: pure number NNNN
91 > + if closes.isdigit():
92 > + closes = 'https://github.com/gentoo/
93 > gentoo/pull/%s' % (closes, )
94 > + else:
95 > + purl = urlsplit(closes)
96 > + # case 2: bug tracker w/ http -> https
97 > + if purl.netloc in self.https_bugtrackers:
98 > + closes = urlunsplit(('https',) +
99 > purl[1:])
100 > + commit_footer += "Closes: %s\n" % (closes, )
101 > +
102 > if dco_sob:
103 > commit_footer += "Signed-off-by: %s\n" % (dco_sob,
104 > )
105 >
106 > + print(commit_footer)
107 > + raise SystemExit(666)
108 >
109
110 Debug lines?
111
112 -A
113
114
115 > +
116 > # Use new footer only for git (see bug #438364).
117 > if self.vcs_settings.vcs in ["git"]:
118 > commit_footer += "Package-Manager: Portage-%s,
119 > Repoman-%s" % (
120 > diff --git a/repoman/pym/repoman/argparser.py b/repoman/pym/repoman/
121 > argparser.py
122 > index 2d56a87e6..f32972288 100644
123 > --- a/repoman/pym/repoman/argparser.py
124 > +++ b/repoman/pym/repoman/argparser.py
125 > @@ -1,5 +1,5 @@
126 > # repoman: Argument parser
127 > -# Copyright 2007-2014 Gentoo Foundation
128 > +# Copyright 2007-2017 Gentoo Foundation
129 > # Distributed under the terms of the GNU General Public License v2
130 >
131 > """This module contains functions used in Repoman to parse CLI
132 > arguments."""
133 > @@ -58,6 +58,20 @@ def parse_args(argv, qahelp, repoman_default_opts):
134 > help='Request a confirmation before commiting')
135 >
136 > parser.add_argument(
137 > + '-b', '--bug', dest='bug', action='append',
138 > metavar='<BUG-NO|BUG-URL>',
139 > + default=[],
140 > + help=(
141 > + 'Mention a Gentoo or upstream bug in the commit
142 > footer; '
143 > + 'takes either Gentoo bug number or full bug URL'))
144 > +
145 > + parser.add_argument(
146 > + '-c', '--closes', dest='closes', action='append',
147 > metavar='<PR-NO|PR-URL>',
148 > + default=[],
149 > + help=(
150 > + 'Adds a Closes footer to close GitHub pull request
151 > (or compatible); '
152 > + 'takes either GitHub PR number or full PR URL'))
153 > +
154 > + parser.add_argument(
155 > '-m', '--commitmsg', dest='commitmsg',
156 > help='specify a commit message on the command line')
157 >
158 > --
159 > 2.13.4
160 >
161 >
162 >

Replies