Skip to content

Conversation

@JiayangZhou
Copy link

@JiayangZhou JiayangZhou commented Dec 4, 2025

Add CopilotCodeReviewRuleParameters struct with ReviewNewPushes and ReviewDraftPullRequests fields to support GitHub's Copilot code review rule for repository rulesets.

Changes:

  • Add RulesetRuleTypeCopilotCodeReview constant
  • Add CopilotCodeReviewRuleParameters struct
  • Add CopilotCodeReview field to RepositoryRulesetRules
  • Implement marshaling and unmarshaling logic
  • Add test coverage for the new rule type

this feature is based on https://github.blog/changelog/2025-09-10-copilot-code-review-independent-repository-rule-for-automatic-reviews/ (an independent repository rule instead of pull request rule)

@google-cla
Copy link

google-cla bot commented Dec 4, 2025

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@JiayangZhou
Copy link
Author

This is for Github Terraform provider to support code review bot feature in repo ruleset, relevant PR:

integrations/terraform-provider-github#2965

@codecov
Copy link

codecov bot commented Dec 4, 2025

Codecov Report

❌ Patch coverage is 88.23529% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 92.35%. Comparing base (66f826c) to head (3f6aeb5).

Files with missing lines Patch % Lines
github/rules.go 88.23% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3857      +/-   ##
==========================================
- Coverage   92.36%   92.35%   -0.01%     
==========================================
  Files         199      199              
  Lines       14308    14324      +16     
==========================================
+ Hits        13215    13229      +14     
- Misses        894      895       +1     
- Partials      199      200       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Add support for GitHub's Copilot code review feature in repository
rulesets, allowing automatic code review requests for pull requests.

Changes:
- Add RulesetRuleTypeCopilotCodeReview constant to rule types
- Add CopilotCodeReviewRuleParameters struct with review_new_pushes
  and review_draft_pull_requests fields
- Implement marshal/unmarshal logic for copilot_code_review rules
- Add comprehensive test coverage for the new rule type

The copilot_code_review rule supports two configuration options:
- review_new_pushes: Automatically review each new push to the PR
- review_draft_pull_requests: Automatically review draft PRs
@JiayangZhou JiayangZhou force-pushed the feature/copilot-code-review-ruleset branch from fab8541 to 2b90cfa Compare December 4, 2025 18:51
@gmlewis
Copy link
Collaborator

gmlewis commented Dec 4, 2025

Force-pushing is completely unnecessary. Please see CONTRIBUTING.md for why.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Are you missing a case between before the original line 1173 (now line 1197)?

Copy link
Author

Choose a reason for hiding this comment

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

looking at it

Copy link
Author

Choose a reason for hiding this comment

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

hopefully fixed it, thank you for staying on top of it, any way we can know coverage from local, like spin up Codecov locally maybe..that way it is easier and you do not have to trigger it every time

Copy link
Collaborator

Choose a reason for hiding this comment

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

hopefully fixed it, thank you for staying on top of it, any way we can know coverage from local, like spin up Codecov locally maybe..that way it is easier and you do not have to trigger it every time

Yes, Go has built-in code coverage tools if you would like to run them locally.
It may be very interesting, but is not required that you use them for this repo.
Here is some more information about it: https://go.dev/blog/integration-test-coverage

Copy link
Author

Choose a reason for hiding this comment

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

Thanks I think based on go tool cover the coverage for patch code is between 88 - 90, some of the uncovered unmarshal error are just defensive error handling and not covered in other GH repo rule types in this file too so maybe we can let them slip? thanks!

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes, clicking on the Codecov link doesn't reveal anything specific, so I'm not going to worry about it. Thanks!

Copy link
Collaborator

Choose a reason for hiding this comment

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

Are you missing a case between before the original line 1173 (now line 1197)?

I'm still seeing what I think might be a missing case. If you search for the previous RulesetRule:

$ rg RulesetRuleTypeWorkflows
github/rules_test.go
901:                            Type: RulesetRuleTypeWorkflows,

github/rules.go
89:     RulesetRuleTypeWorkflows                RepositoryRuleType = "workflows"
726:            bytes, err := marshalRepositoryRulesetRule(RulesetRuleTypeWorkflows, r.Workflows)
952:            case RulesetRuleTypeWorkflows:
1163:           case RulesetRuleTypeWorkflows:
1350:   case RulesetRuleTypeWorkflows:

you will note that there is the longer section around line 726 and then THREE switch statements that need to be handled. In this PR, I only see two case statements for your new Ruleset. Please fix.

Copy link
Author

Choose a reason for hiding this comment

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

Hi the one for RulesetRuleTypeWorkflows at line 1163 is under func (r *BranchRules) UnmarshalJSON(

the code review is only available for repository ruleset, you can also see at line 328, the struct of type BranchRules struct { does not have CopilotCodeReview which is only defined at RepositoryRulesetRules line 291 in new code.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Oh, OK. Sorry about that, my mistake. Thank you, @JiayangZhou!

@gmlewis gmlewis added the NeedsReview PR is awaiting a review before merging. label Dec 7, 2025
@gmlewis gmlewis changed the title feat: Add support for copilot_code_review rule type feat: Add support for copilot_code_review rule type Dec 7, 2025
Copy link
Collaborator

@gmlewis gmlewis left a comment

Choose a reason for hiding this comment

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

Thank you, @JiayangZhou!
LGTM.
Awaiting second LGTM+Approval from any other contributor to this repo before merging.

cc: @stevehipwell - @alexandear - @zyfy29

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

NeedsReview PR is awaiting a review before merging.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants