Skip to content

Commit 5b6dd1e

Browse files
authored
Bug announcer: Replace unpinned npm install with Python stdlib (#163058)
bug announcer: Replace unpinned npm install with Python stdlib
1 parent 128b502 commit 5b6dd1e

3 files changed

Lines changed: 53 additions & 62 deletions

File tree

‎.github/workflows/actions.lock‎

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,7 @@ workflows:
1919
'.github/workflows/mypy.yml':
2020
- 'actions/checkout@v7.0.1'
2121
- 'astral-sh/setup-uv@v10.2.0'
22-
'.github/workflows/new-bugs-announce-notifier.yml':
23-
- 'actions/github-script@v9.0.0'
24-
- 'actions/setup-node@v7.0.0'
22+
'.github/workflows/new-bugs-announce-notifier.yml': []
2523
'.github/workflows/require-pr-label.yml':
2624
- 'mheap/github-action-required-labels@v5.6.0'
2725
'.github/workflows/reusable-check-c-api-docs.yml':
@@ -94,11 +92,6 @@ dependencies:
9492
commit: 'sha1-3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c'
9593
owner_id: 44036562
9694
repo_id: 192626254
97-
'actions/github-script@v9.0.0':
98-
ref: 'v9.0.0'
99-
commit: 'sha1-3a2844b7e9c422d3c10d287c895573f7108da1b3'
100-
owner_id: 44036562
101-
repo_id: 205262760
10295
'actions/setup-node@v7.0.0':
10396
ref: 'v7.0.0'
10497
commit: 'sha1-820762786026740c76f36085b0efc47a31fe5020'

‎.github/workflows/new-bugs-announce-notifier.yml‎

Lines changed: 52 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -5,60 +5,64 @@ on:
55
types:
66
- opened
77

8-
permissions:
9-
contents: read
8+
permissions: {}
109

1110
jobs:
1211
notify-new-bugs-announce:
13-
runs-on: ubuntu-slim
14-
permissions:
15-
issues: read
12+
runs-on: ubuntu-latest
1613
timeout-minutes: 10
1714
steps:
18-
- uses: actions/setup-node@v7.0.0
19-
with:
20-
node-version: 20
21-
# TODO: Replace with a committed lockfile and `npm ci`, or drop npm
22-
# and call the Mailgun REST API from the standard library.
23-
- run: npm install mailgun.js form-data # zizmor: ignore[adhoc-packages]
2415
- name: Send notification
25-
uses: actions/github-script@v9.0.0
2616
env:
2717
MAILGUN_API_KEY: ${{ secrets.MAILGUN_PYTHON_ORG_MAILGUN_KEY }}
28-
with:
29-
script: |
30-
const Mailgun = require("mailgun.js");
31-
const formData = require('form-data');
32-
const mailgun = new Mailgun(formData);
33-
const DOMAIN = "mailgun.python.org";
34-
const mg = mailgun.client({username: 'api', key: process.env.MAILGUN_API_KEY});
35-
github.rest.issues.get({
36-
issue_number: context.issue.number,
37-
owner: context.repo.owner,
38-
repo: context.repo.repo,
39-
})
40-
.then(function(issue) {
41-
const payload = {
42-
author : issue.data.user.login,
43-
issue : issue.data.number,
44-
title : issue.data.title,
45-
url : issue.data.html_url,
46-
labels : issue.data.labels.map(label => { return label.name }).join(", "),
47-
assignee : issue.data.assignees.map(assignee => { return assignee.login }),
48-
// We need to truncate the body size, because the max size for
49-
// the whole payload is 16kb. We want to be safe and assume that
50-
// body can take up to ~8kb of space.
51-
body : (issue.data.body || "").substring(0, 8000)
52-
};
18+
shell: python
19+
run: |
20+
import base64
21+
import json
22+
import os
23+
import urllib.error
24+
import urllib.parse
25+
import urllib.request
5326
54-
const data = {
55-
from: "CPython Issues <github@mailgun.python.org>",
56-
to: "new-bugs-announce@python.org",
57-
subject: `[Issue ${issue.data.number}] ${issue.data.title}`,
58-
template: "new-github-issue",
59-
'o:tracking-clicks': 'no',
60-
'h:X-Mailgun-Variables': JSON.stringify(payload)
61-
};
62-
return mg.messages.create(DOMAIN, data)
63-
})
64-
.then(msg => console.log(msg));
27+
with open(os.environ["GITHUB_EVENT_PATH"], encoding="utf-8") as f:
28+
issue = json.load(f)["issue"]
29+
30+
payload = {
31+
"author": issue["user"]["login"],
32+
"issue": issue["number"],
33+
"title": issue["title"],
34+
"url": issue["html_url"],
35+
"labels": ", ".join(label["name"] for label in issue["labels"]),
36+
"assignee": [assignee["login"] for assignee in issue["assignees"]],
37+
# We need to truncate the body size, because the max size for
38+
# the whole payload is 16 kB. We want to be safe and assume that
39+
# body can take up to ~8 kB of space. Truncate by bytes, not
40+
# characters, so non-ASCII text can't exceed that.
41+
"body": (issue["body"] or "").encode()[:8000].decode(errors="ignore"),
42+
}
43+
44+
data = urllib.parse.urlencode(
45+
{
46+
"from": "CPython Issues <github@mailgun.python.org>",
47+
"to": "new-bugs-announce@python.org",
48+
"subject": f"[Issue {issue['number']}] {issue['title']}",
49+
"template": "new-github-issue",
50+
"o:tracking-clicks": "no",
51+
"h:X-Mailgun-Variables": json.dumps(payload, ensure_ascii=False),
52+
}
53+
).encode()
54+
55+
credentials = b"api:" + os.environ["MAILGUN_API_KEY"].encode()
56+
request = urllib.request.Request(
57+
"https://api.mailgun.net/v3/mailgun.python.org/messages",
58+
data=data,
59+
headers={
60+
"Authorization": "Basic " + base64.b64encode(credentials).decode(),
61+
},
62+
)
63+
try:
64+
with urllib.request.urlopen(request) as response:
65+
print(response.read().decode())
66+
except urllib.error.HTTPError as e:
67+
print(f"Mailgun returned HTTP {e.code}: {e.read().decode()}")
68+
raise SystemExit(1)

‎.github/zizmor.yml‎

Lines changed: 0 additions & 6 deletions
This file was deleted.

0 commit comments

Comments
 (0)