[PATCH] repoman commit: Support --bug (-b) and --closes (-c) for git footer

classic Classic list List threaded Threaded
12 messages Options
Reply | Threaded
Open this post in threaded view
|

[PATCH] repoman commit: Support --bug (-b) and --closes (-c) for git footer

Michał Górny-5
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   | 29 +++++++++++++++++++++++++++++
 repoman/pym/repoman/argparser.py | 16 +++++++++++++++-
 2 files changed, 44 insertions(+), 1 deletion(-)

diff --git a/repoman/pym/repoman/actions.py b/repoman/pym/repoman/actions.py
index 00bb5b2ca..869ca7031 100644
--- a/repoman/pym/repoman/actions.py
+++ b/repoman/pym/repoman/actions.py
@@ -324,6 +324,11 @@ class Actions(object):
  return (changes.new, changes.changed, changes.removed,
  changes.no_expansion, changes.expansion)
 
+ long_bugzilla_url_re = re.compile(
+ r'https?://bugs\.gentoo\.org/show_bug\.cgi\?id=(\d+(#.*)?)')
+ http_bugtracker_url_re = re.compile(
+ r'http://(bugs\.gentoo\.org|bitbucket\.org|git(hub|lab)\.com)/')
+
  def get_commit_footer(self):
  portage_version = getattr(portage, "VERSION", None)
  gpg_key = self.repoman_settings.get("PORTAGE_GPG_KEY", "")
