feat(pre-commit): add review-pre-commit-pr action to auto-approve pre-commit.ci autoupdate PRs#189
Draft
kelly-sovacool with Copilot wants to merge 4 commits into
Draft
feat(pre-commit): add review-pre-commit-pr action to auto-approve pre-commit.ci autoupdate PRs#189kelly-sovacool with Copilot wants to merge 4 commits into
kelly-sovacool with Copilot wants to merge 4 commits into
Conversation
- Add `src/ccbr_actions/pre_commit.py` with functions to validate pre-commit.ci autoupdate PRs and approve/request-review via the GitHub API (REST + GraphQL for auto-merge) - Add `github_graphql_post` helper to `src/ccbr_actions/github.py` - Add `tests/test_pre_commit.py` with 29 unit tests (100% coverage) - Add GraphQL tests to `tests/test_github.py` - Add `review-pre-commit-pr/action.yml` composite action - Add `review-pre-commit-pr/README.qmd` documentation - Add `examples/review-pre-commit-pr.yml` example workflow - Update CHANGELOG.md and README.md
- Narrow `except Exception` to `except (requests.exceptions.RequestException, RuntimeError)` in review_pre_commit_pr to comply with Python coding standards - Update MockResponse.raise_for_status in tests to use requests.exceptions.HTTPError for more realistic mocking
Copilot
AI
changed the title
[WIP] Add action to review pre-commit.ci PRs
feat(pre-commit): add review-pre-commit-pr action to auto-approve pre-commit.ci autoupdate PRs
Jul 2, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds automation to review and (when safe) auto-approve pre-commit.ci autoupdate pull requests by introducing a new ccbr_actions.pre_commit module plus a new composite action that can be called from workflows.
Changes:
- Add
ccbr_actions.pre_commit.review_pre_commit_pr()to validate “only.pre-commit-config.yamlchanged” and “onlyrev:bumps” before approving + enabling squash auto-merge. - Add
github_graphql_post()to support enabling auto-merge via GitHub’s GraphQL API. - Add a new
review-pre-commit-prcomposite action, example workflow, docs, changelog entry, and unit tests.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/test_pre_commit.py | New unit tests for pre-commit autoupdate PR validation and review behavior. |
| tests/test_github.py | Adds tests for the new GraphQL helper and adjusts HTTP error behavior in mocks. |
| src/ccbr_actions/pre_commit.py | New implementation of the pre-commit.ci PR review/auto-approval logic. |
| src/ccbr_actions/github.py | Adds github_graphql_post() helper for GitHub GraphQL requests. |
| review-pre-commit-pr/README.qmd | Documentation for the new composite action. |
| review-pre-commit-pr/action.yml | New composite action that installs ccbr_actions and runs review_pre_commit_pr(). |
| README.md | Adds the new example workflow and action to the repo index. |
| examples/review-pre-commit-pr.yml | Example workflow to run the action on pre-commit.ci PRs. |
| CHANGELOG.md | Adds a development entry announcing the new action. |
|
|
||
| PRE_COMMIT_CI_TITLE = "[pre-commit.ci] pre-commit autoupdate" | ||
| PRE_COMMIT_CONFIG_FILE = ".pre-commit-config.yaml" | ||
| _REV_PATTERN = re.compile(r"^\s+rev:\s+\S+") |
Comment on lines
+283
to
+291
| patch = next( | ||
| ( | ||
| f.get("patch", "") | ||
| for f in pr_files | ||
| if f["filename"] == PRE_COMMIT_CONFIG_FILE | ||
| ), | ||
| "", | ||
| ) | ||
| condition2 = check_only_version_bumps(patch) |
Comment on lines
+304
to
+308
| if not condition2: | ||
| failed.append( | ||
| "the only changes in `.pre-commit-config.yaml` should be " | ||
| "`rev:` version bumps, but other modifications were found" | ||
| ) |
Comment on lines
+214
to
+220
| url = f"{GITHUB_API_URL}/repos/{repo}/pulls/{pr_number}/requested_reviewers" | ||
| return github_api_post( | ||
| url=url, | ||
| token=token, | ||
| session=session, | ||
| json={"reviewers": [reviewer]}, | ||
| ) |
Comment on lines
+293
to
+296
| if condition1 and condition2: | ||
| approve_pr(repo, pr_number, token=token, session=session) | ||
| enable_auto_merge(repo, pr_number, token=token, session=session) | ||
| return True |
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.
Automates review of pre-commit.ci autoupdate PRs: approves and enables squash auto-merge when safe, otherwise requests a human reviewer with an explanatory comment.
New Python module:
ccbr_actions.pre_commitValidates two conditions before auto-approving:
.pre-commit-config.yamlchangedrev:bumps (no new/removed repos, no other field changes), with semver increase verification (falls back to inequality check for commit hashes)Key functions:
Approval path calls the GitHub REST API to submit an
APPROVEreview, then the GraphQL API (enablePullRequestAutoMerge) to enable squash auto-merge. Failure path requests the configured reviewer and posts a comment explaining which conditions failed.New composite action:
review-pre-commit-prInstalls
ccbr_actionsand delegates toreview_pre_commit_pr(). Inputs:github-token,pr-number,repo,reviewer,ccbr-actions-version,python-version.Example workflow
examples/review-pre-commit-pr.yml— triggers onpull_request: opened, guards withif: title == '[pre-commit.ci] pre-commit autoupdate' && sender.type == 'Bot', generates a CCBR-bot token viaactions/create-github-app-token, then calls the action.Supporting changes
github_graphql_post()helper added toccbr_actions.githubfor GraphQL mutationsccbr_actions.pre_commit; 3 additional tests forgithub_graphql_post