Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 # found in the LICENSE file. | |
| 4 | |
| 5 import json | |
|
stgao
2016/10/25 23:01:33
is it used?
Sharu Jiang
2016/10/26 06:13:38
Done.
| |
| 6 import re | |
| 7 import urllib2 | |
|
stgao
2016/10/25 23:01:33
is it used?
Sharu Jiang
2016/10/26 06:13:38
Done.
| |
| 8 | |
| 9 CODE_REVIEW_URL_PATTERN = re.compile( | |
| 10 '^(?:Review URL|Review-Url): (.*\d+).*$', re.IGNORECASE) | |
| 11 COMMIT_POSITION_PATTERN = re.compile( | |
| 12 '^Cr-Commit-Position: refs/heads/master@{#(\d+)}$', re.IGNORECASE) | |
| 13 REVERTED_REVISION_PATTERN = re.compile( | |
| 14 '^> Committed: https://.+/([0-9a-fA-F]{40})$', re.IGNORECASE) | |
| 15 COMMIT_POSITION_CODE_REVIEW_URL_PARSING_START_LINE = -5 | |
| 16 | |
| 17 | |
| 18 def ExtractCommitPositionAndCodeReviewUrl(message): | |
| 19 """Returns the commit position and code review url in the commit message. | |
| 20 | |
| 21 A "commit position" is something similar to SVN version ids; i.e., | |
| 22 numeric identifiers which are issued in sequential order. The reason | |
| 23 we care about them is that they're easier for humans to read than | |
| 24 the hashes that Git uses internally for identifying commits. We | |
| 25 should never actually use them for *identifying* commits; they're | |
| 26 only for pretty printing to humans. | |
| 27 | |
| 28 Returns: | |
| 29 (commit_position, code_review_url) | |
| 30 """ | |
| 31 if not message: | |
| 32 return (None, None) | |
| 33 | |
| 34 commit_position = None | |
| 35 code_review_url = None | |
| 36 | |
| 37 # Commit position and code review url are in the last 5 lines. | |
| 38 lines = message.strip().split('\n')[ | |
| 39 COMMIT_POSITION_CODE_REVIEW_URL_PARSING_START_LINE:] | |
| 40 lines.reverse() | |
| 41 | |
| 42 for line in lines: | |
| 43 if commit_position is None: | |
| 44 match = COMMIT_POSITION_PATTERN.match(line) | |
| 45 if match: | |
| 46 commit_position = int(match.group(1)) | |
| 47 | |
| 48 if code_review_url is None: | |
| 49 match = CODE_REVIEW_URL_PATTERN.match(line) | |
| 50 if match: | |
| 51 code_review_url = match.group(1) | |
| 52 return (commit_position, code_review_url) | |
| 53 | |
| 54 | |
| 55 def NormalizeEmail(email): | |
| 56 """Normalizes the email from git repo. | |
| 57 | |
| 58 Some email is like: test@chromium.org@bbb929c8-8fbe-4397-9dbb-9b2b20218538. | |
| 59 """ | |
| 60 parts = email.split('@') | |
| 61 return '@'.join(parts[0:2]) | |
| 62 | |
| 63 | |
| 64 def GetRevertedRevision(message): | |
| 65 """Parse message to get the reverted revision if there is one.""" | |
| 66 lines = message.strip().splitlines() | |
| 67 if not lines[0].lower().startswith('revert'): | |
| 68 return None | |
| 69 | |
| 70 for line in reversed(lines): # pragma: no cover | |
| 71 # TODO: Handle cases where no reverted_revision in reverting message. | |
| 72 reverted_revision_match = REVERTED_REVISION_PATTERN.match(line) | |
| 73 if reverted_revision_match: | |
| 74 return reverted_revision_match.group(1) | |
| OLD | NEW |