Skip to content

Commit

Permalink
feat: add repository ruleset merge queue support
Browse files Browse the repository at this point in the history
  • Loading branch information
MXfive committed Oct 3, 2024
1 parent a6be28b commit 0250e71
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 0 deletions.
52 changes: 52 additions & 0 deletions github/resource_github_repository_ruleset.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,58 @@ func resourceGithubRepositoryRuleset() *schema.Resource {
},
},
},
"merge_queue": {
Type: schema.TypeList,
MaxItems: 1,
Optional: true,
Description: "Merges must be performed via a merge queue.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"check_response_timeout_minutes": {
Type: schema.TypeInt,
Optional: true,
ValidateDiagFunc: toDiagFunc(validation.IntBetween(0, 360), "check_response_timeout_minutes"),
Description: "Maximum time for a required status check to report a conclusion. After this much time has elapsed, checks that have not reported a conclusion will be assumed to have failed.",
},
"grouping_strategy": {
Type: schema.TypeString,
Optional: true,
ValidateDiagFunc: toDiagFunc(validation.StringInSlice([]string{"ALLGREEN", "HEADGREEN"}, false), "grouping_strategy"),
Description: "When set to ALLGREEN, the merge commit created by merge queue for each PR in the group must pass all required checks to merge. When set to HEADGREEN, only the commit at the head of the merge group, i.e. the commit containing changes from all of the PRs in the group, must pass its required checks to merge. Can be one of: ALLGREEN, HEADGREEN.",
},
"max_entries_to_build": {
Type: schema.TypeInt,
Optional: true,
ValidateDiagFunc: toDiagFunc(validation.IntBetween(0, 100), "max_entries_to_merge"),
Description: "Limit the number of queued pull requests requesting checks and workflow runs at the same time.",
},
"max_entries_to_merge": {
Type: schema.TypeInt,
Optional: true,
ValidateDiagFunc: toDiagFunc(validation.IntBetween(0, 100), "max_entries_to_merge"),
Description: "The maximum number of PRs that will be merged together in a group.",
},
"merge_method": {
Type: schema.TypeString,
Optional: true,
ValidateDiagFunc: toDiagFunc(validation.StringInSlice([]string{"MERGE", "SQUASH", "REBASE"}, false), "merge_method"),
Description: "Method to use when merging changes from queued pull requests. Can be one of: MERGE, SQUASH, REBASE.",
},
"min_entries_to_merge": {
Type: schema.TypeInt,
Optional: true,
ValidateDiagFunc: toDiagFunc(validation.IntBetween(0, 100), "min_entries_to_merge"),
Description: "The minimum number of PRs that will be merged together in a group.",
},
"min_entries_to_merge_wait_minutes": {
Type: schema.TypeInt,
Optional: true,
ValidateDiagFunc: toDiagFunc(validation.IntBetween(0, 360), "min_entries_to_merge_wait_minutes"),
Description: "The time merge queue should wait after the first PR is added to the queue for the minimum group size to be met. After this time has elapsed, the minimum group size will be ignored and a smaller group will be merged.",
},
},
},
},
"non_fast_forward": {
Type: schema.TypeBool,
Optional: true,
Expand Down
10 changes: 10 additions & 0 deletions github/resource_github_repository_ruleset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,16 @@ func TestGithubRepositoryRulesets(t *testing.T) {
required_signatures = false
merge_queue {
check_response_timeout_minutes = 10
grouping_strategy = "ALLGREEN"
max_entries_to_build = 5
max_entries_to_merge = 5
merge_method = "MERGE"
min_entries_to_merge = 1
min_entries_to_merge_wait_minutes = 60
}
pull_request {
required_approving_review_count = 2
required_review_thread_resolution = true
Expand Down
16 changes: 16 additions & 0 deletions github/respository_rules_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,22 @@ func expandRules(input []interface{}, org bool) []*github.RepositoryRule {
rulesSlice = append(rulesSlice, github.NewPullRequestRule(params))
}

// Merge queue rule
if v, ok := rulesMap["merge_queue"].([]interface{}); ok && len(v) != 0 {
mergeQueueMap := v[0].(map[string]interface{})
params := &github.MergeQueueRuleParameters{
CheckResponseTimeoutMinutes: mergeQueueMap["check_response_timeout_minutes"].(int),
GroupingStrategy: mergeQueueMap["grouping_strategy"].(string),
MaxEntriesToBuild: mergeQueueMap["max_entries_to_build"].(int),
MaxEntriesToMerge: mergeQueueMap["max_entries_to_merge"].(int),
MergeMethod: mergeQueueMap["merge_method"].(string),
MinEntriesToMerge: mergeQueueMap["min_entries_to_merge"].(int),
MinEntriesToMergeWaitMinutes: mergeQueueMap["min_entries_to_merge_wait_minutes"].(int),
}

rulesSlice = append(rulesSlice, github.NewMergeQueueRule(params))
}

// Required status checks rule
if v, ok := rulesMap["required_status_checks"].([]interface{}); ok && len(v) != 0 {
requiredStatusMap := v[0].(map[string]interface{})
Expand Down

0 comments on commit 0250e71

Please sign in to comment.