commit 15c79f9461ab2d4a71b192444f6d658c39664377 from: Oliver Lowe date: Fri Jul 18 04:05:22 2025 UTC jira: decode issue due date And test timestamp etc. parsing commit - a49ed26aed68f00abaf9d48e1ba9c25fa5a311d1 commit + 15c79f9461ab2d4a71b192444f6d658c39664377 blob - b5fda3dfa1d1be4ae42a25f38af58a45577a7298 blob + 83c74ab0fcd60f6843b6cae323cd7be93756a179 --- jira/jira.go +++ 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 blob - 569d9044a8d842febb0dddae295bc66bd98a58ca blob + 6df697e71e0111e9cf28d647d5a6a401391b7428 --- jira/jira_test.go +++ jira/jira_test.go @@ -4,24 +4,40 @@ 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") + } } /*