|
| 1 | +""" |
| 2 | +Fetch roadmap issues from GitHub for each package. |
| 3 | +
|
| 4 | +Writes static/{package}/roadmap.json with open issues labeled 'roadmap'. |
| 5 | +""" |
| 6 | + |
| 7 | +import json |
| 8 | +import os |
| 9 | +from datetime import datetime, timezone |
| 10 | +from pathlib import Path |
| 11 | + |
| 12 | +import requests |
| 13 | + |
| 14 | +from .config import PACKAGES, STATIC_DIR |
| 15 | + |
| 16 | + |
| 17 | +def fetch_roadmap_issues(github_repo: str) -> list[dict]: |
| 18 | + """ |
| 19 | + Fetch open issues with the 'roadmap' label from a GitHub repo. |
| 20 | +
|
| 21 | + Args: |
| 22 | + github_repo: GitHub repo in "owner/name" format. |
| 23 | +
|
| 24 | + Returns: |
| 25 | + List of issue dicts with relevant fields. |
| 26 | + """ |
| 27 | + token = os.environ.get("GITHUB_TOKEN", "") |
| 28 | + headers = {"Authorization": f"token {token}"} if token else {} |
| 29 | + |
| 30 | + url = f"https://api.github.com/repos/{github_repo}/issues" |
| 31 | + params = { |
| 32 | + "state": "open", |
| 33 | + "labels": "roadmap", |
| 34 | + "sort": "created", |
| 35 | + "direction": "desc", |
| 36 | + "per_page": 100, |
| 37 | + } |
| 38 | + |
| 39 | + response = requests.get(url, headers=headers, params=params, timeout=30) |
| 40 | + response.raise_for_status() |
| 41 | + raw_issues = response.json() |
| 42 | + |
| 43 | + issues = [] |
| 44 | + for issue in raw_issues: |
| 45 | + # Skip pull requests |
| 46 | + if "pull_request" in issue: |
| 47 | + continue |
| 48 | + |
| 49 | + body = (issue.get("body") or "").strip() |
| 50 | + |
| 51 | + labels = [ |
| 52 | + label["name"] |
| 53 | + for label in issue.get("labels", []) |
| 54 | + if label["name"] != "roadmap" |
| 55 | + ] |
| 56 | + |
| 57 | + issues.append({ |
| 58 | + "number": issue["number"], |
| 59 | + "title": issue["title"], |
| 60 | + "body": body, |
| 61 | + "labels": labels, |
| 62 | + "url": issue["html_url"], |
| 63 | + "created": issue["created_at"], |
| 64 | + }) |
| 65 | + |
| 66 | + return issues |
| 67 | + |
| 68 | + |
| 69 | +def build_roadmap(package_id: str, dry_run: bool = False) -> bool: |
| 70 | + """ |
| 71 | + Fetch and write roadmap.json for a single package. |
| 72 | +
|
| 73 | + Returns True if roadmap items were found. |
| 74 | + """ |
| 75 | + pkg_config = PACKAGES.get(package_id) |
| 76 | + if not pkg_config: |
| 77 | + print(f" Unknown package: {package_id}") |
| 78 | + return False |
| 79 | + |
| 80 | + github_repo = pkg_config.get("github_repo") |
| 81 | + if not github_repo: |
| 82 | + print(f" No github_repo configured for {package_id}") |
| 83 | + return False |
| 84 | + |
| 85 | + output_dir = STATIC_DIR / package_id |
| 86 | + output_path = output_dir / "roadmap.json" |
| 87 | + |
| 88 | + try: |
| 89 | + issues = fetch_roadmap_issues(github_repo) |
| 90 | + except Exception as e: |
| 91 | + print(f" Failed to fetch roadmap for {package_id}: {e}") |
| 92 | + return False |
| 93 | + |
| 94 | + if dry_run: |
| 95 | + print(f" Would write {len(issues)} roadmap items to {output_path}") |
| 96 | + return len(issues) > 0 |
| 97 | + |
| 98 | + output_dir.mkdir(parents=True, exist_ok=True) |
| 99 | + |
| 100 | + roadmap = { |
| 101 | + "package": package_id, |
| 102 | + "repo": github_repo, |
| 103 | + "updated": datetime.now(timezone.utc).strftime("%Y-%m-%dT%H:%M:%SZ"), |
| 104 | + "issues": issues, |
| 105 | + } |
| 106 | + |
| 107 | + with open(output_path, "w", encoding="utf-8") as f: |
| 108 | + json.dump(roadmap, f, indent=2, ensure_ascii=False) |
| 109 | + |
| 110 | + print(f" {len(issues)} roadmap items") |
| 111 | + |
| 112 | + # Remove roadmap.json if empty (so hasRoadmap stays false) |
| 113 | + if not issues: |
| 114 | + output_path.unlink(missing_ok=True) |
| 115 | + |
| 116 | + return len(issues) > 0 |
| 117 | + |
| 118 | + |
| 119 | +def build_all_roadmaps(dry_run: bool = False) -> None: |
| 120 | + """Fetch roadmaps for all configured packages.""" |
| 121 | + print("\nFetching roadmap issues") |
| 122 | + print("=" * 50) |
| 123 | + for package_id in PACKAGES: |
| 124 | + print(f" {PACKAGES[package_id]['display_name']}:") |
| 125 | + build_roadmap(package_id, dry_run) |
0 commit comments