@@ -36,6 +36,8 @@ func makeJobs() *cobra.Command {
36
36
37
37
cmd .Flags ().BoolP ("json" , "j" , false , "Request output in JSON format" )
38
38
39
+ cmd .Flags ().BoolP ("urls" , "u" , false , "Include the URLs to the job in the output" )
40
+
39
41
return cmd
40
42
}
41
43
@@ -51,6 +53,11 @@ func runJobsE(cmd *cobra.Command, args []string) error {
51
53
return err
52
54
}
53
55
56
+ includeURL , err := cmd .Flags ().GetBool ("urls" )
57
+ if err != nil {
58
+ return err
59
+ }
60
+
54
61
staff , err := cmd .Flags ().GetBool ("staff" )
55
62
if err != nil {
56
63
return err
@@ -75,7 +82,6 @@ func runJobsE(cmd *cobra.Command, args []string) error {
75
82
acceptJSON := true
76
83
77
84
res , status , err := c .ListJobs (pat , owner , staff , acceptJSON )
78
-
79
85
if err != nil {
80
86
return err
81
87
}
@@ -100,28 +106,53 @@ func runJobsE(cmd *cobra.Command, args []string) error {
100
106
if err := json .Unmarshal ([]byte (res ), & statuses ); err != nil {
101
107
return err
102
108
}
103
- printEvents (os .Stdout , statuses , verbose )
109
+ printEvents (os .Stdout , statuses , verbose , includeURL )
104
110
}
105
111
106
112
return nil
107
113
108
114
}
109
115
110
- func printEvents (w io.Writer , statuses []JobStatus , verbose bool ) {
116
+ func printEvents (w io.Writer , statuses []JobStatus , verbose , includeURL bool ) {
111
117
tabwriter := tabwriter .NewWriter (w , 0 , 0 , 1 , ' ' , tabwriter .TabIndent )
112
118
if verbose {
113
- fmt .Fprintf (tabwriter , "JOB ID\t OWNER\t REPO\t JOB\t RUNNER\t SERVER\t STATUS\t STARTED\t AGE\t ETA\t LABELS\t URL\n " )
119
+
120
+ st := "JOB ID\t OWNER\t REPO\t JOB\t RUNNER\t SERVER\t STATUS\t STARTED\t AGE\t ETA\t LABELS"
121
+ if includeURL {
122
+ st = st + "\t URL"
123
+ }
124
+
125
+ fmt .Fprintln (tabwriter , st )
114
126
} else {
115
- fmt .Fprintf (tabwriter , "OWNER\t REPO\t JOB\t STATUS\t AGE\t ETA\t URL\n " )
127
+ st := "OWNER\t REPO\t JOB\t STATUS\t AGE\t ETA"
128
+ if includeURL {
129
+ st = st + "\t URL"
130
+ }
131
+
132
+ fmt .Fprintln (tabwriter , st )
116
133
}
117
134
135
+ var (
136
+ totalJobs int
137
+ totalQueued int
138
+ totalRunning int
139
+ )
140
+
141
+ totalJobs = len (statuses )
142
+
118
143
for _ , status := range statuses {
119
144
duration := ""
120
145
121
146
if status .StartedAt != nil && ! status .StartedAt .IsZero () {
122
147
duration = time .Since (* status .StartedAt ).Round (time .Second ).String ()
123
148
}
124
149
150
+ if status .Status == "queued" {
151
+ totalQueued ++
152
+ } else if status .Status == "in_progress" {
153
+ totalRunning ++
154
+ }
155
+
125
156
eta := ""
126
157
if status .Status != "queued" && status .AverageRuntime > time .Second * 0 {
127
158
if status .StartedAt != nil {
@@ -138,34 +169,52 @@ func printEvents(w io.Writer, statuses []JobStatus, verbose bool) {
138
169
}
139
170
140
171
if verbose {
141
- fmt .Fprintf (tabwriter , "%d\t %s\t %s\t %s\t %s\t %s\t %s\t %s\t %s\t %s\t %s\t %s\n " ,
172
+
173
+ line := fmt .Sprintf ("%d\t %s\t %s\t %s\t %s\t %s\t %s\t %s\t %s\t %s" ,
142
174
status .JobID ,
143
175
status .Owner ,
144
176
status .Repo ,
145
177
status .JobName ,
146
178
status .RunnerName ,
147
179
status .AgentName ,
148
180
status .Status ,
149
- status .StartedAt .Format (time .RFC3339 ),
150
181
duration ,
151
182
eta ,
152
- strings .Join (status .Labels , "," ),
153
- fmt .Sprintf ("https://github.com/%s/%s/runs/%d" , status .Owner , status .Repo , status .JobID ),
154
- )
183
+ strings .Join (status .Labels , "," ))
184
+ if includeURL {
185
+ line = line + fmt .Sprintf ("\t https://github.com/%s/%s/runs/%d" , status .Owner , status .Repo , status .JobID )
186
+ }
187
+
188
+ fmt .Fprintln (tabwriter , line )
155
189
} else {
156
- fmt .Fprintf ( tabwriter , "%s\t %s\t %s\t %s\t %s\t %s\t %s \n " ,
190
+ line := fmt .Sprintf ( "%s\t %s\t %s\t %s\t %s\t %s" ,
157
191
status .Owner ,
158
192
status .Repo ,
159
193
status .JobName ,
160
194
status .Status ,
161
195
duration ,
162
- eta ,
163
- fmt .Sprintf ("https://github.com/%s/%s/runs/%d" , status .Owner , status .Repo , status .JobID ))
196
+ eta )
164
197
165
- }
198
+ if includeURL {
199
+ line = line + fmt .Sprintf ("\t https://github.com/%s/%s/runs/%d" , status .Owner , status .Repo , status .JobID )
200
+ }
201
+
202
+ fmt .Fprintln (tabwriter , line )
166
203
204
+ }
167
205
}
206
+
168
207
tabwriter .Flush ()
208
+ if totalJobs > 0 {
209
+
210
+ st := "\n JOBS\t RUNNING\t QUEUED"
211
+
212
+ fmt .Fprintln (tabwriter , st )
213
+
214
+ fmt .Fprintf (tabwriter , "%d\t %d\t %d\n " , totalJobs , totalRunning , totalQueued )
215
+ tabwriter .Flush ()
216
+
217
+ }
169
218
}
170
219
171
220
type JobStatus struct {
0 commit comments