Skip to content

Commit a549690

Browse files
Update extract_contribution_details.py
1 parent 5f102c7 commit a549690

File tree

1 file changed

+14
-16
lines changed

1 file changed

+14
-16
lines changed

.github/scripts/extract_contribution_details.py

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

18-
# Updated extract function that handles markdown code blocks
18+
# Extract plain text response by label
1919
def extract(label, body):
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)
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 ""
2323

24-
if match_md:
25-
return match_md.group(1).strip()
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)
2628

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
29+
# Build rows
3430
output_rows = []
35-
3631
for issue in issues:
3732
body = issue.body or ""
3833
output_rows.append({
3934
"Submission ID": issue.number,
35+
"Contributions": extract_checkboxes(body),
4036
"How Would the Nominee Contribute as an Ambassador?": extract("🏆 How Would the Nominee Contribute as an Ambassador?", body),
4137
"Any Additional Details": extract("Any additional details you'd like to share?", body)
4238
})
4339

4440
# Write to CSV
4541
os.makedirs("ambassador", exist_ok=True)
46-
with open("ambassador/contribution_details.csv", "w", newline='', encoding="utf-8") as f:
42+
output_path = "ambassador/contribution_details.csv"
43+
44+
with open(output_path, "w", newline='', encoding="utf-8") as f:
4745
writer = csv.DictWriter(f, fieldnames=output_rows[0].keys())
4846
writer.writeheader()
4947
writer.writerows(output_rows)
5048

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

0 commit comments

Comments
 (0)