Merlijn van Deen has uploaded a new change for review.
https://gerrit.wikimedia.org/r/291965
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: I74a1856ffb4963240f0b845af209c79a2e7b6e68
---
M forrestbot.py
M utils.py
2 files changed, 46 insertions(+), 4 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/labs/tools/forrestbot
refs/changes/65/291965/1
diff --git a/forrestbot.py b/forrestbot.py
index 64e6784..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,8 +158,10 @@
mail.get('Closes', '') or
mail.get('Task', '')
)
+ 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)
@@ -214,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..ff5d10a 100644
--- a/utils.py
+++ b/utils.py
@@ -40,3 +40,45 @@
minor = '0' + minor
return int(major + minor)
+
+
+class TaskParseException(Exception):
+ pass
+
+import re
+_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
+ >>> parse_task_number("1234") # Bugzilla style, add 2000 to get Phab Task
number
+ 3234
+ >>> parse_task_number("Ttt")
+ Traceback (most recent call last):
+ ...
+ utils.TaskParseException: 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/291965
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I74a1856ffb4963240f0b845af209c79a2e7b6e68
Gerrit-PatchSet: 1
Gerrit-Project: labs/tools/forrestbot
Gerrit-Branch: master
Gerrit-Owner: Merlijn van Deen <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits