diff --git a/.github/workflows/template-label.js b/.github/workflows/template-label.js new file mode 100644 index 000000000..51a2028a3 --- /dev/null +++ b/.github/workflows/template-label.js @@ -0,0 +1,34 @@ +/* + * Script for commenting on issues/PRs when the template is missing or ignored + */ +module.exports = async ({github, context}) => { + + const label = context.payload.label && context.payload.label.name; + if (!label) return; + const isPR = !!context.payload.pull_request; + const number = isPR ? context.payload.pull_request.number : context.payload.issue.number; + + let body = ''; + if (label === 'template-ignored') { + body = 'Please fill in the template completely or at least as much as possible. The team needs more detailed information.'; + } else if (label === 'template-missing') { + const kind = isPR ? 'PR' : 'issue'; + let template; + if (isPR) { + template = '
Raw template\n```\n' + process.env.PR_TEMPLATE + '\n```\n
'; + } else { + 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)'; + } + body = `Thank you for creating this ${kind}. Please edit your description and add the template with the information: ${template}`; + } else { + return; + } + + await github.rest.issues.createComment({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: number, + body + }); + +} \ No newline at end of file diff --git a/.github/workflows/template-label.yml b/.github/workflows/template-label.yml index 52056a572..ee3f4c646 100644 --- a/.github/workflows/template-label.yml +++ b/.github/workflows/template-label.yml @@ -16,6 +16,8 @@ jobs: if: ${{ github.event.label.name == 'template-ignored' || github.event.label.name == 'template-missing' }} runs-on: ubuntu-latest steps: + - uses: actions/checkout@v6 + - name: Get PR template if: ${{ github.event.pull_request && github.event.label.name == 'template-missing' }} run: | @@ -27,35 +29,10 @@ jobs: } >> $GITHUB_ENV - name: Post comment - uses: actions/github-script@v6 + uses: actions/github-script@v8 + timeout-minutes: 2 with: github-token: ${{ secrets.GITHUB_TOKEN }} script: | - const label = context.payload.label && context.payload.label.name; - if (!label) return; - const isPR = !!context.payload.pull_request; - const number = isPR ? context.payload.pull_request.number : context.payload.issue.number; - - let body = ''; - if (label === 'template-ignored') { - body = 'Please fill in the template completely or at least as much as possible. The team needs more detailed information.'; - } else if (label === 'template-missing') { - const kind = isPR ? 'PR' : 'issue'; - let template; - if (isPR) { - template = '
Raw template\n```\n' + process.env.PR_TEMPLATE + '\n```\n
'; - } else { - 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)'; - } - body = `Thank you for creating this ${kind}. Please edit your description and add the template with the information: ${template}`; - } else { - return; - } - - await github.rest.issues.createComment({ - owner: context.repo.owner, - repo: context.repo.repo, - issue_number: number, - body - }); - + const script = require('.github/workflows/template-label.js'); + await script({github, context});