Skip to content

Commit ce6f69a

Browse files
committed
Add workflow to react on missing or ignored templates
The workflow creates a comment on the issue or PR that has a missing or ignored template asking the author to use the template properly.
1 parent 3815f5f commit ce6f69a

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
name: Template label comment
2+
3+
on:
4+
issues:
5+
types: [labeled]
6+
pull_request:
7+
types: [labeled]
8+
9+
permissions:
10+
issues: write
11+
pull-requests: write
12+
13+
jobs:
14+
comment_on_label:
15+
name: Comment on labeled issue/PR
16+
if: ${{ github.event.label.name == 'template-ignored' || github.event.label.name == 'template-missing' }}
17+
runs-on: ubuntu-latest
18+
steps:
19+
- name: Get PR template
20+
if: ${{ github.event.pull_request && github.event.label.name == 'template-missing' }}
21+
run: |
22+
set -euo pipefail
23+
{
24+
echo 'PR_TEMPLATE<<EOF'
25+
curl https://raw.githubusercontent.com/TeamNewPipe/NewPipe/refs/heads/dev/.github/PULL_REQUEST_TEMPLATE.md
26+
echo EOF
27+
} >> $GITHUB_ENV
28+
29+
- name: Post comment
30+
uses: actions/github-script@v6
31+
with:
32+
github-token: ${{ secrets.GITHUB_TOKEN }}
33+
script: |
34+
const label = context.payload.label && context.payload.label.name;
35+
if (!label) return;
36+
const isPR = !!context.payload.pull_request;
37+
const number = isPR ? context.payload.pull_request.number : context.payload.issue.number;
38+
39+
let body = '';
40+
if (label === 'template-ignored') {
41+
body = 'Please fill in the template completely or at least as much as possible. The team needs more detailed information.';
42+
} else if (label === 'template-missing') {
43+
const kind = isPR ? 'PR' : 'issue';
44+
let template;
45+
if (isPR) {
46+
template = '<details><summary>Raw template</summary>\n```\n' + process.env.PR_TEMPLATE + '\n```\n</details>';
47+
} else {
48+
template = '[Bug report template](https://raw.githubusercontent.com/TeamNewPipe/NewPipe/refs/heads/dev/.github/ISSUE_TEMPLATE/bug_report.yml), [Feature request template](https://raw.githubusercontent.com/TeamNewPipe/NewPipe/refs/heads/dev/.github/ISSUE_TEMPLATE/feature_request.yml)';
49+
}
50+
body = `Thank you for creating this ${kind}. Please edit your description and add the template with the information: ${template}`;
51+
} else {
52+
return;
53+
}
54+
55+
await github.rest.issues.createComment({
56+
owner: context.repo.owner,
57+
repo: context.repo.repo,
58+
issue_number: number,
59+
body
60+
});
61+

0 commit comments

Comments
 (0)