|
| 1 | +#!/usr/bin/env python3 |
| 2 | +"""Fetch SDK changelog from JiGuang official docs for a specific version.""" |
| 3 | + |
| 4 | +import sys |
| 5 | +import json |
| 6 | +import re |
| 7 | +import argparse |
| 8 | + |
| 9 | +try: |
| 10 | + import requests |
| 11 | +except ImportError: |
| 12 | + print("ERROR: Missing dependencies. Run: pip3 install requests") |
| 13 | + sys.exit(1) |
| 14 | + |
| 15 | +CONFIG_PATH = ".claude/skills/update-sdk/scripts/config.json" |
| 16 | +HEADERS = {"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36"} |
| 17 | + |
| 18 | + |
| 19 | +def load_config(): |
| 20 | + with open(CONFIG_PATH, "r", encoding="utf-8") as f: |
| 21 | + return json.load(f) |
| 22 | + |
| 23 | + |
| 24 | +def fetch_changelog(url: str, target_version: str) -> str: |
| 25 | + """Fetch and extract changelog section for target_version from a Markdown URL.""" |
| 26 | + md_url = url if url.endswith(".md") else url + ".md" |
| 27 | + |
| 28 | + try: |
| 29 | + resp = requests.get(md_url, headers=HEADERS, timeout=30) |
| 30 | + resp.raise_for_status() |
| 31 | + content = resp.text |
| 32 | + except requests.RequestException as e: |
| 33 | + return f"ERROR: Failed to fetch {md_url}: {e}" |
| 34 | + |
| 35 | + lines = content.split("\n") |
| 36 | + in_section = False |
| 37 | + section_lines = [] |
| 38 | + |
| 39 | + for line in lines: |
| 40 | + # Match headings like: ## JPush Android SDK v6.1.0 |
| 41 | + if re.match(r'^##\s+.*v?' + re.escape(target_version) + r'\b', line): |
| 42 | + in_section = True |
| 43 | + section_lines.append(line) |
| 44 | + elif in_section: |
| 45 | + if re.match(r'^##\s+', line): |
| 46 | + break # next version section starts |
| 47 | + section_lines.append(line) |
| 48 | + |
| 49 | + if not section_lines: |
| 50 | + return f"VERSION_NOT_FOUND: Could not find changelog for version {target_version} at {md_url}" |
| 51 | + |
| 52 | + return "\n".join(section_lines).strip() |
| 53 | + |
| 54 | + |
| 55 | +def main(): |
| 56 | + parser = argparse.ArgumentParser(description="Fetch JiGuang SDK changelog") |
| 57 | + parser.add_argument("--android", help="Android SDK version") |
| 58 | + parser.add_argument("--ios", help="iOS SDK version") |
| 59 | + parser.add_argument("--harmony", help="HarmonyOS SDK version") |
| 60 | + args = parser.parse_args() |
| 61 | + |
| 62 | + config = load_config() |
| 63 | + urls = config.get("changelog_urls", {}) |
| 64 | + result = {} |
| 65 | + |
| 66 | + platforms = [ |
| 67 | + ("android", args.android), |
| 68 | + ("ios", args.ios), |
| 69 | + ("harmony", args.harmony), |
| 70 | + ] |
| 71 | + |
| 72 | + for platform, version in platforms: |
| 73 | + if version and platform in urls: |
| 74 | + print(f"\n=== Fetching {platform} changelog for v{version} ===") |
| 75 | + content = fetch_changelog(urls[platform], version) |
| 76 | + result[platform] = content |
| 77 | + print(content) |
| 78 | + |
| 79 | + cache_path = ".claude/skills/update-sdk/scripts/.changelog_cache.json" |
| 80 | + with open(cache_path, "w", encoding="utf-8") as f: |
| 81 | + json.dump(result, f, ensure_ascii=False, indent=2) |
| 82 | + |
| 83 | + print(f"\n=== Changelog saved to {cache_path} ===") |
| 84 | + |
| 85 | + |
| 86 | +if __name__ == "__main__": |
| 87 | + main() |
0 commit comments