Merge pull request #185 from camandel/add_run_list_info
cmd: add details to run list
This commit is contained in:
commit
2232e2895e
|
@ -18,6 +18,7 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"path"
|
"path"
|
||||||
|
"sort"
|
||||||
|
|
||||||
gwapitypes "agola.io/agola/services/gateway/api/types"
|
gwapitypes "agola.io/agola/services/gateway/api/types"
|
||||||
gwclient "agola.io/agola/services/gateway/client"
|
gwclient "agola.io/agola/services/gateway/client"
|
||||||
|
@ -43,6 +44,18 @@ type runListOptions struct {
|
||||||
start string
|
start string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type runDetails struct {
|
||||||
|
runResponse *gwapitypes.RunResponse
|
||||||
|
tasks []*taskDetails
|
||||||
|
}
|
||||||
|
|
||||||
|
type taskDetails struct {
|
||||||
|
name string
|
||||||
|
level int
|
||||||
|
runTaskResponse *gwapitypes.RunTaskResponse
|
||||||
|
retrieveError error
|
||||||
|
}
|
||||||
|
|
||||||
var runListOpts runListOptions
|
var runListOpts runListOptions
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
@ -60,11 +73,22 @@ func init() {
|
||||||
cmdRun.AddCommand(cmdRunList)
|
cmdRun.AddCommand(cmdRunList)
|
||||||
}
|
}
|
||||||
|
|
||||||
func printRuns(runs []*gwapitypes.RunResponse) {
|
func printRuns(runs []*runDetails) {
|
||||||
for _, run := range runs {
|
for _, run := range runs {
|
||||||
fmt.Printf("%s: Phase: %s, Result: %s\n", run.ID, run.Phase, run.Result)
|
fmt.Printf("%s: Phase: %s, Result: %s\n", run.runResponse.ID, run.runResponse.Phase, run.runResponse.Result)
|
||||||
for _, task := range run.Tasks {
|
for _, task := range run.tasks {
|
||||||
fmt.Printf("\tTaskName: %s, Status: %s\n", task.Name, task.Status)
|
fmt.Printf("\tTaskName: %s, Status: %s\n", task.runTaskResponse.Name, task.runTaskResponse.Status)
|
||||||
|
if task.retrieveError != nil {
|
||||||
|
fmt.Printf("\t\tfailed to retrieve task information: %v\n", task.retrieveError)
|
||||||
|
} else {
|
||||||
|
for n, step := range task.runTaskResponse.Steps {
|
||||||
|
if step.Phase.IsFinished() && step.Type == "run" {
|
||||||
|
fmt.Printf("\t\tStep: %d, Name: %s, Type: %s, Phase: %s, ExitStatus: %d\n", n, step.Name, step.Type, step.Phase, *step.ExitStatus)
|
||||||
|
} else {
|
||||||
|
fmt.Printf("\t\tStep: %d, Name: %s, Type: %s, Phase: %s\n", n, step.Name, step.Type, step.Phase)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -82,13 +106,36 @@ func runList(cmd *cobra.Command, args []string) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
runs := make([]*gwapitypes.RunResponse, len(runsResp))
|
runs := make([]*runDetails, len(runsResp))
|
||||||
for i, runResponse := range runsResp {
|
for i, runResponse := range runsResp {
|
||||||
run, _, err := gwclient.GetRun(context.TODO(), runResponse.ID)
|
run, _, err := gwclient.GetRun(context.TODO(), runResponse.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
runs[i] = run
|
|
||||||
|
tasks := []*taskDetails{}
|
||||||
|
for _, task := range run.Tasks {
|
||||||
|
runTaskResponse, _, err := gwclient.GetRunTask(context.TODO(), run.ID, task.ID)
|
||||||
|
t := &taskDetails{
|
||||||
|
name: task.Name,
|
||||||
|
level: task.Level,
|
||||||
|
runTaskResponse: runTaskResponse,
|
||||||
|
retrieveError: err,
|
||||||
|
}
|
||||||
|
tasks = append(tasks, t)
|
||||||
|
}
|
||||||
|
|
||||||
|
sort.Slice(tasks, func(i, j int) bool {
|
||||||
|
if tasks[i].level != tasks[j].level {
|
||||||
|
return tasks[i].level < tasks[j].level
|
||||||
|
}
|
||||||
|
return tasks[i].name < tasks[j].name
|
||||||
|
})
|
||||||
|
|
||||||
|
runs[i] = &runDetails{
|
||||||
|
runResponse: run,
|
||||||
|
tasks: tasks,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
printRuns(runs)
|
printRuns(runs)
|
||||||
|
|
Loading…
Reference in New Issue