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
6568d265
Commit
6568d265
authored
Oct 26, 2017
by
Peter Bouwdewijn
Committed by
Sander van Harmelen
Oct 26, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
xanzy/go-gitlab#142 Add Jira service (#231)
parent
93f2d521
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
140 additions
and
0 deletions
+140
-0
services.go
services.go
+85
-0
services_test.go
services_test.go
+55
-0
No files found.
services.go
View file @
6568d265
...
...
@@ -315,3 +315,88 @@ func (s *ServicesService) DeleteSlackService(pid interface{}, options ...OptionF
return
s
.
client
.
Do
(
req
,
nil
)
}
// JiraService represents Jira service settings.
type
JiraService
struct
{
Service
Properties
*
JiraServiceProperties
`json:"properties"`
}
// JiraServiceProperties represents Jira specific properties.
type
JiraServiceProperties
struct
{
Url
*
string
`url:"url,omitempty" json:"url,omitempty"`
ProjectKey
*
string
`url:"project_key,omitempty" json:"project_key,omitempty" `
Username
*
string
`url:"username,omitempty" json:"username,omitempty" `
Password
*
string
`url:"password,omitempty" json:"password,omitempty" `
IssueTransitionId
*
string
`url:"jira_issue_transition_id,omitempty" json:"jira_issue_transition_id,omitempty"`
}
// GetJiraService gets Jira service settings for a project.
//
// GitLab API docs:
// https://docs.gitlab.com/ce/api/services.html#get-jira-service-settings
func
(
s
*
ServicesService
)
GetJiraService
(
pid
interface
{},
options
...
OptionFunc
)
(
*
JiraService
,
*
Response
,
error
)
{
project
,
err
:=
parseID
(
pid
)
if
err
!=
nil
{
return
nil
,
nil
,
err
}
u
:=
fmt
.
Sprintf
(
"projects/%s/services/jira"
,
url
.
QueryEscape
(
project
))
req
,
err
:=
s
.
client
.
NewRequest
(
"GET"
,
u
,
nil
,
options
)
if
err
!=
nil
{
return
nil
,
nil
,
err
}
svc
:=
new
(
JiraService
)
resp
,
err
:=
s
.
client
.
Do
(
req
,
svc
)
if
err
!=
nil
{
return
nil
,
resp
,
err
}
return
svc
,
resp
,
err
}
// SetJiraServiceOptions represents the available SetJiraService()
// options.
//
// GitLab API docs:
// https://docs.gitlab.com/ce/api/services.html#edit-jira-service
type
SetJiraServiceOptions
JiraServiceProperties
// SetJiraService sets Jira service for a project
//
// GitLab API docs:
// https://docs.gitlab.com/ce/api/services.html#edit-jira-service
func
(
s
*
ServicesService
)
SetJiraService
(
pid
interface
{},
opt
*
SetJiraServiceOptions
,
options
...
OptionFunc
)
(
*
Response
,
error
)
{
project
,
err
:=
parseID
(
pid
)
if
err
!=
nil
{
return
nil
,
err
}
u
:=
fmt
.
Sprintf
(
"projects/%s/services/jira"
,
url
.
QueryEscape
(
project
))
req
,
err
:=
s
.
client
.
NewRequest
(
"PUT"
,
u
,
opt
,
options
)
if
err
!=
nil
{
return
nil
,
err
}
return
s
.
client
.
Do
(
req
,
nil
)
}
// DeleteJiraService deletes Jira service for project.
//
// GitLab API docs:
// https://docs.gitlab.com/ce/api/services.html#delete-jira-service
func
(
s
*
ServicesService
)
DeleteJiraService
(
pid
interface
{},
options
...
OptionFunc
)
(
*
Response
,
error
)
{
project
,
err
:=
parseID
(
pid
)
if
err
!=
nil
{
return
nil
,
err
}
u
:=
fmt
.
Sprintf
(
"projects/%s/services/jira"
,
url
.
QueryEscape
(
project
))
req
,
err
:=
s
.
client
.
NewRequest
(
"DELETE"
,
u
,
nil
,
options
)
if
err
!=
nil
{
return
nil
,
err
}
return
s
.
client
.
Do
(
req
,
nil
)
}
services_test.go
View file @
6568d265
...
...
@@ -108,3 +108,58 @@ func TestDeleteSlackService(t *testing.T) {
t
.
Fatalf
(
"Services.DeleteSlackService returns an error: %v"
,
err
)
}
}
func
TestGetJiraService
(
t
*
testing
.
T
)
{
mux
,
server
,
client
:=
setup
()
defer
teardown
(
server
)
mux
.
HandleFunc
(
"/projects/1/services/jira"
,
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
testMethod
(
t
,
r
,
"GET"
)
fmt
.
Fprint
(
w
,
`{"id":1}`
)
})
want
:=
&
JiraService
{
Service
:
Service
{
ID
:
1
}}
service
,
_
,
err
:=
client
.
Services
.
GetJiraService
(
1
)
if
err
!=
nil
{
t
.
Fatalf
(
"Services.GetJiraService returns an error: %v"
,
err
)
}
if
!
reflect
.
DeepEqual
(
want
,
service
)
{
t
.
Errorf
(
"Services.GetJiraService returned %+v, want %+v"
,
service
,
want
)
}
}
func
TestSetJiraService
(
t
*
testing
.
T
)
{
mux
,
server
,
client
:=
setup
()
defer
teardown
(
server
)
mux
.
HandleFunc
(
"/projects/1/services/jira"
,
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
testMethod
(
t
,
r
,
"PUT"
)
})
opt
:=
&
SetJiraServiceOptions
{
Url
:
String
(
"asd"
),
ProjectKey
:
String
(
"as"
),
Username
:
String
(
"aas"
),
Password
:
String
(
"asd"
),
IssueTransitionId
:
String
(
"asd"
),
}
_
,
err
:=
client
.
Services
.
SetJiraService
(
1
,
opt
)
if
err
!=
nil
{
t
.
Fatalf
(
"Services.SetJiraService returns an error: %v"
,
err
)
}
}
func
TestDeleteJiraService
(
t
*
testing
.
T
)
{
mux
,
server
,
client
:=
setup
()
defer
teardown
(
server
)
mux
.
HandleFunc
(
"/projects/1/services/jira"
,
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
testMethod
(
t
,
r
,
"DELETE"
)
})
_
,
err
:=
client
.
Services
.
DeleteJiraService
(
1
)
if
err
!=
nil
{
t
.
Fatalf
(
"Services.DeleteJiraService returns an error: %v"
,
err
)
}
}
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