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
c35b3f71
Commit
c35b3f71
authored
Oct 04, 2017
by
Sander van Harmelen
Committed by
GitHub
Oct 04, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #223 from xanzy/f-slack
Tweak PR #222
parents
a97794b9
2ff1fb95
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
84 additions
and
77 deletions
+84
-77
services.go
services.go
+57
-44
services_test.go
services_test.go
+27
-33
No files found.
services.go
View file @
c35b3f71
...
...
@@ -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
}
services_test.go
View file @
c35b3f71
...
...
@@ -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
TestGet
DroneCI
Service
(
t
*
testing
.
T
)
{
func
TestGet
Slack
Service
(
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.Get
DroneCI
Service returns an error: %v"
,
err
)
t
.
Fatalf
(
"Services.Get
Slack
Service returns an error: %v"
,
err
)
}
if
!
reflect
.
DeepEqual
(
want
,
service
)
{
t
.
Errorf
(
"Services.Get
DroneCI
Service returned %+v, want %+v"
,
service
,
want
)
t
.
Errorf
(
"Services.Get
Slack
Service 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
)
}
}
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