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
a11ea797
Commit
a11ea797
authored
Jan 20, 2019
by
Matthias Bartelmeß
Committed by
Jordan Caussat
May 22, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement UnmarshalJSON for Jira Service Properties
parent
dbe6fb3e
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
65 additions
and
2 deletions
+65
-2
services.go
services.go
+38
-0
services_test.go
services_test.go
+27
-2
No files found.
services.go
View file @
a11ea797
...
...
@@ -17,7 +17,11 @@
package
gitlab
import
(
"encoding/json"
"fmt"
"net/url"
"reflect"
"strconv"
"time"
)
...
...
@@ -396,6 +400,40 @@ type JiraServiceProperties struct {
JiraIssueTransitionID
string
`json:"jira_issue_transition_id,omitempty"`
}
// UnmarshalJSON decodes the Jira Service Properties.
//
// The Gitlab API returns under some circumstances JiraIssueTransitionID
// as a string and sometimes as an integer. This function converts the
// returned value into an integer.
func
(
p
*
JiraServiceProperties
)
UnmarshalJSON
(
b
[]
byte
)
error
{
type
Alias
JiraServiceProperties
aux
:=
&
struct
{
JiraIssueTransitionID
interface
{}
`url:"jira_issue_transition_id,omitempty" json:"jira_issue_transition_id,omitempty"`
*
Alias
}{
Alias
:
(
*
Alias
)(
p
),
}
if
err
:=
json
.
Unmarshal
(
b
,
&
aux
);
err
!=
nil
{
return
err
}
switch
id
:=
aux
.
JiraIssueTransitionID
.
(
type
)
{
case
string
:
converted
,
err
:=
strconv
.
Atoi
(
id
)
if
err
!=
nil
{
return
err
}
p
.
JiraIssueTransitionID
=
func
(
i
int
)
*
int
{
return
&
i
}(
converted
)
case
float64
:
p
.
JiraIssueTransitionID
=
Int
(
int
(
id
))
default
:
return
fmt
.
Errorf
(
"failed to unmarshal JiraTransitionID of type: %s"
,
reflect
.
TypeOf
(
id
))
}
return
nil
}
// GetJiraService gets Jira service settings for a project.
//
// GitLab API docs:
...
...
services_test.go
View file @
a11ea797
...
...
@@ -115,14 +115,39 @@ func TestGetJiraService(t *testing.T) {
mux
.
HandleFunc
(
"/api/v4/projects/1/services/jira"
,
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
testMethod
(
t
,
r
,
"GET"
)
fmt
.
Fprint
(
w
,
`{"id":1}`
)
fmt
.
Fprint
(
w
,
`{"id":1
, "properties": {"jira_issue_transition_id": "2"}
}`
)
})
want
:=
&
JiraService
{
Service
:
Service
{
ID
:
1
}}
mux
.
HandleFunc
(
"/api/v4/projects/2/services/jira"
,
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
testMethod
(
t
,
r
,
"GET"
)
fmt
.
Fprint
(
w
,
`{"id":1, "properties": {"jira_issue_transition_id": 2}}`
)
})
mux
.
HandleFunc
(
"/api/v4/projects/3/services/jira"
,
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
testMethod
(
t
,
r
,
"GET"
)
fmt
.
Fprint
(
w
,
`{"id":3, "properties": {"jira_issue_transition_id": "2,3"}}`
)
})
want
:=
&
JiraService
{
Service
:
Service
{
ID
:
1
},
Properties
:
&
JiraServiceProperties
{
JiraIssueTransitionID
:
Int
(
2
),
}}
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
)
}
service
,
_
,
err
=
client
.
Services
.
GetJiraService
(
2
)
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
)
}
...
...
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