-
Notifications
You must be signed in to change notification settings - Fork 23
/
summary.py
executable file
·201 lines (175 loc) · 5.94 KB
/
summary.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
#!/usr/bin/env python
import argparse, json, os, requests
# Utilities
def write_json(filename, data):
with open(filename, "w") as f:
json.dump(data, f, indent=2, separators=(",", ": "))
f.write("\n")
# General processing
def process(issues):
summary = []
for issue in issues:
if is_ignorable_issue(issue):
continue
summary_item = {"id": issue["html_url"]}
summary_item.update(process_labels(issue["labels"]))
summary_item.update(process_body(issue))
summary.append(summary_item)
write_json("summary.json", summary)
def is_ignorable_issue(issue):
if "pull_request" in issue:
return True
for label in issue["labels"]:
if label["name"] in ("duplicate", "invalid", "meta", "proposal withdrawn"):
return True
return False
def process_labels(labels):
position = None
venues = []
concerns = []
topics = []
for label in labels:
# Position
if label["name"] == "blocked":
assert position is None
position = "blocked"
elif label["name"].startswith("position: "):
assert position is None
position = label["name"][len("position: ") :]
# Venue
elif label["name"] == "venue: AOM":
venues.append("AOM")
elif label["name"] == "venue: Ecma TC39":
venues.append("TC39")
elif label["name"].startswith("venue: IETF"):
venues.append("IETF")
elif label["name"].startswith("venue: WHATWG"):
venues.append("WHATWG")
elif label["name"].startswith("venue: W3C"):
venues.append("W3C")
elif label["name"].startswith("venue: "):
venues.append("Other")
# Concerns
elif label["name"].startswith("concerns: "):
concerns.append(label["name"][len("concerns: ") :])
# Topics
elif label["name"].startswith("topic: "):
topics.append(label["name"][len("topic: ") :])
return {
"position": position,
"venues": list(dict.fromkeys(venues)),
"concerns": concerns,
"topics": topics,
}
def process_body(issue):
lines = issue["body"].splitlines()
body = {
"title": None,
"url": None,
"github": None,
"issues": None,
"explainer": None,
"tag": None,
"mozilla": None,
"bugzilla": None,
"radar": None,
}
legacy_mapping = {
"Spec Title": "title",
"Title": "title",
"Spec URL": "url",
"URL": "url",
"GitHub repository": "github",
"Issue Tracker (if not the repository's issue tracker)": "issues",
"Explainer (if not README.md in the repository)": "explainer",
"TAG Design Review": "tag",
"Mozilla standards-positions issue": "mozilla",
"WebKit Bugzilla": "bugzilla",
"Radar": "radar",
}
yaml_mapping = {
"Title of the spec": "title",
"Title of the proposal": "title",
"URL to the spec": "url",
"URL to the spec's repository": "github",
"Issue Tracker URL": "issues",
"Explainer URL": "explainer",
"TAG Design Review URL": "tag",
"Mozilla standards-positions issue URL": "mozilla",
"WebKit Bugzilla URL": "bugzilla",
"Radar URL": "radar",
}
# Legacy mapping applies until the YAML change
if issue["number"] < 162:
for line in lines:
for prefix, key in legacy_mapping.items():
text_prefix = f"* {prefix}: "
if line.startswith(text_prefix):
assert body[key] is None
value = line[len(text_prefix) :].strip()
if value:
body[key] = value
else:
expect_response = None
skip = False
for line in lines:
if line == "### Description":
break
for title, key in yaml_mapping.items():
text_title = f"### {title}"
if line == text_title:
expect_response = key
skip = True
break
if skip:
skip = False
continue
if expect_response:
value = line.strip()
if value and value != "_No response_":
body[expect_response] = value
expect_response = None
return body
# Setup
def main():
parser = argparse.ArgumentParser()
parser.add_argument(
"-u",
"--update",
action="store_true",
help="get the latest issue data from GitHub",
)
parser.add_argument("-p", "--process", action="store_true", help="process the data")
args = parser.parse_args()
if args.update:
# GitHub allows us to read issues in increments of 100, called pages. As we don't have more
# than 3 pages we're not optimizing this for now.
data = []
page = 1
while True:
try:
response = requests.get(
f"https://api.github.com/repos/WebKit/standards-positions/issues?direction=asc&state=all&per_page=100&page={page}",
timeout=5,
)
response.raise_for_status()
except Exception:
print("Updated failed, network failure or request timed out.")
exit(1)
temp_data = response.json()
if not temp_data:
break
data.extend(temp_data)
page += 1
write_json("summary-data.json", data)
print("Done, thanks for updating!")
exit(0)
if args.process:
if not os.path.exists("summary-data.json"):
print("Sorry, you have to update first.")
exit(1)
with open("summary-data.json", "rb") as f:
data = json.load(f)
process(data)
if __name__ == "__main__":
main()