From 6e0fbe6c79ea1923f9a6f8824ccee6180a02f4d3 Mon Sep 17 00:00:00 2001 From: Robert-André Mauchin Date: Jul 25 2021 18:34:11 +0000 Subject: Look for bug number in commit message instead of changelog --- diff --git a/fedpkg/__init__.py b/fedpkg/__init__.py index 0cbaebe..797b637 100644 --- a/fedpkg/__init__.py +++ b/fedpkg/__init__.py @@ -13,6 +13,7 @@ import pyrpkg import os import git import re +import six from datetime import datetime, timedelta @@ -293,6 +294,21 @@ class Commands(pyrpkg.Commands): else: raise pyrpkg.rpkgError('Unable to find rawhide target') + def _getcommitmessage(self): + """Returns the latest commit message on the current branch""" + + try: + commitmsg = six.next(self.repo.iter_commits()).message + except TypeError: + commitmsg = "" + + return commitmsg + + def _isrpmautospec(self): + """Returns whether the spec file uses rpmautospec features""" + + return self._uses_rpmautospec + def _determine_runtime_env(self): """Need to know what the runtime env is, so we can unset anything conflicting diff --git a/fedpkg/cli.py b/fedpkg/cli.py index 545d805..df9c5c4 100644 --- a/fedpkg/cli.py +++ b/fedpkg/cli.py @@ -761,7 +761,7 @@ class fedpkgClient(cliClient): id_pattern_raw = r'(?:fedora|epel|rh(?:bz)?)#(\d{5,})' bz_pattern = re.compile( # says: there is at least one complete (including prefix) Bugzilla bug occurrence - r'\s*(?:fix(?:es)?|close(?:s)?|resolve(?:s)?)(?::|:\s+|\s+)' + id_pattern_raw, + r'(?:fix(?:es)?|close(?:s)?|resolve(?:s)?)(?::|:\s+|\s+)' + id_pattern_raw, re.IGNORECASE, ) id_pattern = re.compile(id_pattern_raw, re.IGNORECASE) @@ -769,7 +769,7 @@ class fedpkgClient(cliClient): issue_ids = set() for line in text.splitlines(): # is there complete Bugzilla ID including prefix - bz_match = bz_pattern.match(line) + bz_match = bz_pattern.search(line) if bz_match is not None: # gather all Bugzilla IDs behind the prefix line_ids = re.findall(id_pattern, line) @@ -804,15 +804,18 @@ class fedpkgClient(cliClient): else: bodhi_args['type_'] = '' - try: - self.cmd.clog() - clog_file = os.path.join(self.cmd.path, 'clog') - with io.open(clog_file, encoding='utf-8') as f: - clog = f.read() - os.unlink(clog_file) - except rpkgError: - # Not an RPM, no changelog to work with - clog = "" + if self.cmd._isrpmautospec(): + clog = self.cmd._getcommitmessage() + else: + try: + self.cmd.clog() + clog_file = os.path.join(self.cmd.path, 'clog') + with io.open(clog_file, encoding='utf-8') as f: + clog = f.read() + os.unlink(clog_file) + except rpkgError: + # Not an RPM, no changelog to work with + clog = "" if self.args.bugs: bodhi_args['bugs'] = ','.join(self.args.bugs)