mirror of
https://github.com/binaricat/Netcatty.git
synced 2026-11-10 16:21:22 +00:00
123 lines
4.4 KiB
YAML
123 lines
4.4 KiB
YAML
name: issue-format
|
|
|
|
on:
|
|
issues:
|
|
types: [opened, edited]
|
|
|
|
permissions:
|
|
contents: read
|
|
issues: write
|
|
|
|
jobs:
|
|
validate:
|
|
runs-on: ubuntu-latest
|
|
# Skip issues opened by bots (e.g. dependabot) and maintainers fixing format
|
|
if: >-
|
|
github.event.issue.user.type != 'Bot' &&
|
|
!contains(github.event.issue.labels.*.name, 'format-exempt')
|
|
steps:
|
|
- name: Checkout format helpers
|
|
uses: actions/checkout@v7
|
|
with:
|
|
sparse-checkout: |
|
|
scripts/issue-format.cjs
|
|
sparse-checkout-cone-mode: false
|
|
|
|
- name: Validate title and body
|
|
uses: actions/github-script@v9
|
|
with:
|
|
script: |
|
|
const format = require(`${process.env.GITHUB_WORKSPACE}/scripts/issue-format.cjs`);
|
|
const issue = context.payload.issue;
|
|
const errors = format.getIssueFormatErrors(issue);
|
|
const labels = new Set(
|
|
(issue.labels || []).map((label) =>
|
|
typeof label === 'string' ? label : label.name
|
|
)
|
|
);
|
|
const formatOk = errors.length === 0;
|
|
const recovery = format.shouldRecoverIssueFormat({
|
|
state: issue.state,
|
|
labels: [...labels],
|
|
formatOk,
|
|
});
|
|
|
|
if (formatOk) {
|
|
if (recovery.recover) {
|
|
labels.delete('invalid-format');
|
|
const update = {
|
|
owner: context.repo.owner,
|
|
repo: context.repo.repo,
|
|
issue_number: issue.number,
|
|
labels: [...labels],
|
|
};
|
|
if (recovery.reopen) {
|
|
update.state = 'open';
|
|
}
|
|
await github.rest.issues.update(update);
|
|
await github.rest.issues.createComment({
|
|
owner: context.repo.owner,
|
|
repo: context.repo.repo,
|
|
issue_number: issue.number,
|
|
body: recovery.reopen
|
|
? '<!-- issue-format-bot --> Format looks good now. Reopening this issue.'
|
|
: '<!-- issue-format-bot --> Format looks good now. Removed the invalid-format label.',
|
|
});
|
|
} else {
|
|
core.info('Issue format OK');
|
|
}
|
|
return;
|
|
}
|
|
|
|
const issueNumber = issue.number;
|
|
const marker = '<!-- issue-format-bot -->';
|
|
const bodyText = [
|
|
marker,
|
|
'## Issue format check failed',
|
|
'',
|
|
'This issue was closed automatically because it does not follow the required format.',
|
|
'',
|
|
...errors.map((e) => `- ${e}`),
|
|
'',
|
|
'### How to resubmit',
|
|
'',
|
|
'1. Go to [New Issue](https://github.com/binaricat/Netcatty/issues/new/choose)',
|
|
'2. Pick **Bug Report** or **Feature Request**',
|
|
'3. Fill in every required field',
|
|
'4. Keep the `[Bug]` or `[Feature]` prefix in the title and add a clear summary after it (older app versions may use `Bug: ...`)',
|
|
'',
|
|
'For questions and open-ended discussion, use [GitHub Discussions](https://github.com/binaricat/Netcatty/discussions) instead.',
|
|
'',
|
|
'Edit the title/body to fix the errors above. This check will run again and reopen the issue once its format is valid.',
|
|
].join('\n');
|
|
|
|
const { data: comments } = await github.rest.issues.listComments({
|
|
owner: context.repo.owner,
|
|
repo: context.repo.repo,
|
|
issue_number: issueNumber,
|
|
per_page: 100,
|
|
});
|
|
const alreadyNotified = comments.some((c) =>
|
|
(c.body || '').includes(marker)
|
|
);
|
|
|
|
if (!alreadyNotified) {
|
|
await github.rest.issues.createComment({
|
|
owner: context.repo.owner,
|
|
repo: context.repo.repo,
|
|
issue_number: issueNumber,
|
|
body: bodyText,
|
|
});
|
|
}
|
|
|
|
labels.add('invalid-format');
|
|
|
|
await github.rest.issues.update({
|
|
owner: context.repo.owner,
|
|
repo: context.repo.repo,
|
|
issue_number: issueNumber,
|
|
state: 'closed',
|
|
state_reason: 'not_planned',
|
|
labels: [...labels],
|
|
});
|