This is an automated email from the ASF dual-hosted git repository. klesh pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/incubator-devlake.git
The following commit(s) were added to refs/heads/main by this push: new e478bd50b fix(github_graphql): add missing runId for graphql jobs (#8420) e478bd50b is described below commit e478bd50b0226cd11db80ce009dc8dad14a70c54 Author: Kostas Petrakis <149613045+kostas-petra...@users.noreply.github.com> AuthorDate: Mon May 12 05:33:38 2025 +0200 fix(github_graphql): add missing runId for graphql jobs (#8420) --- .../plugins/github_graphql/tasks/job_collector.go | 20 ++++++++++++++++---- .../plugins/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 c73ecfa5d..fc5cd2d85 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 5d732eccd..ac4401e06 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,