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

Replies