|
| 1 | +const { |
| 2 | + PR_ACTION, |
| 3 | + PR_AUTHOR, |
| 4 | + PR_BODY, |
| 5 | + PR_NUMBER, |
| 6 | + IGNORE_AUTHORS, |
| 7 | + LABEL_BLOCK, |
| 8 | + LABEL_BLOCK_REASON |
| 9 | +} = require("./constants") |
| 10 | + |
| 11 | +module.exports = async ({github, context, core}) => { |
| 12 | + core.debug(`Number: ${PR_BODY}`); |
| 13 | + core.debug(`Action: ${PR_ACTION}`); |
| 14 | + core.debug(`Author: ${PR_AUTHOR}`); |
| 15 | + core.debug(`Body: ${PR_BODY}`); |
| 16 | + |
| 17 | + if (IGNORE_AUTHORS.includes(PR_AUTHOR)) { |
| 18 | + return core.notice("Author in IGNORE_AUTHORS list; skipping...") |
| 19 | + } |
| 20 | + |
| 21 | + if (PR_ACTION != "opened") { |
| 22 | + return core.notice("Only newly open PRs are labelled to avoid spam; skipping") |
| 23 | + } |
| 24 | + |
| 25 | + const RELATED_ISSUE_REGEX = /Issue number:[^\d\r\n]+(?<issue>\d+)/; |
| 26 | + const isMatch = RELATED_ISSUE_REGEX.exec(PR_BODY); |
| 27 | + if (isMatch == null) { |
| 28 | + core.info(`No related issue found, maybe the author didn't use the template but there is one.`) |
| 29 | + |
| 30 | + let msg = "No related issues found. Please ensure there is an open issue related to this change to avoid significant delays or closure."; |
| 31 | + await github.rest.issues.createComment({ |
| 32 | + owner: context.repo.owner, |
| 33 | + repo: context.repo.repo, |
| 34 | + body: msg, |
| 35 | + issue_number: PR_NUMBER, |
| 36 | + }); |
| 37 | + |
| 38 | + return await github.rest.issues.addLabels({ |
| 39 | + issue_number: PR_NUMBER, |
| 40 | + owner: context.repo.owner, |
| 41 | + repo: context.repo.repo, |
| 42 | + labels: [LABEL_BLOCK, LABEL_BLOCK_REASON] |
| 43 | + }) |
| 44 | + } |
| 45 | +} |
0 commit comments