@@ -48,8 +48,23 @@ type tokenResponse struct {
48
48
JWT string `json:"token"`
49
49
}
50
50
51
+ type pipelineResponse struct {
52
+ Name string `json:"name"`
53
+ SCMRepo struct {
54
+ Name string `json:"name"`
55
+ Branch string `json:"branch"`
56
+ URL string `json:"url"`
57
+ } `json:"scmRepo"`
58
+ }
59
+
51
60
type buildResponse struct {
52
61
EventID int `json:"eventId"`
62
+ JobID int `json:"jobId"`
63
+ }
64
+
65
+ type jobResponse struct {
66
+ PipelineID int `json:"pipelineId"`
67
+ Name string `json:"name"`
53
68
}
54
69
55
70
type eventResponse struct {
@@ -308,6 +323,7 @@ func (sd *SDAPI) ValidatorTemplate(yaml string, retried bool) error {
308
323
func (sd * SDAPI ) GetPipelinePageFromBuildID (buildID string ) error {
309
324
buildIDList := strings .Split (strings .Replace (strings .TrimSpace (buildID ), "\n " , " " , - 1 ), " " )
310
325
buildIDLength := len (buildIDList )
326
+ basePipelineURL := strings .Replace (sd .sdctx .APIURL , "api-cd" , "cd" , 1 ) + "/pipelines/"
311
327
312
328
var wg sync.WaitGroup
313
329
wg .Add (buildIDLength )
@@ -318,17 +334,22 @@ func (sd *SDAPI) GetPipelinePageFromBuildID(buildID string) error {
318
334
go func (b string ) {
319
335
defer wg .Done ()
320
336
321
- br , err := sd .getBuilds (b )
337
+ br , err := sd .getBuild (b )
338
+ if err != nil {
339
+ exit <- err
340
+ return
341
+ }
342
+ jr , err := sd .getJob (br .JobID )
322
343
if err != nil {
323
344
exit <- err
324
345
return
325
346
}
326
- er , err := sd .getEvents ( br . EventID )
347
+ pr , err := sd .getPipeline ( jr . PipelineID )
327
348
if err != nil {
328
349
exit <- err
329
350
return
330
351
}
331
- println ( strings . Replace ( sd . sdctx . APIURL , "api-cd" , "cd" , 1 ) + "/pipelines/ " + strconv . Itoa ( er . PipelineID ) + "/builds/ " + b )
352
+ fmt . Println ( basePipelineURL + strconv . Itoa ( jr . PipelineID ) + "/builds/" + b + "\t " + pr . SCMRepo . Name + "( " + jr . Name + ")" )
332
353
}(b )
333
354
}
334
355
@@ -342,7 +363,21 @@ func (sd *SDAPI) GetPipelinePageFromBuildID(buildID string) error {
342
363
}
343
364
}
344
365
345
- func (sd * SDAPI ) getBuilds (buildID string ) (* buildResponse , error ) {
366
+ func (sd * SDAPI ) getPipeline (pipelineID int ) (* pipelineResponse , error ) {
367
+ path := "/v4/pipelines/" + strconv .Itoa (pipelineID ) + "?token=" + sd .sdctx .SDJWT
368
+ res , err := sd .request (context .TODO (), http .MethodGet , path , nil )
369
+ if err != nil {
370
+ return nil , err
371
+ }
372
+ defer res .Body .Close ()
373
+
374
+ pipelineResponse := new (pipelineResponse )
375
+ err = json .NewDecoder (res .Body ).Decode (pipelineResponse )
376
+
377
+ return pipelineResponse , err
378
+ }
379
+
380
+ func (sd * SDAPI ) getBuild (buildID string ) (* buildResponse , error ) {
346
381
path := "/v4/builds/" + buildID + "?token=" + sd .sdctx .SDJWT
347
382
res , err := sd .request (context .TODO (), http .MethodGet , path , nil )
348
383
if err != nil {
@@ -356,7 +391,21 @@ func (sd *SDAPI) getBuilds(buildID string) (*buildResponse, error) {
356
391
return buildResponse , err
357
392
}
358
393
359
- func (sd * SDAPI ) getEvents (eventID int ) (* eventResponse , error ) {
394
+ func (sd * SDAPI ) getJob (jobID int ) (* jobResponse , error ) {
395
+ path := "/v4/jobs/" + strconv .Itoa (jobID ) + "?token=" + sd .sdctx .SDJWT
396
+ res , err := sd .request (context .TODO (), http .MethodGet , path , nil )
397
+ if err != nil {
398
+ return nil , err
399
+ }
400
+ defer res .Body .Close ()
401
+
402
+ jobResponse := new (jobResponse )
403
+ err = json .NewDecoder (res .Body ).Decode (jobResponse )
404
+
405
+ return jobResponse , err
406
+ }
407
+
408
+ func (sd * SDAPI ) getEvent (eventID int ) (* eventResponse , error ) {
360
409
path := "/v4/events/" + strconv .Itoa (eventID ) + "?token=" + sd .sdctx .SDJWT
361
410
res , err := sd .request (context .TODO (), http .MethodGet , path , nil )
362
411
if err != nil {
0 commit comments