Skip to content

Commit

Permalink
Adds remove_team_request option to team settings
Browse files Browse the repository at this point in the history
Introduces a new boolean option `remove_team_request` to the team settings schema. This option allows automatic removal of team requests when a member is assigned to a pull request. Updates related functions and tests to support this new option.

Enhances team review assignment functionality.
  • Loading branch information
Brett Wright committed Nov 24, 2024
1 parent 84c6bd2 commit efd9768
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 17 deletions.
41 changes: 25 additions & 16 deletions github/resource_github_team_settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,12 @@ func resourceGithubTeamSettings() *schema.Resource {
Default: false,
Description: "whether to notify the entire team when at least one member is also assigned to the pull request.",
},
"remove_team_request": {
Type: schema.TypeBool,
Optional: true,
Default: true,
Description: "whether to remove the team request when a member is assigned to the pull request.",
},
},
},
},
Expand Down Expand Up @@ -180,11 +186,12 @@ func resourceGithubTeamSettingsUpdate(d *schema.ResourceData, meta interface{})
}

return graphql.Mutate(ctx, &mutation, UpdateTeamReviewAssignmentInput{
TeamID: d.Id(),
ReviewRequestDelegation: true,
ReviewRequestDelegationAlgorithm: settings["algorithm"].(string),
ReviewRequestDelegationCount: settings["member_count"].(int),
ReviewRequestDelegationNotifyAll: settings["notify"].(bool),
TeamID: d.Id(),
ReviewRequestDelegation: true,
ReviewRequestDelegationAlgorithm: settings["algorithm"].(string),
ReviewRequestDelegationCount: settings["member_count"].(int),
ReviewRequestDelegationNotifyAll: settings["notify"].(bool),
ReviewRequestDelegationTeamRequest: settings["remove_team_request"].(bool),
}, nil)
}
}
Expand Down Expand Up @@ -256,21 +263,23 @@ func resolveTeamIDs(idOrSlug string, meta *Owner, ctx context.Context) (nodeId s
}

type UpdateTeamReviewAssignmentInput struct {
ClientMutationID string `json:"clientMutationId,omitempty"`
TeamID string `graphql:"id" json:"id"`
ReviewRequestDelegation bool `graphql:"enabled" json:"enabled"`
ReviewRequestDelegationAlgorithm string `graphql:"algorithm" json:"algorithm"`
ReviewRequestDelegationCount int `graphql:"teamMemberCount" json:"teamMemberCount"`
ReviewRequestDelegationNotifyAll bool `graphql:"notifyTeam" json:"notifyTeam"`
ClientMutationID string `json:"clientMutationId,omitempty"`
TeamID string `graphql:"id" json:"id"`
ReviewRequestDelegation bool `graphql:"enabled" json:"enabled"`
ReviewRequestDelegationAlgorithm string `graphql:"algorithm" json:"algorithm"`
ReviewRequestDelegationCount int `graphql:"teamMemberCount" json:"teamMemberCount"`
ReviewRequestDelegationNotifyAll bool `graphql:"notifyTeam" json:"notifyTeam"`
ReviewRequestDelegationTeamRequest bool `graphql:"removeTeamRequest" json:"removeTeamRequest"`
}

func defaultTeamReviewAssignmentSettings(id string) UpdateTeamReviewAssignmentInput {
return UpdateTeamReviewAssignmentInput{
TeamID: id,
ReviewRequestDelegation: false,
ReviewRequestDelegationAlgorithm: "ROUND_ROBIN",
ReviewRequestDelegationCount: 1,
ReviewRequestDelegationNotifyAll: true,
TeamID: id,
ReviewRequestDelegation: false,
ReviewRequestDelegationAlgorithm: "ROUND_ROBIN",
ReviewRequestDelegationCount: 1,
ReviewRequestDelegationNotifyAll: true,
ReviewRequestDelegationTeamRequest: true,
}
}

Expand Down
14 changes: 14 additions & 0 deletions github/resource_github_team_settings_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ func TestCanUpdateTeamSettings(t *testing.T) {
algorithm = "ROUND_ROBIN"
member_count = 1
notify = true
remove_team_request = true
}
}
`, randomID)
Expand Down Expand Up @@ -113,6 +114,12 @@ func TestCanUpdateTeamSettings(t *testing.T) {
"false",
),
),
"remove_team_request": resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(
"github_team_settings.test", "review_request_delegation.0.remove_team_request",
"true",
),
),
}

testCase := func(t *testing.T, mode string) {
Expand Down Expand Up @@ -142,6 +149,12 @@ func TestCanUpdateTeamSettings(t *testing.T) {
`notify = false`, 1),
Check: checks["notify"],
},
{
Config: strings.Replace(config,
`remove_team_request = false`,
`remove_team_request = true`, 1),
Check: checks["remove_team_request"],
},
},
})
}
Expand Down Expand Up @@ -180,6 +193,7 @@ func TestCannotUseReviewSettingsIfDisabled(t *testing.T) {
algorithm = "ROUND_ROBIN"
member_count = 1
notify = true
remove_team_request = true
}
}
`, randomID)
Expand Down
3 changes: 2 additions & 1 deletion website/docs/r/team_settings.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ The following arguments are supported:
* `algorithm` - (Optional) The algorithm to use when assigning pull requests to team members. Supported values are `ROUND_ROBIN` and `LOAD_BALANCE`. Default value is `ROUND_ROBIN`
* `member_count` - (Optional) The number of team members to assign to a pull request
* `notify` - (Optional) whether to notify the entire team when at least one member is also assigned to the pull request
* `remove_team_request` - (Optional) whether to remove the team request when a member is assigned to the pull request.


## Import
Expand All @@ -60,4 +61,4 @@ $ terraform import github_team.code_review_settings 1234567
or,
```
$ terraform import github_team_settings.code_review_settings SomeTeam
```
```

0 comments on commit efd9768

Please sign in to comment.