]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blob - debian/scripts/misc/git-ubuntu-log
4bf738f8fed1ac3bfdad076637190634bb7b4ddf
[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 entry.get('subject', "") == 'UBUNTU: link-to-tracker: update tracking bug':
32 # Construct a key with '__trackingbug__' on the first position
33 # and the tracking bug number afterwards
34 combo.insert(0, '__trackingbug__')
35 # Tracking bug goes at the top
36 keys.insert(0, combo)
37 else:
38 if combo not in keys:
39 keys.append(combo)
40
41 entry['key'] = combo
42 entries.append(entry)
43
44 # Suck up the git log output and extract the information we need.
45 keys = []
46 entry = None
47 subject_wait = False
48 for line in sys.stdin:
49 if line.startswith('commit '):
50 add_entry(entry)
51 entry = {}
52 subject_wait = True
53
54 elif line.startswith('Author: '):
55 bits = line.strip().split(maxsplit=1)
56 entry['author'] = bits[1]
57
58 elif subject_wait and line.startswith(' '):
59 subject_wait = False
60 entry['subject'] = line.strip()
61
62 elif line.startswith(' BugLink: ') and 'launchpad.net' in line:
63 bits = line.strip().split(maxsplit=1)
64 bits = bits[1].split('/')
65 entry.setdefault('bugs', []).append(bits[-1])
66
67 elif line.startswith(' CVE-'):
68 entry.setdefault('cves', []).append(line.strip())
69
70 elif line.startswith(' Ignore:'):
71 entry['ignore'] = True
72
73 add_entry(entry)
74
75 entries.reverse()
76
77 # Go through the entries and clear out authors for upstream commits.
78 for entry in entries:
79 if entry['subject'].startswith('UBUNTU:'):
80 entry['subject'] = entry['subject'][7:].strip()
81 else:
82 del entry['author']
83
84 # Lump everything without a bug at the bottom.
85 keys.append('__packaging__')
86 keys.append('__mainline__')
87
88 emit_nl = False
89 for key in keys:
90 if key == '__packaging__':
91 title_set = [ 'Miscellaneous Ubuntu changes' ]
92 elif key == '__mainline__':
93 title_set = [ 'Miscellaneous upstream changes' ]
94 else:
95 title_set = []
96 for bug in key:
97 if bug.startswith('CVE-'):
98 title_set.append(bug)
99 elif bug == '__trackingbug__':
100 # Look for the tracking bug number on the second
101 # position of the key
102 continue
103 else:
104 bug_info = None
105
106 try:
107 #urllib.request.urlcleanup()
108 request = urllib.request.Request('https://api.launchpad.net/devel/bugs/' + bug)
109 request.add_header('Cache-Control', 'max-age=0')
110 with urllib.request.urlopen(request) as response:
111 data = response.read()
112 bug_info = json.loads(data.decode('utf-8'))
113
114 title = bug_info['title']
115 if 'description' in bug_info:
116 for line in bug_info['description'].split('\n'):
117 if line.startswith('Kernel-Description:'):
118 title = line.split(' ', 1)[1]
119
120 except urllib.error.HTTPError:
121 title = 'INVALID or PRIVATE BUG'
122
123 title += ' (LP###' + bug + ')'
124 title_set.append(title)
125
126
127 emit_title = True
128 for entry in entries:
129 if entry['key'] != key:
130 continue
131
132 if emit_title:
133 if emit_nl:
134 print('')
135 emit_nl = True
136
137 title_lines = textwrap.wrap('#// '.join(title_set), 76)
138 print(' * ' + title_lines[0].replace('LP###', 'LP: #').replace('#//', ' //'))
139 for line in title_lines[1:]:
140 line = line.replace('LP###', 'LP: #').replace('#//', ' //')
141 print(' ' + line)
142
143 emit_title = False
144
145 if key[0] != '__trackingbug__':
146 title_lines = textwrap.wrap(entry['subject'], 76)
147 print(' - ' + title_lines[0])
148 for line in title_lines[1:]:
149 line = line.replace('LP###', 'LP: #')
150 print(' ' + line)