4
4
"context"
5
5
6
6
gitlab "github.com/xanzy/go-gitlab"
7
- "google.golang.org/protobuf/types/known/timestamppb"
8
7
8
+ "github.com/cluttrdev/gitlab-exporter/internal/types"
9
9
"github.com/cluttrdev/gitlab-exporter/protobuf/typespb"
10
10
)
11
11
@@ -41,7 +41,7 @@ func (c *Client) ListPipelineJobs(ctx context.Context, projectID int64, pipeline
41
41
42
42
for _ , j := range jobs {
43
43
ch <- ListPipelineJobsResult {
44
- Job : convertJob (j ),
44
+ Job : types . ConvertJob (j ),
45
45
}
46
46
}
47
47
@@ -87,7 +87,7 @@ func (c *Client) ListPipelineBridges(ctx context.Context, projectID int64, pipel
87
87
88
88
for _ , b := range bridges {
89
89
ch <- ListPipelineBridgesResult {
90
- Bridge : convertBridge (b ),
90
+ Bridge : types . ConvertBridge (b ),
91
91
}
92
92
}
93
93
@@ -101,131 +101,3 @@ func (c *Client) ListPipelineBridges(ctx context.Context, projectID int64, pipel
101
101
102
102
return ch
103
103
}
104
-
105
- func convertJob (job * gitlab.Job ) * typespb.Job {
106
- artifacts := make ([]* typespb.JobArtifacts , 0 , len (job .Artifacts ))
107
- for _ , a := range job .Artifacts {
108
- artifacts = append (artifacts , & typespb.JobArtifacts {
109
- Filename : a .Filename ,
110
- FileType : a .FileType ,
111
- FileFormat : a .FileFormat ,
112
- Size : int64 (a .Size ),
113
- })
114
- }
115
-
116
- return & typespb.Job {
117
- Id : int64 (job .ID ),
118
- Name : job .Name ,
119
- Pipeline : & typespb.PipelineReference {
120
- Id : int64 (job .Pipeline .ID ),
121
- ProjectId : int64 (job .Pipeline .ProjectID ),
122
- Ref : job .Pipeline .Ref ,
123
- Sha : job .Pipeline .Sha ,
124
- Status : job .Pipeline .Status ,
125
- },
126
- Ref : job .Ref ,
127
- CreatedAt : convertTime (job .CreatedAt ),
128
- StartedAt : convertTime (job .StartedAt ),
129
- FinishedAt : convertTime (job .FinishedAt ),
130
- ErasedAt : convertTime (job .ErasedAt ),
131
- Duration : convertDuration (job .Duration ),
132
- QueuedDuration : convertDuration (job .QueuedDuration ),
133
- Coverage : job .Coverage ,
134
- Stage : job .Stage ,
135
- Status : job .Status ,
136
- AllowFailure : job .AllowFailure ,
137
- FailureReason : job .FailureReason ,
138
- Tag : job .Tag ,
139
- WebUrl : job .WebURL ,
140
- TagList : job .TagList ,
141
-
142
- Commit : convertCommit (job .Commit ),
143
- Project : convertProject (job .Project ),
144
- User : convertUser (job .User ),
145
-
146
- Runner : & typespb.JobRunner {
147
- Id : int64 (job .Runner .ID ),
148
- Name : job .Runner .Name ,
149
- Description : job .Runner .Description ,
150
- Active : job .Runner .Active ,
151
- IsShared : job .Runner .IsShared ,
152
- },
153
-
154
- Artifacts : artifacts ,
155
- ArtifactsFile : & typespb.JobArtifactsFile {
156
- Filename : job .ArtifactsFile .Filename ,
157
- Size : int64 (job .ArtifactsFile .Size ),
158
- },
159
- ArtifactsExpireAt : convertTime (job .ArtifactsExpireAt ),
160
- }
161
- }
162
-
163
- func convertCommit (commit * gitlab.Commit ) * typespb.Commit {
164
- var status string
165
- if commit .Status != nil {
166
- status = string (* commit .Status )
167
- }
168
- return & typespb.Commit {
169
- Id : commit .ID ,
170
- ShortId : commit .ShortID ,
171
- ParentIds : commit .ParentIDs ,
172
- ProjectId : int64 (commit .ProjectID ),
173
- AuthorName : commit .AuthorName ,
174
- AuthorEmail : commit .AuthorEmail ,
175
- AuthoredDate : convertTime (commit .AuthoredDate ),
176
- CommitterName : commit .CommitterName ,
177
- CommitterEmail : commit .CommitterEmail ,
178
- CommittedDate : convertTime (commit .CommittedDate ),
179
- CreatedAt : convertTime (commit .CreatedAt ),
180
- Title : commit .Title ,
181
- Message : commit .Message ,
182
- Trailers : commit .Trailers ,
183
- Stats : convertCommitStats (commit .Stats ),
184
- Status : status ,
185
- WebUrl : commit .WebURL ,
186
- }
187
- }
188
-
189
- func convertCommitStats (stats * gitlab.CommitStats ) * typespb.CommitStats {
190
- if stats == nil {
191
- return nil
192
- }
193
- return & typespb.CommitStats {
194
- Additions : int64 (stats .Additions ),
195
- Deletions : int64 (stats .Deletions ),
196
- Total : int64 (stats .Total ),
197
- }
198
- }
199
-
200
- func convertBridge (bridge * gitlab.Bridge ) * typespb.Bridge {
201
- // account for downstream pipeline creation failures
202
- downstreamPipeline := & typespb.PipelineInfo {
203
- CreatedAt : & timestamppb.Timestamp {},
204
- UpdatedAt : & timestamppb.Timestamp {},
205
- }
206
- if bridge .DownstreamPipeline != nil {
207
- downstreamPipeline = convertPipelineInfo (bridge .DownstreamPipeline )
208
- }
209
- return & typespb.Bridge {
210
- // Commit: ConvertCommit(bridge.Commit),
211
- Id : int64 (bridge .ID ),
212
- Name : bridge .Name ,
213
- Pipeline : convertPipelineInfo (& bridge .Pipeline ),
214
- Ref : bridge .Ref ,
215
- CreatedAt : convertTime (bridge .CreatedAt ),
216
- StartedAt : convertTime (bridge .StartedAt ),
217
- FinishedAt : convertTime (bridge .FinishedAt ),
218
- ErasedAt : convertTime (bridge .ErasedAt ),
219
- Duration : convertDuration (bridge .Duration ),
220
- QueuedDuration : convertDuration (bridge .QueuedDuration ),
221
- Coverage : bridge .Coverage ,
222
- Stage : bridge .Stage ,
223
- Status : bridge .Status ,
224
- AllowFailure : bridge .AllowFailure ,
225
- FailureReason : bridge .FailureReason ,
226
- Tag : bridge .Tag ,
227
- WebUrl : bridge .WebURL ,
228
- // User: ConvertUser(bridge.User),
229
- DownstreamPipeline : downstreamPipeline ,
230
- }
231
- }
0 commit comments