]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blob - debian/scripts/misc/git-ubuntu-log
490ecce73c484e098c2b3bf7ea8875ab28f09e9f
[mirror_ubuntu-bionic-kernel.git] / debian / scripts / misc / git-ubuntu-log
1 #!/usr/bin/python3
2
3 import os
4 import sys
5
6 import codecs
7 import urllib.request
8 import json
9
10 import textwrap
11
12 sys.stdin = codecs.getreader("utf-8")(sys.stdin.detach())
13 sys.stdout = codecs.getwriter("utf-8")(sys.stdout.detach())
14
15 entries = []
16 def add_entry(entry):
17 if entry and 'ignore' not in entry:
18 combo = []
19 for bug in entry.get('bugs', []):
20 combo.append(bug)
21 for cve in entry.get('cves', []):
22 combo.append(cve)
23 combo = sorted(combo)
24
25 if len(combo) == 0:
26 if entry.get('subject', "").startswith('UBUNTU'):
27 combo = '__packaging__'
28 else:
29 combo = '__mainline__'
30 else:
31 if combo not in keys:
32 keys.append(combo)
33
34 entry['key'] = combo
35 entries.append(entry)
36
37
38 # Suck up the git log output and extract the information we need.
39 keys = []
40 entry = None
41 subject_wait = False
42 for line in sys.stdin:
43 if line.startswith('commit '):
44 add_entry(entry)
45 entry = {}
46 subject_wait = True
47
48 elif line.startswith('Author: '):
49 bits = line.strip().split(maxsplit=1)
50 entry['author'] = bits[1]
51
52 elif subject_wait and line.startswith(' '):
53 subject_wait = False
54 entry['subject'] = line.strip()
55
56 elif line.startswith(' BugLink: ') and 'launchpad.net' in line:
57 bits = line.strip().split(maxsplit=1)
58 bits = bits[1].split('/')
59 entry.setdefault('bugs', []).append(bits[-1])
60
61 elif line.startswith(' CVE-'):
62 entry.setdefault('cves', []).append(line.strip())
63
64 elif line.startswith(' Ignore:'):
65 entry['ignore'] = True
66
67 add_entry(entry)
68
69 entries.reverse()
70
71 # Go through the entries and clear out authors for upstream commits.
72 for entry in entries:
73 if entry['subject'].startswith('UBUNTU:'):
74 entry['subject'] = entry['subject'][7:].strip()
75 else:
76 del entry['author']
77
78 # Lump everything without a bug at the bottom.
79 keys.append('__packaging__')
80 keys.append('__mainline__')
81
82 emit_nl = False
83 for key in keys:
84 if key == '__packaging__':
85 title_set = [ 'Miscellaneous Ubuntu changes' ]
86 elif key == '__mainline__':
87 title_set = [ 'Miscellaneous upstream changes' ]
88 else:
89 title_set = []
90 for bug in key:
91 if bug.startswith('CVE-'):
92 title_set.append(bug)
93 else:
94 bug_info = None
95
96 try:
97 #urllib.request.urlcleanup()
98 request = urllib.request.Request('https://api.launchpad.net/devel/bugs/' + bug)
99 request.add_header('Cache-Control', 'max-age=0')
100 with urllib.request.urlopen(request) as response:
101 data = response.read()
102 bug_info = json.loads(data.decode('utf-8'))
103
104 title = bug_info['title']
105 if 'description' in bug_info:
106 for line in bug_info['description'].split('\n'):
107 if line.startswith('Kernel-Description:'):
108 title = line.split(' ', 1)[1]
109
110 except urllib.error.HTTPError:
111 title = 'INVALID or PRIVATE BUG'
112
113 title += ' (LP###' + bug + ')'
114 title_set.append(title)
115
116
117 emit_title = True
118 for entry in entries:
119 if entry['key'] != key:
120 continue
121
122 if emit_title:
123 if emit_nl:
124 print('')
125 emit_nl = True
126
127 title_lines = textwrap.wrap('#// '.join(title_set), 76)
128 print(' * ' + title_lines[0].replace('LP###', 'LP: #').replace('#//', ' //'))
129 for line in title_lines[1:]:
130 line = line.replace('LP###', 'LP: #').replace('#//', ' //')
131 print(' ' + line)
132
133 emit_title = False
134
135 title_lines = textwrap.wrap(entry['subject'], 76)
136 print(' - ' + title_lines[0])
137 for line in title_lines[1:]:
138 line = line.replace('LP###', 'LP: #')
139 print(' ' + line)