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