| OLD | NEW |
| (Empty) | |
| 1 #!/usr/bin/env python |
| 2 # Copyright 2017 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. |
| 5 |
| 6 from __future__ import print_function |
| 7 |
| 8 |
| 9 import argparse |
| 10 import json |
| 11 import os |
| 12 import subprocess |
| 13 import string |
| 14 import sys |
| 15 import urllib2 |
| 16 |
| 17 |
| 18 def main(argv): |
| 19 parser = argparse.ArgumentParser() |
| 20 parser.add_argument('revisions', action='store') |
| 21 args = parser.parse_args(argv) |
| 22 |
| 23 # From ipc/SECURITY_OWNERS |
| 24 security_owners = ['dcheng@chromium.org', |
| 25 'jln@chromium.org', |
| 26 'kenrb@chromium.org', |
| 27 'meacer@chromium.org', |
| 28 'mbarbella@chromium.org', |
| 29 'mkwst@chromium.org', |
| 30 'nasko@chromium.org', |
| 31 'ochang@chromium.org', |
| 32 'palmer@chromium.org', |
| 33 'rickyz@chromium.org', |
| 34 'rsesek@chromium.org', |
| 35 'tsepez@chromium.org', |
| 36 'wfh@chromium.org',] |
| 37 |
| 38 try: |
| 39 affected_revisions = git_log(args.revisions) |
| 40 print("There are %d affected revisions." % len(affected_revisions)) |
| 41 |
| 42 affected_cls = cls_from_revisions(affected_revisions) |
| 43 print("There are %d potentially affected CLs." % len(affected_cls)) |
| 44 for cl in affected_cls: |
| 45 issue = rietveld_props_for_issue(cl) |
| 46 approvers = rietveld_approvers(issue) |
| 47 has_security_reviewer = reduce(lambda x,y: x or (y in security_owners), ap
provers, False) |
| 48 if not has_security_reviewer: |
| 49 print('http://codereview.chromium.org/%d (approvers:%s)' % (cl, ", ".joi
n(approvers))) |
| 50 |
| 51 #props = rietveld_props_for_issue(args.issue) |
| 52 #for approver in rietveld_approvers_for_issue(args.issue): |
| 53 # print(approver) |
| 54 #return 0 |
| 55 except Exception as e: |
| 56 print('Exception raised: %s' % str(e), file=sys.stderr) |
| 57 return 1 |
| 58 |
| 59 |
| 60 def git(args): |
| 61 command = subprocess.Popen(['/usr/bin/git'] + args, stdout=subprocess.PIPE, st
derr=subprocess.PIPE) |
| 62 output = command.stdout.readlines() |
| 63 if command.stderr.read(): |
| 64 raise Exception("git failed: (" + repr(args) + ")") |
| 65 return output |
| 66 |
| 67 |
| 68 def git_show_raw(revision): |
| 69 return git(['show', '--format=raw', '--name-only', revision]) |
| 70 |
| 71 |
| 72 def cls_from_revisions(affected_revisions): |
| 73 affected_cls = set() |
| 74 for revision in affected_revisions: |
| 75 revision_cls = set() |
| 76 lines = git_show_raw(revision) |
| 77 while lines and lines[0].rstrip() and lines[0][0] not in string.whitespace: |
| 78 line, lines = lines[0], lines[1:] |
| 79 while lines and lines[0] and lines[0][0] in string.whitespace: |
| 80 line, lines = lines[0].strip(), lines[1:] |
| 81 if line[:11] == 'Review-Url:': |
| 82 cl_url_parts = line[11:].strip().split('/') |
| 83 if cl_url_parts[0] != 'https:' or cl_url_parts[1] != '': |
| 84 raise Exception("Strange CL URL format: " + repr(cl_url_parts)) |
| 85 revision_cls.add(int(cl_url_parts[3].split()[0])) |
| 86 while lines: |
| 87 line, lines = lines[0].strip(), lines[1:] |
| 88 if line[-6:] == '.mojom': |
| 89 affected_cls |= revision_cls |
| 90 return sorted(list(affected_cls)) |
| 91 |
| 92 # if ( |
| 93 # lines = map(lambda x: x.strip(), git_show_raw(revision)) |
| 94 # lines = filter(lambda x: x[:44] == 'Review-Url: https://codereview.chromiu
m.org/', lines) |
| 95 # if not lines: |
| 96 # raise "revision %s has no CL!" % revision |
| 97 # for line in lines: |
| 98 # cl = int(line[44:]) |
| 99 # affected_cls.add(cl) |
| 100 # return sorted(list(affected_cls)) |
| 101 |
| 102 |
| 103 def git_log(revisions): |
| 104 return map(lambda x: x.split()[0], |
| 105 git(['log', '--format=oneline', revisions])) |
| 106 |
| 107 |
| 108 def rietveld_props_for_issue(issue): |
| 109 """Returns a dictionary of properties, including messages, for the issue.""" |
| 110 |
| 111 url = 'https://codereview.chromium.org/api/%d?messages=true' % issue |
| 112 fp = None |
| 113 try: |
| 114 fp = urllib2.urlopen(url) |
| 115 return json.load(fp) |
| 116 finally: |
| 117 if fp: |
| 118 fp.close() |
| 119 |
| 120 |
| 121 def rietveld_approvers(props): |
| 122 """Returns a sorted list of the approvers, from an issue's props.""" |
| 123 messages = props.get('messages', []) |
| 124 return sorted(set(m['sender'] for m in messages if m.get('approval'))) |
| 125 |
| 126 |
| 127 if __name__ == '__main__': |
| 128 sys.exit(main(sys.argv[1:])) |
| OLD | NEW |