Skip to content

Commit c49c7f4

Browse files
author
Nate Smith
authored
Merge pull request cli#3575 from g14a/feature/action-headers
add column headers and age column in listing runs
2 parents 09a92c6 + 9c61424 commit c49c7f4

File tree

2 files changed

+23
-13
lines changed

2 files changed

+23
-13
lines changed

pkg/cmd/run/list/list.go

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package list
33
import (
44
"fmt"
55
"net/http"
6+
"time"
67

78
"github.com/cli/cli/api"
89
"github.com/cli/cli/internal/ghrepo"
@@ -108,6 +109,18 @@ func listRun(opts *ListOptions) error {
108109

109110
out := opts.IO.Out
110111

112+
if !opts.PlainOutput {
113+
tp.AddField("STATUS", nil, nil)
114+
tp.AddField("NAME", nil, nil)
115+
tp.AddField("WORKFLOW", nil, nil)
116+
tp.AddField("BRANCH", nil, nil)
117+
tp.AddField("EVENT", nil, nil)
118+
tp.AddField("ID", nil, nil)
119+
tp.AddField("ELAPSED", nil, nil)
120+
tp.AddField("AGE", nil, nil)
121+
tp.EndRow()
122+
}
123+
111124
for _, run := range runs {
112125
if opts.PlainOutput {
113126
tp.AddField(string(run.Status), nil, nil)
@@ -122,17 +135,14 @@ func listRun(opts *ListOptions) error {
122135
tp.AddField(run.Name, nil, nil)
123136
tp.AddField(run.HeadBranch, nil, cs.Bold)
124137
tp.AddField(string(run.Event), nil, nil)
125-
126-
if opts.PlainOutput {
127-
elapsed := run.UpdatedAt.Sub(run.CreatedAt)
128-
if elapsed < 0 {
129-
elapsed = 0
130-
}
131-
tp.AddField(elapsed.String(), nil, nil)
132-
}
133-
134138
tp.AddField(fmt.Sprintf("%d", run.ID), nil, cs.Cyan)
135139

140+
elapsed := run.UpdatedAt.Sub(run.CreatedAt)
141+
if elapsed < 0 {
142+
elapsed = 0
143+
}
144+
tp.AddField(elapsed.String(), nil, nil)
145+
tp.AddField(utils.FuzzyAgoAbbr(time.Now(), run.CreatedAt), nil, nil)
136146
tp.EndRow()
137147
}
138148

pkg/cmd/run/list/list_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ func TestListRun(t *testing.T) {
108108
WorkflowRuns: shared.TestRuns,
109109
}))
110110
},
111-
wantOut: "X cool commit timed out trunk push 1\n- cool commit in progress trunk push 2\n✓ cool commit successful trunk push 3\n✓ cool commit cancelled trunk push 4\nX cool commit failed trunk push 1234\n✓ cool commit neutral trunk push 6\n✓ cool commit skipped trunk push 7\n- cool commit requested trunk push 8\n- cool commit queued trunk push 9\nX cool commit stale trunk push 10\n\nFor details on a run, try: gh run view <run-id>\n",
111+
wantOut: "STATUS NAME WORKFLOW BRANCH EVENT ID ELAPSED AGE\nX cool commit timed out trunk push 1 4m34s Feb 23, 2021\n- cool commit in progress trunk push 2 4m34s Feb 23, 2021\n cool commit successful trunk push 3 4m34s Feb 23, 2021\n cool commit cancelled trunk push 4 4m34s Feb 23, 2021\nX cool commit failed trunk push 1234 4m34s Feb 23, 2021\n cool commit neutral trunk push 6 4m34s Feb 23, 2021\n cool commit skipped trunk push 7 4m34s Feb 23, 2021\n- cool commit requested trunk push 8 4m34s Feb 23, 2021\n- cool commit queued trunk push 9 4m34s Feb 23, 2021\nX cool commit stale trunk push 10 4m34s Feb 23, 2021\n\nFor details on a run, try: gh run view <run-id>\n",
112112
},
113113
{
114114
name: "blank nontty",
@@ -124,7 +124,7 @@ func TestListRun(t *testing.T) {
124124
WorkflowRuns: shared.TestRuns,
125125
}))
126126
},
127-
wantOut: "completed\ttimed_out\tcool commit\ttimed out\ttrunk\tpush\t4m34s\t1\nin_progress\t\tcool commit\tin progress\ttrunk\tpush\t4m34s\t2\ncompleted\tsuccess\tcool commit\tsuccessful\ttrunk\tpush\t4m34s\t3\ncompleted\tcancelled\tcool commit\tcancelled\ttrunk\tpush\t4m34s\t4\ncompleted\tfailure\tcool commit\tfailed\ttrunk\tpush\t4m34s\t1234\ncompleted\tneutral\tcool commit\tneutral\ttrunk\tpush\t4m34s\t6\ncompleted\tskipped\tcool commit\tskipped\ttrunk\tpush\t4m34s\t7\nrequested\t\tcool commit\trequested\ttrunk\tpush\t4m34s\t8\nqueued\t\tcool commit\tqueued\ttrunk\tpush\t4m34s\t9\ncompleted\tstale\tcool commit\tstale\ttrunk\tpush\t4m34s\t10\n",
127+
wantOut: "completed\ttimed_out\tcool commit\ttimed out\ttrunk\tpush\t1\t4m34s\tFeb 23, 2021\nin_progress\t\tcool commit\tin progress\ttrunk\tpush\t2\t4m34s\tFeb 23, 2021\ncompleted\tsuccess\tcool commit\tsuccessful\ttrunk\tpush\t3\t4m34s\tFeb 23, 2021\ncompleted\tcancelled\tcool commit\tcancelled\ttrunk\tpush\t4\t4m34s\tFeb 23, 2021\ncompleted\tfailure\tcool commit\tfailed\ttrunk\tpush\t1234\t4m34s\tFeb 23, 2021\ncompleted\tneutral\tcool commit\tneutral\ttrunk\tpush\t6\t4m34s\tFeb 23, 2021\ncompleted\tskipped\tcool commit\tskipped\ttrunk\tpush\t7\t4m34s\tFeb 23, 2021\nrequested\t\tcool commit\trequested\ttrunk\tpush\t8\t4m34s\tFeb 23, 2021\nqueued\t\tcool commit\tqueued\ttrunk\tpush\t9\t4m34s\tFeb 23, 2021\ncompleted\tstale\tcool commit\tstale\ttrunk\tpush\t10\t4m34s\tFeb 23, 2021\n",
128128
},
129129
{
130130
name: "pagination",
@@ -196,7 +196,7 @@ func TestListRun(t *testing.T) {
196196
WorkflowRuns: shared.WorkflowRuns,
197197
}))
198198
},
199-
wantOut: "- cool commit in progress trunk push 2\n✓ cool commit successful trunk push 3\nX cool commit failed trunk push 1234\n\nFor details on a run, try: gh run view <run-id>\n",
199+
wantOut: "STATUS NAME WORKFLOW BRANCH EVENT ID ELAPSED AGE\n- cool commit in progress trunk push 2 4m34s Feb 23, 2021\n cool commit successful trunk push 3 4m34s Feb 23, 2021\nX cool commit failed trunk push 1234 4m34s Feb 23, 2021\n\nFor details on a run, try: gh run view <run-id>\n",
200200
},
201201
}
202202

