Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds remove_team_request option to team settings #2480

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
```
```