Skip to content

Speed up stale with GraphQL, add conflicts-only, move script to JS - #195

Merged
Jesse Hills (jesserockz) merged 2 commits into
jesserockz-2026-778from
jesserockz-2026-779
Oct 27, 2026
Merged

Jesse Hills (jesserockz) merged 2 commits into
jesserockz-2026-778from
jesserockz-2026-779

Conversation

@jesserockz

Copy link
Copy Markdown
Member

Stacked on #194.

The stale run in esphome/esphome went from about 3 minutes to 8-10 minutes once conflict handling landed. Most of that time was the mergeability pre-pass: one REST pulls.get per open PR, one after another, then a second fetch for the PRs GitHub had not decided yet. That came to about 650 calls and 350s of a 490s run.

GraphQL prefetch. Open PRs are now read with paged GraphQL queries: number, mergeable, labels, locked, timestamps, author and, for the full pass, the head commit date. Undecided PRs are re-queried on their own, up to 3 times, 10s apart. Pages hold 50 PRs because GitHub aborts a GraphQL request after 10s, and a page of 100 returned 502s. mergeStateStatus is not requested (about 100ms per PR), so a conflict is mergeable == CONFLICTING. The head commit date replaces the per-PR repos.getCommit, and anything missing from the GraphQL data falls back to the existing REST calls.

conflicts-only input. When true, only open PRs are processed: conflicts get the label and review, the label is removed (and the review dismissed) once the PR is mergeable, and a stale PR that is mergeable again loses both labels. Stale marking, closing, the conflict-to-stale step, event lookups and activity checks are skipped. This lets a caller check conflicts every 3 hours and run the full pass once a day, for example conflicts-only: ${{ github.event.schedule == '30 3-21/3 * * *' }} alongside a 30 0 * * * cron.

Script moved to scripts/stale/. The inline github-script body is now CommonJS modules (config, pulls, activity, actions, process, index). A reusable workflow runs in the caller's workspace, so a new step checks out scripts/stale from job.workflow_repository at job.workflow_sha, the commit the caller pinned. Inputs reach the script through env vars rather than ${{ }} interpolation into the JS. There are 91 node:test tests against an in-memory GitHub client, with 100% line, branch and function coverage enforced by npm test in a new CI job.

Dry runs against esphome/esphome with a read-only token, old inline script vs this branch, made the same decisions in both modes:

Mode Before After
Full pass 459s, 751 req 177s, 304 req
Conflicts-only n/a 10s, 9 req

The new checkout step and the require from github-script have not run in Actions yet: the checkout clones with a GITHUB_TOKEN that has no permissions (permissions: {}). A dry-run workflow_dispatch from esphome/esphome against this branch would confirm both. actionlint 1.7.12 reports false errors on job.workflow_repository and job.workflow_sha; they are documented job context properties.

The mergeability pre-pass made one REST pulls.get per open PR, in
sequence, then fetched the undecided ones again: about 650 calls and 350s
of a 490s run in esphome/esphome. Open PRs are now read with paged GraphQL
queries (50 per page, to stay under the 10s GraphQL timeout), which also
carry the head commit date used by the activity check.

A new conflicts-only input labels and unlabels merge conflicts without the
stale pass, so callers can check conflicts several times a day cheaply.
The inline github-script body is now scripts/stale/, checked out at the
commit the caller pinned (job.workflow_sha), with inputs passed through
env instead of being interpolated into the JS. Unit tests run against an
in-memory GitHub client with 100% coverage enforced in CI.
@jesserockz
Jesse Hills (jesserockz) merged commit c6e6282 into main Oct 27, 2026
40 checks passed
@jesserockz
Jesse Hills (jesserockz) deleted the jesserockz-2026-779 branch October 27, 2026 01:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant