1
0
mirror of https://github.com/interviewstreet/go-jira.git synced 2025-03-17 20:47:57 +02:00

Merge pull request #157 from oroshnivskyy/master

Add CreatedTime() (time.Time, error) func to ChangelogHistory
This commit is contained in:
rbriski 2018-09-12 12:30:26 -07:00 committed by GitHub
commit 47f48bdc59
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 42 additions and 0 deletions

View File

@ -1107,3 +1107,13 @@ func (s *IssueService) UpdateAssignee(issueID string, assignee *User) (*Response
return resp, err
}
func (c ChangelogHistory) CreatedTime() (time.Time, error) {
var t time.Time
// Ignore null
if string(c.Created) == "null" {
return t, nil
}
t, err := time.Parse("2006-01-02T15:04:05.999-0700", c.Created)
return t, err
}

View File

@ -10,6 +10,7 @@ import (
"testing"
"github.com/trivago/tgo/tcontainer"
"time"
)
func TestIssueService_Get_Success(t *testing.T) {
@ -1330,3 +1331,34 @@ func TestIssueService_UpdateAssignee(t *testing.T) {
t.Errorf("Error given: %s", err)
}
}
func TestIssueService_Get_Fields_Changelog(t *testing.T) {
setup()
defer teardown()
testMux.HandleFunc("/rest/api/2/issue/10002", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
testRequestURL(t, r, "/rest/api/2/issue/10002")
fmt.Fprint(w, `{"expand":"changelog","id":"10002","self":"http://www.example.com/jira/rest/api/2/issue/10002","key":"EX-1","changelog":{"startAt": 0,"maxResults": 1, "total": 1, "histories": [{"id": "10002", "author": {"self": "http://www.example.com/jira/rest/api/2/user?username=fred", "name": "fred", "key": "fred", "emailAddress": "fred@example.com", "avatarUrls": {"48x48": "http://www.example.com/secure/useravatar?ownerId=fred&avatarId=33072", "24x24": "http://www.example.com/secure/useravatar?size=small&ownerId=fred&avatarId=33072", "16x16": "http://www.example.com/secure/useravatar?size=xsmall&ownerId=fred&avatarId=33072", "32x32": "http://www.example.com/secure/useravatar?size=medium&ownerId=fred&avatarId=33072"},"displayName":"Fred","active": true,"timeZone":"Australia/Sydney"},"created":"2018-06-20T16:50:35.000+0300","items":[{"field":"Rank","fieldtype":"custom","from":"","fromString":"","to":"","toString":"Ranked higher"}]}]}}`)
})
issue, _, _ := testClient.Issue.Get("10002", &GetQueryOptions{Expand:"changelog"})
if issue == nil {
t.Error("Expected issue. Issue is nil")
}
if len(issue.Changelog.Histories) != 1 {
t.Errorf("Expected one history item, %v found", len(issue.Changelog.Histories))
}
if issue.Changelog.Histories[0].Created != "2018-06-20T16:50:35.000+0300" {
t.Errorf("Expected created time of history item 2018-06-20T16:50:35.000+0300, %v got", issue.Changelog.Histories[0].Created)
}
tm, _ := time.Parse("2006-01-02T15:04:05.999-0700", "2018-06-20T16:50:35.000+0300")
if ct, _ := issue.Changelog.Histories[0].CreatedTime(); !tm.Equal(ct) {
t.Errorf("Expected CreatedTime func return %v time, %v got", tm, ct)
}
}