|
15 | 15 | permissions: |
16 | 16 | contents: write |
17 | 17 | id-token: write |
| 18 | + issues: write |
18 | 19 | env: |
19 | 20 | PUBLISH_ENABLED: ${{ vars.PUBLISH_ENABLED || 'true' }} |
20 | 21 | PUBLISH_MODE: ${{ vars.PUBLISH_MODE || 'core_major' }} |
@@ -91,15 +92,69 @@ jobs: |
91 | 92 | - name: Create Monthly Review Issue |
92 | 93 | if: success() && env.PUBLISH_ENABLED != 'false' |
93 | 94 | env: |
94 | | - GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 95 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 96 | + GITHUB_REPOSITORY: ${{ github.repository }} |
95 | 97 | run: | |
96 | 98 | set -euo pipefail |
97 | | - AS_OF_DATE=$(python -c "import json; print(json.load(open('data/output/monthly_report_bundle/monthly_report_bundle.json'))['as_of_date'])") |
98 | | - gh label create monthly-review --description "Automated monthly report AI review" --color "0E8A16" 2>/dev/null || true |
99 | | - gh issue create \ |
100 | | - --title "Monthly Report Review: ${AS_OF_DATE}" \ |
101 | | - --label "monthly-review" \ |
102 | | - --body-file data/output/monthly_report_bundle/ai_review_input.md |
| 99 | + python - <<'PY' |
| 100 | + import json |
| 101 | + import os |
| 102 | + import urllib.error |
| 103 | + import urllib.parse |
| 104 | + import urllib.request |
| 105 | + |
| 106 | + token = os.environ["GITHUB_TOKEN"] |
| 107 | + repository = os.environ["GITHUB_REPOSITORY"] |
| 108 | + headers = { |
| 109 | + "Authorization": f"Bearer {token}", |
| 110 | + "Accept": "application/vnd.github+json", |
| 111 | + "X-GitHub-Api-Version": "2022-11-28", |
| 112 | + "User-Agent": "crypto-leader-rotation-monthly-publish", |
| 113 | + } |
| 114 | + api_base = f"https://api.github.com/repos/{repository}" |
| 115 | + label_name = "monthly-review" |
| 116 | + label_path = urllib.parse.quote(label_name, safe="") |
| 117 | + |
| 118 | + with open("data/output/monthly_report_bundle/monthly_report_bundle.json", "r", encoding="utf-8") as handle: |
| 119 | + bundle = json.load(handle) |
| 120 | + with open("data/output/monthly_report_bundle/ai_review_input.md", "r", encoding="utf-8") as handle: |
| 121 | + issue_body = handle.read() |
| 122 | + |
| 123 | + def request_json(method: str, url: str, payload: dict | None = None) -> dict: |
| 124 | + data = None |
| 125 | + if payload is not None: |
| 126 | + data = json.dumps(payload).encode("utf-8") |
| 127 | + request = urllib.request.Request(url, data=data, method=method, headers=headers) |
| 128 | + with urllib.request.urlopen(request) as response: |
| 129 | + body = response.read().decode("utf-8") |
| 130 | + return json.loads(body) if body else {} |
| 131 | + |
| 132 | + try: |
| 133 | + request_json("GET", f"{api_base}/labels/{label_path}") |
| 134 | + except urllib.error.HTTPError as exc: |
| 135 | + if exc.code != 404: |
| 136 | + raise |
| 137 | + request_json( |
| 138 | + "POST", |
| 139 | + f"{api_base}/labels", |
| 140 | + { |
| 141 | + "name": label_name, |
| 142 | + "description": "Automated monthly report AI review", |
| 143 | + "color": "0E8A16", |
| 144 | + }, |
| 145 | + ) |
| 146 | + |
| 147 | + issue = request_json( |
| 148 | + "POST", |
| 149 | + f"{api_base}/issues", |
| 150 | + { |
| 151 | + "title": f"Monthly Report Review: {bundle['as_of_date']}", |
| 152 | + "labels": [label_name], |
| 153 | + "body": issue_body, |
| 154 | + }, |
| 155 | + ) |
| 156 | + print(f"Created issue #{issue['number']}: {issue['html_url']}") |
| 157 | + PY |
103 | 158 |
|
104 | 159 | - name: Write Release Heartbeat |
105 | 160 | if: success() && env.PUBLISH_ENABLED != 'false' |
|
0 commit comments