Skip to content
This repository has been archived by the owner on Nov 22, 2022. It is now read-only.

fix(ci/status): adding list of external jobs #752

Merged
merged 1 commit into from
Jun 7, 2021
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ _test

# VsCode
.vscode/
.devcontainer

# Dist binaries created at build with make rt
/dist
Expand Down
19 changes: 19 additions & 0 deletions api/commit.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package api

import "github.com/xanzy/go-gitlab"

var GetCommitStatuses = func(client *gitlab.Client, pid interface{}, sha string) ([]*gitlab.CommitStatus, error) {
if client == nil {
client = apiClient.Lab()
}

opt := &gitlab.GetCommitStatusesOptions{
All: gitlab.Bool(true),
}

statuses, _, err := client.Commits.GetCommitStatuses(pid, sha, opt, nil)
if err != nil {
return nil, err
}
return statuses, nil
}
1 change: 1 addition & 0 deletions commands/ci/ciutils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ func DisplayMultiplePipelines(c *iostreams.ColorPalette, p []*gitlab.PipelineInf
if pipeline.CreatedAt != nil {
duration = c.Magenta("(" + utils.TimeToPrettyTimeAgo(*pipeline.CreatedAt) + ")")
}

var pipeState string
if pipeline.Status == "success" {
pipeState = c.Green(fmt.Sprintf("(%s) • #%d", pipeline.Status, pipeline.ID))
Expand Down
27 changes: 26 additions & 1 deletion commands/ci/trace/trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,33 @@ func TraceRun(opts *TraceOpts) error {
re := regexp.MustCompile(`(?s)\((.*)\)`)
m := re.FindAllStringSubmatch(selectedJob, -1)
opts.JobID = utils.StringToInt(m[0][1])
} else {
} else if len(jobs) > 0 {
opts.JobID = jobs[0].ID
} else {
// use commit statuses to show external jobs
cs, err := api.GetCommitStatuses(apiClient, repo.FullName(), pipeline.SHA)
if err != nil {
return nil
}

c := opts.IO.Color()

fmt.Fprint(opts.IO.StdOut, "Getting external jobs...")
for _, status := range cs {
var s string

switch status.Status {
case "success":
s = c.Green(status.Status)
case "error":
s = c.Red(status.Status)
default:
s = c.Gray(status.Status)
}
fmt.Fprintf(opts.IO.StdOut, "(%s) %s\nURL: %s\n\n", s, c.Bold(status.Name), c.Gray(status.TargetURL))
}

return nil
}
}

Expand Down