Skip to content

Commit 87fa1cd

Browse files
Update extract_contribution_details.py
1 parent 55fd0a2 commit 87fa1cd

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

.github/scripts/extract_contribution_details.py

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,35 +15,37 @@
1515
issues = list(repo.get_issues(state="open", labels=["ambassador"]))
1616
print(f"✅ Found {len(issues)} issues")
1717

18-
# Extract plain text response by label
18+
# Updated extract function that handles markdown code blocks
1919
def extract(label, body):
20-
pattern = rf"{re.escape(label)}\s*\n+(.+?)(\n\S|\Z)"
21-
match = re.search(pattern, body, re.DOTALL)
22-
return match.group(1).strip() if match else ""
20+
# Try to extract content inside markdown code block first
21+
pattern_md = rf"{re.escape(label)}\s*\n+```(?:markdown)?\n(.*?)\n```"
22+
match_md = re.search(pattern_md, body, re.DOTALL)
2323

24-
# Extract checked checkbox lines
25-
def extract_checkboxes(body):
26-
matches = re.findall(r"- \[x\] (.+)", body, re.IGNORECASE)
27-
return "\n".join(f"- [x] {m.strip()}" for m in matches)
24+
if match_md:
25+
return match_md.group(1).strip()
2826

29-
# Build rows
27+
# Fallback to plain text if no code block is found
28+
pattern_txt = rf"{re.escape(label)}\s*\n+(.+?)(\n\S|\Z)"
29+
match_txt = re.search(pattern_txt, body, re.DOTALL)
30+
31+
return match_txt.group(1).strip() if match_txt else ""
32+
33+
# Create output list
3034
output_rows = []
35+
3136
for issue in issues:
3237
body = issue.body or ""
3338
output_rows.append({
3439
"Submission ID": issue.number,
35-
"Contributions": extract_checkboxes(body),
3640
"How Would the Nominee Contribute as an Ambassador?": extract("🏆 How Would the Nominee Contribute as an Ambassador?", body),
3741
"Any Additional Details": extract("Any additional details you'd like to share?", body)
3842
})
3943

4044
# Write to CSV
4145
os.makedirs("ambassador", exist_ok=True)
42-
output_path = "ambassador/contribution_details.csv"
43-
44-
with open(output_path, "w", newline='', encoding="utf-8") as f:
46+
with open("ambassador/contribution_details.csv", "w", newline='', encoding="utf-8") as f:
4547
writer = csv.DictWriter(f, fieldnames=output_rows[0].keys())
4648
writer.writeheader()
4749
writer.writerows(output_rows)
4850

49-
print(f"📄 File written to {output_path}")
51+
print("📄 File written to ambassador/contribution_details.csv")

0 commit comments

Comments
 (0)