Gentoo Archives: gentoo-portage-dev

From: "Michał Górny" <mgorny@g.o>
To: gentoo-portage-dev@l.g.o
Cc: "Michał Górny" <mgorny@g.o>
Subject: [gentoo-portage-dev] [PATCH v3] repoman commit: Support --bug (-b) and --closes (-c) for git footer
Date: Sat, 05 Aug 2017 21:26:07
Message-Id: 20170805212601.11947-1-mgorny@gentoo.org
In Reply to: [gentoo-portage-dev] [PATCH] repoman commit: Support --bug (-b) and --closes (-c) for git footer by "Michał Górny"
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 | 42 ++++++++++++++++++++++++++++++++++++++++
18 repoman/pym/repoman/argparser.py | 16 ++++++++++++++-
19 2 files changed, 57 insertions(+), 1 deletion(-)
20
21 New in v3: no more debug
22
23 diff --git a/repoman/pym/repoman/actions.py b/repoman/pym/repoman/actions.py
24 index 00bb5b2ca..2112299c0 100644
25 --- a/repoman/pym/repoman/actions.py
26 +++ b/repoman/pym/repoman/actions.py
27 @@ -14,6 +14,11 @@ import tempfile
28 import time
29 from itertools import chain
30
31 +try:
32 + from urllib.parse import parse_qs, urlsplit, urlunsplit
33 +except ImportError:
34 + from urlparse import parse_qs, urlsplit, urlunsplit
35 +
36 from _emerge.UserQuery import UserQuery
37
38 from repoman._portage import portage
39 @@ -324,6 +329,13 @@ class Actions(object):
40 return (changes.new, changes.changed, changes.removed,
41 changes.no_expansion, changes.expansion)
42
43 + https_bugtrackers = frozenset([
44 + 'bitbucket.org',
45 + 'bugs.gentoo.org',
46 + 'github.com',
47 + 'gitlab.com',
48 + ])
49 +
50 def get_commit_footer(self):
51 portage_version = getattr(portage, "VERSION", None)
52 gpg_key = self.repoman_settings.get("PORTAGE_GPG_KEY", "")
53 @@ -345,6 +357,36 @@ class Actions(object):
54
55 # Common part of commit footer
56 commit_footer = "\n"
57 + for bug in self.options.bug:
58 + # case 1: pure number NNNNNN
59 + if bug.isdigit():
60 + bug = 'https://bugs.gentoo.org/%s' % (bug, )
61 + else:
62 + purl = urlsplit(bug)
63 + qs = parse_qs(purl.query)
64 + # case 2: long Gentoo bugzilla URL to shorten
65 + if (purl.netloc == 'bugs.gentoo.org' and
66 + purl.path == '/show_bug.cgi' and
67 + tuple(qs.keys()) == ('id',)):
68 + bug = urlunsplit(('https', purl.netloc,
69 + qs['id'][-1], '', purl.fragment))
70 + # case 3: bug tracker w/ http -> https
71 + elif (purl.scheme == 'http' and
72 + purl.netloc in self.https_bugtrackers):
73 + bug = urlunsplit(('https',) + purl[1:])
74 + commit_footer += "Bug: %s\n" % (bug, )
75 +
76 + for closes in self.options.closes:
77 + # case 1: pure number NNNN
78 + if closes.isdigit():
79 + closes = 'https://github.com/gentoo/gentoo/pull/%s' % (closes, )
80 + else:
81 + purl = urlsplit(closes)
82 + # case 2: bug tracker w/ http -> https
83 + if purl.netloc in self.https_bugtrackers:
84 + closes = urlunsplit(('https',) + purl[1:])
85 + commit_footer += "Closes: %s\n" % (closes, )
86 +
87 if dco_sob:
88 commit_footer += "Signed-off-by: %s\n" % (dco_sob, )
89
90 diff --git a/repoman/pym/repoman/argparser.py b/repoman/pym/repoman/argparser.py
91 index 2d56a87e6..f32972288 100644
92 --- a/repoman/pym/repoman/argparser.py
93 +++ b/repoman/pym/repoman/argparser.py
94 @@ -1,5 +1,5 @@
95 # repoman: Argument parser
96 -# Copyright 2007-2014 Gentoo Foundation
97 +# Copyright 2007-2017 Gentoo Foundation
98 # Distributed under the terms of the GNU General Public License v2
99
100 """This module contains functions used in Repoman to parse CLI arguments."""
101 @@ -57,6 +57,20 @@ def parse_args(argv, qahelp, repoman_default_opts):
102 default=False,
103 help='Request a confirmation before commiting')
104
105 + parser.add_argument(
106 + '-b', '--bug', dest='bug', action='append', metavar='<BUG-NO|BUG-URL>',
107 + default=[],
108 + help=(
109 + 'Mention a Gentoo or upstream bug in the commit footer; '
110 + 'takes either Gentoo bug number or full bug URL'))
111 +
112 + parser.add_argument(
113 + '-c', '--closes', dest='closes', action='append', metavar='<PR-NO|PR-URL>',
114 + default=[],
115 + help=(
116 + 'Adds a Closes footer to close GitHub pull request (or compatible); '
117 + 'takes either GitHub PR number or full PR URL'))
118 +
119 parser.add_argument(
120 '-m', '--commitmsg', dest='commitmsg',
121 help='specify a commit message on the command line')
122 --
123 2.14.0

Replies