Skip to content

Commit 78bfcad

Browse files
committed
Extract JS script into single file
1 parent 2934201 commit 78bfcad

File tree

2 files changed

+40
-29
lines changed

2 files changed

+40
-29
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Script for commenting on issues/PRs when the template is missing or ignored
3+
*/
4+
module.exports = async ({github, context}) => {
5+
6+
const label = context.payload.label && context.payload.label.name;
7+
if (!label) return;
8+
const isPR = !!context.payload.pull_request;
9+
const number = isPR ? context.payload.pull_request.number : context.payload.issue.number;
10+
11+
let body = '';
12+
if (label === 'template-ignored') {
13+
body = 'Please fill in the template completely or at least as much as possible. The team needs more detailed information.';
14+
} else if (label === 'template-missing') {
15+
const kind = isPR ? 'PR' : 'issue';
16+
let template;
17+
if (isPR) {
18+
template = '<details><summary>Raw template</summary>\n```\n' + process.env.PR_TEMPLATE + '\n```\n</details>';
19+
} else {
20+
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)';
21+
}
22+
body = `Thank you for creating this ${kind}. Please edit your description and add the template with the information: ${template}`;
23+
} else {
24+
return;
25+
}
26+
27+
await github.rest.issues.createComment({
28+
owner: context.repo.owner,
29+
repo: context.repo.repo,
30+
issue_number: number,
31+
body
32+
});
33+
34+
}

.github/workflows/template-label.yml

Lines changed: 6 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ jobs:
1616
if: ${{ github.event.label.name == 'template-ignored' || github.event.label.name == 'template-missing' }}
1717
runs-on: ubuntu-latest
1818
steps:
19+
- uses: actions/checkout@v6
20+
1921
- name: Get PR template
2022
if: ${{ github.event.pull_request && github.event.label.name == 'template-missing' }}
2123
run: |
@@ -27,35 +29,10 @@ jobs:
2729
} >> $GITHUB_ENV
2830
2931
- name: Post comment
30-
uses: actions/github-script@v6
32+
uses: actions/github-script@v8
33+
timeout-minutes: 2
3134
with:
3235
github-token: ${{ secrets.GITHUB_TOKEN }}
3336
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-
37+
const script = require('.github/workflows/template-label.js');
38+
await script({github, context});

0 commit comments

Comments
 (0)