dsh-brain/vendor/dsh-mnemon/.github/workflows/reject-docs-pr.yml

67 lines
2.9 KiB
YAML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

name: 拒绝仅文档 PR / Reject Documentation-only PRs
on:
pull_request_target:
types: [opened, reopened, edited, ready_for_review]
permissions:
contents: read
issues: write
pull-requests: write
jobs:
reject:
name: 关闭外部仅文档 PR / Close external documentation-only PRs
runs-on: ubuntu-latest
if: ${{ !github.event.pull_request.draft }}
steps:
- name: 自动关闭外部仅文档 PR / Auto-close external documentation-only PRs
uses: actions/github-script@v8
with:
script: |
const pr = context.payload.pull_request;
const title = (pr.title || '').trim();
if (!/^docs(?:\b|\s*\()/i.test(title)) {
return;
}
let isMaintainer = false;
try {
const { data } = await github.rest.repos.getCollaboratorPermissionLevel({
owner: context.repo.owner,
repo: context.repo.repo,
username: pr.user.login,
});
isMaintainer = ['admin', 'maintain', 'write'].includes(data.permission);
} catch (error) {
core.info(`Contributor permission lookup returned no write grant: ${error.message}`);
}
if (isMaintainer) {
core.info(`PR #${pr.number} is a maintainer documentation change; keeping it open.`);
return;
}
const comment = [
'本仓库不直接接受外部贡献者的仅文档类 PR,此 PR 已被自动关闭。',
'This repository does not directly accept documentation-only PRs from external contributors, so this PR was closed automatically.',
'',
`请先到 https://github.com/${context.repo.owner}/${context.repo.repo}/issues 使用 Issue Form 说明需要修正的内容。 / Please use an Issue Form at https://github.com/${context.repo.owner}/${context.repo.repo}/issues to describe the requested documentation change first.`,
'若本 PR 实际包含代码修复,请使用对应的 Conventional Commits 标题并按完整 PR 模板重新提交。',
'If this PR contains a code fix, use the corresponding Conventional Commits title and resubmit with the complete PR template.',
].join('\n');
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: pr.number,
body: comment,
});
await github.rest.issues.update({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: pr.number,
state: 'closed',
state_reason: 'not_planned',
});
core.setFailed(`PR #${pr.number} 是外部仅文档贡献,已自动关闭。 / PR #${pr.number} is an external documentation-only contribution and was closed automatically.`);