Skip to content

Commit

Permalink
Merge pull request #1709 from hsmade/env-stop-add-env
Browse files Browse the repository at this point in the history
Return Environment on stop.
  • Loading branch information
svanharmelen authored Apr 27, 2023
2 parents e6df6f8 + 7f2c7ab commit c84b5de
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
14 changes: 10 additions & 4 deletions environments.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,17 +208,23 @@ func (s *EnvironmentsService) DeleteEnvironment(pid interface{}, environment int
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/environments.html#stop-an-environment
func (s *EnvironmentsService) StopEnvironment(pid interface{}, environmentID int, options ...RequestOptionFunc) (*Response, error) {
func (s *EnvironmentsService) StopEnvironment(pid interface{}, environmentID int, options ...RequestOptionFunc) (*Environment, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, err
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)
if err != nil {
return nil, err
return nil, nil, err
}

return s.client.Do(req, nil)
env := new(Environment)
resp, err := s.client.Do(req, env)
if err != nil {
return nil, resp, err
}

return env, resp, nil
}
3 changes: 2 additions & 1 deletion environments_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,9 @@ func TestStopEnvironment(t *testing.T) {
mux.HandleFunc("/api/v4/projects/1/environments/1/stop", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodPost)
testURL(t, r, "/api/v4/projects/1/environments/1/stop")
fmt.Fprint(w, `{"id": 1,"name": "staging", "state": "stopping", "slug": "staging", "external_url": "https://staging.example.gitlab.com", "tier": "staging"}`)
})
_, err := client.Environments.StopEnvironment(1, 1)
_, _, err := client.Environments.StopEnvironment(1, 1)
if err != nil {
log.Fatal(err)
}
Expand Down

0 comments on commit c84b5de

Please sign in to comment.