| OLD | NEW |
| 1 # Copyright 2011 Google Inc. | 1 # Copyright 2011 Google Inc. |
| 2 # | 2 # |
| 3 # Licensed under the Apache License, Version 2.0 (the "License"); | 3 # Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 # you may not use this file except in compliance with the License. | 4 # you may not use this file except in compliance with the License. |
| 5 # You may obtain a copy of the License at | 5 # You may obtain a copy of the License at |
| 6 # | 6 # |
| 7 # http://www.apache.org/licenses/LICENSE-2.0 | 7 # http://www.apache.org/licenses/LICENSE-2.0 |
| 8 # | 8 # |
| 9 # Unless required by applicable law or agreed to in writing, software | 9 # Unless required by applicable law or agreed to in writing, software |
| 10 # distributed under the License is distributed on an "AS IS" BASIS, | 10 # distributed under the License is distributed on an "AS IS" BASIS, |
| 11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 # See the License for the specific language governing permissions and | 12 # See the License for the specific language governing permissions and |
| 13 # limitations under the License. | 13 # limitations under the License. |
| 14 | 14 |
| 15 """Collection of helper functions.""" | 15 """Collection of helper functions.""" |
| 16 | 16 |
| 17 import re |
| 17 import urlparse | 18 import urlparse |
| 18 | 19 |
| 19 from google.appengine.ext import db | 20 from google.appengine.ext import db |
| 20 | 21 |
| 21 from codereview.exceptions import FetchError | 22 from codereview.exceptions import FetchError |
| 22 | 23 |
| 23 | 24 |
| 24 def make_url(base, filename, rev): | 25 def make_url(base, filename, rev): |
| 25 """Helper to construct the URL to fetch. | 26 """Helper to construct the URL to fetch. |
| 26 | 27 |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 def unify_linebreaks(text): | 87 def unify_linebreaks(text): |
| 87 """Helper to return a string with all line breaks converted to LF. | 88 """Helper to return a string with all line breaks converted to LF. |
| 88 | 89 |
| 89 Args: | 90 Args: |
| 90 text: a string. | 91 text: a string. |
| 91 | 92 |
| 92 Returns: | 93 Returns: |
| 93 A string with all line breaks converted to LF. | 94 A string with all line breaks converted to LF. |
| 94 """ | 95 """ |
| 95 return text.replace('\r\n', '\n').replace('\r', '\n') | 96 return text.replace('\r\n', '\n').replace('\r', '\n') |
| 97 |
| 98 |
| 99 _CQ_STATUS_REGEX = re.compile( |
| 100 '(dry run: )?CQ is trying da patch. Follow status at\s+' |
| 101 '(https://.+/patch-status/(.+/)?(\d+)/(\d+))\s*', re.I) |
| 102 |
| 103 |
| 104 def parse_cq_status_url_message(msg): |
| 105 """Returns url, issue, patchset parsed from CQ status message. |
| 106 |
| 107 If parsing failed, returns None, None, None. |
| 108 """ |
| 109 # Example of message, Dry Run prefix is optional. |
| 110 # Dry run: CQ is trying da patch. Follow status at |
| 111 # https://chromium-cq-status.appspot.com/v2/patch-status/codereview.chromium.o
rg/2131593002/1 |
| 112 match = _CQ_STATUS_REGEX.match(msg) |
| 113 if not match: |
| 114 return None, None, None |
| 115 _, url, _, issue, patchset = match.groups() |
| 116 return url, int(issue), int(patchset) |
| OLD | NEW |