commit 15c79f9461ab2d4a71b192444f6d658c39664377
parent a49ed26aed68f00abaf9d48e1ba9c25fa5a311d1
Author: Oliver Lowe <o@olowe.co>
Date: Fri, 18 Jul 2025 10:59:56 +0700
jira: decode issue due date
And test timestamp etc. parsing
Diffstat:
2 files changed, 32 insertions(+), 13 deletions(-)
diff --git a/jira/jira.go b/jira/jira.go
@@ -8,6 +8,9 @@ import (
const timestamp = "2006-01-02T15:04:05.999-0700"
+// Issue represents a limited subset of a Jira issue's data.
+// For a complete example of all issue data,
+// see https://jira.atlassian.com/rest/api/2/issue/JRA-9.
type Issue struct {
ID string `json:"id,omitempty"` // TODO(otl): int?
URL string `json:"url,omitempty"`
@@ -22,7 +25,7 @@ type Issue struct {
Project Project `json:"project"`
Created time.Time `json:"created,omitzero"`
Updated time.Time `json:"updated,omitzero"`
- Due time.Time `json:"duedate,omitzero"`
+ Due time.Time `json:"duedate,omitzero"`
Type struct {
Name string `json:"name"`
} `json:"issuetype"`
@@ -103,7 +106,7 @@ func (issue *Issue) UnmarshalJSON(b []byte) error {
iaux := &struct {
Created string `json:"created"`
Updated string `json:"updated"`
- Due string `json:"duedate"`
+ Due string `json:"duedate"`
Comment map[string]json.RawMessage
IssueLinks []struct {
InwardIssue *Issue
diff --git a/jira/jira_test.go b/jira/jira_test.go
@@ -4,23 +4,39 @@ import (
"encoding/json"
"os"
"testing"
+ "time"
)
func TestDecode(t *testing.T) {
- dents, err := os.ReadDir("testdata/issue")
+ name := "testdata/issue/TEST-1"
+ f, err := os.Open(name)
if err != nil {
t.Fatal(err)
}
- for _, d := range dents {
- f, err := os.Open("testdata/issue/" + d.Name())
- if err != nil {
- t.Fatal(err)
- }
- var i Issue
- if err := json.NewDecoder(f).Decode(&i); err != nil {
- t.Errorf("decode %s: %v", f.Name(), err)
- }
- f.Close()
+ defer f.Close()
+
+ var issue Issue
+ if err := json.NewDecoder(f).Decode(&issue); err != nil {
+ t.Fatal(err)
+ }
+
+ want := Issue{
+ ID: "10148",
+ URL: "https://jira.atlassian.com/rest/api/latest/issue/10148",
+ Key: "TEST-1",
+ Created: time.Date(2002, time.Month(2), 8, 5, 8, 0, 0, time.UTC),
+ Updated: time.Date(2022, time.Month(5), 18, 18, 35, 49, 533*1e6, time.UTC),
+ }
+
+ if !issue.Created.Equal(want.Created) {
+ t.Errorf("Created: got %s want %s", issue.Created, want.Created)
+ }
+ if !issue.Updated.Equal(want.Updated) {
+ t.Errorf("Updated: got %s want %s", issue.Updated, want.Updated)
+ }
+
+ if len(issue.Links) == 0 {
+ t.Errorf("Links: no linked issues decoded")
}
}