From 52a34db96cd48a0de096b58e2a4645b2f62623c9 Mon Sep 17 00:00:00 2001 From: Kostas Petrakis Date: Thu, 1 May 2025 16:52:34 +0200 Subject: [PATCH] fix(github_graphql): add missing runId for graphql jobs --- .../github_graphql/tasks/job_collector.go | 20 +++++++++++++++---- .../github_graphql/tasks/job_extractor.go | 4 ++-- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/backend/plugins/github_graphql/tasks/job_collector.go b/backend/plugins/github_graphql/tasks/job_collector.go index c73ecfa5d69..fc5cd2d85f3 100644 --- a/backend/plugins/github_graphql/tasks/job_collector.go +++ b/backend/plugins/github_graphql/tasks/job_collector.go @@ -93,6 +93,13 @@ type SimpleWorkflowRun struct { CheckSuiteNodeID string } +// DbCheckRun is used to store additional fields (like RunId) required for database storage +// and application logic, while embedding the GraphqlQueryCheckRun struct for API data. +type DbCheckRun struct { + RunId int // WorkflowRunId, required for DORA calculation + *GraphqlQueryCheckRun +} + var CollectJobsMeta = plugin.SubTaskMeta{ Name: "Collect Job Runs", EntryPoint: CollectJobs, @@ -188,15 +195,20 @@ func CollectJobs(taskCtx plugin.SubTaskContext) errors.Error { ResponseParser: func(queryWrapper any) (messages []json.RawMessage, err errors.Error) { query := queryWrapper.(*GraphqlQueryCheckRunWrapper) for _, node := range query.Node { + runId := node.CheckSuite.WorkflowRun.DatabaseId for _, checkRun := range node.CheckSuite.CheckRuns.Nodes { - updatedAt := checkRun.StartedAt - if checkRun.CompletedAt != nil { - updatedAt = checkRun.CompletedAt + dbCheckRun := &DbCheckRun{ + RunId: runId, + GraphqlQueryCheckRun: &checkRun, + } + updatedAt := dbCheckRun.StartedAt + if dbCheckRun.CompletedAt != nil { + updatedAt = dbCheckRun.CompletedAt } if apiCollector.GetSince() != nil && !apiCollector.GetSince().Before(*updatedAt) { return messages, helper.ErrFinishCollect } - messages = append(messages, errors.Must1(json.Marshal(checkRun))) + messages = append(messages, errors.Must1(json.Marshal(dbCheckRun))) } } return diff --git a/backend/plugins/github_graphql/tasks/job_extractor.go b/backend/plugins/github_graphql/tasks/job_extractor.go index 5d732eccd60..ac4401e0659 100644 --- a/backend/plugins/github_graphql/tasks/job_extractor.go +++ b/backend/plugins/github_graphql/tasks/job_extractor.go @@ -51,7 +51,7 @@ func ExtractJobs(taskCtx plugin.SubTaskContext) errors.Error { Table: RAW_GRAPHQL_JOBS_TABLE, }, Extract: func(row *api.RawData) ([]interface{}, errors.Error) { - checkRun := &GraphqlQueryCheckRun{} + checkRun := &DbCheckRun{} err := errors.Convert(json.Unmarshal(row.Data, checkRun)) if err != nil { return nil, err @@ -65,7 +65,7 @@ func ExtractJobs(taskCtx plugin.SubTaskContext) errors.Error { } githubJob := &models.GithubJob{ ConnectionId: data.Options.ConnectionId, - RunID: checkRun.DatabaseId, + RunID: checkRun.RunId, RepoId: data.Options.GithubId, ID: checkRun.DatabaseId, NodeID: checkRun.Id,