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