Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pkg/github/commit_files.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}),
Expand All @@ -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()),
Expand Down
15 changes: 13 additions & 2 deletions pkg/github/commits.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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{}),
)

Expand All @@ -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),
)
}
Expand Down
5 changes: 2 additions & 3 deletions pkg/github/commits_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand Down
9 changes: 5 additions & 4 deletions pkg/github/testdata/commits.golden.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
// +----------------+-----------------+--------------------+--------------------+----------------------+---------------------------------+---------------------------------+----------------+
//
Expand Down Expand Up @@ -67,7 +67,8 @@
"name": "pushed_at",
"type": "time",
"typeInfo": {
"frame": "time.Time"
"frame": "time.Time",
"nullable": true
}
},
{
Expand Down Expand Up @@ -106,7 +107,7 @@
1598376116000
],
[
1598372636000,
null,
1598379716000
],
[
Expand Down
5 changes: 3 additions & 2 deletions pkg/github/testdata/commits_with_files.golden.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down Expand Up @@ -80,7 +80,8 @@
"name": "pushed_at",
"type": "time",
"typeInfo": {
"frame": "time.Time"
"frame": "time.Time",
"nullable": true
}
},
{
Expand Down
Loading