Skip to content

Commit 4b53405

Browse files
committed
Tell draft authors why their PR is closed before it's marked ready
1 parent b3a5054 commit 4b53405

2 files changed

Lines changed: 12 additions & 8 deletions

File tree

.github/scripts/pr_intake_gate.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ module.exports = async function run({ github, context, core }) {
121121
async function fail(linkedIssues) {
122122
console.log(`FAIL: ${linkedIssues.length ? `not assigned to ${linkedIssues.map((n) => `#${n}`).join(', ')}` : 'no usable issue link'}`);
123123
await addLabel(prNumber, LABEL);
124-
await upsertGateComment(prNumber, closedComment(linkedIssues));
124+
await upsertGateComment(prNumber, closedComment(pr.draft, linkedIssues));
125125
if (pr.state === 'open') {
126126
await mutate(`close PR #${prNumber}`, () => github.rest.pulls.update({ owner, repo, pull_number: prNumber, state: 'closed' }));
127127
}
@@ -134,10 +134,12 @@ module.exports = async function run({ github, context, core }) {
134134

135135
// ── Comment text ─────────────────────────────────────────────────────────
136136

137-
function closedComment(linkedIssues) {
137+
function closedComment(draft, linkedIssues) {
138138
const issues = linkedIssues.map((n) => `#${n}`).join(', ');
139-
const rule =
140-
'This PR has been closed automatically. This repo only keeps pull requests open when they come from a maintainer, or from a contributor a maintainer has assigned to the linked issue';
139+
const opener = draft
140+
? "This PR has been closed automatically. It's still a draft, but we close those early so you don't put in more time only to have it closed the moment you mark it ready.\n\n"
141+
: 'This PR has been closed automatically. ';
142+
const rule = `${opener}This repo only keeps pull requests open when they come from a maintainer, or from a contributor a maintainer has assigned to the linked issue`;
141143
const situation = linkedIssues.length
142144
? [
143145
`${rule}, and you aren't currently assigned to ${issues}.`,

.github/scripts/pr_intake_gate.test.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ const PEOPLE = {
2828
// ── Scenarios ──────────────────────────────────────────────────────────────
2929
// `prs` / `issues` describe the world before the event; `expect` describes each
3030
// PR afterwards: state, labels, and comment ('closed' = the "this PR has been
31-
// closed" comment, 'cannot-reopen' = the refused-reopen comment, null = none).
31+
// closed" comment, 'closed-draft' = its draft wording, 'cannot-reopen' = the
32+
// refused-reopen comment, null = none).
3233
// `writes: 0` additionally asserts the gate touched nothing at all.
3334

3435
const scenarios = [
@@ -146,10 +147,10 @@ const scenarios = [
146147
writes: 0,
147148
},
148149
{
149-
name: 'draft PR with no issue link is closed like any other',
150+
name: 'draft PR with no issue link is closed like any other, with a note about why drafts are closed early',
150151
prs: [pr(3300, 'outsider', { draft: true })],
151152
event: opened(3300, 'outsider'),
152-
expect: { 3300: { state: 'closed', labels: [LABEL], comment: 'closed' } },
153+
expect: { 3300: { state: 'closed', labels: [LABEL], comment: 'closed-draft' } },
153154
},
154155
{
155156
name: 'pre-existing draft marked ready for review with no link → closed',
@@ -298,7 +299,8 @@ function observe(world, expect) {
298299
const p = world.prs.get(Number(num));
299300
const gateComments = p.comments.filter((c) => c.user === 'github-actions[bot]' && c.body.includes('<!-- require-linked-issue -->'));
300301
assert.ok(gateComments.length <= 1, `PR #${num} has ${gateComments.length} gate comments`);
301-
const kind = !gateComments.length ? null : gateComments[0].body.includes("won't let it be reopened") ? 'cannot-reopen' : 'closed';
302+
const body = gateComments[0]?.body;
303+
const kind = !body ? null : body.includes("won't let it be reopened") ? 'cannot-reopen' : body.includes('still a draft') ? 'closed-draft' : 'closed';
302304
out[num] = { state: p.state, labels: [...p.labels].sort(), comment: kind };
303305
if ('foreignComments' in expect[num]) out[num].foreignComments = p.comments.length - gateComments.length;
304306
}

0 commit comments

Comments
 (0)