-
Notifications
You must be signed in to change notification settings - Fork 770
Expand file tree
/
Copy pathclose-contribution-workflow-violation.yml
More file actions
97 lines (87 loc) · 4.16 KB
/
Copy pathclose-contribution-workflow-violation.yml
File metadata and controls
97 lines (87 loc) · 4.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
name: Close contribution workflow violation
on:
# zizmor: ignore[dangerous-triggers] -- only maintainers can apply the label;
# the pinned action reads event metadata and never executes PR-controlled code.
pull_request_target:
types: [labeled]
permissions: {}
concurrency:
group: close-contribution-workflow-violation-${{ github.event.pull_request.number }}
cancel-in-progress: false
jobs:
close:
name: Close PR for contribution workflow violation
if: "github.event.label.name == 'status: contribution workflow violation'"
runs-on: ubuntu-latest
permissions:
pull-requests: write # Needed to comment on and close the PR.
steps:
- uses: actions/github-script@v9
env:
COMMENT_MARKER: "<!-- contribution-workflow-violation -->"
TARGET_LABEL: "status: contribution workflow violation"
with:
script: |
const owner = context.repo.owner;
const repo = context.repo.repo;
const marker = process.env.COMMENT_MARKER;
const targetLabel = process.env.TARGET_LABEL;
const pull_number = context.payload.pull_request.number;
const { data: pullRequest } = await github.rest.pulls.get({
owner,
repo,
pull_number,
});
const author = pullRequest.user?.login;
const closureSubject = author ? `@${author}, this PR` : "This PR";
if (pullRequest.state !== "open") {
core.info(`PR #${pull_number} is already ${pullRequest.state}; skipping.`);
return;
}
const hasTargetLabel = pullRequest.labels.some((label) => {
return label.name === targetLabel;
});
if (!hasTargetLabel) {
core.info(`PR #${pull_number} no longer has the "${targetLabel}" label; skipping.`);
return;
}
const body = [
marker,
"",
`${closureSubject} is being closed because it was opened before completing the required contribution workflow. Every PR must link to a triaged issue assigned to the PR author; this PR does not link to such an issue.`,
"",
"The PR description must also use our current template, including the Related Issue, Verification, and AI Assistance sections. If AI tools substantially assisted with the contribution, disclose the tool and extent of assistance. The human contributor must review, verify, understand, and take responsibility for every submitted change. If no AI tools were used, select that option in the template.",
"",
"Before submitting another PR:",
"",
"1. Search for an existing issue or manually open one using the appropriate issue template.",
"2. Wait for a maintainer to triage the issue and assign it to you.",
"3. After assignment, open a new PR from `develop` using the complete PR template, a Conventional Commit-style title, and the documented validation commands.",
"",
"Please do not reopen this PR. You’re welcome to submit a new one after completing the workflow.",
"",
`See [CONTRIBUTING.md](https://github.com/${owner}/${repo}/blob/develop/CONTRIBUTING.md) and [AI_POLICY.md](https://github.com/${owner}/${repo}/blob/develop/AI_POLICY.md).`,
].join("\n");
const comments = await github.paginate(github.rest.issues.listComments, {
owner,
repo,
issue_number: pull_number,
per_page: 100,
});
const existingComment = comments.find((comment) => {
return comment.user?.type === "Bot" && comment.body?.startsWith(marker);
});
if (!existingComment) {
await github.rest.issues.createComment({
owner,
repo,
issue_number: pull_number,
body,
});
}
await github.rest.pulls.update({
owner,
repo,
pull_number,
state: "closed",
});