forked from oppia/oppia
-
Notifications
You must be signed in to change notification settings - Fork 0
58 lines (52 loc) · 2.14 KB
/
check_pr_description.yml
File metadata and controls
58 lines (52 loc) · 2.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
name: Check PR description
on:
pull_request:
types:
- opened
- reopened
permissions: read-all
jobs:
check_pr_description:
permissions:
pull-requests: write
runs-on: ubuntu-latest
steps:
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: '16'
- name: Run PR description check
uses: actions/github-script@v6
with:
script: |
const pr = context.payload.pull_request;
const prDescription = pr.body;
if (!prDescription) {
core.setFailed("The PR description is missing or does not meet the required format.");
}
const requiredSections = [
'## Overview',
'## Essential Checklist',
'## Proof that changes are correct',
'## PR Pointers'
];
const missingSections = requiredSections.filter(
section => !prDescription.includes(section)
);
if (missingSections.length > 0) {
const username = pr.user.login;
const comment = `Hi @${username}, it looks like the description of this PR doesn't use our [template](https://github.com/oppia/oppia/blob/develop/.github/PULL_REQUEST_TEMPLATE.md), which is pre-populated when you open a new PR. Specifically, it's missing the following required sections:\n\n` + missingSections.map(s => `- ${s.replace(/^##\s*/, '')}`).join('\n') + `Please re-open this PR and fill in the template without deleting any required sections.`
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: pr.number,
body: comment
});
await github.rest.pulls.update({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: pr.number,
state: 'closed'
});
core.setFailed("The PR description is missing required sections.");
}