⚡ Project management that doesn't become the project. Boards, Gantt charts, and GitHub integration. Self-host it or use Kaneo Cloud.
TypeScript honoissue-managementissue-trackerjira-alternativekanbanlinear-alternativemcpproject-managementreactself-hostedtypescript
fix(ci): ci errors for contribution workflow
justine6e60bf92788
diff --git a/.github/workflows/contribution-eligibility.yml b/.github/workflows/contribution-eligibility.ymlindex 5b5d3c414..e36ad2b1c 100644--- a/.github/workflows/contribution-eligibility.yml+++ b/.github/workflows/contribution-eligibility.yml@@ -27,12 +27,15 @@ on:permissions:contents: read- pull-requests: write- issues: read- checks: writejobs:reconcile:+ permissions:+ # GitHub's draft-conversion mutation also requires repository write access.+ contents: write+ pull-requests: write+ issues: read+ checks: write# Dependabot-triggered runs may receive a read-only token. CI completion# rechecks its PR using a token issued in the trusted workflow context.if: >-diff --git a/scripts/contribution-eligibility/check.mjs b/scripts/contribution-eligibility/check.mjsindex 9f700258c..101204b7d 100644--- a/scripts/contribution-eligibility/check.mjs+++ b/scripts/contribution-eligibility/check.mjs@@ -73,7 +73,11 @@ export async function reconcile(github, loadPolicy) {try {result = await checkPullRequest(github, pull, policy, policyError);} catch (error) {- errors.push(error);+ errors.push(+ new Error(`PR #${pull.number}: Eligibility reconciliation failed.`, {+ cause: error,+ }),+ );result = {state: "error",description:diff --git a/scripts/contribution-eligibility/check.test.mjs b/scripts/contribution-eligibility/check.test.mjsindex ab7b06021..2c252fcf3 100644--- a/scripts/contribution-eligibility/check.test.mjs+++ b/scripts/contribution-eligibility/check.test.mjs@@ -229,6 +229,21 @@ test("conversion failures fail the check and retry on the next run", async () =>}});+test("reconciliation errors identify the PR and retain the rejection cause", async () => {+ const { github, statuses } = fixture({ links: [], conversionErrors: true });+ await assert.rejects(+ reconcile(github, async () => policy),+ (error) => {+ assert.ok(error instanceof AggregateError);+ assert.match(error.errors[0].message, /PR #1/);+ assert.match(error.errors[0].cause.message, /synthetic failure/);+ return true;+ },+ );+ assert.equal(statuses.at(-1).state, "failure");+ assert.match(statuses.at(-1).description, /could not be checked/);+});+test("approved issue publishes pending then success on the fork's exact head", async () => {const { github, statuses } = fixture();const results = await reconcile(github, async () => policy);diff --git a/scripts/contribution-eligibility/github.mjs b/scripts/contribution-eligibility/github.mjsindex 39dc732da..3c78d85fc 100644--- a/scripts/contribution-eligibility/github.mjs+++ b/scripts/contribution-eligibility/github.mjs@@ -33,8 +33,22 @@ export class GitHub {throw new Error(`GitHub request failed (${response.status}).`);}const result = await response.json();- if (result.errors?.length)- throw new Error("GitHub GraphQL request failed.");+ if (result.errors?.length) {+ const details = result.errors+ .map((error) =>+ [error?.type, error?.message]+ .filter((value) => typeof value === "string")+ .join(": "),+ )+ .join("; ")+ .replaceAll(this.token, "[redacted]")+ .replace(/\p{Cc}/gu, " ")+ .slice(0, 1_000)+ .trim();+ throw new Error(+ `GitHub GraphQL request failed: ${details || "No error details returned."}`,+ );+ }return result;}diff --git a/scripts/contribution-eligibility/github.test.mjs b/scripts/contribution-eligibility/github.test.mjsnew file mode 100644index 000000000..a78a4bc09--- /dev/null+++ b/scripts/contribution-eligibility/github.test.mjs@@ -0,0 +1,61 @@+import assert from "node:assert/strict";+import test from "node:test";+import { GitHub } from "./github.mjs";++const token = "synthetic-token";++function githubResponse(response) {+ return new GitHub(+ { GITHUB_REPOSITORY: "test/repo", GH_TOKEN: token },+ async () => Response.json(response),+ );+}++test("draft conversion reports the GraphQL permission rejection", async () => {+ const github = githubResponse({+ data: { convertPullRequestToDraft: null },+ errors: [+ {+ type: "FORBIDDEN",+ message: "Resource not accessible by integration",+ path: ["convertPullRequestToDraft"],+ },+ ],+ });+ await assert.rejects(github.convertToDraft("PR_test_1"), (error) => {+ assert.match(error.message, /FORBIDDEN/);+ assert.match(error.message, /Resource not accessible by integration/);+ return true;+ });+});++test("GraphQL diagnostics redact tokens and omit response data", async () => {+ const github = githubResponse({+ data: { privateData: "not-for-logs" },+ errors: [+ {+ type: "FORBIDDEN",+ message: `Rejected ${token}\n::error::injected`,+ extensions: { privateData: "not-for-logs" },+ },+ ],+ });+ await assert.rejects(github.convertToDraft("PR_test_1"), (error) => {+ assert.match(error.message, /Rejected \[redacted\]/);+ assert.equal(error.message.includes(token), false);+ assert.equal(error.message.includes("not-for-logs"), false);+ assert.equal(/\p{Cc}/u.test(error.message), false);+ return true;+ });+});++test("GraphQL diagnostics remain bounded for oversized errors", async () => {+ const github = githubResponse({+ errors: [{ type: "FORBIDDEN", message: "x".repeat(10_000) }],+ });+ await assert.rejects(github.convertToDraft("PR_test_1"), (error) => {+ assert.ok(error.message.length < 1_100);+ assert.match(error.message, /FORBIDDEN/);+ return true;+ });+});