Skip to content

Commit 37567c1

Browse files
committed
fix: remove gh dependency from monthly review issue step
1 parent ccbc91e commit 37567c1

2 files changed

Lines changed: 71 additions & 7 deletions

File tree

.github/workflows/monthly_publish.yml

Lines changed: 62 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ jobs:
1515
permissions:
1616
contents: write
1717
id-token: write
18+
issues: write
1819
env:
1920
PUBLISH_ENABLED: ${{ vars.PUBLISH_ENABLED || 'true' }}
2021
PUBLISH_MODE: ${{ vars.PUBLISH_MODE || 'core_major' }}
@@ -91,15 +92,69 @@ jobs:
9192
- name: Create Monthly Review Issue
9293
if: success() && env.PUBLISH_ENABLED != 'false'
9394
env:
94-
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
95+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
96+
GITHUB_REPOSITORY: ${{ github.repository }}
9597
run: |
9698
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
103158
104159
- name: Write Release Heartbeat
105160
if: success() && env.PUBLISH_ENABLED != 'false'

tests/test_monthly_publish_workflow_config.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,18 @@ def test_publish_targets_use_vars_only(self) -> None:
1515
self.assertIn("GCP_PROJECT_ID: ${{ vars.GCP_PROJECT_ID }}", workflow)
1616
self.assertIn("GCS_BUCKET: ${{ vars.GCS_BUCKET }}", workflow)
1717
self.assertIn("credentials_json: ${{ secrets.GCP_SERVICE_ACCOUNT_KEY }}", workflow)
18+
self.assertIn("issues: write", workflow)
1819
self.assertNotIn("secrets.GCP_PROJECT_ID", workflow)
1920
self.assertNotIn("secrets.GCS_BUCKET", workflow)
2021

22+
def test_monthly_review_issue_creation_does_not_require_gh_cli(self) -> None:
23+
workflow = WORKFLOW_PATH.read_text(encoding="utf-8")
24+
25+
self.assertNotIn("gh label create", workflow)
26+
self.assertNotIn("gh issue create", workflow)
27+
self.assertIn("https://api.github.com/repos/{repository}", workflow)
28+
self.assertIn('GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}', workflow)
29+
2130

2231
if __name__ == "__main__":
2332
unittest.main()

0 commit comments

Comments
 (0)