Skip to content

fix(github): skip jobs with no started_at in cicd_job_convertor #8488

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 7, 2025
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
8 changes: 4 additions & 4 deletions backend/plugins/github/tasks/cicd_job_convertor.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package tasks

import (
"reflect"
"time"

"github.com/apache/incubator-devlake/core/dal"
"github.com/apache/incubator-devlake/core/errors"
Expand Down Expand Up @@ -87,10 +86,11 @@ func ConvertJobs(taskCtx plugin.SubTaskContext) (err errors.Error) {
Convert: func(inputRow interface{}) ([]interface{}, errors.Error) {
line := inputRow.(*models.GithubJob)

createdAt := time.Now()
if line.StartedAt != nil {
createdAt = *line.StartedAt
// Skip jobs with no started_at value (workaround for https://github.com/apache/incubator-devlake/issues/8442)
if line.StartedAt == nil {
return nil, nil
}
createdAt := *line.StartedAt
domainJob := &devops.CICDTask{
DomainEntity: domainlayer.DomainEntity{Id: jobIdGen.Generate(data.Options.ConnectionId, line.RunID,
line.ID)},
Expand Down
67 changes: 66 additions & 1 deletion backend/plugins/github/tasks/cicd_job_convertor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,15 @@ package tasks

import (
"fmt"
"testing"
"time"

"github.com/apache/incubator-devlake/core/models/domainlayer/devops"
"github.com/apache/incubator-devlake/core/models/domainlayer/didgen"
"github.com/apache/incubator-devlake/core/plugin"
mockplugin "github.com/apache/incubator-devlake/mocks/core/plugin"
"github.com/apache/incubator-devlake/plugins/github/models"
"github.com/stretchr/testify/assert"
"testing"
)

func GenJobIDWithReflect(jobIdGen *didgen.DomainIdGenerator) {
Expand Down Expand Up @@ -63,3 +66,65 @@ func BenchmarkGenJobID(b *testing.B) {
}
//BenchmarkGenJobID-8 11078593 99.43 ns/op
}

func TestConvertJobs_SkipNoStartedAt(t *testing.T) {
job := &models.GithubJob{
ID: 123,
RunID: 456,
Name: "test-job",
StartedAt: nil,
}

convert := func(inputRow interface{}) ([]interface{}, error) {
line := inputRow.(*models.GithubJob)
if line.StartedAt == nil {
return nil, nil
}
createdAt := *line.StartedAt
domainJob := &devops.CICDTask{
Name: line.Name,
TaskDatesInfo: devops.TaskDatesInfo{
CreatedDate: createdAt,
StartedDate: line.StartedAt,
FinishedDate: line.CompletedAt,
},
}
return []interface{}{domainJob}, nil
}

result, err := convert(job)
assert.Nil(t, err)
assert.Nil(t, result)
}

func TestConvertJobs_WithStartedAt(t *testing.T) {
now := time.Now()
job := &models.GithubJob{
ID: 123,
RunID: 456,
Name: "test-job",
StartedAt: &now,
}

convert := func(inputRow interface{}) ([]interface{}, error) {
line := inputRow.(*models.GithubJob)
if line.StartedAt == nil {
return nil, nil
}
createdAt := *line.StartedAt
domainJob := &devops.CICDTask{
Name: line.Name,
TaskDatesInfo: devops.TaskDatesInfo{
CreatedDate: createdAt,
StartedDate: line.StartedAt,
FinishedDate: line.CompletedAt,
},
}
return []interface{}{domainJob}, nil
}

result, err := convert(job)
assert.Nil(t, err)
assert.NotNil(t, result)
assert.Equal(t, "test-job", result[0].(*devops.CICDTask).Name)
}
Loading