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

Side by Side Diff: infra/tools/antibody/git_commit_parser.py

Issue 1235373004: Added script to generate stats on a git checkout (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@new_antibody_db_schema
Patch Set: Created 5 years, 5 months 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
OLDNEW
1 # Copyright 2015 The Chromium Authors. All rights reserved. 1 # Copyright 2015 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 datetime 5 import datetime
6 import dateutil.parser 6 import dateutil.parser
7 import pytz 7 import pytz
8 import re 8 import re
9 import subprocess 9 import subprocess
10 10
11 import infra.tools.antibody.cloudsql_connect as csql 11 import infra.tools.antibody.cloudsql_connect as csql
12 12
13 curr_time = datetime.datetime.now() 13 curr_time = datetime.datetime.now()
14 14
15 15
16 def read_commit_info(git_checkout_path, commits_after_date, 16 def read_commit_info(git_checkout_path, commits_after_date,
17 git_log_format=('%H', '%b', '%ae', 17 git_log_format=('%H', '%b', '%ae',
18 '%ci')): # pragma: no cover 18 '%ci')): # pragma: no cover
19 """Read commit messages and other information 19 """Read commit messages and other information
20 20
21 Args: 21 Args:
22 git_checkout_path(str): path to a local git checkout 22 git_checkout_path(str): path to a local git checkout
23 git_log_format(str): formatting directives passed to git log --format 23 git_log_format(str): formatting directives passed to git log --format
24
24 Return: 25 Return:
25 log(str): output of git log 26 log(str): output of git log
26 """ 27 """
27 git_log_format = '%x1f'.join(git_log_format) + '%x1e' 28 git_log_format = '%x1f'.join(git_log_format) + '%x1e'
28 log = subprocess.check_output(['git', 'log', 29 log = subprocess.check_output(['git', 'log',
29 '--format=%s' % git_log_format, '--after=%s' % commits_after_date], 30 '--format=%s' % git_log_format, '--after=%s' % commits_after_date],
30 cwd=git_checkout_path) 31 cwd=git_checkout_path)
31 return log 32 return log
32 33
33 34
(...skipping 24 matching lines...) Expand all
58 or re.match(r'^BUG=https?://crbug.com/(\d+)', git_line) 59 or re.match(r'^BUG=https?://crbug.com/(\d+)', git_line)
59 or re.match(r'^BUG=chromium:(\d+)', git_line) 60 or re.match(r'^BUG=chromium:(\d+)', git_line)
60 or re.match(r'^BUG=(\d+)', git_line)) 61 or re.match(r'^BUG=(\d+)', git_line))
61 if bug_match: 62 if bug_match:
62 bug_url = bug_match.group(1) 63 bug_url = bug_match.group(1)
63 return bug_url 64 return bug_url
64 65
65 66
66 def get_tbr(git_line): 67 def get_tbr(git_line):
67 tbr = None 68 tbr = None
68 if git_line.startswith('TBR=') and len(git_line) > 4: 69 if git_line.startswith('TBR='):
69 tbr = git_line[4:] 70 if len(git_line) > 4:
70 tbr = [x.strip() for x in tbr.split(',')] 71 tbr = git_line[4:]
72 tbr = [x.strip() for x in tbr.split(',')]
73 else:
74 tbr = ['NOBODY']
71 return tbr 75 return tbr
72 76
73 77
78 # TODO(keelerh): figure out how to parse existence of a review url if
79 # not prefaced by any indicator (because review urls for other commits
80 # appear in the commit message frequently for reverts and references)
74 def get_review_url(git_line): 81 def get_review_url(git_line):
75 review_url = None 82 review_url = None
76 if re.match(r'^Review:.+$', git_line): 83 if re.match(r'^Review:.+$', git_line):
77 review_url = git_line[8:] 84 review_url = git_line[8:]
78 elif re.match(r'^Review URL:.+$', git_line): 85 elif re.match(r'^Review URL:.+$', git_line):
79 review_url = git_line[12:] 86 review_url = git_line[12:]
80 elif re.match(r'^Code review URL:.+$', git_line): 87 elif re.match(r'^Code review URL:.+$', git_line):
81 review_url = git_line[17:] 88 review_url = git_line[17:]
82 return review_url 89 return review_url
83 90
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 count(*) as c FROM commit_people WHERE type='tbr' 197 count(*) as c FROM commit_people WHERE type='tbr'
191 GROUP BY git_commit_hash) tbr_count 198 GROUP BY git_commit_hash) tbr_count
192 ON commit_people.git_commit_hash = tbr_count.git_commit_hash 199 ON commit_people.git_commit_hash = tbr_count.git_commit_hash
193 INNER JOIN git_commit 200 INNER JOIN git_commit
194 ON commit_people.git_commit_hash = git_commit.hash 201 ON commit_people.git_commit_hash = git_commit.hash
195 WHERE tbr_count.c <> 0 202 WHERE tbr_count.c <> 0
196 AND git_commit.review_url IS NOT NULL 203 AND git_commit.review_url IS NOT NULL
197 AND commit_people.type='author'""") 204 AND commit_people.type='author'""")
198 commits_with_review_urls = cc.fetchall() 205 commits_with_review_urls = cc.fetchall()
199 return [x[0] for x in commits_with_review_urls] 206 return [x[0] for x in commits_with_review_urls]
OLDNEW
« infra/tools/antibody/compute_stats.py ('K') | « infra/tools/antibody/compute_stats.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698