Repository navigation
Speed up stale with GraphQL, add conflicts-only, move script to JS - #195
Merged
Jesse Hills (jesserockz) merged 2 commits intoOct 27, 2026
Merged
Conversation
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.
1 of 19 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.getper 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.mergeStateStatusis not requested (about 100ms per PR), so a conflict ismergeable == CONFLICTING. The head commit date replaces the per-PRrepos.getCommit, and anything missing from the GraphQL data falls back to the existing REST calls.conflicts-onlyinput. 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 exampleconflicts-only: ${{ github.event.schedule == '30 3-21/3 * * *' }}alongside a30 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 outscripts/stalefromjob.workflow_repositoryatjob.workflow_sha, the commit the caller pinned. Inputs reach the script through env vars rather than${{ }}interpolation into the JS. There are 91node:testtests against an in-memory GitHub client, with 100% line, branch and function coverage enforced bynpm testin 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:
The new checkout step and the
requirefrom github-script have not run in Actions yet: the checkout clones with a GITHUB_TOKEN that has no permissions (permissions: {}). A dry-runworkflow_dispatchfrom esphome/esphome against this branch would confirm both. actionlint 1.7.12 reports false errors onjob.workflow_repositoryandjob.workflow_sha; they are documentedjobcontext properties.