Skip to content

armgit / kaneo

Public Imported from GitHub
0

⚡ Project management that doesn't become the project. Boards, Gantt charts, and GitHub integration. Self-host it or use Kaneo Cloud.

fix(ci): explain automatic pull request draft conversions

Tin5c425995019c
diff --git a/scripts/contribution-eligibility/check.mjs b/scripts/contribution-eligibility/check.mjs
index 101204b7d..f546bfca0 100644
--- a/scripts/contribution-eligibility/check.mjs
+++ b/scripts/contribution-eligibility/check.mjs
@@ -2,6 +2,7 @@ import { readFile } from "node:fs/promises";
import { pathToFileURL } from "node:url";
import { GitHub } from "./github.mjs";
import { checkPublisher } from "./check-runs.mjs";
+import { draftComment } from "./draft-comment.mjs";
import { assessIssues, authorExemption, validatePolicy } from "./policy.mjs";
async function checkPullRequest(github, pull, policy, policyError) {
@@ -36,6 +37,10 @@ async function checkPullRequest(github, pull, policy, policyError) {
}
if (result.state === "failure" && !current.draft) {
await github.convertToDraft(current.node_id);
+ await github.request(
+ `repos/${github.repository}/issues/${current.number}/comments`,
+ { method: "POST", body: { body: draftComment } },
+ );
}
return result;
}
diff --git a/scripts/contribution-eligibility/check.test.mjs b/scripts/contribution-eligibility/check.test.mjs
index 2c252fcf3..51858b8b7 100644
--- a/scripts/contribution-eligibility/check.test.mjs
+++ b/scripts/contribution-eligibility/check.test.mjs
@@ -37,6 +37,7 @@ function fixture(options = {}) {
const checks = new Map();
const drafts = new Set();
const conversions = [];
+ const comments = [];
const pulls = options.pulls ?? [pull];
const fetcher = async (url, init) => {
const parsed = new URL(url);
@@ -80,6 +81,19 @@ function fixture(options = {}) {
draft: drafts.has(current.node_id) || current.draft,
...options.current,
};
+ } else if (/^\/repos\/test\/repo\/issues\/\d+\/comments$/.test(path)) {
+ assert.equal(init.method, "POST");
+ assert.ok(
+ drafts.has(
+ pulls.find((item) => item.number === Number(path.split("/").at(-2)))
+ .node_id,
+ ),
+ );
+ comments.push({
+ number: Number(path.split("/").at(-2)),
+ body: body.body,
+ });
+ data = { id: comments.length };
} else if (path.includes("/collaborators/")) {
status = options.permissionStatus ?? (options.permission ? 200 : 404);
data = options.permission ?? {};
@@ -147,21 +161,33 @@ function fixture(options = {}) {
},
fetcher,
);
- return { github, requests, statuses, conversions };
+ return { github, requests, statuses, conversions, comments };
}
test("ineligible PRs become drafts once and are re-drafted if marked ready", async () => {
const options = { links: [] };
- const { github, conversions, statuses } = fixture(options);
+ const { github, conversions, statuses, comments } = fixture(options);
await reconcile(github, async () => policy);
assert.deepEqual(conversions, [pull.node_id]);
assert.equal(statuses.at(-1).state, "failure");
+ assert.equal(comments.length, 1);
+ assert.equal(comments[0].number, pull.number);
+ assert.match(comments[0].body, /automatically converted to a draft/);
+ assert.match(comments[0].body, /Since October 5, 2026/);
+ assert.match(comments[0].body, /ready-for-contribution/);
+ assert.match(comments[0].body, /bug report or feature request/);
+ assert.match(
+ comments[0].body,
+ /https:\/\/github\.com\/usekaneo\/kaneo\?tab=contributing-ov-file#contribution-eligibility/,
+ );
await reconcile(github, async () => policy);
assert.deepEqual(conversions, [pull.node_id]);
+ assert.equal(comments.length, 1);
options.current = { draft: false };
await reconcile(github, async () => policy);
assert.deepEqual(conversions, [pull.node_id, pull.node_id]);
+ assert.equal(comments.length, 2);
});
test("eligible PRs and existing drafts keep their draft status", async () => {
@@ -171,9 +197,10 @@ test("eligible PRs and existing drafts keep their draft status", async () => {
{ pulls: [{ ...pull, draft: true }], links: [] },
{ links: [], permission: { permission: "admin" } },
]) {
- const { github, conversions } = fixture(options);
+ const { github, conversions, comments } = fixture(options);
await reconcile(github, async () => policy);
assert.deepEqual(conversions, []);
+ assert.deepEqual(comments, []);
}
});
@@ -200,9 +227,10 @@ test("stale or closed ineligible PRs are not converted", async () => {
{ base: { ref: "other" } },
{ state: "closed" },
]) {
- const { github, conversions } = fixture({ current, links: [] });
+ const { github, conversions, comments } = fixture({ current, links: [] });
await reconcile(github, async () => policy);
assert.deepEqual(conversions, []);
+ assert.deepEqual(comments, []);
}
});
@@ -214,13 +242,14 @@ test("conversion failures fail the check and retry on the next run", async () =>
{ current: { node_id: undefined } },
]) {
const options = { links: [], ...failure };
- const { github, statuses } = fixture(options);
+ const { github, statuses, comments } = fixture(options);
await assert.rejects(
reconcile(github, async () => policy),
AggregateError,
);
assert.equal(statuses.at(-1).state, "failure");
assert.match(statuses.at(-1).description, /could not be checked/);
+ assert.deepEqual(comments, []);
for (const key of Object.keys(failure)) delete options[key];
options.current = { draft: false };
await reconcile(github, async () => policy);
diff --git a/scripts/contribution-eligibility/draft-comment.mjs b/scripts/contribution-eligibility/draft-comment.mjs
new file mode 100644
index 000000000..8730d05a1
--- /dev/null
+++ b/scripts/contribution-eligibility/draft-comment.mjs
@@ -0,0 +1,9 @@
+export const draftComment = `Hello there!
+
+Your pull request was automatically converted to a draft.
+
+Since October 5, 2026, contributors who have not been vouched for must link their pull requests to an open issue in this repository labeled \`ready-for-contribution\`.
+
+Please open a bug report or feature request first, then wait for a maintainer to approve the scope and add the label. If an approved issue already exists, link it in your pull request description with \`Fixes #123\` or \`Closes #123\`. Once the contribution eligibility check passes, you can mark your pull request ready for review.
+
+Read more: https://github.com/usekaneo/kaneo?tab=contributing-ov-file#contribution-eligibility`;