2022-04-10 14:48:53 -03:00
|
|
|
name: new-bugs-announce notifier
|
|
|
|
|
|
|
|
on:
|
|
|
|
issues:
|
|
|
|
types:
|
|
|
|
- opened
|
|
|
|
|
2022-05-21 04:55:21 -03:00
|
|
|
permissions:
|
|
|
|
issues: read
|
|
|
|
|
2022-04-10 14:48:53 -03:00
|
|
|
jobs:
|
|
|
|
notify-new-bugs-announce:
|
|
|
|
runs-on: ubuntu-latest
|
2023-04-14 06:01:10 -03:00
|
|
|
timeout-minutes: 10
|
2022-04-10 14:48:53 -03:00
|
|
|
steps:
|
2023-11-02 07:49:01 -03:00
|
|
|
- uses: actions/setup-node@v4
|
2022-04-10 14:48:53 -03:00
|
|
|
with:
|
2023-11-02 07:49:01 -03:00
|
|
|
node-version: 20
|
2022-04-10 14:48:53 -03:00
|
|
|
- run: npm install mailgun.js form-data
|
|
|
|
- name: Send notification
|
2023-12-01 06:41:09 -04:00
|
|
|
uses: actions/github-script@v7
|
2022-04-10 14:48:53 -03:00
|
|
|
env:
|
2023-02-28 09:23:39 -04:00
|
|
|
MAILGUN_API_KEY: ${{ secrets.MAILGUN_PYTHON_ORG_MAILGUN_KEY }}
|
2022-04-10 14:48:53 -03:00
|
|
|
with:
|
|
|
|
script: |
|
|
|
|
const Mailgun = require("mailgun.js");
|
|
|
|
const formData = require('form-data');
|
|
|
|
const mailgun = new Mailgun(formData);
|
2023-02-28 09:23:39 -04:00
|
|
|
const DOMAIN = "mailgun.python.org";
|
2022-04-10 14:48:53 -03: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 11:15:28 -03: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 15:20:00 -03:00
|
|
|
body : issue.data.body.substring(0, 8000)
|
2022-04-10 14:48:53 -03:00
|
|
|
};
|
2022-05-21 04:55:21 -03:00
|
|
|
|
2022-04-10 14:48:53 -03:00
|
|
|
const data = {
|
2023-02-28 09:23:39 -04:00
|
|
|
from: "CPython Issues <github@mailgun.python.org>",
|
2022-04-10 14:48:53 -03: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));
|