From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id EDC051382C5 for ; Mon, 19 Feb 2018 14:28:05 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 9E9A8E0A7D; Mon, 19 Feb 2018 14:28:04 +0000 (UTC) Received: from smtp.gentoo.org (woodpecker.gentoo.org [IPv6:2001:470:ea4a:1:5054:ff:fec7:86e4]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 5E1ADE0A6E for ; Mon, 19 Feb 2018 14:28:04 +0000 (UTC) Received: from pomiot (d202-252.icpnet.pl [109.173.202.252]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: mgorny) by smtp.gentoo.org (Postfix) with ESMTPSA id 4E6CC335C07; Mon, 19 Feb 2018 14:28:01 +0000 (UTC) Message-ID: <1519050477.1104.0.camel@gentoo.org> Subject: Re: [gentoo-portage-dev] [PATCH v2 1/3] repoman: Add commit message verification From: =?UTF-8?Q?Micha=C5=82_G=C3=B3rny?= To: gentoo-portage-dev@lists.gentoo.org Date: Mon, 19 Feb 2018 15:27:57 +0100 In-Reply-To: <20180217125648.1697-1-mgorny@gentoo.org> References: <20180217125648.1697-1-mgorny@gentoo.org> Organization: Gentoo Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.24.6 Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-portage-dev@lists.gentoo.org Reply-to: gentoo-portage-dev@lists.gentoo.org Mime-Version: 1.0 Content-Transfer-Encoding: 8bit X-Archives-Salt: dc6f93e3-ca50-4391-bca5-0319d89e31d5 X-Archives-Hash: ed5fa3a1c93bb0c8d8fab76a9727d6d7 W dniu sob, 17.02.2018 o godzinie 13∶56 +0100, użytkownik Michał Górny napisał: > Add a check for common mistakes in commit messages. For now, it is > pretty rough and works only for -m/-F. It will be extended to work > in the interactive mode in the future. > --- > repoman/pym/repoman/actions.py | 74 ++++++++++++++++++++++++- > repoman/pym/repoman/tests/commit/__init__.py | 2 + > repoman/pym/repoman/tests/commit/__test__.py | 1 + Oh, great. Now I see that I haven't added the new tests, and the file is gone now, and now I'm going to waste another hour writing them all again... > repoman/pym/repoman/tests/simple/test_simple.py | 8 +-- > 4 files changed, 80 insertions(+), 5 deletions(-) > create mode 100644 repoman/pym/repoman/tests/commit/__init__.py > create mode 100644 repoman/pym/repoman/tests/commit/__test__.py > > diff --git a/repoman/pym/repoman/actions.py b/repoman/pym/repoman/actions.py > index b76a6e466..91603865c 100644 > --- a/repoman/pym/repoman/actions.py > +++ b/repoman/pym/repoman/actions.py > @@ -119,7 +119,16 @@ class Actions(object): > if commitmessage[:9].lower() in ("cat/pkg: ",): > commitmessage = self.msg_prefix() + commitmessage[9:] > > - if not commitmessage or not commitmessage.strip(): > + if commitmessage is not None and commitmessage.strip(): > + res, expl = self.verify_commit_message(commitmessage) > + if not res: > + print(bad("RepoMan does not like your commit message:")) > + print(expl) > + if self.options.force: > + print('(but proceeding due to --force)') > + else: > + sys.exit(1) > + else: > commitmessage = self.get_new_commit_message(qa_output) > > commitmessage = commitmessage.rstrip() > @@ -585,3 +594,66 @@ class Actions(object): > print("* no commit message? aborting commit.") > sys.exit(1) > return commitmessage > + > + footer_re = re.compile(r'^[\w-]+:') > + > + @classmethod > + def verify_commit_message(cls, msg): > + """ > + Check whether the message roughly complies with GLEP66. Returns > + (True, None) if it does, (False, ) if it does not. > + """ > + > + problems = [] > + paras = msg.strip().split('\n\n') > + summary = paras.pop(0) > + > + if ':' not in summary: > + problems.append('summary line must start with a logical unit name, e.g. "cat/pkg:"') > + if '\n' in summary.strip(): > + problems.append('commit message must start with a *single* line of summary, followed by empty line') > + # accept 69 overall or unit+50, in case of very long package names > + elif len(summary.strip()) > 69 and len(summary.split(':', 1)[-1]) > 50: > + problems.append('summary line is too long (max 69 characters)') > + > + multiple_footers = False > + gentoo_bug_used = False > + bug_closes_without_url = False > + body_too_long = False > + > + found_footer = False > + for p in paras: > + lines = p.splitlines() > + # if all lines look like footer material, we assume it's footer > + # else, we assume it's body text > + if all(cls.footer_re.match(l) for l in lines if l.strip()): > + # multiple footer-like blocks? > + if found_footer: > + multiple_footers = True > + found_footer = True > + for l in lines: > + if l.startswith('Gentoo-Bug'): > + gentoo_bug_used = True > + elif l.startswith('Bug:') or l.startswith('Closes:'): > + if 'http://' not in l and 'https://' not in l: > + bug_closes_without_url = True > + else: > + for l in lines: > + # we recommend wrapping at 72 but accept up to 80; > + # do not complain if we have single word (usually > + # it means very long URL) > + if len(l.strip()) > 80 and len(l.split()) > 1: > + body_too_long = True > + > + if multiple_footers: > + problems.append('multiple footer-style blocks found, please combine them into one') > + if gentoo_bug_used: > + problems.append('please replace Gentoo-Bug with GLEP 66-compliant Bug/Closes') > + if bug_closes_without_url: > + problems.append('Bug/Closes footers require full URL') > + if body_too_long: > + problems.append('body lines should be wrapped at 72 (max 80) characters') > + > + if problems: > + return (False, '\n'.join('- %s' % x for x in problems)) > + return (True, None) > diff --git a/repoman/pym/repoman/tests/commit/__init__.py b/repoman/pym/repoman/tests/commit/__init__.py > new file mode 100644 > index 000000000..d74fd94a7 > --- /dev/null > +++ b/repoman/pym/repoman/tests/commit/__init__.py > @@ -0,0 +1,2 @@ > +# Copyright 2011-2018 Gentoo Foundation > +# Distributed under the terms of the GNU General Public License v2 > diff --git a/repoman/pym/repoman/tests/commit/__test__.py b/repoman/pym/repoman/tests/commit/__test__.py > new file mode 100644 > index 000000000..8b1378917 > --- /dev/null > +++ b/repoman/pym/repoman/tests/commit/__test__.py > @@ -0,0 +1 @@ > + > diff --git a/repoman/pym/repoman/tests/simple/test_simple.py b/repoman/pym/repoman/tests/simple/test_simple.py > index a24e0d5a3..3d7a70ad0 100644 > --- a/repoman/pym/repoman/tests/simple/test_simple.py > +++ b/repoman/pym/repoman/tests/simple/test_simple.py > @@ -1,4 +1,4 @@ > -# Copyright 2011-2015 Gentoo Foundation > +# Copyright 2011-2018 Gentoo Foundation > # Distributed under the terms of the GNU General Public License v2 > > import subprocess > @@ -194,13 +194,13 @@ class SimpleRepomanTestCase(TestCase): > ("", repoman_cmd + ("full", "-d")), > ("", cp_cmd + (test_ebuild, test_ebuild[:-8] + "2.ebuild")), > ("", git_cmd + ("add", test_ebuild[:-8] + "2.ebuild")), > - ("", repoman_cmd + ("commit", "-m", "bump to version 2")), > + ("", repoman_cmd + ("commit", "-m", "cat/pkg: bump to version 2")), > ("", cp_cmd + (test_ebuild, test_ebuild[:-8] + "3.ebuild")), > ("", git_cmd + ("add", test_ebuild[:-8] + "3.ebuild")), > - ("dev-libs", repoman_cmd + ("commit", "-m", "bump to version 3")), > + ("dev-libs", repoman_cmd + ("commit", "-m", "cat/pkg: bump to version 3")), > ("", cp_cmd + (test_ebuild, test_ebuild[:-8] + "4.ebuild")), > ("", git_cmd + ("add", test_ebuild[:-8] + "4.ebuild")), > - ("dev-libs/A", repoman_cmd + ("commit", "-m", "bump to version 4")), > + ("dev-libs/A", repoman_cmd + ("commit", "-m", "cat/pkg: bump to version 4")), > ) > > env = { -- Best regards, Michał Górny