-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmake_project_table.py
133 lines (106 loc) · 5.01 KB
/
make_project_table.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
"""
Make the Project Plan table by accessing GitHub issue/PR information.
Requires python 3.4+ and pygithub to be installed.
"""
from github import Github
import re
import os
import sys
table_header = """Status | # | Simulator(s) | Sim. Components | Analysis Components | Assigned |
-----------| -----|--------------|-----------------|---------------------|----------|
"""
if __name__=="__main__":
if len(sys.argv) > 1:
GH_TOKEN = sys.argv[-1]
else:
if not os.path.exists(os.path.expanduser('~/.validation-github-token')):
raise ValueError(
"You do not yet have a personal access token for github installed. Create one at "
"https://github.com/settings/tokens "
"and paste it into the file ~/.validation-github-token.")
with open(os.path.expanduser("~/.validation-github-token")) as fl:
GH_TOKEN = fl.read()
g = Github(GH_TOKEN)
repo = g.get_repo("HERA-Team/hera-validation")
projects = repo.get_projects()
# issues = repo.get_issues(state='all')
# prs = repo.get_pulls(state='all')
#
# # Isolate issues/prs that define formal tests/steps
# steps = [issue for issue in everything if "formal-test" in [lbl.name for lbl in issue.labels]]
#
# everything = [issue for issue in issues] + [pr for pr in prs]
# This finds anything with the pattern X.X.X in a string (i.e. the STEP.MAJOR part of a
# step identifier)
step_number_pattern = re.compile(r"(-?\d+(\.\d+){0,2})")
tables = """## Project Plan
Here follows a formal plan for envisaged tests, automatically generated from our Projects.
This list is *not final*: it may be extended or
modified at any time. However, it provides a reasonable snapshot of the current status and plans of
the validation team.
What the symbols mean:
Sym. | Meaning | Sym. | Meaning | Sym. |Meaning
-------| ----- | ----- | ---- | ----- | ------
:egg: | Idea in gestation | :hammer: | Currently being worked on | :thinking: | PR submitted...
:heavy_check_mark: | Passed | :x: | Failed | :watch: | Not required for H1C IDR2
"""
for proj in sorted(projects, key=lambda p: p.name):
cols = proj.get_columns()
steps = sum([list(col.get_cards()) for col in cols], [])
steps = [step.get_content() for step in steps]
step_dict = {}
for step in steps:
if step.__class__.__name__ not in ["Issue", "PullRequest"]:
print("card ", step, " has class", step.__class__.__name__)
continue
# get status
if step.milestone is None or step.milestone.title != "H1C IDR2":
status = ":egg:"
status_num = 0
elif step.__class__.__name__ == "Issue" and step.state == 'open':
status = ":hammer:"
status_num = 1
elif step.__class__.__name__ == "PullRequest" and step.state == "open":
status = ":thinking:"
status_num = 2
elif step.state == "closed":
status = ":heavy_check_mark:"
status_num = 3
else:
raise ValueError("status not recognized for ", step)
# Get step number
step_number = step_number_pattern.search(step.title).group()
major_step = ".".join(step_number.split(".")[:2]) # only up to X.X
description = step.title.split(step_number)[-1].split(":")[-1].split('--')[-1]
if description:
description = ": " + description
# Get title
title = f"[{major_step}]({step.url})"
# Get simulators used
labels = step.labels
sims = ", ".join([lbl.name.split(":")[-1] for lbl in labels if lbl.name.split(":")[0] == 'simulator'])
simcmp = ", ".join([lbl.name.split(":")[-1] for lbl in labels if lbl.name.split(":")[0] == 'simcmp'])
anlcmp = ", ".join([lbl.name.split(":")[-1] for lbl in labels if lbl.name.split(":")[0] == 'pipeline'])
assigned = ", ".join([f"[@{assgn.login}]({assgn.url})" for assgn in step.assignees])
if major_step in step_dict:
if status_num <= step_dict[major_step]['status_num']:
continue
step_dict[major_step] = dict(
status = status,
title = title,
description=description,
sims = sims,
simcmp = simcmp,
anlcmp = anlcmp,
assigned = assigned,
status_num = status_num
)
tables += f"### [{proj.name}]({proj.url})\n"
tables += f"{proj.body}\n\n"
tables += table_header
for major_step in sorted(step_dict.keys()):
d = step_dict[major_step]
tables += f"{d['status']} | {d['title']}{d['description']} | {d['sims']} | {d['simcmp']} | {d['anlcmp']} | {d['assigned']} |\n"
tables += "\n\n"
with open("project_table.md", 'w') as fl:
fl.write(tables)