Commit c35b3f71 authored by Sander van Harmelen's avatar Sander van Harmelen Committed by GitHub

Merge pull request #223 from xanzy/f-slack

Tweak PR #222
parents a97794b9 2ff1fb95
......@@ -34,16 +34,18 @@ type ServicesService struct {
//
// GitLab API docs: https://docs.gitlab.com/ce/api/services.html
type Service struct {
ID *int `json:"id"`
Title *string `json:"title"`
ID int `json:"id"`
Title string `json:"title"`
CreatedAt *time.Time `json:"created_at"`
UpdatedAt *time.Time `json:"created_at"`
Active *bool `json:"active"`
PushEvents *bool `json:"push_events"`
IssuesEvents *bool `json:"issues_events"`
MergeRequestsEvents *bool `json:"merge_requests_events"`
TagPushEvents *bool `json:"tag_push_events"`
NoteEvents *bool `json:"note_events"`
UpdatedAt *time.Time `json:"updated_at"`
Active bool `json:"active"`
PushEvents bool `json:"push_events"`
IssuesEvents bool `json:"issues_events"`
MergeRequestsEvents bool `json:"merge_requests_events"`
TagPushEvents bool `json:"tag_push_events"`
NoteEvents bool `json:"note_events"`
PipelineEvents bool `json:"pipeline_events"`
JobEvents bool `json:"job_events"`
}
// SetGitLabCIServiceOptions represents the available SetGitLabCIService()
......@@ -191,19 +193,19 @@ func (s *ServicesService) DeleteDroneCIService(pid interface{}, options ...Optio
return s.client.Do(req, nil)
}
// DroneCIServiceProperties represents Drone CI specific properties.
type DroneCIServiceProperties struct {
Token *string `url:"token" json:"token"`
DroneURL *string `url:"drone_url" json:"drone_url"`
EnableSSLVerification *bool `url:"enable_ssl_verification" json:"enable_ssl_verification"`
}
// DroneCIService represents Drone CI service settings.
type DroneCIService struct {
Service
Properties *DroneCIServiceProperties `json:"properties"`
}
// DroneCIServiceProperties represents Drone CI specific properties.
type DroneCIServiceProperties struct {
Token string `json:"token"`
DroneURL string `json:"drone_url"`
EnableSSLVerification bool `json:"enable_ssl_verification"`
}
// GetDroneCIService gets Drone CI service settings for a project.
//
// GitLab API docs:
......@@ -220,13 +222,49 @@ func (s *ServicesService) GetDroneCIService(pid interface{}, options ...OptionFu
return nil, nil, err
}
opt := new(DroneCIService)
resp, err := s.client.Do(req, opt)
svc := new(DroneCIService)
resp, err := s.client.Do(req, svc)
if err != nil {
return nil, resp, err
}
return svc, resp, err
}
// SlackService represents Slack service settings.
type SlackService struct {
Service
Properties *SlackServiceProperties `json:"properties"`
}
// SlackServiceProperties represents Slack specific properties.
type SlackServiceProperties struct {
NotifyOnlyBrokenPipelines bool `json:"notify_only_broken_pipelines"`
}
// 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) (*SlackService, *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
}
svc := new(SlackService)
resp, err := s.client.Do(req, svc)
if err != nil {
return nil, resp, err
}
return opt, resp, err
return svc, resp, err
}
// SetSlackServiceOptions represents the available SetSlackService()
......@@ -277,28 +315,3 @@ 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
}
......@@ -7,6 +7,25 @@ import (
"testing"
)
func TestGetDroneCIService(t *testing.T) {
mux, server, client := setup()
defer teardown(server)
mux.HandleFunc("/projects/1/services/drone-ci", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
fmt.Fprint(w, `{"id":1}`)
})
want := &DroneCIService{Service: Service{ID: 1}}
service, _, err := client.Services.GetDroneCIService(1)
if err != nil {
t.Fatalf("Services.GetDroneCIService returns an error: %v", err)
}
if !reflect.DeepEqual(want, service) {
t.Errorf("Services.GetDroneCIService returned %+v, want %+v", service, want)
}
}
func TestSetDroneCIService(t *testing.T) {
mux, server, client := setup()
defer teardown(server)
......@@ -16,8 +35,8 @@ func TestSetDroneCIService(t *testing.T) {
})
opt := &SetDroneCIServiceOptions{String("t"), String("u"), Bool(true)}
_, err := client.Services.SetDroneCIService(1, opt)
_, err := client.Services.SetDroneCIService(1, opt)
if err != nil {
t.Fatalf("Services.SetDroneCIService returns an error: %v", err)
}
......@@ -32,30 +51,27 @@ func TestDeleteDroneCIService(t *testing.T) {
})
_, err := client.Services.DeleteDroneCIService(1)
if err != nil {
t.Fatalf("Services.DeleteDroneCIService returns an error: %v", err)
}
}
func TestGetDroneCIService(t *testing.T) {
func TestGetSlackService(t *testing.T) {
mux, server, client := setup()
defer teardown(server)
mux.HandleFunc("/projects/1/services/drone-ci", func(w http.ResponseWriter, r *http.Request) {
mux.HandleFunc("/projects/1/services/slack", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
fmt.Fprint(w, `{"id":1}`)
})
want := &DroneCIService{Service: Service{ID: Int(1)}}
service, _, err := client.Services.GetDroneCIService(1)
want := &SlackService{Service: Service{ID: 1}}
service, _, err := client.Services.GetSlackService(1)
if err != nil {
t.Fatalf("Services.GetDroneCIService returns an error: %v", err)
t.Fatalf("Services.GetSlackService returns an error: %v", err)
}
if !reflect.DeepEqual(want, service) {
t.Errorf("Services.GetDroneCIService returned %+v, want %+v", service, want)
t.Errorf("Services.GetSlackService returned %+v, want %+v", service, want)
}
}
......@@ -72,8 +88,8 @@ func TestSetSlackService(t *testing.T) {
Username: String("username"),
Channel: String("#development"),
}
_, err := client.Services.SetSlackService(1, opt)
_, err := client.Services.SetSlackService(1, opt)
if err != nil {
t.Fatalf("Services.SetSlackService returns an error: %v", err)
}
......@@ -88,29 +104,7 @@ func TestDeleteSlackService(t *testing.T) {
})
_, 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