@@ -24,6 +24,8 @@ type ChecksOptions struct {
2424 Branch func () (string , error )
2525 Remotes func () (context.Remotes , error )
2626
27+ WebMode bool
28+
2729 SelectorArg string
2830}
2931
@@ -60,6 +62,8 @@ func NewCmdChecks(f *cmdutil.Factory, runF func(*ChecksOptions) error) *cobra.Co
6062 },
6163 }
6264
65+ cmd .Flags ().BoolVarP (& opts .WebMode , "web" , "w" , false , "Open the web browser to show details about checks" )
66+
6367 return cmd
6468}
6569
@@ -70,7 +74,7 @@ func checksRun(opts *ChecksOptions) error {
7074 }
7175 apiClient := api .NewClientFromHTTP (httpClient )
7276
73- pr , _ , err := shared .PRFromArgs (apiClient , opts .BaseRepo , opts .Branch , opts .Remotes , opts .SelectorArg )
77+ pr , baseRepo , err := shared .PRFromArgs (apiClient , opts .BaseRepo , opts .Branch , opts .Remotes , opts .SelectorArg )
7478 if err != nil {
7579 return err
7680 }
@@ -84,6 +88,16 @@ func checksRun(opts *ChecksOptions) error {
8488 return fmt .Errorf ("no checks reported on the '%s' branch" , pr .BaseRefName )
8589 }
8690
91+ isTerminal := opts .IO .IsStdoutTTY ()
92+
93+ if opts .WebMode {
94+ openURL := ghrepo .GenerateRepoURL (baseRepo , "pull/%d/checks" , pr .Number )
95+ if isTerminal {
96+ fmt .Fprintf (opts .IO .ErrOut , "Opening %s in your browser.\n " , utils .DisplayURL (openURL ))
97+ }
98+ return utils .OpenInBrowser (openURL )
99+ }
100+
87101 passing := 0
88102 failing := 0
89103 pending := 0
@@ -164,9 +178,8 @@ func checksRun(opts *ChecksOptions) error {
164178 if b0 == b1 {
165179 if n0 == n1 {
166180 return l0 < l1
167- } else {
168- return n0 < n1
169181 }
182+ return n0 < n1
170183 }
171184
172185 return (b0 == "fail" ) || (b0 == "pending" && b1 == "success" )
@@ -175,7 +188,7 @@ func checksRun(opts *ChecksOptions) error {
175188 tp := utils .NewTablePrinter (opts .IO )
176189
177190 for _ , o := range outputs {
178- if opts . IO . IsStdoutTTY () {
191+ if isTerminal {
179192 tp .AddField (o .mark , nil , o .markColor )
180193 tp .AddField (o .name , nil , nil )
181194 tp .AddField (o .elapsed , nil , nil )
@@ -211,7 +224,7 @@ func checksRun(opts *ChecksOptions) error {
211224 summary = fmt .Sprintf ("%s\n %s" , cs .Bold (summary ), tallies )
212225 }
213226
214- if opts . IO . IsStdoutTTY () {
227+ if isTerminal {
215228 fmt .Fprintln (opts .IO .Out , summary )
216229 fmt .Fprintln (opts .IO .Out )
217230 }
0 commit comments