Skip to content

Commit 7372df0

Browse files
committed
feat: Add support for Copilot code review in repository rulesets
This change adds support for GitHub's Copilot code review feature in repository rulesets, allowing automatic code review requests for pull requests. Changes: - Add copilot_code_review rule to repository ruleset schema - Add CopilotCodeReviewRuleParameters and related types to go-github - Implement expand/flatten logic for copilot_code_review rules 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 Both options default to false, matching GitHub UI behavior.
1 parent 3109c39 commit 7372df0

2 files changed

Lines changed: 42 additions & 0 deletions

File tree

github/resource_github_repository_ruleset.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -584,6 +584,28 @@ func resourceGithubRepositoryRuleset() *schema.Resource {
584584
},
585585
},
586586
},
587+
"copilot_code_review": {
588+
Type: schema.TypeList,
589+
Optional: true,
590+
MaxItems: 1,
591+
Description: "Automatically request Copilot code review for new pull requests if the author has access to Copilot code review and their premium requests quota has not reached the limit.",
592+
Elem: &schema.Resource{
593+
Schema: map[string]*schema.Schema{
594+
"review_on_push": {
595+
Type: schema.TypeBool,
596+
Optional: true,
597+
Default: false,
598+
Description: "Copilot automatically reviews each new push to the pull request. Defaults to `false`.",
599+
},
600+
"review_draft_pull_requests": {
601+
Type: schema.TypeBool,
602+
Optional: true,
603+
Default: false,
604+
Description: "Copilot automatically reviews draft pull requests before they are marked as ready for review. Defaults to `false`.",
605+
},
606+
},
607+
},
608+
},
587609
},
588610
},
589611
},

github/util_rules.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,16 @@ func expandRules(input []any, org bool) *github.RepositoryRulesetRules {
496496
rulesetRules.FileExtensionRestriction = params
497497
}
498498

499+
// Copilot code review rule
500+
if v, ok := rulesMap["copilot_code_review"].([]any); ok && len(v) != 0 {
501+
copilotCodeReviewMap := v[0].(map[string]any)
502+
params := &github.CopilotCodeReviewRuleParameters{
503+
ReviewOnPush: copilotCodeReviewMap["review_on_push"].(bool),
504+
ReviewDraftPullRequests: copilotCodeReviewMap["review_draft_pull_requests"].(bool),
505+
}
506+
rulesetRules.CopilotCodeReview = params
507+
}
508+
499509
return rulesetRules
500510
}
501511

@@ -706,6 +716,16 @@ func flattenRules(rules *github.RepositoryRulesetRules, org bool) []any {
706716
rulesMap["file_extension_restriction"] = fileExtensionRestrictionSlice
707717
}
708718

719+
// Copilot code review rule
720+
if rules.CopilotCodeReview != nil {
721+
copilotCodeReviewSlice := make([]map[string]any, 0)
722+
copilotCodeReviewSlice = append(copilotCodeReviewSlice, map[string]any{
723+
"review_on_push": rules.CopilotCodeReview.ReviewOnPush,
724+
"review_draft_pull_requests": rules.CopilotCodeReview.ReviewDraftPullRequests,
725+
})
726+
rulesMap["copilot_code_review"] = copilotCodeReviewSlice
727+
}
728+
709729
return []any{rulesMap}
710730
}
711731

0 commit comments

Comments
 (0)