Skip to content

Commit e478bd5

Browse files
fix(github_graphql): add missing runId for graphql jobs (#8420)
1 parent 30960f3 commit e478bd5

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

backend/plugins/github_graphql/tasks/job_collector.go

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,13 @@ type SimpleWorkflowRun struct {
9393
CheckSuiteNodeID string
9494
}
9595

96+
// DbCheckRun is used to store additional fields (like RunId) required for database storage
97+
// and application logic, while embedding the GraphqlQueryCheckRun struct for API data.
98+
type DbCheckRun struct {
99+
RunId int // WorkflowRunId, required for DORA calculation
100+
*GraphqlQueryCheckRun
101+
}
102+
96103
var CollectJobsMeta = plugin.SubTaskMeta{
97104
Name: "Collect Job Runs",
98105
EntryPoint: CollectJobs,
@@ -188,15 +195,20 @@ func CollectJobs(taskCtx plugin.SubTaskContext) errors.Error {
188195
ResponseParser: func(queryWrapper any) (messages []json.RawMessage, err errors.Error) {
189196
query := queryWrapper.(*GraphqlQueryCheckRunWrapper)
190197
for _, node := range query.Node {
198+
runId := node.CheckSuite.WorkflowRun.DatabaseId
191199
for _, checkRun := range node.CheckSuite.CheckRuns.Nodes {
192-
updatedAt := checkRun.StartedAt
193-
if checkRun.CompletedAt != nil {
194-
updatedAt = checkRun.CompletedAt
200+
dbCheckRun := &DbCheckRun{
201+
RunId: runId,
202+
GraphqlQueryCheckRun: &checkRun,
203+
}
204+
updatedAt := dbCheckRun.StartedAt
205+
if dbCheckRun.CompletedAt != nil {
206+
updatedAt = dbCheckRun.CompletedAt
195207
}
196208
if apiCollector.GetSince() != nil && !apiCollector.GetSince().Before(*updatedAt) {
197209
return messages, helper.ErrFinishCollect
198210
}
199-
messages = append(messages, errors.Must1(json.Marshal(checkRun)))
211+
messages = append(messages, errors.Must1(json.Marshal(dbCheckRun)))
200212
}
201213
}
202214
return

backend/plugins/github_graphql/tasks/job_extractor.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func ExtractJobs(taskCtx plugin.SubTaskContext) errors.Error {
5151
Table: RAW_GRAPHQL_JOBS_TABLE,
5252
},
5353
Extract: func(row *api.RawData) ([]interface{}, errors.Error) {
54-
checkRun := &GraphqlQueryCheckRun{}
54+
checkRun := &DbCheckRun{}
5555
err := errors.Convert(json.Unmarshal(row.Data, checkRun))
5656
if err != nil {
5757
return nil, err
@@ -65,7 +65,7 @@ func ExtractJobs(taskCtx plugin.SubTaskContext) errors.Error {
6565
}
6666
githubJob := &models.GithubJob{
6767
ConnectionId: data.Options.ConnectionId,
68-
RunID: checkRun.DatabaseId,
68+
RunID: checkRun.RunId,
6969
RepoId: data.Options.GithubId,
7070
ID: checkRun.DatabaseId,
7171
NodeID: checkRun.Id,

0 commit comments

Comments
 (0)