forked from whatwg/meta
-
Notifications
You must be signed in to change notification settings - Fork 0
/
review.py
112 lines (87 loc) · 3.97 KB
/
review.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
#!/usr/bin/env python
import argparse, datetime, json, os, subprocess, requests
def fetch_json(url):
return json.loads(requests.get(url).text)
def is_third_monday(d):
return d.weekday() == 0 and 15 <= d.day <= 21
def find_third_monday(d, days=1, limit=10):
i = 0
while not is_third_monday(d):
d = d + datetime.timedelta(days=days)
i += 1
if i > limit:
return None
return i * days
def days_from_third_monday(d):
if d.day < 15:
return find_third_monday(d)
elif d.day > 21:
return find_third_monday(d, -1)
else:
forward = find_third_monday(d)
if not forward:
return find_third_monday(d, -1)
return forward
def find_shortnames(workstreams, month=None):
shortnames = []
for workstream in workstreams:
for standard in workstream["standards"]:
if month and month not in standard["review_draft_schedule"]:
continue
shortnames.append(href_to_shortname(standard["href"]))
return shortnames
def href_to_shortname(href):
return href[len("https://"):href.index(".")]
def maybe_create_prs(shortnames):
for shortname in shortnames:
os.chdir("../{}".format(shortname))
maybe_create_pr(shortname)
os.chdir(".")
def maybe_create_pr(shortname):
subprocess.run(["git", "checkout", "main"], capture_output=True)
commits = subprocess.run(["git", "log", "--format=%s", "--max-count=40"], capture_output=True).stdout
for subject in commits.split(b"\n"):
if subject.startswith(b"Meta:"):
continue
elif subject.startswith(b"Review Draft Publication:"):
print("{} had no non-Meta commits since the last publication".format(shortname))
return
else:
break
today = datetime.datetime.today()
nice_month = today.strftime("%B %Y")
path_month = today.strftime("%Y-%m")
# We should consider merging
# https://github.com/whatwg/whatwg.org/blob/main/resources.whatwg.org/build/review.sh and
# https://github.com/whatwg/html/blob/main/review-draft.sh into this script.
subprocess.run(["make", "review"])
# This is straight from MAINTAINERS.md and needs to be kept in sync with that.
pr_body = """The [{} Review Draft](https://{}.spec.whatwg.org/review-drafts/{}/) for this Workstream will be published shortly after merging this pull request.
Under the [WHATWG IPR Policy](https://whatwg.org/ipr-policy), Participants may, within 45 days after publication of a Review Draft, exclude certain Essential Patent Claims from the Review Draft Licensing Obligations. See the [IPR Policy](https://whatwg.org/ipr-policy) for details.""".format(nice_month, shortname, path_month)
subprocess.run(["gh", "pr", "create", "--title", "Review Draft Publication: {}".format(nice_month), "--body", pr_body])
def main():
parser = argparse.ArgumentParser()
parser.add_argument("--force", dest="force", action="store_true")
args = parser.parse_args()
today = datetime.datetime.today()
ideal_publication_diff = days_from_third_monday(today)
if ideal_publication_diff == 0:
print("Right on, today is the day!")
if not args.force:
if ideal_publication_diff == None:
print("Publication is at least ten days away. Better wait. Use --force to ignore.")
exit(1)
elif ideal_publication_diff > 3:
print("It's still more than 3 days before publication. Use --force to ignore.")
exit(1)
elif ideal_publication_diff < -3:
print("It's 3 days after publication, hopefully you already published. Use --force to ignore.")
exit(1)
db = fetch_json("https://github.com/whatwg/sg/raw/main/db.json")
shortnames = find_shortnames(db["workstreams"], today.month)
if len(shortnames) == 0:
print("Looks like there's nothing to be published this month.")
exit(1)
maybe_create_prs(shortnames)
if __name__ == "__main__":
main()