Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
G
go-gitlab
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
go-gitlab
Commits
bddadc88
Commit
bddadc88
authored
Nov 24, 2015
by
Martin Sefcik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added support for Drone CI service API calls
parent
0436cb25
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
178 additions
and
0 deletions
+178
-0
services.go
services.go
+113
-0
services_test.go
services_test.go
+65
-0
No files found.
services.go
View file @
bddadc88
...
@@ -19,6 +19,7 @@ package gitlab
...
@@ -19,6 +19,7 @@ package gitlab
import
(
import
(
"fmt"
"fmt"
"net/url"
"net/url"
"time"
)
)
// ServicesService handles communication with the services related methods of
// ServicesService handles communication with the services related methods of
...
@@ -29,6 +30,19 @@ type ServicesService struct {
...
@@ -29,6 +30,19 @@ type ServicesService struct {
client
*
Client
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()
// SetGitLabCIServiceOptions represents the available SetGitLabCIService()
// options.
// options.
//
//
...
@@ -148,3 +162,102 @@ func (s *ServicesService) DeleteHipChatService(pid interface{}) (*Response, erro
...
@@ -148,3 +162,102 @@ func (s *ServicesService) DeleteHipChatService(pid interface{}) (*Response, erro
return
resp
,
err
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
}
services_test.go
0 → 100644
View file @
bddadc88
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
)
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment