forked from marxin/script-misc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
find-missing-bz-commits.py
executable file
·59 lines (51 loc) · 2.05 KB
/
find-missing-bz-commits.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
#!/usr/bin/env python3
import requests
import json
import argparse
import subprocess
import re
import sys
import xmltodict
base_url = 'https://gcc.gnu.org/bugzilla/rest.cgi/'
pr_regex = re.compile('PR\ (.*)\/([0-9]+)')
def find_prs(message):
for line in message.split('\n'):
m = pr_regex.search(line)
if m:
yield m.group(2)
def get_commits_from_comments(pr):
sys.stderr.write('... get ' + pr + '\n')
r = requests.get('https://gcc.gnu.org/bugzilla/show_bug.cgi?id=%s&ctype=xml' % pr)
data = xmltodict.parse(r.text)
comments = data['bugzilla']['bug']['long_desc']
if type(comments) == list:
for comment in comments:
text = comment['thetext']
for l in text.split('\n'):
l = l.rstrip()
if l.startswith('commit '):
yield l
commits = {}
branches = ['origin/releases/gcc-8', 'origin/releases/gcc-9', 'origin/master']
for b in branches:
r = subprocess.check_output('git log %s --since=2020-03-10 --oneline --pretty=tformat:"%%H"' % b, shell = True, encoding = 'utf')
for hash in r.strip().split('\n'):
commits[hash] = subprocess.check_output('git log --format=medium -n 1 ' + hash, shell = True, encoding = 'utf8').strip()
items = commits.items()
counter = 0
for hash, message in items:
counter += 1
sys.stderr.write('%d/%d\n' % (counter, len(items)))
prs = list(sorted(list(set(find_prs(message)))))
if prs:
for pr in prs:
descr = subprocess.check_output('git gcc-descr --full ' + hash, shell = True, encoding = 'utf8').strip()
needle = 'commit ' + descr
needle2 = 'commit ' + hash
comment_commits = set(get_commits_from_comments(pr))
if not needle in comment_commits and not needle2 in comment_commits:
print('https://gcc.gnu.org/bugzilla/show_bug.cgi?id=%s' % pr)
message_lines = message.split('\n')
message_lines[0] = needle
message = '\n'.join(message_lines)
print(message)