-
Notifications
You must be signed in to change notification settings - Fork 698
135 lines (114 loc) · 4.91 KB
/
pr-decline.yml
File metadata and controls
135 lines (114 loc) · 4.91 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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
name: PR manual decline (label or button)
on:
pull_request_target:
types: [labeled]
workflow_dispatch:
inputs:
pr_number:
description: "PR number to act on"
required: true
reason:
description: "Reason to use"
required: true
type: choice
options: [Out of scope, Low info, Duplicate, Spam]
permissions:
pull-requests: write
contents: read
env:
REPO: ${{ github.repository }}
IDEAS_URL: https://github.com/buildermethods/agent-os/discussions/categories/ideas
CONTRIBUTING_URL: https://github.com/buildermethods/agent-os/blob/main/.github/CONTRIBUTING.md
jobs:
decline:
runs-on: ubuntu-latest
steps:
- name: Determine PR number and reason (from label or dispatch)
id: vars
uses: actions/github-script@v7
with:
script: |
let prNumber = "";
let reason = "";
let skip = false;
if (context.eventName === "pull_request_target" && context.payload.action === "labeled") {
prNumber = String(context.payload.pull_request.number);
const label = (context.payload.label?.name || "").trim();
const map = {
"Close PR: Out of scope": "Out of scope",
"Close PR: Low info": "Low info",
"Close PR: Duplicate": "Duplicate",
"Close PR: Spam": "Spam",
};
if (map[label]) {
reason = map[label];
} else {
skip = true; // not one of your decline labels
}
}
if (context.eventName === "workflow_dispatch") {
prNumber = (core.getInput("pr_number") || "").trim();
reason = (core.getInput("reason") || "").trim();
}
core.setOutput("skip", skip ? "true" : "false");
core.setOutput("pr", prNumber);
core.setOutput("reason", reason);
- name: Stop if not a decline event
if: steps.vars.outputs.skip == 'true' || steps.vars.outputs.pr == '' || steps.vars.outputs.reason == ''
run: echo "No decline action to run."
- name: Build canned message
if: steps.vars.outputs.skip != 'true' && steps.vars.outputs.pr != '' && steps.vars.outputs.reason != ''
id: msg
uses: actions/github-script@v7
env:
REASON: ${{ steps.vars.outputs.reason }} # <-- pass raw string
IDEAS_URL: ${{ env.IDEAS_URL }}
CONTRIBUTING_URL: ${{ env.CONTRIBUTING_URL }}
with:
script: |
const reason = process.env.REASON; // <-- read raw string
const IDEAS = process.env.IDEAS_URL;
const CONTRIB = process.env.CONTRIBUTING_URL;
let body = "";
switch (reason) {
case "Out of scope":
body =
"Thanks for the PR! After review, this change isn’t on the current roadmap for Agent OS. " +
"We keep core focused to manage long-term maintenance and compatibility.\n\n" +
`If you'd like to continue the conversation, please start a proposal in **Ideas**: ${IDEAS}\n` +
"If you publish a fork/plugin/example, feel free to share it in **Show & Tell** so others can try it.\n\n" +
"_Closing to keep the backlog focused._";
break;
case "Low info":
body =
"Thanks for the PR! We’re missing required details for review.\n\n" +
"Please update the PR with:\n" +
"• **Summary**\n" +
"• **Checklist**\n" +
"• **Documented steps to test**\n\n" +
`Guidelines: ${CONTRIB}\n\n` +
"Once updated, you can open a new PR or ask a maintainer to reopen.";
break;
case "Duplicate":
body =
"Thanks for the PR! This appears to duplicate existing work or discussion. " +
"We’ll consolidate on the canonical thread/PR to reduce churn.\n\n" +
"_Closing this one to keep things tidy._";
break;
case "Spam":
body = "Closing this PR. It doesn’t meet our contribution policy.";
break;
default:
body = "Thanks for the PR! Closing per maintainer review.";
}
core.setOutput("body", body);
- name: Comment and close PR
if: steps.vars.outputs.skip != 'true' && steps.vars.outputs.pr != '' && steps.msg.outputs.body != ''
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
REPO: ${{ env.REPO }}
run: |
PR="${{ steps.vars.outputs.pr }}"
BODY="${{ steps.msg.outputs.body }}"
gh pr comment "$PR" --repo "$REPO" --body "$BODY"
gh pr close "$PR" --repo "$REPO"