Skip to content

Commit b695167

Browse files
Brend-Smitsrbstp
authored andcommitted
fix(github): skip jobs with no started_at in cicd_job_convertor (apache#8488)
This change skips GitHub job records that have no started_at value, as a workaround for apache#8442. Closes apache#8442
1 parent 7ba5930 commit b695167

File tree

2 files changed

+70
-5
lines changed

2 files changed

+70
-5
lines changed

backend/plugins/github/tasks/cicd_job_convertor.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ package tasks
1919

2020
import (
2121
"reflect"
22-
"time"
2322

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

90-
createdAt := time.Now()
91-
if line.StartedAt != nil {
92-
createdAt = *line.StartedAt
89+
// Skip jobs with no started_at value (workaround for https://github.com/apache/incubator-devlake/issues/8442)
90+
if line.StartedAt == nil {
91+
return nil, nil
9392
}
93+
createdAt := *line.StartedAt
9494
domainJob := &devops.CICDTask{
9595
DomainEntity: domainlayer.DomainEntity{Id: jobIdGen.Generate(data.Options.ConnectionId, line.RunID,
9696
line.ID)},

backend/plugins/github/tasks/cicd_job_convertor_test.go

Lines changed: 66 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,15 @@ package tasks
1919

2020
import (
2121
"fmt"
22+
"testing"
23+
"time"
24+
25+
"github.com/apache/incubator-devlake/core/models/domainlayer/devops"
2226
"github.com/apache/incubator-devlake/core/models/domainlayer/didgen"
2327
"github.com/apache/incubator-devlake/core/plugin"
2428
mockplugin "github.com/apache/incubator-devlake/mocks/core/plugin"
2529
"github.com/apache/incubator-devlake/plugins/github/models"
2630
"github.com/stretchr/testify/assert"
27-
"testing"
2831
)
2932

3033
func GenJobIDWithReflect(jobIdGen *didgen.DomainIdGenerator) {
@@ -63,3 +66,65 @@ func BenchmarkGenJobID(b *testing.B) {
6366
}
6467
//BenchmarkGenJobID-8 11078593 99.43 ns/op
6568
}
69+
70+
func TestConvertJobs_SkipNoStartedAt(t *testing.T) {
71+
job := &models.GithubJob{
72+
ID: 123,
73+
RunID: 456,
74+
Name: "test-job",
75+
StartedAt: nil,
76+
}
77+
78+
convert := func(inputRow interface{}) ([]interface{}, error) {
79+
line := inputRow.(*models.GithubJob)
80+
if line.StartedAt == nil {
81+
return nil, nil
82+
}
83+
createdAt := *line.StartedAt
84+
domainJob := &devops.CICDTask{
85+
Name: line.Name,
86+
TaskDatesInfo: devops.TaskDatesInfo{
87+
CreatedDate: createdAt,
88+
StartedDate: line.StartedAt,
89+
FinishedDate: line.CompletedAt,
90+
},
91+
}
92+
return []interface{}{domainJob}, nil
93+
}
94+
95+
result, err := convert(job)
96+
assert.Nil(t, err)
97+
assert.Nil(t, result)
98+
}
99+
100+
func TestConvertJobs_WithStartedAt(t *testing.T) {
101+
now := time.Now()
102+
job := &models.GithubJob{
103+
ID: 123,
104+
RunID: 456,
105+
Name: "test-job",
106+
StartedAt: &now,
107+
}
108+
109+
convert := func(inputRow interface{}) ([]interface{}, error) {
110+
line := inputRow.(*models.GithubJob)
111+
if line.StartedAt == nil {
112+
return nil, nil
113+
}
114+
createdAt := *line.StartedAt
115+
domainJob := &devops.CICDTask{
116+
Name: line.Name,
117+
TaskDatesInfo: devops.TaskDatesInfo{
118+
CreatedDate: createdAt,
119+
StartedDate: line.StartedAt,
120+
FinishedDate: line.CompletedAt,
121+
},
122+
}
123+
return []interface{}{domainJob}, nil
124+
}
125+
126+
result, err := convert(job)
127+
assert.Nil(t, err)
128+
assert.NotNil(t, result)
129+
assert.Equal(t, "test-job", result[0].(*devops.CICDTask).Name)
130+
}

0 commit comments

Comments
 (0)