-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathreview-o-matic.py
executable file
·62 lines (47 loc) · 1.79 KB
/
review-o-matic.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/python3
import argparse
import logging
import re
import subprocess
import sys
from reviewer import CommitRef
from reviewer import Reviewer
logging.basicConfig(stream=sys.stdout, level=logging.WARNING)
logger = logging.getLogger(__name__)
def review_change(reviewer, local_sha):
local_sha = CommitRef(sha=local_sha)
upstream_sha = reviewer.get_cherry_pick_sha_from_local_sha(local_sha.sha)
upstream_patch = reviewer.get_commit_from_sha(CommitRef(sha=upstream_sha))
local_patch = reviewer.get_commit_from_sha(local_sha)
result = reviewer.compare_diffs(upstream_patch, local_patch)
if reviewer.verbose or reviewer.chatty or len(result):
logger.info('Reviewing %s (rmt=%s)' % (local_sha.sha, upstream_sha[:11]))
for l in result:
logger.info(l)
if len(result):
logger.info('')
return len(result)
def main():
parser = argparse.ArgumentParser(description='Auto review UPSTREAM patches')
parser.add_argument('--start', help='commit hash to start from',
required=True)
parser.add_argument('--prefix', default='UPSTREAM', help='subject prefix')
parser.add_argument('--verbose', help='print commits', action='store_true')
parser.add_argument('--chatty', help='print diffs', action='store_true')
args = parser.parse_args()
if args.verbose or args.chatty:
logger.setLevel(logging.DEBUG)
proc = subprocess.check_output(
['git', 'log', '--oneline', '%s^..' % args.start])
regex = re.compile('([0-9a-f]*) (%s): ' % (args.prefix), flags=re.I)
ret = 0
reviewer = Reviewer(args.verbose, args.chatty)
for l in reversed(proc.decode('UTF-8').split('\n')):
this_ret = 0
m = regex.match(l)
if m:
this_ret = review_change(reviewer, m.group(1))
ret += this_ret
return ret
if __name__ == '__main__':
sys.exit(main())