|
15 | 15 | issues = list(repo.get_issues(state="open", labels=["ambassador"])) |
16 | 16 | print(f"✅ Found {len(issues)} issues") |
17 | 17 |
|
18 | | -# Updated extract function that handles markdown code blocks |
| 18 | +# Extract plain text response by label |
19 | 19 | 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 "" |
23 | 23 |
|
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) |
26 | 28 |
|
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 |
34 | 30 | output_rows = [] |
35 | | - |
36 | 31 | for issue in issues: |
37 | 32 | body = issue.body or "" |
38 | 33 | output_rows.append({ |
39 | 34 | "Submission ID": issue.number, |
| 35 | + "Contributions": extract_checkboxes(body), |
40 | 36 | "How Would the Nominee Contribute as an Ambassador?": extract("🏆 How Would the Nominee Contribute as an Ambassador?", body), |
41 | 37 | "Any Additional Details": extract("Any additional details you'd like to share?", body) |
42 | 38 | }) |
43 | 39 |
|
44 | 40 | # Write to CSV |
45 | 41 | 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: |
47 | 45 | writer = csv.DictWriter(f, fieldnames=output_rows[0].keys()) |
48 | 46 | writer.writeheader() |
49 | 47 | writer.writerows(output_rows) |
50 | 48 |
|
51 | | -print("📄 File written to ambassador/contribution_details.csv") |
| 49 | +print(f"📄 File written to {output_path}") |
0 commit comments