| OLD | NEW |
| 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 Loading... |
| 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().split('@')[0] 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 21 matching lines...) Expand all Loading... |
| 105 def get_features_for_commit_people(git_commit): | 112 def get_features_for_commit_people(git_commit): |
| 106 """Retrieves the people associated with a git commit | 113 """Retrieves the people associated with a git commit |
| 107 | 114 |
| 108 Arg: | 115 Arg: |
| 109 git_commit(dict): a commit message parsed into a dictionary | 116 git_commit(dict): a commit message parsed into a dictionary |
| 110 | 117 |
| 111 Return: | 118 Return: |
| 112 (tuple): relevant people and type extracted from the commit | 119 (tuple): relevant people and type extracted from the commit |
| 113 """ | 120 """ |
| 114 git_hash = git_commit['id'] | 121 git_hash = git_commit['id'] |
| 115 author = git_commit['author'] | 122 author = git_commit['author'].split('@')[0] |
| 116 people_rows = [(author, git_hash, curr_time, 'author')] | 123 people_rows = [(author, git_hash, curr_time, 'author')] |
| 117 TBR = None | 124 TBR = None |
| 118 for line in git_commit['body'].split('\n'): | 125 for line in git_commit['body'].split('\n'): |
| 119 TBR = get_tbr(line) or TBR | 126 TBR = get_tbr(line) or TBR |
| 120 if TBR is not None: | 127 if TBR is not None: |
| 121 for person in TBR: | 128 for person in TBR: |
| 122 people_rows.append((person, git_hash, curr_time, 'tbr')) | 129 people_rows.append((person, git_hash, curr_time, 'tbr')) |
| 123 return people_rows | 130 return people_rows |
| 124 | 131 |
| 125 | 132 |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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] |
| OLD | NEW |