@@ -36,6 +36,8 @@ func makeJobs() *cobra.Command {
3636
3737 cmd .Flags ().BoolP ("json" , "j" , false , "Request output in JSON format" )
3838
39+ cmd .Flags ().BoolP ("urls" , "u" , false , "Include the URLs to the job in the output" )
40+
3941 return cmd
4042}
4143
@@ -51,6 +53,11 @@ func runJobsE(cmd *cobra.Command, args []string) error {
5153 return err
5254 }
5355
56+ includeURL , err := cmd .Flags ().GetBool ("urls" )
57+ if err != nil {
58+ return err
59+ }
60+
5461 staff , err := cmd .Flags ().GetBool ("staff" )
5562 if err != nil {
5663 return err
@@ -75,7 +82,6 @@ func runJobsE(cmd *cobra.Command, args []string) error {
7582 acceptJSON := true
7683
7784 res , status , err := c .ListJobs (pat , owner , staff , acceptJSON )
78-
7985 if err != nil {
8086 return err
8187 }
@@ -100,28 +106,53 @@ func runJobsE(cmd *cobra.Command, args []string) error {
100106 if err := json .Unmarshal ([]byte (res ), & statuses ); err != nil {
101107 return err
102108 }
103- printEvents (os .Stdout , statuses , verbose )
109+ printEvents (os .Stdout , statuses , verbose , includeURL )
104110 }
105111
106112 return nil
107113
108114}
109115
110- func printEvents (w io.Writer , statuses []JobStatus , verbose bool ) {
116+ func printEvents (w io.Writer , statuses []JobStatus , verbose , includeURL bool ) {
111117 tabwriter := tabwriter .NewWriter (w , 0 , 0 , 1 , ' ' , tabwriter .TabIndent )
112118 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 )
114126 } 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 )
116133 }
117134
135+ var (
136+ totalJobs int
137+ totalQueued int
138+ totalRunning int
139+ )
140+
141+ totalJobs = len (statuses )
142+
118143 for _ , status := range statuses {
119144 duration := ""
120145
121146 if status .StartedAt != nil && ! status .StartedAt .IsZero () {
122147 duration = time .Since (* status .StartedAt ).Round (time .Second ).String ()
123148 }
124149
150+ if status .Status == "queued" {
151+ totalQueued ++
152+ } else if status .Status == "in_progress" {
153+ totalRunning ++
154+ }
155+
125156 eta := ""
126157 if status .Status != "queued" && status .AverageRuntime > time .Second * 0 {
127158 if status .StartedAt != nil {
@@ -138,34 +169,52 @@ func printEvents(w io.Writer, statuses []JobStatus, verbose bool) {
138169 }
139170
140171 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" ,
142174 status .JobID ,
143175 status .Owner ,
144176 status .Repo ,
145177 status .JobName ,
146178 status .RunnerName ,
147179 status .AgentName ,
148180 status .Status ,
149- status .StartedAt .Format (time .RFC3339 ),
150181 duration ,
151182 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 )
155189 } 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" ,
157191 status .Owner ,
158192 status .Repo ,
159193 status .JobName ,
160194 status .Status ,
161195 duration ,
162- eta ,
163- fmt .Sprintf ("https://github.com/%s/%s/runs/%d" , status .Owner , status .Repo , status .JobID ))
196+ eta )
164197
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 )
166203
204+ }
167205 }
206+
168207 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+ }
169218}
170219
171220type JobStatus struct {
0 commit comments