diff --git a/pkg/github/commit_files.go b/pkg/github/commit_files.go index 44d9253f..eda854be 100644 --- a/pkg/github/commit_files.go +++ b/pkg/github/commit_files.go @@ -107,7 +107,7 @@ func (c CommitsWithFiles) Frames() data.Frames { data.NewField("author_email", nil, []string{}), data.NewField("author_company", nil, []string{}), data.NewField("committed_at", nil, []time.Time{}), - data.NewField("pushed_at", nil, []time.Time{}), + data.NewField("pushed_at", nil, []*time.Time{}), data.NewField("message", nil, []string{}), data.NewField("file_path", nil, []string{}), data.NewField("file_additions", nil, []int64{}), @@ -126,7 +126,7 @@ func (c CommitsWithFiles) Frames() data.Frames { cwf.Commit.Author.Email, cwf.Commit.Author.User.Company, cwf.Commit.CommittedDate.Time, - cwf.Commit.PushedDate.Time, + nullableTime(cwf.Commit.PushedDate.Time), string(cwf.Commit.Message), f.GetFilename(), int64(f.GetAdditions()), diff --git a/pkg/github/commits.go b/pkg/github/commits.go index a5fd6a37..f5205a22 100644 --- a/pkg/github/commits.go +++ b/pkg/github/commits.go @@ -24,6 +24,17 @@ type Commit struct { // Commits is a slice of git commits type Commits []Commit +// nullableTime returns nil for a zero time so an absent value is emitted as a +// null cell instead of the Go zero date (0001-01-01). GitHub deprecated the +// GraphQL Commit.pushedDate field and now always returns null for it, which +// otherwise surfaced as a bogus 0001-01-01 pushed_at (issue #469). +func nullableTime(t time.Time) *time.Time { + if t.IsZero() { + return nil + } + return &t +} + // Frames converts the list of commits to a Grafana DataFrame func (c Commits) Frames() data.Frames { frame := data.NewFrame( @@ -34,7 +45,7 @@ func (c Commits) Frames() data.Frames { data.NewField("author_email", nil, []string{}), data.NewField("author_company", nil, []string{}), data.NewField("committed_at", nil, []time.Time{}), - data.NewField("pushed_at", nil, []time.Time{}), + data.NewField("pushed_at", nil, []*time.Time{}), data.NewField("message", nil, []string{}), ) @@ -46,7 +57,7 @@ func (c Commits) Frames() data.Frames { v.Author.Email, v.Author.User.Company, v.CommittedDate.Time, - v.PushedDate.Time, + nullableTime(v.PushedDate.Time), string(v.Message), ) } diff --git a/pkg/github/commits_test.go b/pkg/github/commits_test.go index c1d371b8..1ed08d78 100644 --- a/pkg/github/commits_test.go +++ b/pkg/github/commits_test.go @@ -115,9 +115,8 @@ func TestCommitsDataframe(t *testing.T) { commits := Commits{ Commit{ OID: "", - PushedDate: githubv4.DateTime{ - Time: committedAt.Add(time.Minute * 2), - }, + // PushedDate intentionally left zero: GitHub deprecated Commit.pushedDate + // and returns null, which must surface as a null pushed_at (issue #469). AuthoredDate: githubv4.DateTime{ Time: committedAt, }, diff --git a/pkg/github/testdata/commits.golden.jsonc b/pkg/github/testdata/commits.golden.jsonc index f341b555..8bcfb5f7 100644 --- a/pkg/github/testdata/commits.golden.jsonc +++ b/pkg/github/testdata/commits.golden.jsonc @@ -6,9 +6,9 @@ // +----------------+-----------------+--------------------+--------------------+----------------------+---------------------------------+---------------------------------+----------------+ // | Name: id | Name: author | Name: author_login | Name: author_email | Name: author_company | Name: committed_at | Name: pushed_at | Name: message | // | Labels: | Labels: | Labels: | Labels: | Labels: | Labels: | Labels: | Labels: | -// | Type: []string | Type: []string | Type: []string | Type: []string | Type: []string | Type: []time.Time | Type: []time.Time | Type: []string | +// | Type: []string | Type: []string | Type: []string | Type: []string | Type: []string | Type: []time.Time | Type: []*time.Time | Type: []string | // +----------------+-----------------+--------------------+--------------------+----------------------+---------------------------------+---------------------------------+----------------+ -// | | firstCommitter | firstCommitter | first@example.com | ACME Corp | 2020-08-25 16:21:56 +0000 +0000 | 2020-08-25 16:23:56 +0000 +0000 | commit #1 | +// | | firstCommitter | firstCommitter | first@example.com | ACME Corp | 2020-08-25 16:21:56 +0000 +0000 | null | commit #1 | // | | secondCommitter | secondCommitter | second@example.com | ACME Corp | 2020-08-25 17:21:56 +0000 +0000 | 2020-08-25 18:21:56 +0000 +0000 | commit #2 | // +----------------+-----------------+--------------------+--------------------+----------------------+---------------------------------+---------------------------------+----------------+ // @@ -67,7 +67,8 @@ "name": "pushed_at", "type": "time", "typeInfo": { - "frame": "time.Time" + "frame": "time.Time", + "nullable": true } }, { @@ -106,7 +107,7 @@ 1598376116000 ], [ - 1598372636000, + null, 1598379716000 ], [ diff --git a/pkg/github/testdata/commits_with_files.golden.jsonc b/pkg/github/testdata/commits_with_files.golden.jsonc index 47cc7a3c..86dbb880 100644 --- a/pkg/github/testdata/commits_with_files.golden.jsonc +++ b/pkg/github/testdata/commits_with_files.golden.jsonc @@ -12,7 +12,7 @@ // +----------------+----------------+--------------------+--------------------+----------------------+---------------------------------+---------------------------------+----------------+----------------------+----------------------+----------------------+--------------------+-------------------+-------------------------+ // | Name: id | Name: author | Name: author_login | Name: author_email | Name: author_company | Name: committed_at | Name: pushed_at | Name: message | Name: file_path | Name: file_additions | Name: file_deletions | Name: file_changes | Name: file_status | Name: previous_filename | // | Labels: | Labels: | Labels: | Labels: | Labels: | Labels: | Labels: | Labels: | Labels: | Labels: | Labels: | Labels: | Labels: | Labels: | -// | Type: []string | Type: []string | Type: []string | Type: []string | Type: []string | Type: []time.Time | Type: []time.Time | Type: []string | Type: []string | Type: []int64 | Type: []int64 | Type: []int64 | Type: []string | Type: []string | +// | Type: []string | Type: []string | Type: []string | Type: []string | Type: []string | Type: []time.Time | Type: []*time.Time | Type: []string | Type: []string | Type: []int64 | Type: []int64 | Type: []int64 | Type: []string | Type: []string | // +----------------+----------------+--------------------+--------------------+----------------------+---------------------------------+---------------------------------+----------------+----------------------+----------------------+----------------------+--------------------+-------------------+-------------------------+ // | abc123def456 | firstCommitter | firstCommitter | first@example.com | ACME Corp | 2020-08-25 16:21:56 +0000 +0000 | 2020-08-25 16:23:56 +0000 +0000 | initial commit | pkg/server/server.go | 10 | 2 | 12 | modified | | // | abc123def456 | firstCommitter | firstCommitter | first@example.com | ACME Corp | 2020-08-25 16:21:56 +0000 +0000 | 2020-08-25 16:23:56 +0000 +0000 | initial commit | pkg/renamed.go | 0 | 0 | 0 | renamed | pkg/old.go | @@ -80,7 +80,8 @@ "name": "pushed_at", "type": "time", "typeInfo": { - "frame": "time.Time" + "frame": "time.Time", + "nullable": true } }, {