forked from rms-support-letter/rms-support-letter.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
add-from-issue.py
35 lines (29 loc) · 1.4 KB
/
add-from-issue.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
import subprocess
import os
parts = subprocess.run(["gh", "issue", "view", "837", "-c"], capture_output=True).stdout.split(b"\n--\n")
for info, content in zip(parts[::2], parts[1::2]):
info_dict = {}
for line in info.decode().split("\n"):
key, value = line.split(":\t")
info_dict[key] = value
author = info_dict["author"]
content_lines = [line.strip() for line in content.decode().replace("`", "").strip().split("\n") if line.strip()]
imported = False
for i in range(len(content_lines) - 1):
if content_lines[i].lower().startswith("name:") and content_lines[i + 1].lower().startswith("link:"):
if not os.path.isfile(f"_data/signed/{author}.yaml"):
with open(f"_data/signed/{author}.yaml", "w") as f:
f.write("name:" + content_lines[i][5:] + "\nlink:" + content_lines[i + 1][5:] + "\n")
imported = True
if not imported and len(content_lines) == 2:
name, link = content_lines
if name.lower().startswith("name:"):
name = name[5:]
name = name.strip()
if link.lower().startswith("link:"):
link = link[5:]
link = link.strip()
if "/" in link or "@" in link:
if not os.path.isfile(f"_data/signed/{author}.yaml"):
with open(f"_data/signed/{author}.yaml", "w") as f:
f.write(f"name: {name}\nlink: {link}\n")