Skip to content

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
mainfrom
copilot/review-pre-commit-ci-prs
Draft

feat(pre-commit): add review-pre-commit-pr action to auto-approve pre-commit.ci autoupdate PRs#189
kelly-sovacool with Copilot wants to merge 4 commits into
mainfrom
copilot/review-pre-commit-ci-prs

Conversation

Copilot AI commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

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_commit

Validates two conditions before auto-approving:

  • Condition 1 – only .pre-commit-config.yaml changed
  • Condition 2 – the only diff lines are rev: bumps (no new/removed repos, no other field changes), with semver increase verification (falls back to inequality check for commit hashes)

Key functions:

from ccbr_actions.pre_commit import review_pre_commit_pr

# Returns True (approved + auto-merge enabled) or False (human reviewer requested)
result = review_pre_commit_pr(repo="CCBR/actions", pr_number=42, reviewer="alice", token=token)

Approval path calls the GitHub REST API to submit an APPROVE review, 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-pr

Installs ccbr_actions and delegates to review_pre_commit_pr(). Inputs: github-token, pr-number, repo, reviewer, ccbr-actions-version, python-version.

Example workflow

examples/review-pre-commit-pr.yml — triggers on pull_request: opened, guards with if: title == '[pre-commit.ci] pre-commit autoupdate' && sender.type == 'Bot', generates a CCBR-bot token via actions/create-github-app-token, then calls the action.

Supporting changes

  • github_graphql_post() helper added to ccbr_actions.github for GraphQL mutations
  • 29 unit tests with 100% coverage on ccbr_actions.pre_commit; 3 additional tests for github_graphql_post

Copilot AI linked an issue Jul 2, 2026 that may be closed by this pull request
Copilot AI added 2 commits July 2, 2026 16:25
- 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
Copilot AI requested a review from kelly-sovacool July 2, 2026 16:27
@kelly-sovacool
kelly-sovacool requested a review from Copilot July 24, 2026 16:39

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.yaml changed” and “only rev: 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-pr composite 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
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.

action to review pre-commit.ci PRs

3 participants