Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(26)

Side by Side Diff: appengine/findit/lib/gitiles/commit_util.py

Issue 2538373003: [Culprit-Finder] Merge lib/ to libs/. (Closed)
Patch Set: . Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « appengine/findit/lib/gitiles/change_log.py ('k') | appengine/findit/lib/gitiles/diff.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 re
6
7 CODE_REVIEW_URL_PATTERN = re.compile(
8 '^(?:Review URL|Review-Url): (.*\d+).*$', re.IGNORECASE)
9 COMMIT_POSITION_PATTERN = re.compile(
10 '^Cr-Commit-Position: refs/heads/master@{#(\d+)}$', re.IGNORECASE)
11 REVERTED_REVISION_PATTERN = re.compile(
12 '^> Committed: https://.+/([0-9a-fA-F]{40})$', re.IGNORECASE)
13 START_OF_CR_COMMIT_POSITION = -5
14
15
16 def ExtractCommitPositionAndCodeReviewUrl(message):
17 """Returns the commit position and code review url in the commit message.
18
19 A "commit position" is something similar to SVN version ids; i.e.,
20 numeric identifiers which are issued in sequential order. The reason
21 we care about them is that they're easier for humans to read than
22 the hashes that Git uses internally for identifying commits. We
23 should never actually use them for *identifying* commits; they're
24 only for pretty printing to humans.
25
26 Returns:
27 (commit_position, code_review_url)
28 """
29 if not message:
30 return (None, None)
31
32 commit_position = None
33 code_review_url = None
34
35 # Commit position and code review url are in the last 5 lines.
36 lines = message.strip().split('\n')[START_OF_CR_COMMIT_POSITION:]
37 lines.reverse()
38
39 for line in lines:
40 if commit_position is None:
41 match = COMMIT_POSITION_PATTERN.match(line)
42 if match:
43 commit_position = int(match.group(1))
44
45 if code_review_url is None:
46 match = CODE_REVIEW_URL_PATTERN.match(line)
47 if match:
48 code_review_url = match.group(1)
49 return (commit_position, code_review_url)
50
51
52 def NormalizeEmail(email):
53 """Normalizes the email from git repo.
54
55 Some email is like: test@chromium.org@bbb929c8-8fbe-4397-9dbb-9b2b20218538.
56 """
57 parts = email.split('@')
58 return '@'.join(parts[0:2])
59
60
61 def GetRevertedRevision(message):
62 """Parse message to get the reverted revision if there is one."""
63 lines = message.strip().splitlines()
64 if not lines[0].lower().startswith('revert'):
65 return None
66
67 for line in reversed(lines): # pragma: no cover
68 # TODO: Handle cases where no reverted_revision in reverting message.
69 reverted_revision_match = REVERTED_REVISION_PATTERN.match(line)
70 if reverted_revision_match:
71 return reverted_revision_match.group(1)
OLDNEW
« no previous file with comments | « appengine/findit/lib/gitiles/change_log.py ('k') | appengine/findit/lib/gitiles/diff.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698