Skip to content

Commit 026c8b8

Browse files
committed
Fix resource to be able to set empty review_request_delegation block
Signed-off-by: Timo Sand <[email protected]>
1 parent 7fc881a commit 026c8b8

2 files changed

Lines changed: 17 additions & 5 deletions

File tree

github/resource_github_team_settings.go

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,10 @@ func resourceGithubTeamSettings() *schema.Resource {
5353
ValidateDiagFunc: validation.ToDiagFunc(validation.StringInSlice([]string{string(githubv4.TeamReviewAssignmentAlgorithmRoundRobin), string(githubv4.TeamReviewAssignmentAlgorithmLoadBalance)}, false)),
5454
},
5555
"member_count": {
56-
Type: schema.TypeInt,
57-
Optional: true,
58-
RequiredWith: []string{"review_request_delegation"},
59-
Description: "The number of team members to assign to a pull request.",
56+
Type: schema.TypeInt,
57+
Optional: true,
58+
Default: 1,
59+
Description: "The number of team members to assign to a pull request.",
6060
ValidateDiagFunc: validation.ToDiagFunc(validation.All(
6161
validation.IntAtLeast(1),
6262
)),
@@ -112,6 +112,13 @@ func resourceGithubTeamSettingsCreate(ctx context.Context, d *schema.ResourceDat
112112
} `graphql:"updateTeamReviewAssignment(input:$input)"`
113113
}
114114

115+
tflog.Debug(ctx, "Review request delegation settings", map[string]any{
116+
"team_id": d.Id(),
117+
"team_slug": slug,
118+
"review_request_delegation": reviewRequestDelegation,
119+
"length_of_settings": len(reviewRequestDelegation),
120+
})
121+
115122
if len(reviewRequestDelegation) == 0 {
116123
tflog.Debug(ctx, "No review request delegation settings provided, disabling review request delegation", map[string]any{
117124
"team_id": d.Id(),
@@ -123,6 +130,11 @@ func resourceGithubTeamSettingsCreate(ctx context.Context, d *schema.ResourceDat
123130
return diag.FromErr(err)
124131
}
125132
} else {
133+
tflog.Debug(ctx, "Review request delegation settings provided, setting according to provided configuration", map[string]any{
134+
"team_id": d.Id(),
135+
"team_slug": slug,
136+
"review_request_delegation": reviewRequestDelegation,
137+
})
126138
settings := reviewRequestDelegation[0].(map[string]any)
127139

128140
teamReviewAlgorithm := githubv4.TeamReviewAssignmentAlgorithm(settings["algorithm"].(string))
@@ -133,6 +145,7 @@ func resourceGithubTeamSettingsCreate(ctx context.Context, d *schema.ResourceDat
133145
TeamMemberCount: githubv4.NewInt(githubv4.Int(settings["member_count"].(int))),
134146
NotifyTeam: githubv4.NewBoolean(githubv4.Boolean(settings["notify"].(bool))),
135147
}
148+
136149
err := graphql.Mutate(ctx, &mutation, updateTeamReviewAssignmentInput, nil)
137150
if err != nil {
138151
return diag.FromErr(err)

github/resource_github_team_settings_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,6 @@ func TestAccGithubTeamSettings(t *testing.T) {
219219
})
220220

221221
t.Run("creates_with_empty_review_request_delegation_block_without_error", func(t *testing.T) {
222-
t.Skip("TODO this isn't working as expected")
223222
randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum)
224223
teamName := fmt.Sprintf("%steam-settings-%s", testResourcePrefix, randomID)
225224
config := fmt.Sprintf(`

0 commit comments

Comments
 (0)