Skip to content

Commit 9549eb7

Browse files
authored
Add runStartedAt field to workflow runs query response (#501)
Fixes: #493
1 parent 7b8b74c commit 9549eb7

File tree

4 files changed

+67
-38
lines changed

4 files changed

+67
-38
lines changed

.changeset/five-suits-rescue.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'grafana-github-datasource': patch
3+
---
4+
5+
Add runStartedAt field for workflow runs query response

pkg/github/testdata/workflowRuns.golden.jsonc

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@
88
// "preferredVisualisationType": "table"
99
// }
1010
// Name: workflow_run
11-
// Dimensions: 13 Fields by 2 Rows
12-
// +----------------+-----------------+-------------------+-----------------+-------------------------------+-------------------------------+-----------------+-----------------+-----------------+------------------+-----------------+-------------------+------------------+
13-
// | Name: id | Name: name | Name: head_branch | Name: head_sha | Name: created_at | Name: updated_at | Name: html_url | Name: url | Name: status | Name: conclusion | Name: event | Name: workflow_id | Name: run_number |
14-
// | Labels: | Labels: | Labels: | Labels: | Labels: | Labels: | Labels: | Labels: | Labels: | Labels: | Labels: | Labels: | Labels: |
15-
// | Type: []*int64 | Type: []*string | Type: []*string | Type: []*string | Type: []*time.Time | Type: []*time.Time | Type: []*string | Type: []*string | Type: []*string | Type: []*string | Type: []*string | Type: []*int64 | Type: []int64 |
16-
// +----------------+-----------------+-------------------+-----------------+-------------------------------+-------------------------------+-----------------+-----------------+-----------------+------------------+-----------------+-------------------+------------------+
17-
// | 2 | name_2 | head_branch_2 | head_sha_2 | 2013-02-03 00:00:00 +0000 UTC | 2013-02-04 00:00:00 +0000 UTC | html_url_2 | url_2 | status_2 | conclusion_2 | event_2 | 2 | 2 |
18-
// | 1 | name_1 | head_branch_1 | head_sha_1 | 2013-02-01 00:00:00 +0000 UTC | 2013-02-02 00:00:00 +0000 UTC | html_url_1 | url_1 | status_1 | conclusion_1 | event_1 | 1 | 1 |
19-
// +----------------+-----------------+-------------------+-----------------+-------------------------------+-------------------------------+-----------------+-----------------+-----------------+------------------+-----------------+-------------------+------------------+
11+
// Dimensions: 14 Fields by 2 Rows
12+
// +----------------+-----------------+-------------------+-----------------+-------------------------------+-------------------------------+-------------------------------+-----------------+-----------------+-----------------+------------------+-----------------+-------------------+------------------+
13+
// | Name: id | Name: name | Name: head_branch | Name: head_sha | Name: created_at | Name: updated_at | Name: run_started_at | Name: html_url | Name: url | Name: status | Name: conclusion | Name: event | Name: workflow_id | Name: run_number |
14+
// | Labels: | Labels: | Labels: | Labels: | Labels: | Labels: | Labels: | Labels: | Labels: | Labels: | Labels: | Labels: | Labels: | Labels: |
15+
// | Type: []*int64 | Type: []*string | Type: []*string | Type: []*string | Type: []*time.Time | Type: []*time.Time | Type: []*time.Time | Type: []*string | Type: []*string | Type: []*string | Type: []*string | Type: []*string | Type: []*int64 | Type: []int64 |
16+
// +----------------+-----------------+-------------------+-----------------+-------------------------------+-------------------------------+-------------------------------+-----------------+-----------------+-----------------+------------------+-----------------+-------------------+------------------+
17+
// | 2 | name_2 | head_branch_2 | head_sha_2 | 2013-02-03 00:00:00 +0000 UTC | 2013-02-04 00:00:00 +0000 UTC | 2013-02-04 00:00:00 +0000 UTC | html_url_2 | url_2 | status_2 | conclusion_2 | event_2 | 2 | 2 |
18+
// | 1 | name_1 | head_branch_1 | head_sha_1 | 2013-02-01 00:00:00 +0000 UTC | 2013-02-02 00:00:00 +0000 UTC | 2013-02-02 00:00:00 +0000 UTC | html_url_1 | url_1 | status_1 | conclusion_1 | event_1 | 1 | 1 |
19+
// +----------------+-----------------+-------------------+-----------------+-------------------------------+-------------------------------+-------------------------------+-----------------+-----------------+-----------------+------------------+-----------------+-------------------+------------------+
2020
//
2121
//
2222
// 🌟 This was machine generated. Do not edit. 🌟
@@ -82,6 +82,14 @@
8282
"nullable": true
8383
}
8484
},
85+
{
86+
"name": "run_started_at",
87+
"type": "time",
88+
"typeInfo": {
89+
"frame": "time.Time",
90+
"nullable": true
91+
}
92+
},
8593
{
8694
"name": "html_url",
8795
"type": "string",
@@ -165,6 +173,10 @@
165173
1359936000000,
166174
1359763200000
167175
],
176+
[
177+
1359936000000,
178+
1359763200000
179+
],
168180
[
169181
"html_url_2",
170182
"html_url_1"

pkg/github/workflows.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@ import (
66
"time"
77

88
googlegithub "github.com/google/go-github/v72/github"
9-
"github.com/grafana/github-datasource/pkg/models"
109
"github.com/grafana/grafana-plugin-sdk-go/backend"
1110
"github.com/grafana/grafana-plugin-sdk-go/data"
11+
12+
"github.com/grafana/github-datasource/pkg/models"
1213
)
1314

1415
// WorkflowsWrapper is a list of GitHub workflows
@@ -199,6 +200,7 @@ func (workflowRuns WorkflowRunsWrapper) Frames() data.Frames {
199200
data.NewField("head_sha", nil, []*string{}),
200201
data.NewField("created_at", nil, []*time.Time{}),
201202
data.NewField("updated_at", nil, []*time.Time{}),
203+
data.NewField("run_started_at", nil, []*time.Time{}),
202204
data.NewField("html_url", nil, []*string{}),
203205
data.NewField("url", nil, []*string{}),
204206
data.NewField("status", nil, []*string{}),
@@ -217,6 +219,7 @@ func (workflowRuns WorkflowRunsWrapper) Frames() data.Frames {
217219
workflowRun.HeadSHA,
218220
workflowRun.CreatedAt.GetTime(),
219221
workflowRun.UpdatedAt.GetTime(),
222+
workflowRun.RunStartedAt.GetTime(),
220223
workflowRun.HTMLURL,
221224
workflowRun.URL,
222225
workflowRun.Status,

pkg/github/workflows_test.go

Lines changed: 37 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@ import (
77
"time"
88

99
googlegithub "github.com/google/go-github/v72/github"
10-
"github.com/grafana/github-datasource/pkg/models"
11-
"github.com/grafana/github-datasource/pkg/testutil"
1210
"github.com/grafana/grafana-plugin-sdk-go/backend"
1311
"github.com/stretchr/testify/assert"
1412
"pgregory.net/rapid"
13+
14+
"github.com/grafana/github-datasource/pkg/models"
15+
"github.com/grafana/github-datasource/pkg/testutil"
1516
)
1617

1718
func githubWorkflowGen() *rapid.Generator[*googlegithub.Workflow] {
@@ -254,42 +255,50 @@ func TestWorkflowRunsDataFrame(t *testing.T) {
254255
updatedAt1, err := time.Parse("2006-Jan-02", "2013-Feb-02")
255256
assert.NoError(t, err)
256257

258+
runStartedAt1, err := time.Parse("2006-Jan-02", "2013-Feb-02")
259+
assert.NoError(t, err)
260+
257261
createdAt2, err := time.Parse("2006-Jan-02", "2013-Feb-03")
258262
assert.NoError(t, err)
259263

260264
updatedAt2, err := time.Parse("2006-Jan-02", "2013-Feb-04")
261265
assert.NoError(t, err)
262266

267+
runStartedAt2, err := time.Parse("2006-Jan-02", "2013-Feb-04")
268+
assert.NoError(t, err)
269+
263270
workflowRuns := WorkflowRunsWrapper([]*googlegithub.WorkflowRun{
264271
{
265-
ID: ptr(int64(1)),
266-
Name: ptr("name_1"),
267-
HeadBranch: ptr("head_branch_1"),
268-
HeadSHA: ptr("head_sha_1"),
269-
CreatedAt: &googlegithub.Timestamp{Time: createdAt1},
270-
UpdatedAt: &googlegithub.Timestamp{Time: updatedAt1},
271-
HTMLURL: ptr("html_url_1"),
272-
URL: ptr("url_1"),
273-
Status: ptr("status_1"),
274-
Conclusion: ptr("conclusion_1"),
275-
Event: ptr("event_1"),
276-
WorkflowID: ptr(int64(1)),
277-
RunNumber: ptr(int(1)),
272+
ID: ptr(int64(1)),
273+
Name: ptr("name_1"),
274+
HeadBranch: ptr("head_branch_1"),
275+
HeadSHA: ptr("head_sha_1"),
276+
CreatedAt: &googlegithub.Timestamp{Time: createdAt1},
277+
UpdatedAt: &googlegithub.Timestamp{Time: updatedAt1},
278+
RunStartedAt: &googlegithub.Timestamp{Time: runStartedAt1},
279+
HTMLURL: ptr("html_url_1"),
280+
URL: ptr("url_1"),
281+
Status: ptr("status_1"),
282+
Conclusion: ptr("conclusion_1"),
283+
Event: ptr("event_1"),
284+
WorkflowID: ptr(int64(1)),
285+
RunNumber: ptr(int(1)),
278286
},
279287
{
280-
ID: ptr(int64(2)),
281-
Name: ptr("name_2"),
282-
HeadBranch: ptr("head_branch_2"),
283-
HeadSHA: ptr("head_sha_2"),
284-
CreatedAt: &googlegithub.Timestamp{Time: createdAt2},
285-
UpdatedAt: &googlegithub.Timestamp{Time: updatedAt2},
286-
HTMLURL: ptr("html_url_2"),
287-
URL: ptr("url_2"),
288-
Status: ptr("status_2"),
289-
Conclusion: ptr("conclusion_2"),
290-
Event: ptr("event_2"),
291-
WorkflowID: ptr(int64(2)),
292-
RunNumber: ptr(int(2)),
288+
ID: ptr(int64(2)),
289+
Name: ptr("name_2"),
290+
HeadBranch: ptr("head_branch_2"),
291+
HeadSHA: ptr("head_sha_2"),
292+
CreatedAt: &googlegithub.Timestamp{Time: createdAt2},
293+
UpdatedAt: &googlegithub.Timestamp{Time: updatedAt2},
294+
RunStartedAt: &googlegithub.Timestamp{Time: runStartedAt2},
295+
HTMLURL: ptr("html_url_2"),
296+
URL: ptr("url_2"),
297+
Status: ptr("status_2"),
298+
Conclusion: ptr("conclusion_2"),
299+
Event: ptr("event_2"),
300+
WorkflowID: ptr(int64(2)),
301+
RunNumber: ptr(int(2)),
293302
},
294303
})
295304

0 commit comments

Comments
 (0)