Skip to content

A modern and easy to use dashboard. 80+ integrations. 20K+ icons built in. Authentication out of the box. No YAML, drag and drop configuration.

feat(ci): sync triage replies with GitHub Projects (#7249)

Thomas160f4b91b1c5
diff --git a/.github/scripts/triage-project.cjs b/.github/scripts/triage-project.cjs
new file mode 100644
index 000000000..c008773d8
--- /dev/null
+++ b/.github/scripts/triage-project.cjs
@@ -0,0 +1,227 @@
+const states = new Map([
+ ["needs triage", "Needs triage"],
+ ["specced-out", "Ready to implement"],
+ ["waiting-for-reporter", "Waiting for reply"],
+ ["needs info from the maintainer", "Needs maintainer"],
+ ["wontfix", "Not planned"],
+]);
+const waiting = "waiting-for-reporter";
+const ready = "ready for test";
+const aiDisclaimer =
+ /^\s*(?:>\s*)?[*_]*(?:This was (?:generated|written|created|assisted|authored) by (?:an? )?AI\b|AI[- ](?:generated|assisted|written|authored) (?:reply|response|comment|message)\b)/i;
+const labels = (issue) => issue.labels.map((label) => label.name);
+const activeStates = (issue) => labels(issue).filter((label) => states.has(label));
+const latestLabel = (events, name) =>
+ events
+ .filter((event) => event.event === "labeled" && event.label?.name === name)
+ .reduce((latest, event) => Math.max(latest, Date.parse(event.created_at)), 0);
+const statusFor = (issue) => {
+ if (issue.state === "closed") {
+ if (issue.state_reason === "not_planned" || labels(issue).includes("wontfix")) return "Not planned";
+ return "Done";
+ }
+ const current = activeStates(issue);
+ if (current.length === 0) return "Needs triage";
+ if (current.length === 1) return states.get(current[0]);
+};
+
+module.exports = async ({ github, context, core }) => {
+ const repo = context.repo;
+ const read = async (number) => (await github.rest.issues.get({ ...repo, issue_number: number })).data;
+ const number = context.payload.issue?.number ?? context.payload.pull_request?.number;
+ let targets = [];
+
+ if (number) {
+ let comment;
+ if (context.eventName === "issue_comment") {
+ comment = (await github.rest.issues.getComment({ ...repo, comment_id: context.payload.comment.id })).data;
+ }
+ const issue = await read(number);
+ const current = activeStates(issue);
+ let remove = [];
+ if (issue.state === "open") {
+ if (
+ comment &&
+ current.length === 1 &&
+ current[0] === waiting &&
+ comment.user?.id === issue.user.id &&
+ comment.user.type === "User" &&
+ !comment.user.login.endsWith("[bot]") &&
+ !comment.performed_via_github_app &&
+ !aiDisclaimer.test(comment.body ?? "")
+ ) {
+ const events = await github.paginate(github.rest.issues.listEvents, {
+ ...repo,
+ issue_number: number,
+ per_page: 100,
+ });
+ const waitingSince = latestLabel(events, waiting);
+ // A queued old comment must not release a newer request for reporter testing.
+ if (waitingSince && Date.parse(comment.created_at) > waitingSince) remove = [waiting];
+ }
+ if (context.eventName === "pull_request_target" && context.payload.action === "synchronize") {
+ const { data: pull } = await github.rest.pulls.get({ ...repo, pull_number: number });
+ const pushedAt = Date.parse(context.payload.pull_request.updated_at);
+ if (pull.head.sha === context.payload.pull_request.head.sha && Number.isFinite(pushedAt)) {
+ const events = await github.paginate(github.rest.issues.listEvents, {
+ ...repo,
+ issue_number: number,
+ per_page: 100,
+ });
+ // Replays must preserve readiness applied after this push, including ambiguous same-second events.
+ remove = labels(issue).filter((label) => {
+ if (label !== ready && !(current.length === 1 && label === waiting)) return false;
+ const appliedAt = latestLabel(events, label);
+ return appliedAt > 0 && appliedAt < pushedAt;
+ });
+ if (remove.includes(ready) && current.length === 1 && current[0] === "specced-out") {
+ const specifiedAt = latestLabel(events, current[0]);
+ if (specifiedAt > 0 && specifiedAt < pushedAt) remove.push(current[0]);
+ }
+ }
+ }
+ if (remove.length) {
+ // Recheck after reading comments/events/PR metadata; never replace the whole label set.
+ const fresh = await read(number);
+ if (
+ fresh.state === "open" &&
+ fresh.updated_at === issue.updated_at &&
+ JSON.stringify(labels(fresh)) === JSON.stringify(labels(issue))
+ ) {
+ for (const name of new Set(remove))
+ await github.rest.issues.removeLabel({ ...repo, issue_number: number, name });
+ const afterRemoval = await read(number);
+ if (afterRemoval.state === "open" && activeStates(afterRemoval).length === 0) {
+ await github.rest.issues.addLabels({ ...repo, issue_number: number, labels: ["needs triage"] });
+ }
+ }
+ }
+ }
+ targets = [number];
+ } else if (context.eventName === "workflow_dispatch") {
+ const input = context.payload.inputs?.number?.trim();
+ if (input) {
+ if (!/^[1-9]\d*$/.test(input) || !Number.isSafeInteger(Number(input)))
+ throw new Error("Enter a positive issue or PR number.");
+ targets = [Number(input)];
+ const issue = await read(targets[0]);
+ if (issue.state === "open" && activeStates(issue).length === 0) {
+ await github.rest.issues.addLabels({ ...repo, issue_number: targets[0], labels: ["needs triage"] });
+ }
+ } else {
+ const found = new Set();
+ backfill: for (const label of states.keys()) {
+ for await (const response of github.paginate.iterator(github.rest.issues.listForRepo, {
+ ...repo,
+ state: "open",
+ labels: label,
+ per_page: 100,
+ })) {
+ for (const issue of response.data) {
+ found.add(issue.number);
+ if (found.size >= 500) {
+ core.warning("Backfill limited to 500 open triaged items. Sync remaining items individually.");
+ break backfill;
+ }
+ }
+ }
+ }
+ targets = [...found];
+ }
+ }
+
+ if (!process.env.TRIAGE_PROJECT_NUMBER || !process.env.TRIAGE_PROJECT_TOKEN) {
+ core.notice(
+ "Project sync skipped: configure TRIAGE_PROJECT_NUMBER and App credentials or TRIAGE_PROJECT_TOKEN. Reply label handling remains active.",
+ );
+ return;
+ }
+ const projectNumber = Number(process.env.TRIAGE_PROJECT_NUMBER);
+ if (!Number.isSafeInteger(projectNumber) || projectNumber < 1)
+ throw new Error("TRIAGE_PROJECT_NUMBER must be a positive integer.");
+ const graphql = new github.constructor({
+ auth: process.env.TRIAGE_PROJECT_TOKEN,
+ baseUrl: github.request.endpoint.DEFAULTS.baseUrl,
+ }).graphql;
+ let project;
+ let field;
+ let cursor = null;
+ do {
+ const result = await graphql(
+ `
+ query ($owner: String!, $number: Int!, $cursor: String) {
+ organization(login: $owner) {
+ projectV2(number: $number) {
+ id
+ fields(first: 100, after: $cursor) {
+ nodes {
+ ... on ProjectV2SingleSelectField {
+ id
+ name
+ options {
+ id
+ name
+ }
+ }
+ }
+ pageInfo {
+ hasNextPage
+ endCursor
+ }
+ }
+ }
+ }
+ }
+ `,
+ { owner: process.env.TRIAGE_PROJECT_OWNER || "homarr-labs", number: projectNumber, cursor },
+ );
+ project = result.organization?.projectV2;
+ if (!project) throw new Error("Configured organization Project was not found or is inaccessible.");
+ field = project.fields.nodes.find((candidate) => candidate?.name === "Status") ?? field;
+ cursor = project.fields.pageInfo.endCursor;
+ } while (!field && project.fields.pageInfo.hasNextPage);
+ const options = new Map(field?.options.map((option) => [option.name, option.id]));
+ for (const status of new Set([...states.values(), "Done"])) {
+ if (!options.has(status)) throw new Error(`Project Status option missing: ${status}`);
+ }
+ for (const target of targets) {
+ // GITHUB_TOKEN label writes do not start another run; mirror the fresh state here.
+ const issue = await read(target);
+ if (!statusFor(issue)) {
+ core.warning(`#${target}: Project sync skipped because triage state labels conflict.`);
+ continue;
+ }
+ const added = await graphql(
+ `
+ mutation ($project: ID!, $content: ID!) {
+ addProjectV2ItemById(input: { projectId: $project, contentId: $content }) {
+ item {
+ id
+ }
+ }
+ }
+ `,
+ { project: project.id, content: issue.node_id },
+ );
+ const status = statusFor(await read(target));
+ if (!status) {
+ core.warning(`#${target}: Project Status update skipped because triage state changed.`);
+ continue;
+ }
+ await graphql(
+ `
+ mutation ($project: ID!, $item: ID!, $field: ID!, $option: String!) {
+ updateProjectV2ItemFieldValue(
+ input: { projectId: $project, itemId: $item, fieldId: $field, value: { singleSelectOptionId: $option } }
+ ) {
+ projectV2Item {
+ id
+ }
+ }
+ }
+ `,
+ { project: project.id, item: added.addProjectV2ItemById.item.id, field: field.id, option: options.get(status) },
+ );
+ core.info(`#${target}: Project Status → ${status}`);
+ }
+};
diff --git a/.github/workflows/triage-project.yml b/.github/workflows/triage-project.yml
new file mode 100644
index 000000000..61c8f7031
--- /dev/null
+++ b/.github/workflows/triage-project.yml
@@ -0,0 +1,63 @@
+name: "[Triage] Project sync"
+
+on:
+ issues:
+ types: [opened, labeled, unlabeled, closed, reopened]
+ issue_comment:
+ types: [created]
+ pull_request_target:
+ types: [opened, labeled, unlabeled, closed, reopened, synchronize]
+ workflow_dispatch:
+ inputs:
+ number:
+ description: "Issue/PR number; leave empty to sync up to 500 open triaged items"
+ type: string
+ required: false
+
+permissions:
+ contents: read
+ issues: write
+ pull-requests: write
+
+concurrency:
+ group: triage-project-${{ github.event.issue.number || github.event.pull_request.number || inputs.number || 'backfill' }}
+ queue: max
+ cancel-in-progress: false
+
+jobs:
+ sync:
+ runs-on: ubuntu-latest
+ timeout-minutes: 15
+ env:
+ TRIAGE_APP_CONFIGURED: ${{ vars.HOMARR_UPDATE_CONTRIBUTORS_CLIENT_ID != '' && secrets.HOMARR_UPDATE_CONTRIBUTORS_PRIVATE_KEY != '' }}
+ steps:
+ - uses: actions/checkout@v7
+ with:
+ ref: dev
+ persist-credentials: false
+ - name: Create Project App token
+ id: project-token
+ if: env.TRIAGE_APP_CONFIGURED == 'true' && vars.TRIAGE_PROJECT_NUMBER != ''
+ continue-on-error: true # Label handling must also work if Project authentication fails.
+ uses: actions/create-github-app-token@v3
+ with:
+ client-id: ${{ vars.HOMARR_UPDATE_CONTRIBUTORS_CLIENT_ID }}
+ private-key: ${{ secrets.HOMARR_UPDATE_CONTRIBUTORS_PRIVATE_KEY }}
+ owner: ${{ vars.TRIAGE_PROJECT_OWNER || 'homarr-labs' }}
+ repositories: ${{ github.event.repository.name }}
+ permission-organization-projects: write
+ permission-issues: read
+ permission-pull-requests: read
+ - uses: actions/github-script@v8
+ env:
+ TRIAGE_PROJECT_OWNER: ${{ vars.TRIAGE_PROJECT_OWNER }}
+ TRIAGE_PROJECT_NUMBER: ${{ vars.TRIAGE_PROJECT_NUMBER }}
+ TRIAGE_PROJECT_TOKEN: ${{ steps.project-token.outputs.token || secrets.TRIAGE_PROJECT_TOKEN }}
+ TRIAGE_APP_FAILED: ${{ steps.project-token.outcome == 'failure' }}
+ with:
+ script: |
+ const sync = require('./.github/scripts/triage-project.cjs');
+ await sync({ github, context, core });
+ if (process.env.TRIAGE_APP_FAILED === 'true' && !process.env.TRIAGE_PROJECT_TOKEN) {
+ core.setFailed('Project App authentication failed; reply label handling completed.');
+ }
diff --git a/docs/agents/triage-project.md b/docs/agents/triage-project.md
new file mode 100644
index 000000000..6bbe93010
--- /dev/null
+++ b/docs/agents/triage-project.md
@@ -0,0 +1,33 @@
+# Triage Project automation
+
+The `[Triage] Project sync` workflow mirrors [triage state labels](triage-labels.md) into an organization Project's `Status` field. Labels are authoritative; dragging a card does not change them.
+
+## Setup
+
+Set repository variable `TRIAGE_PROJECT_NUMBER` to the Project number from its URL. `TRIAGE_PROJECT_OWNER` defaults to `homarr-labs`. Create these exact `Status` options:
+
+| Label | Status |
+| -------------------------------- | ------------------ |
+| `needs triage` | Needs triage |
+| `specced-out` | Ready to implement |
+| `waiting-for-reporter` | Waiting for reply |
+| `needs info from the maintainer` | Needs maintainer |
+| `wontfix` | Not planned |
+| Closed | Done |
+
+Closed items with `wontfix` or a `not_planned` closure reason remain **Not planned**. Open items without a triage state enter **Needs triage** without adding a label; conflicting states are skipped. Supplementary labels such as size and `ready for test` do not choose a column. Initial bulk backfill includes only open items with existing triage state labels.
+
+Install or reuse a GitHub App on the organization with organization **Projects: read/write** and repository **Issues: read** and **Pull requests: read**, limited to this repository. This repository reuses the installed `homarr-update-contributors` App through existing repository variable `HOMARR_UPDATE_CONTRIBUTORS_CLIENT_ID` and secret `HOMARR_UPDATE_CONTRIBUTORS_PRIVATE_KEY`. Accept updated permissions on the App installation after changing its registration. The workflow creates a short-lived installation token and revokes it after the job. The exact permission inputs follow [the token action's definition](https://github.com/actions/create-github-app-token/blob/v3/action.yml).
+
+Alternatively, set secret `TRIAGE_PROJECT_TOKEN` to a dedicated PAT with organization Projects read/write and access to this repository's issues and PRs. It is also the fallback if App authentication fails. Expiring PATs need renewal. The repository `GITHUB_TOKEN` only changes labels and cannot access Projects. See [GitHub's Projects automation guidance](https://docs.github.com/en/issues/planning-and-tracking-with-projects/automating-your-project/automating-projects-using-actions).
+
+Missing Project configuration skips board synchronization with a workflow notice; reply label handling still runs. A configured but inaccessible Project or missing Status option fails the run. Run the workflow manually with an issue/PR number to retry a sync, or leave the input empty to backfill up to 500 open items with existing triage states. Historical closed items are not backfilled.
+
+## Automatic transitions
+
+- A human original author's new top-level **Conversation** comment on an open issue or PR changes the single `waiting-for-reporter` state to `needs triage`. Bot/App comments and replies with an AI-generation disclaimer are ignored. Comments predating the current waiting label are ignored, including delayed workflow events. Inline review replies are not handled.
+- A new PR head removes testing labels applied before that push and returns the item to `needs triage` when no newer triage state is present. Delayed events for older heads and readiness labels reapplied after the push are preserved; same-second chronology is treated conservatively. Stale supplementary `ready for test` is also removed under a maintainer hold or `wontfix`, while those primary states are preserved. Conflicting primary states are preserved.
+
+Events queue per item rather than replacing a pending reply. Label writes preserve unrelated labels and recheck current states before adding `needs triage`, but separate GitHub API calls are not atomic. A failed write fails the run. Manually dispatching a specific item number repairs an open item's missing triage state by adding `needs triage` before syncing; bulk backfill does not repair labels. Existing states, holds, conflicts, and closed items are preserved.
+
+A reply requests re-triage; it never establishes acceptance. The workflow does not post comments, approve, merge, close, or mark an image ready. It runs only trusted `dev` metadata code and never checks out or executes PR code.