Merge pull request #9079 from cli/pr_checks_json
feat: add json output for `gh pr checks`
This commit is contained in:
commit
e14f0d79bd
2 changed files with 24 additions and 0 deletions
|
|
@ -6,6 +6,7 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/cli/cli/v2/api"
|
||||
"github.com/cli/cli/v2/pkg/cmdutil"
|
||||
)
|
||||
|
||||
type check struct {
|
||||
|
|
@ -28,6 +29,10 @@ type checkCounts struct {
|
|||
Canceled int
|
||||
}
|
||||
|
||||
func (ch *check) ExportData(fields []string) map[string]interface{} {
|
||||
return cmdutil.StructExportData(ch, fields)
|
||||
}
|
||||
|
||||
func aggregateChecks(checkContexts []api.CheckContext, requiredChecks bool) (checks []check, counts checkCounts) {
|
||||
for _, c := range eliminateDuplicates(checkContexts) {
|
||||
if requiredChecks && !c.IsRequired {
|
||||
|
|
|
|||
|
|
@ -20,10 +20,23 @@ import (
|
|||
|
||||
const defaultInterval time.Duration = 10 * time.Second
|
||||
|
||||
var prCheckFields = []string{
|
||||
"name",
|
||||
"state",
|
||||
"startedAt",
|
||||
"completedAt",
|
||||
"link",
|
||||
"bucket",
|
||||
"event",
|
||||
"workflow",
|
||||
"description",
|
||||
}
|
||||
|
||||
type ChecksOptions struct {
|
||||
HttpClient func() (*http.Client, error)
|
||||
IO *iostreams.IOStreams
|
||||
Browser browser.Browser
|
||||
Exporter cmdutil.Exporter
|
||||
|
||||
Finder shared.PRFinder
|
||||
Detector fd.Detector
|
||||
|
|
@ -97,6 +110,8 @@ func NewCmdChecks(f *cmdutil.Factory, runF func(*ChecksOptions) error) *cobra.Co
|
|||
cmd.Flags().IntVarP(&interval, "interval", "i", 10, "Refresh interval in seconds when using `--watch` flag")
|
||||
cmd.Flags().BoolVar(&opts.Required, "required", false, "Only show checks that are required")
|
||||
|
||||
cmdutil.AddJSONFlags(cmd, &opts.Exporter, prCheckFields)
|
||||
|
||||
return cmd
|
||||
}
|
||||
|
||||
|
|
@ -161,6 +176,10 @@ func checksRun(opts *ChecksOptions) error {
|
|||
return err
|
||||
}
|
||||
|
||||
if opts.Exporter != nil {
|
||||
return opts.Exporter.Write(opts.IO, checks)
|
||||
}
|
||||
|
||||
if opts.Watch {
|
||||
opts.IO.StartAlternateScreenBuffer()
|
||||
} else {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue