|
| 1 | +package ci |
| 2 | + |
| 3 | +import ( |
| 4 | + "fmt" |
| 5 | + |
| 6 | + "github.com/depot/cli/pkg/api" |
| 7 | + "github.com/depot/cli/pkg/helpers" |
| 8 | + "github.com/spf13/cobra" |
| 9 | +) |
| 10 | + |
| 11 | +func NewCmdStatus() *cobra.Command { |
| 12 | + var token string |
| 13 | + |
| 14 | + cmd := &cobra.Command{ |
| 15 | + Use: "status <run-id>", |
| 16 | + Short: "Look up the status of a CI run [beta]", |
| 17 | + Long: "Look up the status of a CI run, including its workflows, jobs, and attempts.\n\nThis command is in beta and subject to change.", |
| 18 | + RunE: func(cmd *cobra.Command, args []string) error { |
| 19 | + if len(args) == 0 { |
| 20 | + return cmd.Help() |
| 21 | + } |
| 22 | + |
| 23 | + ctx := cmd.Context() |
| 24 | + runID := args[0] |
| 25 | + |
| 26 | + tokenVal, err := helpers.ResolveOrgAuth(ctx, token) |
| 27 | + if err != nil { |
| 28 | + return err |
| 29 | + } |
| 30 | + if tokenVal == "" { |
| 31 | + return fmt.Errorf("missing API token, please run `depot login`") |
| 32 | + } |
| 33 | + |
| 34 | + resp, err := api.CIGetRunStatus(ctx, tokenVal, runID) |
| 35 | + if err != nil { |
| 36 | + return fmt.Errorf("failed to get run status: %w", err) |
| 37 | + } |
| 38 | + |
| 39 | + fmt.Printf("Org: %s\n", resp.OrgId) |
| 40 | + fmt.Printf("Run: %s (%s)\n", resp.RunId, resp.Status) |
| 41 | + |
| 42 | + for _, workflow := range resp.Workflows { |
| 43 | + fmt.Println() |
| 44 | + fmt.Printf(" Workflow: %s (%s)\n", workflow.WorkflowId, workflow.Status) |
| 45 | + if workflow.WorkflowPath != "" { |
| 46 | + fmt.Printf(" Path: %s\n", workflow.WorkflowPath) |
| 47 | + } |
| 48 | + |
| 49 | + for _, job := range workflow.Jobs { |
| 50 | + fmt.Printf(" Job: %s [%s] (%s)\n", job.JobId, job.JobKey, job.Status) |
| 51 | + |
| 52 | + for _, attempt := range job.Attempts { |
| 53 | + fmt.Printf(" Attempt: %s #%d (%s)\n", attempt.AttemptId, attempt.Attempt, attempt.Status) |
| 54 | + } |
| 55 | + } |
| 56 | + } |
| 57 | + |
| 58 | + return nil |
| 59 | + }, |
| 60 | + } |
| 61 | + |
| 62 | + cmd.Flags().StringVar(&token, "token", "", "Depot API token") |
| 63 | + |
| 64 | + return cmd |
| 65 | +} |
0 commit comments