Commit bddadc88 authored by Martin Sefcik's avatar Martin Sefcik

Added support for Drone CI service API calls

parent 0436cb25
......@@ -19,6 +19,7 @@ package gitlab
import (
"fmt"
"net/url"
"time"
)
// ServicesService handles communication with the services related methods of
......@@ -29,6 +30,19 @@ type ServicesService struct {
client *Client
}
type Service struct {
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"`
}
// SetGitLabCIServiceOptions represents the available SetGitLabCIService()
// options.
//
......@@ -148,3 +162,102 @@ func (s *ServicesService) DeleteHipChatService(pid interface{}) (*Response, erro
return resp, err
}
// SetDroneCIServiceOptions represents the available SetDroneCIService()
// options.
//
// GitLab API docs:
// http://doc.gitlab.com/ce/api/services.html#createedit-drone-ci-service
type SetDroneCIServiceOptions struct {
Token string `url:"token"`
DroneURL string `url:"drone_url"`
EnableSSLVerification string `url:"enable_ssl_verification,omitempty"`
}
// SetDroneCIService sets Drone CI service for a project.
//
// GitLab API docs:
// http://doc.gitlab.com/ce/api/services.html#createedit-drone-ci-service
func (s *ServicesService) SetDroneCIService(
pid interface{},
opt *SetDroneCIServiceOptions) (*Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, err
}
u := fmt.Sprintf("projects/%s/services/drone-ci", url.QueryEscape(project))
req, err := s.client.NewRequest("PUT", u, opt)
if err != nil {
return nil, err
}
resp, err := s.client.Do(req, nil)
if err != nil {
return resp, err
}
return resp, err
}
// DeleteDroneCIService deletes Drone CI service settings for a project.
//
// GitLab API docs:
// http://doc.gitlab.com/ce/api/services.html#delete-drone-ci-service
func (s *ServicesService) DeleteDroneCIService(pid interface{}) (*Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, err
}
u := fmt.Sprintf("projects/%s/services/drone-ci", url.QueryEscape(project))
req, err := s.client.NewRequest("DELETE", u, nil)
if err != nil {
return nil, err
}
resp, err := s.client.Do(req, nil)
if err != nil {
return resp, err
}
return resp, err
}
// DroneCIServiceProperties represents Drone CI specific properties.
type DroneCIServiceProperties struct {
Token *string `url:"token"`
DroneURL *string `url:"drone_url"`
EnableSSLVerification *string `url:"enable_ssl_verification"`
}
// DroneCIService represents Drone CI service settings.
type DroneCIService struct {
Service
Properties *DroneCIServiceProperties `json:"properties"`
}
// GetDroneCIService gets Drone CI service settings for a project.
//
// GitLab API docs:
// http://doc.gitlab.com/ce/api/services.html#get-drone-ci-service-settings
func (s *ServicesService) GetDroneCIService(pid interface{}) (*DroneCIService, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/services/drone-ci", url.QueryEscape(project))
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
return nil, nil, err
}
opt := new(DroneCIService)
resp, err := s.client.Do(req, opt)
if err != nil {
return nil, resp, err
}
return opt, resp, err
}
package gitlab
import (
"fmt"
"net/http"
"reflect"
"testing"
)
func TestSetDroneCIService(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, "PUT")
testFormValues(t, r, values{
"token": "t",
"drone_url": "u",
"enable_ssl_verification": "true",
})
})
opt := &SetDroneCIServiceOptions{"t", "u", "true"}
_, err := client.Services.SetDroneCIService(1, opt)
if err != nil {
t.Fatalf("Services.SetDroneCIService returns an error: %v", err)
}
}
func TestDeleteDroneCIService(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, "DELETE")
})
_, err := client.Services.DeleteDroneCIService(1)
if err != nil {
t.Fatalf("Services.DeleteDroneCIService returns an error: %v", err)
}
}
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: Int(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)
}
}
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