Gentoo Archives: gentoo-portage-dev

From: "Michał Górny" <mgorny@g.o>
To: gentoo-portage-dev@l.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:23:08
Message-Id: 1501968175.10933.0.camel@gentoo.org
In Reply to: Re: [gentoo-portage-dev] [PATCH v2] repoman commit: Support --bug (-b) and --closes (-c) for git footer by Alec Warner
1 On sob, 2017-08-05 at 17:11 -0400, Alec Warner wrote:
2 > On Fri, Aug 4, 2017 at 6:37 PM, Michał Górny <mgorny@g.o> wrote:
3 >
4 > > Support two new options: --bug (-b) and --closes (-c) to add a plain
5 > > 'Bug' reference and a 'Closes' footer for a GitHub pull request. Both
6 > > options can be specified multiple times, resulting in multiple footer
7 > > tags being written.
8 > >
9 > > The --bug option accepts either a Gentoo Bugzilla bug number or an URL
10 > > to any bug tracker. In the latter case, it performs two trivial
11 > > transformations automatically: replaces long 'show_bug.cgi' Bugzilla
12 > > URLs with the short 'https://bugs.gentoo.org/NNNNNN', and forces
13 > > https:// for a few known services.
14 > >
15 > > The --closes option accepts either a GitHub Gentoo repository pull
16 > > request number or an URL to any pull request (or bug) that uses
17 > > the 'Closes' tag. In the latter case, https:// is forced for a few known
18 > > services.
19 > >
20 > > Changes in v2: use urlparse instead of regexps
21 > >
22 > > ---
23 > > repoman/pym/repoman/actions.py | 45 ++++++++++++++++++++++++++++++
24 > > ++++++++++
25 > > repoman/pym/repoman/argparser.py | 16 +++++++++++++-
26 > > 2 files changed, 60 insertions(+), 1 deletion(-)
27 > >
28 > > diff --git a/repoman/pym/repoman/actions.py b/repoman/pym/repoman/actions.
29 > > py
30 > > index 00bb5b2ca..8299ed0fe 100644
31 > > --- a/repoman/pym/repoman/actions.py
32 > > +++ b/repoman/pym/repoman/actions.py
33 > > @@ -14,6 +14,11 @@ import tempfile
34 > > import time
35 > > from itertools import chain
36 > >
37 > > +try:
38 > > + from urllib.parse import parse_qs, urlsplit, urlunsplit
39 > > +except ImportError:
40 > > + from urlparse import parse_qs, urlsplit, urlunsplit
41 > > +
42 > > from _emerge.UserQuery import UserQuery
43 > >
44 > > from repoman._portage import portage
45 > > @@ -324,6 +329,13 @@ class Actions(object):
46 > > return (changes.new, changes.changed, changes.removed,
47 > > changes.no_expansion, changes.expansion)
48 > >
49 > > + https_bugtrackers = frozenset([
50 > > + 'bitbucket.org',
51 > > + 'bugs.gentoo.org',
52 > > + 'github.com',
53 > > + 'gitlab.com',
54 > > + ])
55 > > +
56 > > def get_commit_footer(self):
57 > > portage_version = getattr(portage, "VERSION", None)
58 > > gpg_key = self.repoman_settings.get("PORTAGE_GPG_KEY", "")
59 > > @@ -345,9 +357,42 @@ class Actions(object):
60 > >
61 > > # Common part of commit footer
62 > > commit_footer = "\n"
63 > > + for bug in self.options.bug:
64 > > + # case 1: pure number NNNNNN
65 > > + if bug.isdigit():
66 > > + bug = 'https://bugs.gentoo.org/%s' %
67 > > (bug, )
68 > > + else:
69 > > + purl = urlsplit(bug)
70 > > + qs = parse_qs(purl.query)
71 > > + # case 2: long Gentoo bugzilla URL to
72 > > shorten
73 > > + if (purl.netloc == 'bugs.gentoo.org' and
74 > > + purl.path ==
75 > > '/show_bug.cgi' and
76 > > + tuple(qs.keys()) ==
77 > > ('id',)):
78 > > + bug = urlunsplit(('https',
79 > > purl.netloc,
80 > > + qs['id'][-1], '',
81 > > purl.fragment))
82 > > + # case 3: bug tracker w/ http -> https
83 > > + elif (purl.scheme == 'http' and
84 > > + purl.netloc in
85 > > self.https_bugtrackers):
86 > > + bug = urlunsplit(('https',) +
87 > > purl[1:])
88 > > + commit_footer += "Bug: %s\n" % (bug, )
89 > > +
90 > > + for closes in self.options.closes:
91 > > + # case 1: pure number NNNN
92 > > + if closes.isdigit():
93 > > + closes = 'https://github.com/gentoo/
94 > > gentoo/pull/%s' % (closes, )
95 > > + else:
96 > > + purl = urlsplit(closes)
97 > > + # case 2: bug tracker w/ http -> https
98 > > + if purl.netloc in self.https_bugtrackers:
99 > > + closes = urlunsplit(('https',) +
100 > > purl[1:])
101 > > + commit_footer += "Closes: %s\n" % (closes, )
102 > > +
103 > > if dco_sob:
104 > > commit_footer += "Signed-off-by: %s\n" % (dco_sob,
105 > > )
106 > >
107 > > + print(commit_footer)
108 > > + raise SystemExit(666)
109 > >
110 >
111 > Debug lines?
112 >
113
114 Yeah, that happens when you work instead of sleeping ;-).
115
116 --
117 Best regards,
118 Michał Górny

Attachments

File name MIME type
signature.asc application/pgp-signature