Skip to content
This repository has been archived by the owner on Dec 10, 2024. It is now read-only.

Update StopEnvironment to accept a StopEnvironmentOptions struct to support the force boolean #1849

Merged
merged 2 commits into from
Dec 9, 2023
Merged
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
14 changes: 11 additions & 3 deletions environments.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,18 +204,26 @@ func (s *EnvironmentsService) DeleteEnvironment(pid interface{}, environment int
return s.client.Do(req, nil)
}

// StopEnvironment stop an environment from a project team.
// StopEnvironmentOptions represents the available StopEnvironment() options.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/environments.html#stop-an-environment
func (s *EnvironmentsService) StopEnvironment(pid interface{}, environmentID int, options ...RequestOptionFunc) (*Environment, *Response, error) {
type StopEnvironmentOptions struct {
Force *bool `url:"force,omitempty" json:"force,omitempty"`
}

// StopEnvironment stops an environment within a specific project.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/environments.html#stop-an-environment
func (s *EnvironmentsService) StopEnvironment(pid interface{}, environmentID int, opt *StopEnvironmentOptions, options ...RequestOptionFunc) (*Environment, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/environments/%d/stop", PathEscape(project), environmentID)

req, err := s.client.NewRequest(http.MethodPost, u, nil, options)
req, err := s.client.NewRequest(http.MethodPost, u, opt, options)
if err != nil {
return nil, nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion environments_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ func TestStopEnvironment(t *testing.T) {
"tier": "staging"
}`)
})
_, _, err := client.Environments.StopEnvironment(1, 1)
_, _, err := client.Environments.StopEnvironment(1, 1, &StopEnvironmentOptions{})
if err != nil {
log.Fatal(err)
}
Expand Down
Loading