2022-04-10 19:48:53 +02:00
|
|
|
name: new-bugs-announce notifier
|
|
|
|
|
|
|
|
on:
|
|
|
|
issues:
|
|
|
|
types:
|
|
|
|
- opened
|
|
|
|
|
2022-05-21 09:55:21 +02:00
|
|
|
permissions:
|
|
|
|
issues: read
|
|
|
|
|
2022-04-10 19:48:53 +02:00
|
|
|
jobs:
|
|
|
|
notify-new-bugs-announce:
|
|
|
|
runs-on: ubuntu-latest
|
2023-04-14 11:01:10 +02:00
|
|
|
timeout-minutes: 10
|
2022-04-10 19:48:53 +02:00
|
|
|
steps:
|
2023-11-02 11:49:01 +01:00
|
|
|
- uses: actions/setup-node@v4
|
2022-04-10 19:48:53 +02:00
|
|
|
with:
|
2023-11-02 11:49:01 +01:00
|
|
|
node-version: 20
|
2022-04-10 19:48:53 +02:00
|
|
|
- run: npm install mailgun.js form-data
|
|
|
|
- name: Send notification
|
2023-12-01 11:41:09 +01:00
|
|
|
uses: actions/github-script@v7
|
2022-04-10 19:48:53 +02:00
|
|
|
env:
|
2023-02-28 14:23:39 +01:00
|
|
|
MAILGUN_API_KEY: ${{ secrets.MAILGUN_PYTHON_ORG_MAILGUN_KEY }}
|
2022-04-10 19:48:53 +02:00
|
|
|
with:
|
|
|
|
script: |
|
|
|
|
const Mailgun = require("mailgun.js");
|
|
|
|
const formData = require('form-data');
|
|
|
|
const mailgun = new Mailgun(formData);
|
2023-02-28 14:23:39 +01:00
|
|
|
const DOMAIN = "mailgun.python.org";
|
2022-04-10 19:48:53 +02:00
|
|
|
const mg = mailgun.client({username: 'api', key: process.env.MAILGUN_API_KEY});
|
|
|
|
github.rest.issues.get({
|
|
|
|
issue_number: context.issue.number,
|
|
|
|
owner: context.repo.owner,
|
|
|
|
repo: context.repo.repo,
|
|
|
|
})
|
|
|
|
.then(function(issue) {
|
|
|
|
const payload = {
|
|
|
|
author : issue.data.user.login,
|
|
|
|
issue : issue.data.number,
|
|
|
|
title : issue.data.title,
|
|
|
|
url : issue.data.html_url,
|
|
|
|
labels : issue.data.labels.map(label => { return label.name }).join(", "),
|
|
|
|
assignee : issue.data.assignees.map(assignee => { return assignee.login }),
|
2023-07-02 16:15:28 +02:00
|
|
|
// We need to truncate the body size, because the max size for
|
|
|
|
// the whole payload is 16kb. We want to be safe and assume that
|
|
|
|
// body can take up to ~8kb of space.
|
2023-07-04 20:20:00 +02:00
|
|
|
body : issue.data.body.substring(0, 8000)
|
2022-04-10 19:48:53 +02:00
|
|
|
};
|
2022-05-21 09:55:21 +02:00
|
|
|
|
2022-04-10 19:48:53 +02:00
|
|
|
const data = {
|
2023-02-28 14:23:39 +01:00
|
|
|
from: "CPython Issues <github@mailgun.python.org>",
|
2022-04-10 19:48:53 +02:00
|
|
|
to: "new-bugs-announce@python.org",
|
|
|
|
subject: `[Issue ${issue.data.number}] ${issue.data.title}`,
|
|
|
|
template: "new-github-issue",
|
|
|
|
'o:tracking-clicks': 'no',
|
|
|
|
'h:X-Mailgun-Variables': JSON.stringify(payload)
|
|
|
|
};
|
|
|
|
return mg.messages.create(DOMAIN, data)
|
|
|
|
})
|
|
|
|
.then(msg => console.log(msg));
|