| 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 import json | 5 import json |
| 6 import re | 6 import re |
| 7 import subprocess |
| 7 import urllib2 | 8 import urllib2 |
| 8 | 9 |
| 9 CODE_REVIEW_URL_PATTERN = re.compile( | 10 CODE_REVIEW_URL_PATTERN = re.compile( |
| 10 '^(?:Review URL|Review-Url): (.*\d+).*$', re.IGNORECASE) | 11 '^(?:Review URL|Review-Url): (.*\d+).*$', re.IGNORECASE) |
| 11 COMMIT_POSITION_PATTERN = re.compile( | 12 COMMIT_POSITION_PATTERN = re.compile( |
| 12 '^Cr-Commit-Position: refs/heads/master@{#(\d+)}$', re.IGNORECASE) | 13 '^Cr-Commit-Position: refs/heads/master@{#(\d+)}$', re.IGNORECASE) |
| 13 REVERTED_REVISION_PATTERN = re.compile( | 14 REVERTED_REVISION_PATTERN = re.compile( |
| 14 '^> Committed: https://.+/([0-9a-fA-F]{40})$', re.IGNORECASE) | 15 '^> Committed: https://.+/([0-9a-fA-F]{40})$', re.IGNORECASE) |
| 15 COMMIT_POSITION_CODE_REVIEW_URL_PARSING_START_LINE = -5 | 16 COMMIT_POSITION_CODE_REVIEW_URL_PARSING_START_LINE = -5 |
| 16 | 17 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 """Parse message to get the reverted revision if there is one.""" | 66 """Parse message to get the reverted revision if there is one.""" |
| 66 lines = message.strip().splitlines() | 67 lines = message.strip().splitlines() |
| 67 if not lines[0].lower().startswith('revert'): | 68 if not lines[0].lower().startswith('revert'): |
| 68 return None | 69 return None |
| 69 | 70 |
| 70 for line in reversed(lines): # pragma: no cover | 71 for line in reversed(lines): # pragma: no cover |
| 71 # TODO: Handle cases where no reverted_revision in reverting message. | 72 # TODO: Handle cases where no reverted_revision in reverting message. |
| 72 reverted_revision_match = REVERTED_REVISION_PATTERN.match(line) | 73 reverted_revision_match = REVERTED_REVISION_PATTERN.match(line) |
| 73 if reverted_revision_match: | 74 if reverted_revision_match: |
| 74 return reverted_revision_match.group(1) | 75 return reverted_revision_match.group(1) |
| 76 |
| 77 |
| 78 # TODO(katesonia): Add local cache for this function. |
| 79 def GetCommandOutput(command): |
| 80 """Gets the output stream of executable command. |
| 81 |
| 82 Args: |
| 83 command (str): Command to execute to get output. |
| 84 |
| 85 Return: |
| 86 Output steam of the command. |
| 87 """ |
| 88 p = subprocess.Popen( |
| 89 command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=True) |
| 90 return p.communicate()[0] |
| OLD | NEW |