-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathparse-maintainer.py
More file actions
executable file
·160 lines (140 loc) · 4.93 KB
/
parse-maintainer.py
File metadata and controls
executable file
·160 lines (140 loc) · 4.93 KB
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
#!/usr/bin/env python3
"""Convert maintainer issue markdown to JSON"""
import os
import sys
import json
import re
import subprocess
from datetime import datetime
from pathlib import Path
REQUIRED_QUESTIONS = [
"How to support",
"A small brief about your project",
"One FOSS maintainer lesson for your younger self",
"Why do you do it? Why do you bother maintaining a FOSS project?",
"If your repo had a theme song, what would it be?",
"Which file in your project would you most like to set on fire?",
"What's your open-source villain origin story?",
"If you had to use one emoji to convey what it is like to be a FOSS maintainer, what would it be?",
]
LABEL_MAP = {
"github": "GitHub",
"Github": "GitHub",
"gitlab": "GitLab",
"Gitlab": "GitLab",
"codeberg": "Codeberg",
"bitbucket": "BitBucket",
"Bitbucket": "BitBucket",
"linkedin": "LinkedIn",
"Linkedin": "LinkedIn",
"mastodon": "Mastodon",
"bluesky": "Bluesky",
"substack": "Substack",
"discourse": "Discourse",
"twitter": "Twitter",
"email": "Email",
"mail": "Email",
"Mail": "Email",
"rss": "RSS",
"web": "Web",
"website": "Web",
"Website": "Web",
"blog": "Web",
"Blog": "Web",
"x": "X",
"X/Twitter": "X",
"Twitter/X": "X",
"reddit": "Reddit",
"medium": "Medium",
"youtube": "Youtube",
"YouTube": "Youtube",
}
def parse_issue(md):
md = re.sub(r"<!--.*?-->", "", md, flags=re.DOTALL)
data = {
"username": "",
"full_name": "",
"photo": "",
"designation": "",
"socials": [],
"projects": [],
"form": [],
"created_on": datetime.now().astimezone().isoformat(),
}
for field in ["username", "full_name", "photo", "designation"]:
m = re.search(
rf"\*\*{field}:\*\*\s*(.+?)(?=\n\*\*|\n---|\Z)",
md,
re.IGNORECASE | re.DOTALL,
)
if m:
data[field] = m.group(1).strip()
socials_m = re.search(r"\*\*socials:\*\*\s*\n((?:^- .+\n?)+)", md, re.MULTILINE)
if socials_m:
for line in socials_m.group(1).strip().split("\n"):
if ":" in line:
line = line.lstrip("- ").strip()
label, link = line.split(":", 1)
label = label.strip()
normalized = LABEL_MAP.get(label, label)
data["socials"].append({"label": normalized, "link": link.strip()})
for block in re.findall(
r"\*\*project:\*\*\s*\n((?:^- .+(?:\n(?: .+)?)*\n?)+)", md, re.MULTILINE
):
project = {
"name": "",
"project_link": "",
"website_link": "",
"logo": "",
"short_description": "",
"description": "",
}
for field in project:
m = re.search(
rf"^- {field}:\s*(.+?)(?=\n- |\Z)", block, re.MULTILINE | re.DOTALL
)
if m:
value = re.sub(r"\n\s{4}", "\n", m.group(1).strip())
project[field] = value.strip()
if project["name"]:
data["projects"].append(project)
questions_m = re.search(r"## Questions(.+)", md, re.DOTALL)
if questions_m:
parsed = {}
for q, r in re.findall(
r"\*\*(.+?):\*\*\s*\n(.+?)(?=\n\*\*|\Z)", questions_m.group(1), re.DOTALL
):
parsed[q.strip().rstrip(":")] = r.rstrip("\n").replace("\n", "<br>")
for req_q in REQUIRED_QUESTIONS:
if req_q not in parsed:
print(f"Warning: Missing question: '{req_q}'", file=sys.stderr)
data["form"].append({"question": req_q, "response": parsed.get(req_q, "")})
return data
if __name__ == "__main__":
if os.getenv("CI") == "true":
sys.exit(0)
if len(sys.argv) < 2 or sys.argv[1] == "--help":
print("Usage: python parse-maintainer.py <input.md>")
sys.exit(1)
md = Path(sys.argv[1]).read_text(encoding="utf-8")
result = parse_issue(md)
username = result.get("username") or "output"
output_file = f"content/maintainers/{username}.json"
json_output = json.dumps(result, indent=2, ensure_ascii=False)
Path(output_file).write_text(json_output + "\n", encoding="utf-8")
print(json_output)
try:
subprocess.run(
["check-jsonschema", "--schemafile", "maintainer.schema.json", output_file],
check=True,
)
print(f"✓ Validation passed. Saved to {output_file}", file=sys.stderr)
except subprocess.CalledProcessError:
print("✗ Validation failed. Fix errors above and re-run.", file=sys.stderr)
sys.exit(1)
except FileNotFoundError:
print("[WARN] check-jsonschema not found, skipping validation", file=sys.stderr)
try:
subprocess.run(["python3", "sync-image.py", f"{username}.json"], check=True)
except subprocess.CalledProcessError as e:
print(f"[WARN] Image sync failed: {e}", file=sys.stderr)