mirror of
https://chromium.googlesource.com/chromium/tools/depot_tools.git
synced 2026-01-11 10:41:31 +00:00
my_activity: Add some tests and fix some bugs
Change-Id: Ib5625ae9d052eca9d6c6b64f12f64e6697aef7a8 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/2072874 Reviewed-by: Anthony Polito <apolito@google.com> Commit-Queue: Edward Lesmes <ehmaldonado@chromium.org>
This commit is contained in:
@@ -129,7 +129,7 @@ def datetime_to_midnight(date):
|
||||
|
||||
def get_quarter_of(date):
|
||||
begin = (datetime_to_midnight(date) -
|
||||
relativedelta(months=(date.month % 3) - 1, days=(date.day - 1)))
|
||||
relativedelta(months=(date.month - 1) % 3, days=(date.day - 1)))
|
||||
return begin, begin + relativedelta(months=3)
|
||||
|
||||
|
||||
@@ -160,6 +160,24 @@ def datetime_from_gerrit(date_string):
|
||||
def datetime_from_monorail(date_string):
|
||||
return datetime.strptime(date_string, '%Y-%m-%dT%H:%M:%S')
|
||||
|
||||
def extract_bug_numbers_from_description(issue):
|
||||
# Getting the description for REST Gerrit
|
||||
revision = issue['revisions'][issue['current_revision']]
|
||||
description = revision['commit']['message']
|
||||
|
||||
bugs = []
|
||||
# Handle both "Bug: 99999" and "BUG=99999" bug notations
|
||||
# Multiple bugs can be noted on a single line or in multiple ones.
|
||||
matches = re.findall(
|
||||
r'^(BUG=|(Bug|Fixed):\s*)((((?:[a-zA-Z0-9-]+:)?\d+)(,\s?)?)+)',
|
||||
description, flags=re.IGNORECASE | re.MULTILINE)
|
||||
if matches:
|
||||
for match in matches:
|
||||
bugs.extend(match[2].replace(' ', '').split(','))
|
||||
# Add default chromium: prefix if none specified.
|
||||
bugs = [bug if ':' in bug else 'chromium:%s' % bug for bug in bugs]
|
||||
|
||||
return sorted(set(bugs))
|
||||
|
||||
class MyActivity(object):
|
||||
def __init__(self, options):
|
||||
@@ -180,32 +198,6 @@ class MyActivity(object):
|
||||
sys.stdout.write(how)
|
||||
sys.stdout.flush()
|
||||
|
||||
def extract_bug_numbers_from_description(self, issue):
|
||||
description = None
|
||||
|
||||
if 'description' in issue:
|
||||
# Getting the description for Rietveld
|
||||
description = issue['description']
|
||||
elif 'revisions' in issue:
|
||||
# Getting the description for REST Gerrit
|
||||
revision = issue['revisions'][issue['current_revision']]
|
||||
description = revision['commit']['message']
|
||||
|
||||
bugs = []
|
||||
if description:
|
||||
# Handle both "Bug: 99999" and "BUG=99999" bug notations
|
||||
# Multiple bugs can be noted on a single line or in multiple ones.
|
||||
matches = re.findall(
|
||||
r'BUG[=:]\s?((((?:[a-zA-Z0-9-]+:)?\d+)(,\s?)?)+)', description,
|
||||
flags=re.IGNORECASE)
|
||||
if matches:
|
||||
for match in matches:
|
||||
bugs.extend(match[0].replace(' ', '').split(','))
|
||||
# Add default chromium: prefix if none specified.
|
||||
bugs = [bug if ':' in bug else 'chromium:%s' % bug for bug in bugs]
|
||||
|
||||
return sorted(set(bugs))
|
||||
|
||||
def gerrit_changes_over_rest(self, instance, filters):
|
||||
# Convert the "key:value" filter to a list of (key, value) pairs.
|
||||
req = list(f.split(':', 1) for f in filters)
|
||||
@@ -272,7 +264,7 @@ class MyActivity(object):
|
||||
ret['replies'] = []
|
||||
ret['reviewers'] = set(r['author'] for r in ret['replies'])
|
||||
ret['reviewers'].discard(ret['author'])
|
||||
ret['bugs'] = self.extract_bug_numbers_from_description(issue)
|
||||
ret['bugs'] = extract_bug_numbers_from_description(issue)
|
||||
return ret
|
||||
|
||||
@staticmethod
|
||||
|
||||
Reference in New Issue
Block a user