feat: auto-close stale sync PRs when source file reverts to match target#192
Merged
Conversation
Add closeStaleActionPrs helper that searches for open PRs by branch name and closes them with an explanatory comment when the source matches target. - Warns instead of closing if PR has more commits than expected (safety check) - Supports dry-run mode (logs which PRs would be closed) - Integrates into syncFilesViaPullRequest (covers dependabot, gitignore, PR template, workflow files, copilot-instructions, CODEOWNERS) - Integrates into syncPackageJson - Reports closed/would-close PRs as subResults in job summary - Cleans up sync branch after closing PR (best-effort) Bump version to 2.9.0 Agent-Logs-Url: https://github.com/joshjohanning/bulk-github-repo-settings-sync-action/sessions/c0c32f54-fdb6-4368-bac4-25de5bf8188b Co-authored-by: joshjohanning <19912012+joshjohanning@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Add auto-close logic for stale sync PRs
Auto-close stale sync PRs when source file reverts to match target
Apr 23, 2026
- Use fixed threshold of 1 commit instead of unreliable expectedCommits parameter (action always creates exactly 1 commit per sync PR) - Only delete branch when exactly 1 PR exists on it (prevents orphaning other PRs sharing the same branch) - Add tests for multi-commit warning and multi-PR branch safety
Contributor
There was a problem hiding this comment.
Pull request overview
Adds automatic cleanup for stale sync pull requests when a previously-changed source file is reverted to match the target repo again, preventing orphaned “sync” PRs from lingering open.
Changes:
- Introduces
closeStaleActionPrs()and integrates it into the “unchanged” early-return paths for file-sync PR flows and package.json sync. - Extends summary/status reporting with
stale-pr-closed/would-close-stale-prand propagates stale-PR warnings intosubResults. - Updates tests and bumps package version (2.8.0 → 2.9.0); refreshes coverage badge.
Show a summary per file
| File | Description |
|---|---|
| src/index.js | Adds stale-PR auto-close helper + integrates it into sync paths and job summary messaging. |
| tests/index.test.js | Adds unit/integration tests for stale-PR closing behavior and updates Octokit mocks. |
| package.json | Version bump to 2.9.0 for published behavior change. |
| package-lock.json | Lockfile version bump alignment with package.json. |
| badges/coverage.svg | Updates coverage badge output. |
Copilot's findings
- Files reviewed: 3/5 changed files
- Comments generated: 3
- Restore expectedCommits parameter (default 1, callers pass fileInfos.length) - Iterate and close all matching stale PRs instead of just first - Only delete branch when no open PRs remain after closing - Add tests for multi-file expected commits, close-all, mixed warn/close
The action can update PR branches multiple times, so commit count is unreliable for detecting manual changes. Instead, compare PR author against the authenticated user/app login. - Fetch authenticated user once at startup via users.getAuthenticated() - Thread authenticatedLogin through all sync functions - Only close PRs created by the same user/app - Warn (skip) PRs created by different users - Graceful degradation when authenticatedLogin is empty
- Skip stale PR check entirely when authenticatedLogin is empty (prevents closing unrelated PRs when auth fails) - Fix stale comments referencing old commit-count check - Update test for empty authenticatedLogin to expect skip
- Check authenticatedLogin before calling pulls.list (saves API call) - Track closedResult separately to prefer closed/would-close over warned when multiple PRs exist with mixed authors
- Mark authenticatedLogin as optional in closeStaleActionPrs JSDoc - Document authenticatedLogin and contentTransformer in options JSDoc - Clarify branch deletion condition in README - Document issues:write permission requirement
- Swap order: close PR first, then add comment as best-effort - Comment failure no longer prevents PR from being closed - Fix README permission key to use hyphenated format (pull-requests)
📦 Draft Release CreatedA draft release v2.9.0 has been created for this PR. Next Steps
|
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.
Summary
Closes #189. Auto-closes stale sync PRs when the source file has been reverted to match the target.
How it works
When a file sync determines "no changes needed" (source matches target), it checks for open PRs on the sync branch. If found and created by the same user/app running the action, it closes them with an explanatory comment and cleans up the branch.
Safety checks
would-closewithout mutating.Changes
closeStaleActionPrs()helper functionusers.getAuthenticated())authenticatedLoginthrough all sync functionssyncFilesViaPullRequest()(covers dependabot, gitignore, PR template, workflow files, copilot instructions, codeowners) andsyncPackageJson()stale-pr-closed,would-close-stale-prTests