@@ -226,4 +226,4 @@ func TestListRun(t *testing.T) {
226226
}
227227
}
228228

229-
const longRunOutput = "- cool commit 0 trunk push 0\n- cool commit 1 trunk push 1\n- cool commit 2 trunk push 2\n- cool commit 3 trunk push 3\n- cool commit 4 trunk push 4\n- cool commit 5 trunk push 5\n- cool commit 6 trunk push 6\n- cool commit 7 trunk push 7\n- cool commit 8 trunk push 8\n- cool commit 9 trunk push 9\n- cool commit 10 trunk push 10\n- cool commit 11 trunk push 11\n- cool commit 12 trunk push 12\n- cool commit 13 trunk push 13\n- cool commit 14 trunk push 14\n- cool commit 15 trunk push 15\n- cool commit 16 trunk push 16\n- cool commit 17 trunk push 17\n- cool commit 18 trunk push 18\n- cool commit 19 trunk push 19\n- cool commit 20 trunk push 20\n- cool commit 21 trunk push 21\n- cool commit 22 trunk push 22\n- cool commit 23 trunk push 23\n- cool commit 24 trunk push 24\n- cool commit 25 trunk push 25\n- cool commit 26 trunk push 26\n- cool commit 27 trunk push 27\n- cool commit 28 trunk push 28\n- cool commit 29 trunk push 29\n- cool commit 30 trunk push 30\n- cool commit 31 trunk push 31\n- cool commit 32 trunk push 32\n- cool commit 33 trunk push 33\n- cool commit 34 trunk push 34\n- cool commit 35 trunk push 35\n- cool commit 36 trunk push 36\n- cool commit 37 trunk push 37\n- cool commit 38 trunk push 38\n- cool commit 39 trunk push 39\n- cool commit 40 trunk push 40\n- cool commit 41 trunk push 41\n- cool commit 42 trunk push 42\n- cool commit 43 trunk push 43\n- cool commit 44 trunk push 44\n- cool commit 45 trunk push 45\n- cool commit 46 trunk push 46\n- cool commit 47 trunk push 47\n- cool commit 48 trunk push 48\n- cool commit 49 trunk push 49\n- cool commit 50 trunk push 50\n- cool commit 51 trunk push 51\n- cool commit 52 trunk push 52\n- cool commit 53 trunk push 53\n- cool commit 54 trunk push 54\n- cool commit 55 trunk push 55\n- cool commit 56 trunk push 56\n- cool commit 57 trunk push 57\n- cool commit 58 trunk push 58\n- cool commit 59 trunk push 59\n- cool commit 60 trunk push 60\n- cool commit 61 trunk push 61\n- cool commit 62 trunk push 62\n- cool commit 63 trunk push 63\n- cool commit 64 trunk push 64\n- cool commit 65 trunk push 65\n- cool commit 66 trunk push 66\n- cool commit 67 trunk push 67\n- cool commit 68 trunk push 68\n- cool commit 69 trunk push 69\n- cool commit 70 trunk push 70\n- cool commit 71 trunk push 71\n- cool commit 72 trunk push 72\n- cool commit 73 trunk push 73\n- cool commit 74 trunk push 74\n- cool commit 75 trunk push 75\n- cool commit 76 trunk push 76\n- cool commit 77 trunk push 77\n- cool commit 78 trunk push 78\n- cool commit 79 trunk push 79\n- cool commit 80 trunk push 80\n- cool commit 81 trunk push 81\n- cool commit 82 trunk push 82\n- cool commit 83 trunk push 83\n- cool commit 84 trunk push 84\n- cool commit 85 trunk push 85\n- cool commit 86 trunk push 86\n- cool commit 87 trunk push 87\n- cool commit 88 trunk push 88\n- cool commit 89 trunk push 89\n- cool commit 90 trunk push 90\n- cool commit 91 trunk push 91\n- cool commit 92 trunk push 92\n- cool commit 93 trunk push 93\n- cool commit 94 trunk push 94\n- cool commit 95 trunk push 95\n- cool commit 96 trunk push 96\n- cool commit 97 trunk push 97\n- cool commit 98 trunk push 98\n- cool commit 99 trunk push 99\n- cool commit 100 trunk push 100\n\nFor details on a run, try: gh run view <run-id>\n"
229+
const longRunOutput = "STATUS NAME WORKFLOW BRANCH EVENT ID ELAPSED AGE\n- cool commit 0 trunk push 0 4m34s Feb 23, 2021\n- cool commit 1 trunk push 1 4m34s Feb 23, 2021\n- cool commit 2 trunk push 2 4m34s Feb 23, 2021\n- cool commit 3 trunk push 3 4m34s Feb 23, 2021\n- cool commit 4 trunk push 4 4m34s Feb 23, 2021\n- cool commit 5 trunk push 5 4m34s Feb 23, 2021\n- cool commit 6 trunk push 6 4m34s Feb 23, 2021\n- cool commit 7 trunk push 7 4m34s Feb 23, 2021\n- cool commit 8 trunk push 8 4m34s Feb 23, 2021\n- cool commit 9 trunk push 9 4m34s Feb 23, 2021\n- cool commit 10 trunk push 10 4m34s Feb 23, 2021\n- cool commit 11 trunk push 11 4m34s Feb 23, 2021\n- cool commit 12 trunk push 12 4m34s Feb 23, 2021\n- cool commit 13 trunk push 13 4m34s Feb 23, 2021\n- cool commit 14 trunk push 14 4m34s Feb 23, 2021\n- cool commit 15 trunk push 15 4m34s Feb 23, 2021\n- cool commit 16 trunk push 16 4m34s Feb 23, 2021\n- cool commit 17 trunk push 17 4m34s Feb 23, 2021\n- cool commit 18 trunk push 18 4m34s Feb 23, 2021\n- cool commit 19 trunk push 19 4m34s Feb 23, 2021\n- cool commit 20 trunk push 20 4m34s Feb 23, 2021\n- cool commit 21 trunk push 21 4m34s Feb 23, 2021\n- cool commit 22 trunk push 22 4m34s Feb 23, 2021\n- cool commit 23 trunk push 23 4m34s Feb 23, 2021\n- cool commit 24 trunk push 24 4m34s Feb 23, 2021\n- cool commit 25 trunk push 25 4m34s Feb 23, 2021\n- cool commit 26 trunk push 26 4m34s Feb 23, 2021\n- cool commit 27 trunk push 27 4m34s Feb 23, 2021\n- cool commit 28 trunk push 28 4m34s Feb 23, 2021\n- cool commit 29 trunk push 29 4m34s Feb 23, 2021\n- cool commit 30 trunk push 30 4m34s Feb 23, 2021\n- cool commit 31 trunk push 31 4m34s Feb 23, 2021\n- cool commit 32 trunk push 32 4m34s Feb 23, 2021\n- cool commit 33 trunk push 33 4m34s Feb 23, 2021\n- cool commit 34 trunk push 34 4m34s Feb 23, 2021\n- cool commit 35 trunk push 35 4m34s Feb 23, 2021\n- cool commit 36 trunk push 36 4m34s Feb 23, 2021\n- cool commit 37 trunk push 37 4m34s Feb 23, 2021\n- cool commit 38 trunk push 38 4m34s Feb 23, 2021\n- cool commit 39 trunk push 39 4m34s Feb 23, 2021\n- cool commit 40 trunk push 40 4m34s Feb 23, 2021\n- cool commit 41 trunk push 41 4m34s Feb 23, 2021\n- cool commit 42 trunk push 42 4m34s Feb 23, 2021\n- cool commit 43 trunk push 43 4m34s Feb 23, 2021\n- cool commit 44 trunk push 44 4m34s Feb 23, 2021\n- cool commit 45 trunk push 45 4m34s Feb 23, 2021\n- cool commit 46 trunk push 46 4m34s Feb 23, 2021\n- cool commit 47 trunk push 47 4m34s Feb 23, 2021\n- cool commit 48 trunk push 48 4m34s Feb 23, 2021\n- cool commit 49 trunk push 49 4m34s Feb 23, 2021\n- cool commit 50 trunk push 50 4m34s Feb 23, 2021\n- cool commit 51 trunk push 51 4m34s Feb 23, 2021\n- cool commit 52 trunk push 52 4m34s Feb 23, 2021\n- cool commit 53 trunk push 53 4m34s Feb 23, 2021\n- cool commit 54 trunk push 54 4m34s Feb 23, 2021\n- cool commit 55 trunk push 55 4m34s Feb 23, 2021\n- cool commit 56 trunk push 56 4m34s Feb 23, 2021\n- cool commit 57 trunk push 57 4m34s Feb 23, 2021\n- cool commit 58 trunk push 58 4m34s Feb 23, 2021\n- cool commit 59 trunk push 59 4m34s Feb 23, 2021\n- cool commit 60 trunk push 60 4m34s Feb 23, 2021\n- cool commit 61 trunk push 61 4m34s Feb 23, 2021\n- cool commit 62 trunk push 62 4m34s Feb 23, 2021\n- cool commit 63 trunk push 63 4m34s Feb 23, 2021\n- cool commit 64 trunk push 64 4m34s Feb 23, 2021\n- cool commit 65 trunk push 65 4m34s Feb 23, 2021\n- cool commit 66 trunk push 66 4m34s Feb 23, 2021\n- cool commit 67 trunk push 67 4m34s Feb 23, 2021\n- cool commit 68 trunk push 68 4m34s Feb 23, 2021\n- cool commit 69 trunk push 69 4m34s Feb 23, 2021\n- cool commit 70 trunk push 70 4m34s Feb 23, 2021\n- cool commit 71 trunk push 71 4m34s Feb 23, 2021\n- cool commit 72 trunk push 72 4m34s Feb 23, 2021\n- cool commit 73 trunk push 73 4m34s Feb 23, 2021\n- cool commit 74 trunk push 74 4m34s Feb 23, 2021\n- cool commit 75 trunk push 75 4m34s Feb 23, 2021\n- cool commit 76 trunk push 76 4m34s Feb 23, 2021\n- cool commit 77 trunk push 77 4m34s Feb 23, 2021\n- cool commit 78 trunk push 78 4m34s Feb 23, 2021\n- cool commit 79 trunk push 79 4m34s Feb 23, 2021\n- cool commit 80 trunk push 80 4m34s Feb 23, 2021\n- cool commit 81 trunk push 81 4m34s Feb 23, 2021\n- cool commit 82 trunk push 82 4m34s Feb 23, 2021\n- cool commit 83 trunk push 83 4m34s Feb 23, 2021\n- cool commit 84 trunk push 84 4m34s Feb 23, 2021\n- cool commit 85 trunk push 85 4m34s Feb 23, 2021\n- cool commit 86 trunk push 86 4m34s Feb 23, 2021\n- cool commit 87 trunk push 87 4m34s Feb 23, 2021\n- cool commit 88 trunk push 88 4m34s Feb 23, 2021\n- cool commit 89 trunk push 89 4m34s Feb 23, 2021\n- cool commit 90 trunk push 90 4m34s Feb 23, 2021\n- cool commit 91 trunk push 91 4m34s Feb 23, 2021\n- cool commit 92 trunk push 92 4m34s Feb 23, 2021\n- cool commit 93 trunk push 93 4m34s Feb 23, 2021\n- cool commit 94 trunk push 94 4m34s Feb 23, 2021\n- cool commit 95 trunk push 95 4m34s Feb 23, 2021\n- cool commit 96 trunk push 96 4m34s Feb 23, 2021\n- cool commit 97 trunk push 97 4m34s Feb 23, 2021\n- cool commit 98 trunk push 98 4m34s Feb 23, 2021\n- cool commit 99 trunk push 99 4m34s Feb 23, 2021\n- cool commit 100 trunk push 100 4m34s Feb 23, 2021\n\nFor details on a run, try: gh run view <run-id>\n"

0 commit comments

Comments
 (0)