forked from WeblateOrg/meta
-
Notifications
You must be signed in to change notification settings - Fork 0
/
update-issue-config
executable file
·42 lines (30 loc) · 1.02 KB
/
update-issue-config
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
#!/usr/bin/env python3
"""Synchronizes GitHub issue template links for Weblate repositories."""
import os
import sys
import ruamel.yaml
root = sys.argv[1]
yaml = ruamel.yaml.YAML()
filename = ".github/ISSUE_TEMPLATE/config.yml"
sourcename = os.path.join(root, filename)
dirname = os.path.dirname(filename)
if not os.path.exists(dirname):
os.makedirs(dirname)
with open(sourcename, "r") as handle:
template = yaml.load(handle)
links = {link["url"]: link for link in template["contact_links"]}
try:
with open(filename, "r") as handle:
data = yaml.load(handle)
except IOError:
with open(sourcename, "r") as handle:
data = yaml.load(handle)
if "contact_links" not in data:
data["contact_links"] = []
for pos, item in enumerate(data["contact_links"]):
if item["url"] in links:
data["contact_links"][pos] = links.pop(item["url"])
data["contact_links"].extend(links.values())
with open(filename, "w") as handle:
yaml.indent(mapping=2, sequence=4, offset=2)
yaml.dump(data, handle)