| OLD | NEW |
| 1 # Copyright 2016 The Chromium Authors. All rights reserved. | 1 # Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 """Utility functions to extract information from commit log data.""" | 5 """Utility functions to extract information from commit log data.""" |
| 6 | 6 |
| 7 import re | 7 import re |
| 8 from collections import defaultdict | 8 from collections import defaultdict |
| 9 | 9 |
| 10 | 10 |
| 11 BUG_LINE_REGEX = re.compile( | 11 BUG_LINE_REGEX = re.compile( |
| 12 r'(?m)^(?P<flag>[>\s]*(?:BUGS?|ISSUE) *[ :=] *)(?P<data>.*)$') | 12 r'(?m)^(?P<flag>[>\s]*(?:BUGS?|ISSUE|Bugs?) *[ :=] *)(?P<data>.*)$') |
| 13 | 13 |
| 14 PROJECT_NAME_REGEX = r'(?P<project>[a-z0-9][-a-z0-9]*[a-z0-9])' | 14 PROJECT_NAME_REGEX = r'(?P<project>[a-z0-9][-a-z0-9]*[a-z0-9])' |
| 15 BUG_NUMBER_REGEX = r'(?P<bugnum>[0-9]+)' | 15 BUG_NUMBER_REGEX = r'(?P<bugnum>[0-9]+)' |
| 16 | 16 |
| 17 SHORTFORM_REGEX = r'(?:%s:)?#?%s' % ( | 17 SHORTFORM_REGEX = r'(?:%s:)?#?%s' % ( |
| 18 PROJECT_NAME_REGEX, BUG_NUMBER_REGEX) | 18 PROJECT_NAME_REGEX, BUG_NUMBER_REGEX) |
| 19 CRBUG_REGEX = r'(?:https?://)?crbug\.com/(%s/)?%s' % ( | 19 CRBUG_REGEX = r'(?:https?://)?crbug\.com/(%s/)?%s' % ( |
| 20 PROJECT_NAME_REGEX, BUG_NUMBER_REGEX) | 20 PROJECT_NAME_REGEX, BUG_NUMBER_REGEX) |
| 21 MONORAIL_REGEX = r'(?:https?://)?bugs\.chromium\.org/p/%s/[^?]+\?id=%s' % ( | 21 MONORAIL_REGEX = r'(?:https?://)?bugs\.chromium\.org/p/%s/[^?]+\?id=%s' % ( |
| 22 PROJECT_NAME_REGEX, BUG_NUMBER_REGEX) | 22 PROJECT_NAME_REGEX, BUG_NUMBER_REGEX) |
| 23 CODESITE_REGEX = '(?:https?://)?code\.google\.com/p/%s/[^?]+\?id=%s' % ( | 23 CODESITE_REGEX = '(?:https?://)?code\.google\.com/p/%s/[^?]+\?id=%s' % ( |
| 24 PROJECT_NAME_REGEX, BUG_NUMBER_REGEX) | 24 PROJECT_NAME_REGEX, BUG_NUMBER_REGEX) |
| 25 | 25 |
| 26 REGEXES = [ | 26 REGEXES = [ |
| 27 re.compile(SHORTFORM_REGEX), | 27 re.compile(SHORTFORM_REGEX), |
| 28 re.compile(CRBUG_REGEX), | 28 re.compile(CRBUG_REGEX), |
| 29 re.compile(MONORAIL_REGEX), | 29 re.compile(MONORAIL_REGEX), |
| 30 re.compile(CODESITE_REGEX), | 30 re.compile(CODESITE_REGEX), |
| 31 ] | 31 ] |
| 32 | 32 |
| 33 | 33 |
| 34 def normalize_project_name(project): | 34 def normalize_project_name(project): # pragma: no cover |
| 35 """Return the canonical name for a project specification.""" | 35 """Return the canonical name for a project specification.""" |
| 36 mapping = { | 36 mapping = { |
| 37 'nacl': 'nativeclient', | 37 'nacl': 'nativeclient', |
| 38 'cros': 'chromium-os', | 38 'cros': 'chromium-os', |
| 39 } | 39 } |
| 40 return mapping.get(project, project) | 40 return mapping.get(project, project) |
| 41 | 41 |
| 42 | 42 |
| 43 def get_issues(log_entry, default_project): | 43 def get_issues(log_entry, default_project): # pragma: no cover |
| 44 """Extract bug #'s from a SCM commit log message. | 44 """Extract bug #'s from a SCM commit log message. |
| 45 | 45 |
| 46 Args: | 46 Args: |
| 47 log_entry: The commit log_entry to search for bug #'s. | 47 log_entry: The commit log_entry to search for bug #'s. |
| 48 default_project: If a bug doesn't have an project specifier (e.g. foo:123), | 48 default_project: If a bug doesn't have an project specifier (e.g. foo:123), |
| 49 then assume it belongs in this project. | 49 then assume it belongs in this project. |
| 50 | 50 |
| 51 Returns: | 51 Returns: |
| 52 Dictionary of {'project': [list, of, bug, numbers]}. | 52 Dictionary of {'project': [list, of, bug, numbers]}. |
| 53 | 53 |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 bugproject = m.groupdict().get('project') or line_project | 101 bugproject = m.groupdict().get('project') or line_project |
| 102 bugproject = normalize_project_name(bugproject) | 102 bugproject = normalize_project_name(bugproject) |
| 103 bugnum = m.groupdict().get('bugnum') | 103 bugnum = m.groupdict().get('bugnum') |
| 104 # Only check for None, since empty project name is the default. | 104 # Only check for None, since empty project name is the default. |
| 105 bug_dict[bugproject].add(bugnum) | 105 bug_dict[bugproject].add(bugnum) |
| 106 line_project = bugproject | 106 line_project = bugproject |
| 107 | 107 |
| 108 rtn = {proj: sorted([int(b.strip()) for b in bugs]) | 108 rtn = {proj: sorted([int(b.strip()) for b in bugs]) |
| 109 for proj, bugs in bug_dict.iteritems()} | 109 for proj, bugs in bug_dict.iteritems()} |
| 110 return rtn | 110 return rtn |
| OLD | NEW |