Adding GET request for Slack Integration on a Project

parent d11d546f
......@@ -277,3 +277,28 @@ func (s *ServicesService) DeleteSlackService(pid interface{}, options ...OptionF
return s.client.Do(req, nil)
}
// GetSlackService gets Slack service settings for a project.
//
// GitLab API docs:
// https://docs.gitlab.com/ce/api/services.html#get-slack-service-settings
func (s *ServicesService) GetSlackService(pid interface{}, options ...OptionFunc) (*SetSlackServiceOptions, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/services/slack", url.QueryEscape(project))
req, err := s.client.NewRequest("GET", u, nil, options)
if err != nil {
return nil, nil, err
}
opt := new(SetSlackServiceOptions)
resp, err := s.client.Do(req, opt)
if err != nil {
return nil, resp, err
}
return opt, resp, err
}
......@@ -58,3 +58,59 @@ func TestGetDroneCIService(t *testing.T) {
t.Errorf("Services.GetDroneCIService returned %+v, want %+v", service, want)
}
}
func TestSetSlackService(t *testing.T) {
mux, server, client := setup()
defer teardown(server)
mux.HandleFunc("/projects/1/services/slack", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "PUT")
})
opt := &SetSlackServiceOptions{
WebHook: String("webhook_uri"),
Username: String("username"),
Channel: String("#development"),
}
_, err := client.Services.SetSlackService(1, opt)
if err != nil {
t.Fatalf("Services.SetSlackService returns an error: %v", err)
}
}
func TestDeleteSlackService(t *testing.T) {
mux, server, client := setup()
defer teardown(server)
mux.HandleFunc("/projects/1/services/slack", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "DELETE")
})
_, err := client.Services.DeleteSlackService(1)
if err != nil {
t.Fatalf("Services.DeleteSlackService returns an error: %v", err)
}
}
func TestGetSlackService(t *testing.T) {
mux, server, client := setup()
defer teardown(server)
mux.HandleFunc("/projects/1/services/slack", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
fmt.Fprint(w, `{"id":1}`)
})
want := &SetSlackServiceOptions{}
service, _, err := client.Services.GetSlackService(1)
if err != nil {
t.Fatalf("Services.GetSlackService returns an error: %v", err)
}
if !reflect.DeepEqual(want, service) {
t.Errorf("Services.GetSlackService returned %+v, want %+v", service, want)
}
}
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