-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathgenerate_issue_template.py
43 lines (37 loc) · 1.52 KB
/
generate_issue_template.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
"""
The script is to generate the YAML file
which helps GitHub to generate a issue template
for CEFI resource contribution.
"""
import yaml
import generate_readme
# read source json file (data type definition)
cefi_data = generate_readme.get_cefi_list()
# read the title part of the issue template
ISSUE_TEMP = ".github/ISSUE_TEMPLATE/header_file/add_cefi_resource_head.yml"
with open(ISSUE_TEMP,'r',encoding='utf8') as f:
issue_temp_head = yaml.load(f,Loader=yaml.loader.SafeLoader)
# solve the unique name issue in ISSUE_TEMPLATE
issue_temp_head['name'] = 'Contribute to the CEFI resource list'
# loop over all categories (variable is skipped at the moment)
for cat in cefi_data['categories_definition'].keys():
if cat != 'cvar':
options = [f"{nt-1}-{text}" for nt,text in enumerate(cefi_data['categories_definition'][cat].values())]
elif cat == 'cvar':
options = [f"{nt-1}-{list[0]}" for nt,list in enumerate(cefi_data['categories_definition'][cat].values())]
issue_temp_head['body'].append({
'type': 'dropdown',
'id': cat,
'attributes': {
'label': cefi_data['categories_definition'][cat]['name'],
'multiple': True,
'options': options[1:] # skip key name = 'name'
},
'validations': {
'required': True
}
})
# output yml file
OUT_FNAME = '.github/ISSUE_TEMPLATE/add_cefi_resource.yml'
with open(OUT_FNAME, 'w',encoding='utf8') as f:
data = yaml.dump(issue_temp_head, f, sort_keys=False, default_flow_style=False)