@@ -345,6 +350,30 @@ 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 = '<a href="https://bugs.gentoo.org/%s'">https://bugs.gentoo.org/%s' % (bug, )
+ else:
+ # case 2: long Gentoo bugzilla URL to shorten
+ m = self.long_bugzilla_url_re.match(bug)
+ if m is not None:
+ bug = '<a href="https://bugs.gentoo.org/%s'">https://bugs.gentoo.org/%s' % (m.group(1), )
+ # case 3: bug tracker w/ http -> https
+ m = self.http_bugtracker_url_re.match(bug)
+ if m is not None:
+ bug = bug.replace('http', 'https', 1)
+ commit_footer += "Bug: %s\n" % (bug, )
+ for closes in self.options.closes:
+ # case 1: pure number NNNN
+ if closes.isdigit():
+ closes = '<a href="https://github.com/gentoo/gentoo/pull/%s'">https://github.com/gentoo/gentoo/pull/%s' % (closes, )
+ else:
+ # case 2: bug tracker w/ http -> https
+ m = self.http_bugtracker_url_re.match(closes)
+ if m is not None:
+ closes = closes.replace('http', 'https', 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."""
@@ -58,6 +58,20 @@ def parse_args(argv, qahelp, repoman_default_opts):
  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.13.4


Reply | Threaded
Open this post in threaded view
|

Re: [PATCH] repoman commit: Support --bug (-b) and --closes (-c) for git footer

Alec Warner-2


On Thu, Aug 3, 2017 at 10:18 AM, Michał Górny <[hidden email]> wrote:
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   | 29 +++++++++++++++++++++++++++++
 repoman/pym/repoman/argparser.py | 16 +++++++++++++++-
 2 files changed, 44 insertions(+), 1 deletion(-)

diff --git a/repoman/pym/repoman/actions.py b/repoman/pym/repoman/actions.py
index 00bb5b2ca..869ca7031 100644
--- a/repoman/pym/repoman/actions.py
+++ b/repoman/pym/repoman/actions.py
@@ -324,6 +324,11 @@ class Actions(object):
                return (changes.new, changes.changed, changes.removed,
                                changes.no_expansion, changes.expansion)

+       long_bugzilla_url_re = re.compile(
+               r'https?://bugs\.gentoo\.org/show_bug\.cgi\?id=(\d+(#.*)?)')
+       http_bugtracker_url_re = re.compile(
+               r'http://(bugs\.gentoo\.org|bitbucket\.org|git(hub|lab)\.com)/')
+

Would you consider using the urlparse module here, instead of regexp?
 
        def get_commit_footer(self):
                portage_version = getattr(portage, "VERSION", None)
                gpg_key = self.repoman_settings.get("PORTAGE_GPG_KEY", "")
@@ -345,6 +350,30 @@ 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 = '<a href="https://bugs.gentoo.org/%s" rel="noreferrer" target="_blank">https://bugs.gentoo.org/%s' % (bug, )
+                       else:
+                               # case 2: long Gentoo bugzilla URL to shorten
+                               m = self.long_bugzilla_url_re.match(bug)
+                               if m is not None:
+                                       bug = '<a href="https://bugs.gentoo.org/%s" rel="noreferrer" target="_blank">https://bugs.gentoo.org/%s' % (m.group(1), )
+                               # case 3: bug tracker w/ http -> https
+                               m = self.http_bugtracker_url_re.match(bug)
+                               if m is not None:
+                                       bug = bug.replace('http', 'https', 1)
+                       commit_footer += "Bug: %s\n" % (bug, )
+               for closes in self.options.closes:
+                       # case 1: pure number NNNN
+                       if closes.isdigit():
+                               closes = '<a href="https://github.com/gentoo/gentoo/pull/%s" rel="noreferrer" target="_blank">https://github.com/gentoo/gentoo/pull/%s' % (closes, )
+                       else:
+                               # case 2: bug tracker w/ http -> https
+                               m = self.http_bugtracker_url_re.match(closes)
+                               if m is not None:
+                                       closes = closes.replace('http', 'https', 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."""
@@ -58,6 +58,20 @@ def parse_args(argv, qahelp, repoman_default_opts):
                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.13.4



Reply | Threaded
Open this post in threaded view
|

Re: [PATCH] repoman commit: Support --bug (-b) and --closes (-c) for git footer

Michał Górny-5
On czw, 2017-08-03 at 11:18 -0400, Alec Warner wrote:

> On Thu, Aug 3, 2017 at 10:18 AM, Michał Górny <[hidden email]> wrote:
>
> > 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   | 29 +++++++++++++++++++++++++++++
> >  repoman/pym/repoman/argparser.py | 16 +++++++++++++++-
> >  2 files changed, 44 insertions(+), 1 deletion(-)
> >
> > diff --git a/repoman/pym/repoman/actions.py b/repoman/pym/repoman/actions.
> > py
> > index 00bb5b2ca..869ca7031 100644
> > --- a/repoman/pym/repoman/actions.py
> > +++ b/repoman/pym/repoman/actions.py
> > @@ -324,6 +324,11 @@ class Actions(object):
> >                 return (changes.new, changes.changed, changes.removed,
> >                                 changes.no_expansion, changes.expansion)
> >
> > +       long_bugzilla_url_re = re.compile(
> > +               r'https?://bugs\.gentoo\.org/
> > show_bug\.cgi\?id=(\d+(#.*)?)')
> > +       http_bugtracker_url_re = re.compile(
> > +               r'http://(bugs\.gentoo\.org|bitbucket\.org|git(hub|lab)\.
> > com)/')
> > +
> >
>
> Would you consider using the urlparse module here, instead of regexp?
Sure. Just for the second case, or for both?

--
Best regards,
Michał Górny

signature.asc (1007 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH] repoman commit: Support --bug (-b) and --closes (-c) for git footer

Alec Warner-2


On Thu, Aug 3, 2017 at 12:15 PM, Michał Górny <[hidden email]> wrote:
On czw, 2017-08-03 at 11:18 -0400, Alec Warner wrote:
> On Thu, Aug 3, 2017 at 10:18 AM, Michał Górny <[hidden email]> wrote:
>
> > 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   | 29 +++++++++++++++++++++++++++++
> >  repoman/pym/repoman/argparser.py | 16 +++++++++++++++-
> >  2 files changed, 44 insertions(+), 1 deletion(-)
> >
> > diff --git a/repoman/pym/repoman/actions.py b/repoman/pym/repoman/actions.
> > py
> > index 00bb5b2ca..869ca7031 100644
> > --- a/repoman/pym/repoman/actions.py
> > +++ b/repoman/pym/repoman/actions.py
> > @@ -324,6 +324,11 @@ class Actions(object):
> >                 return (changes.new, changes.changed, changes.removed,
> >                                 changes.no_expansion, changes.expansion)
> >
> > +       long_bugzilla_url_re = re.compile(
> > +               r'https?://bugs\.gentoo\.org/
> > show_bug\.cgi\?id=(\d+(#.*)?)')
> > +       http_bugtracker_url_re = re.compile(
> > +               r'http://(bugs\.gentoo\.org|bitbucket\.org|git(hub|lab)\.
> > com)/')
> > +
> >
>
> Would you consider using the urlparse module here, instead of regexp?

Sure. Just for the second case, or for both?

I was actually more concerned about parsing the id query string than the hostname; so I'd say both; but I leave it to your judgement.

-A
 

--
Best regards,
Michał Górny

Reply | Threaded
Open this post in threaded view
|

[PATCH v2] repoman commit: Support --bug (-b) and --closes (-c) for git footer

Michał Górny-5
In reply to this post by Michał Górny-5
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.

Changes in v2: use urlparse instead of regexps

---
 repoman/pym/repoman/actions.py   | 45 ++++++++++++++++++++++++++++++++++++++++
 repoman/pym/repoman/argparser.py | 16 +++++++++++++-
 2 files changed, 60 insertions(+), 1 deletion(-)

diff --git a/repoman/pym/repoman/actions.py b/repoman/pym/repoman/actions.py
index 00bb5b2ca..8299ed0fe 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,9 +357,42 @@ 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 = '<a href="https://bugs.gentoo.org/%s'">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 = '<a href="https://github.com/gentoo/gentoo/pull/%s'">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, )
 
+ print(commit_footer)
+ raise SystemExit(666)
+
  # Use new footer only for git (see bug #438364).
  if self.vcs_settings.vcs in ["git"]:
  commit_footer += "Package-Manager: Portage-%s, Repoman-%s" % (
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."""
@@ -58,6 +58,20 @@ def parse_args(argv, qahelp, repoman_default_opts):
  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.13.4


Reply | Threaded
Open this post in threaded view
|

Re: [PATCH v2] repoman commit: Support --bug (-b) and --closes (-c) for git footer

Alec Warner-2


On Fri, Aug 4, 2017 at 6:37 PM, Michał Górny <[hidden email]> wrote:
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.

Changes in v2: use urlparse instead of regexps

---
 repoman/pym/repoman/actions.py   | 45 ++++++++++++++++++++++++++++++++++++++++
 repoman/pym/repoman/argparser.py | 16 +++++++++++++-
 2 files changed, 60 insertions(+), 1 deletion(-)

diff --git a/repoman/pym/repoman/actions.py b/repoman/pym/repoman/actions.py
index 00bb5b2ca..8299ed0fe 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,9 +357,42 @@ 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 = '<a href="https://bugs.gentoo.org/%s" rel="noreferrer" target="_blank">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 = '<a href="https://github.com/gentoo/gentoo/pull/%s" rel="noreferrer" target="_blank">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, )

+               print(commit_footer)
+               raise SystemExit(666)

Debug lines?

-A
 
+
                # Use new footer only for git (see bug #438364).
                if self.vcs_settings.vcs in ["git"]:
                        commit_footer += "Package-Manager: Portage-%s, Repoman-%s" % (
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."""
@@ -58,6 +58,20 @@ def parse_args(argv, qahelp, repoman_default_opts):
                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.13.4



Reply | Threaded
Open this post in threaded view
|

Re: [PATCH v2] repoman commit: Support --bug (-b) and --closes (-c) for git footer

Michał Górny-5
On sob, 2017-08-05 at 17:11 -0400, Alec Warner wrote:

> On Fri, Aug 4, 2017 at 6:37 PM, Michał Górny <[hidden email]> wrote:
>
> > 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.
> >
> > Changes in v2: use urlparse instead of regexps
> >
> > ---
> >  repoman/pym/repoman/actions.py   | 45 ++++++++++++++++++++++++++++++
> > ++++++++++
> >  repoman/pym/repoman/argparser.py | 16 +++++++++++++-
> >  2 files changed, 60 insertions(+), 1 deletion(-)
> >
> > diff --git a/repoman/pym/repoman/actions.py b/repoman/pym/repoman/actions.
> > py
> > index 00bb5b2ca..8299ed0fe 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,9 +357,42 @@ 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 = '<a href="https://bugs.gentoo.org/%s'">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,
> > )
> >
> > +               print(commit_footer)
> > +               raise SystemExit(666)
> >
>
> Debug lines?
>
Yeah, that happens when you work instead of sleeping ;-).

--
Best regards,
Michał Górny

signature.asc (1007 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

[PATCH v3] repoman commit: Support --bug (-b) and --closes (-c) for git footer

Michał Górny-5
In reply to this post by Michał Górny-5
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 = '<a href="https://bugs.gentoo.org/%s'">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 = '<a href="https://github.com/gentoo/gentoo/pull/%s'">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


Reply | Threaded
Open this post in threaded view
|

Re: [PATCH v3] repoman commit: Support --bug (-b) and --closes (-c) for git footer

Zac Medico-2
On Sat, Aug 5, 2017 at 2:26 PM, Michał Górny <[hidden email]> wrote:

> +       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'))
> +

We should document these in repoman/man/repoman.1 as well.
--
Thanks,
Zac

Reply | Threaded
Open this post in threaded view
|

[PATCH v4] repoman commit: Support --bug (-b) and --closes (-c) for git footer

Michał Górny-5
In reply to this post by Michał Górny-5
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/man/repoman.1            | 14 ++++++++++++++
 repoman/pym/repoman/actions.py   | 42 ++++++++++++++++++++++++++++++++++++++++
 repoman/pym/repoman/argparser.py | 16 ++++++++++++++-
 3 files changed, 71 insertions(+), 1 deletion(-)

v4: now with manpage update

diff --git a/repoman/man/repoman.1 b/repoman/man/repoman.1
index 4101c283f..a49c72c0d 100644
--- a/repoman/man/repoman.1
+++ b/repoman/man/repoman.1
@@ -21,6 +21,20 @@ BASH.
 \fB-a\fR, \fB--ask\fR
 Request a confirmation before commiting
 .TP
+\fB-b\fR, \fB--bug\fR
+Include a bug reference in the commit message footer. The argument can
+be either a Gentoo bug number or a full bug URL (either Gentoo
+or upstream). Gentoo bug URLs are automatically shortened to
+the canonical \fBhttps://bugs.gentoo.org/NNNNNN\fR form, and HTTPS
+is forced for known bug trackers.
+.TP
+\fB-c\fR, \fB--closes\fR
+Include a \fBCloses\fR tag in the commit message footer that can be used
+to close pull requests (and issues) on GitHub and other compatible
+services (GitLab, Bitbucket). The argument can be either a PR number for
+the gentoo/gentoo GitHub repository or a full PR/bug URL. For bug URLs,
+HTTPS is forced automatically for known bug/PR trackers.
+.TP
 \fB\-\-digest=<y|n>\fR
 Automatically update Manifest digests for modified files. This
 option triggers a behavior that is very similar to that enabled
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 = '<a href="https://bugs.gentoo.org/%s'">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 = '<a href="https://github.com/gentoo/gentoo/pull/%s'">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


Reply | Threaded
Open this post in threaded view
|

Re: [PATCH v4] repoman commit: Support --bug (-b) and --closes (-c) for git footer

Zac Medico-2
On Sat, Aug 5, 2017 at 11:53 PM, Michał Górny <[hidden email]> wrote:

> 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/man/repoman.1            | 14 ++++++++++++++
>  repoman/pym/repoman/actions.py   | 42 ++++++++++++++++++++++++++++++++++++++++
>  repoman/pym/repoman/argparser.py | 16 ++++++++++++++-
>  3 files changed, 71 insertions(+), 1 deletion(-)
>
> v4: now with manpage update

Looks good.
--
Thanks,
Zac

Reply | Threaded
Open this post in threaded view
|

Re: [PATCH v4] repoman commit: Support --bug (-b) and --closes (-c) for git footer

Michał Górny-5
On nie, 2017-08-06 at 00:18 -0700, Zac Medico wrote:

> On Sat, Aug 5, 2017 at 11:53 PM, Michał Górny <[hidden email]> wrote:
> > 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/man/repoman.1            | 14 ++++++++++++++
> >  repoman/pym/repoman/actions.py   | 42 ++++++++++++++++++++++++++++++++++++++++
> >  repoman/pym/repoman/argparser.py | 16 ++++++++++++++-
> >  3 files changed, 71 insertions(+), 1 deletion(-)
> >
> > v4: now with manpage update
>
> Looks good.
Thanks. Pushed now.

--
Best regards,
Michał Górny

signature.asc (1007 bytes) Download Attachment