* [gentoo-portage-dev] [PATCH v3] repoman commit: Support --bug (-b) and --closes (-c) for git footer
@ 2017-08-05 21:26 99% ` Michał Górny
0 siblings, 0 replies; 1+ results
From: Michał Górny @ 2017-08-05 21:26 UTC (permalink / raw
To: gentoo-portage-dev; +Cc: Michał Górny
Support two new options: --bug (-b) and --closes (-c) to add a plain
'Bug' reference and a 'Closes' footer for a GitHub pull request. Both
options can be specified multiple times, resulting in multiple footer
tags being written.
The --bug option accepts either a Gentoo Bugzilla bug number or an URL
to any bug tracker. In the latter case, it performs two trivial
transformations automatically: replaces long 'show_bug.cgi' Bugzilla
URLs with the short 'https://bugs.gentoo.org/NNNNNN', and forces
https:// for a few known services.
The --closes option accepts either a GitHub Gentoo repository pull
request number or an URL to any pull request (or bug) that uses
the 'Closes' tag. In the latter case, https:// is forced for a few known
services.
---
repoman/pym/repoman/actions.py | 42 ++++++++++++++++++++++++++++++++++++++++
repoman/pym/repoman/argparser.py | 16 ++++++++++++++-
2 files changed, 57 insertions(+), 1 deletion(-)
New in v3: no more debug
diff --git a/repoman/pym/repoman/actions.py b/repoman/pym/repoman/actions.py
index 00bb5b2ca..2112299c0 100644
--- a/repoman/pym/repoman/actions.py
+++ b/repoman/pym/repoman/actions.py
@@ -14,6 +14,11 @@ import tempfile
import time
from itertools import chain
+try:
+ from urllib.parse import parse_qs, urlsplit, urlunsplit
+except ImportError:
+ from urlparse import parse_qs, urlsplit, urlunsplit
+
from _emerge.UserQuery import UserQuery
from repoman._portage import portage
@@ -324,6 +329,13 @@ class Actions(object):
return (changes.new, changes.changed, changes.removed,
changes.no_expansion, changes.expansion)
+ https_bugtrackers = frozenset([
+ 'bitbucket.org',
+ 'bugs.gentoo.org',
+ 'github.com',
+ 'gitlab.com',
+ ])
+
def get_commit_footer(self):
portage_version = getattr(portage, "VERSION", None)
gpg_key = self.repoman_settings.get("PORTAGE_GPG_KEY", "")
@@ -345,6 +357,36 @@ class Actions(object):
# Common part of commit footer
commit_footer = "\n"
+ for bug in self.options.bug:
+ # case 1: pure number NNNNNN
+ if bug.isdigit():
+ bug = 'https://bugs.gentoo.org/%s' % (bug, )
+ else:
+ purl = urlsplit(bug)
+ qs = parse_qs(purl.query)
+ # case 2: long Gentoo bugzilla URL to shorten
+ if (purl.netloc == 'bugs.gentoo.org' and
+ purl.path == '/show_bug.cgi' and
+ tuple(qs.keys()) == ('id',)):
+ bug = urlunsplit(('https', purl.netloc,
+ qs['id'][-1], '', purl.fragment))
+ # case 3: bug tracker w/ http -> https
+ elif (purl.scheme == 'http' and
+ purl.netloc in self.https_bugtrackers):
+ bug = urlunsplit(('https',) + purl[1:])
+ commit_footer += "Bug: %s\n" % (bug, )
+
+ for closes in self.options.closes:
+ # case 1: pure number NNNN
+ if closes.isdigit():
+ closes = 'https://github.com/gentoo/gentoo/pull/%s' % (closes, )
+ else:
+ purl = urlsplit(closes)
+ # case 2: bug tracker w/ http -> https
+ if purl.netloc in self.https_bugtrackers:
+ closes = urlunsplit(('https',) + purl[1:])
+ commit_footer += "Closes: %s\n" % (closes, )
+
if dco_sob:
commit_footer += "Signed-off-by: %s\n" % (dco_sob, )
diff --git a/repoman/pym/repoman/argparser.py b/repoman/pym/repoman/argparser.py
index 2d56a87e6..f32972288 100644
--- a/repoman/pym/repoman/argparser.py
+++ b/repoman/pym/repoman/argparser.py
@@ -1,5 +1,5 @@
# repoman: Argument parser
-# Copyright 2007-2014 Gentoo Foundation
+# Copyright 2007-2017 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
"""This module contains functions used in Repoman to parse CLI arguments."""
@@ -57,6 +57,20 @@ def parse_args(argv, qahelp, repoman_default_opts):
default=False,
help='Request a confirmation before commiting')
+ parser.add_argument(
+ '-b', '--bug', dest='bug', action='append', metavar='<BUG-NO|BUG-URL>',
+ default=[],
+ help=(
+ 'Mention a Gentoo or upstream bug in the commit footer; '
+ 'takes either Gentoo bug number or full bug URL'))
+
+ parser.add_argument(
+ '-c', '--closes', dest='closes', action='append', metavar='<PR-NO|PR-URL>',
+ default=[],
+ help=(
+ 'Adds a Closes footer to close GitHub pull request (or compatible); '
+ 'takes either GitHub PR number or full PR URL'))
+
parser.add_argument(
'-m', '--commitmsg', dest='commitmsg',
help='specify a commit message on the command line')
--
2.14.0
^ permalink raw reply related [relevance 99%]
Results 1-1 of 1 | reverse | options above
-- pct% links below jump to the message on this page, permalinks otherwise --
2017-08-03 14:18 [gentoo-portage-dev] [PATCH] repoman commit: Support --bug (-b) and --closes (-c) for git footer Michał Górny
2017-08-05 21:26 99% ` [gentoo-portage-dev] [PATCH v3] " Michał Górny
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox