Skip to content

Commit

Permalink
Merge pull request #1849 from inputvalidation/force-stop-environment
Browse files Browse the repository at this point in the history
Update StopEnvironment to accept a StopEnvironmentOptions struct to support the `force` boolean
  • Loading branch information
svanharmelen committed Dec 9, 2023
2 parents f344220 + cf58b28 commit 62bfc4a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
14 changes: 11 additions & 3 deletions environments.go
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
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

0 comments on commit 62bfc4a

Please sign in to comment.