@@ -20,17 +20,13 @@ package tasks
20
20
import (
21
21
"encoding/json"
22
22
"fmt"
23
- "io"
24
23
"net/http"
25
24
"net/url"
26
- "reflect"
27
25
"time"
28
26
29
- "github.com/apache/incubator-devlake/core/dal"
30
27
"github.com/apache/incubator-devlake/core/errors"
31
28
"github.com/apache/incubator-devlake/core/plugin"
32
29
helper "github.com/apache/incubator-devlake/helpers/pluginhelper/api"
33
- "github.com/apache/incubator-devlake/plugins/jenkins/models"
34
30
)
35
31
36
32
const RAW_BUILD_TABLE = "jenkins_api_builds"
@@ -55,7 +51,6 @@ type SimpleJenkinsApiBuild struct {
55
51
56
52
func CollectApiBuilds (taskCtx plugin.SubTaskContext ) errors.Error {
57
53
data := taskCtx .GetData ().(* JenkinsTaskData )
58
- db := taskCtx .GetDal ()
59
54
collector , err := helper .NewStatefulApiCollectorForFinalizableEntity (helper.FinalizableApiCollectorArgs {
60
55
RawDataSubTaskArgs : helper.RawDataSubTaskArgs {
61
56
Params : JenkinsApiParams {
@@ -87,7 +82,20 @@ func CollectApiBuilds(taskCtx plugin.SubTaskContext) errors.Error {
87
82
if err != nil {
88
83
return nil , err
89
84
}
90
- return data .Builds , nil
85
+
86
+ builds := make ([]json.RawMessage , 0 , len (data .Builds ))
87
+ for _ , build := range data .Builds {
88
+ var buildObj map [string ]interface {}
89
+ err := json .Unmarshal (build , & buildObj )
90
+ if err != nil {
91
+ return nil , errors .Convert (err )
92
+ }
93
+ if buildObj ["result" ] != nil {
94
+ builds = append (builds , build )
95
+ }
96
+ }
97
+
98
+ return builds , nil
91
99
},
92
100
},
93
101
GetCreated : func (item json.RawMessage ) (time.Time , errors.Error ) {
@@ -101,34 +109,6 @@ func CollectApiBuilds(taskCtx plugin.SubTaskContext) errors.Error {
101
109
return time .Unix (seconds , nanos ), nil
102
110
},
103
111
},
104
- CollectUnfinishedDetails : & helper.FinalizableApiCollectorDetailArgs {
105
- BuildInputIterator : func () (helper.Iterator , errors.Error ) {
106
- cursor , err := db .Cursor (
107
- dal .Select ("number" ),
108
- dal .From (& models.JenkinsBuild {}),
109
- dal .Where (
110
- "full_name = ? AND connection_id = ? AND result != 'SUCCESS' AND result != 'FAILURE'" ,
111
- data .Options .JobFullName , data .Options .ConnectionId ,
112
- ),
113
- )
114
- if err != nil {
115
- return nil , err
116
- }
117
- return helper .NewDalCursorIterator (db , cursor , reflect .TypeOf (SimpleJenkinsApiBuild {}))
118
- },
119
- FinalizableApiCollectorCommonArgs : helper.FinalizableApiCollectorCommonArgs {
120
- UrlTemplate : fmt .Sprintf ("%sjob/%s/{{ .Input.Number }}/api/json?tree=number,url,result,timestamp,id,duration,estimatedDuration,building" ,
121
- data .Options .JobPath , data .Options .JobName ),
122
- ResponseParser : func (res * http.Response ) ([]json.RawMessage , errors.Error ) {
123
- body , err := io .ReadAll (res .Body )
124
- if err != nil {
125
- return nil , errors .Convert (err )
126
- }
127
- res .Body .Close ()
128
- return []json.RawMessage {body }, nil
129
- },
130
- },
131
- },
132
112
})
133
113
134
114
if err != nil {
0 commit comments