Commit 3a152ef5 authored by Ilan Shamir's avatar Ilan Shamir

implemneted get environment

parent e4d31990
......@@ -32,10 +32,11 @@ type EnvironmentsService struct {
//
// GitLab API docs: https://docs.gitlab.com/ce/api/environments.html
type Environment struct {
ID int `json:"id"`
Name string `json:"name"`
Slug string `json:"slug"`
ExternalURL string `json:"external_url"`
ID int `json:"id"`
Name string `json:"name"`
Slug string `json:"slug"`
ExternalURL string `json:"external_url"`
LastDeployment Deployment `json:"last_deployment,omitempty"`
}
func (env Environment) String() string {
......@@ -74,6 +75,31 @@ func (s *EnvironmentsService) ListEnvironments(pid interface{}, opts *ListEnviro
return envs, resp, err
}
// GetEnvironment gets a specific environment from a project
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/environments.html#get-a-specific-environment
func (s *EnvironmentsService) GetEnvironment(pid interface{}, environment int, options ...OptionFunc) (*Environment, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/environments/%d", pathEscape(project), environment)
req, err := s.client.NewRequest("GET", u, nil, options)
if err != nil {
return nil, nil, err
}
env := new(Environment)
resp, err := s.client.Do(req, env)
if err != nil {
return nil, resp, err
}
return env, resp, err
}
// CreateEnvironmentOptions represents the available CreateEnvironment() options.
//
// GitLab API docs:
......
......@@ -29,6 +29,26 @@ func TestListEnvironments(t *testing.T) {
}
}
func TestGetEnvironment(t *testing.T) {
mux, server, client := setup()
defer teardown(server)
mux.HandleFunc("/api/v4/projects/1/environments/5949167", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
fmt.Fprint(w, `{"id":1,"name":"test/test"}`)
})
env, _, err := client.Environments.GetEnvironment(1, 5949167)
if err != nil {
t.Errorf("Environemtns.GetEnvironment returned error: %v", err)
}
want := &Environment{ID: 1, Name: "test/test"}
if !reflect.DeepEqual(want, env) {
t.Errorf("Environments.GetEnvironment returned %+v, want %+v", env, want)
}
}
func TestCreateEnvironment(t *testing.T) {
mux, server, client := setup()
defer teardown(server)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment