jenkins-bot has submitted this change and it was merged. Change subject: Make Bug: parsing more lenient ......................................................................
Make Bug: parsing more lenient T1, T2, T3 will now be parsed as 'T1' and Bugzilla-style identifiers are now also accepted. Bug: T136623 Bug: T108502 Change-Id: I470dd20974e4a736986aa66eefdcc9c5255fa0cb --- M forrestbot.py M utils.py 2 files changed, 55 insertions(+), 5 deletions(-) Approvals: Merlijn van Deen: Looks good to me, approved jenkins-bot: Verified diff --git a/forrestbot.py b/forrestbot.py index 90562de..c7b6536 100644 --- a/forrestbot.py +++ b/forrestbot.py @@ -13,7 +13,7 @@ import gerrit_rest import phabricator as legophab import config -from utils import wmf_number +from utils import wmf_number, parse_task_number parser = LoggingSetupParser( description="Process changesets and add release tags as required", @@ -158,9 +158,10 @@ mail.get('Closes', '') or mail.get('Task', '') ) - task = task.split(':')[-1].strip() + task = task.strip() if not task: raise KeyError('No Task ID (Bug, Closes or Task)') + task = parse_task_number(task) except KeyError as e: raise SkipMailException(e) @@ -215,10 +216,8 @@ pass # after parsing all entries, make sure we only do a single edit per Task. - # When detecting the bug header, strip arbitrary whitespace so bad headers - # like "Bug: T###" are OK def key(x): - return int(x['task'].strip()[1:]) + return x['task'] for task, acts in itertools.groupby(sorted(actions, key=key), key=key): acts = sorted(acts, key=lambda x: x['slugs']) diff --git a/utils.py b/utils.py index b8636e5..e47fcb6 100644 --- a/utils.py +++ b/utils.py @@ -1,3 +1,6 @@ +import re + + def wmf_number(branchname): """ >>> wmf_number('1.27.0-wmf.21') @@ -40,3 +43,51 @@ minor = '0' + minor return int(major + minor) + + +class TaskParseException(Exception): + pass + + +_task_number_re = re.compile(r'T(\d+)') +_bugzilla_number_re = re.compile(r'(\d+)') + + +def parse_task_number(bugstring): + """ + Find the first bug-like entry in the Bug: field + This can be either a Phabricator T bug, or a Bugzilla-style bug number. + Badly formed entries (e.g. Bug: T1234) are also OK. + + >>> parse_task_number("T1234") + 1234 + >>> parse_task_number("T1234 ") + 1234 + >>> parse_task_number(" T1234") + 1234 + >>> parse_task_number("Bug: T1234") + 1234 + >>> parse_task_number("T1234, T1235, T1236") + 1234 + >>> # Bugzilla style, add 2000 to get Phab Task number + >>> parse_task_number("1234") + 3234 + >>> try: + ... parse_task_number("Ttt") + ... except TaskParseException as e: + ... assert str(e) == "Could not parse bug string 'Ttt'" + """ + try: + phab_match = _task_number_re.search(bugstring) + if phab_match: + return int(phab_match.groups()[0]) + bz_match = _bugzilla_number_re.search(bugstring) + if bz_match: + return int(bz_match.groups()[0]) + 2000 + except Exception as e: + raise TaskParseException( + "Could not parse bug string %r: %r" % (bugstring, e) + ) + raise TaskParseException( + "Could not parse bug string %r" % (bugstring, ) + ) -- To view, visit https://gerrit.wikimedia.org/r/291966 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I470dd20974e4a736986aa66eefdcc9c5255fa0cb Gerrit-PatchSet: 4 Gerrit-Project: labs/tools/forrestbot Gerrit-Branch: master Gerrit-Owner: Merlijn van Deen <valhall...@arctus.nl> Gerrit-Reviewer: Merlijn van Deen <valhall...@arctus.nl> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits