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"
|
"time"
|
||||||
|
|
||||||
"github.com/cli/cli/v2/api"
|
"github.com/cli/cli/v2/api"
|
||||||
|
"github.com/cli/cli/v2/pkg/cmdutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
type check struct {
|
type check struct {
|
||||||
|
|
@ -28,6 +29,10 @@ type checkCounts struct {
|
||||||
Canceled int
|
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) {
|
func aggregateChecks(checkContexts []api.CheckContext, requiredChecks bool) (checks []check, counts checkCounts) {
|
||||||
for _, c := range eliminateDuplicates(checkContexts) {
|
for _, c := range eliminateDuplicates(checkContexts) {
|
||||||
if requiredChecks && !c.IsRequired {
|
if requiredChecks && !c.IsRequired {
|
||||||
|
|
|
||||||
|
|
@ -20,10 +20,23 @@ import (
|
||||||
|
|
||||||
const defaultInterval time.Duration = 10 * time.Second
|
const defaultInterval time.Duration = 10 * time.Second
|
||||||
|
|
||||||
|
var prCheckFields = []string{
|
||||||
|
"name",
|
||||||
|
"state",
|
||||||
|
"startedAt",
|
||||||
|
"completedAt",
|
||||||
|
"link",
|
||||||
|
"bucket",
|
||||||
|
"event",
|
||||||
|
"workflow",
|
||||||
|
"description",
|
||||||
|
}
|
||||||
|
|
||||||
type ChecksOptions struct {
|
type ChecksOptions struct {
|
||||||
HttpClient func() (*http.Client, error)
|
HttpClient func() (*http.Client, error)
|
||||||
IO *iostreams.IOStreams
|
IO *iostreams.IOStreams
|
||||||
Browser browser.Browser
|
Browser browser.Browser
|
||||||
|
Exporter cmdutil.Exporter
|
||||||
|
|
||||||
Finder shared.PRFinder
|
Finder shared.PRFinder
|
||||||
Detector fd.Detector
|
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().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")
|
cmd.Flags().BoolVar(&opts.Required, "required", false, "Only show checks that are required")
|
||||||
|
|
||||||
|
cmdutil.AddJSONFlags(cmd, &opts.Exporter, prCheckFields)
|
||||||
|
|
||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -161,6 +176,10 @@ func checksRun(opts *ChecksOptions) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if opts.Exporter != nil {
|
||||||
|
return opts.Exporter.Write(opts.IO, checks)
|
||||||
|
}
|
||||||
|
|
||||||
if opts.Watch {
|
if opts.Watch {
|
||||||
opts.IO.StartAlternateScreenBuffer()
|
opts.IO.StartAlternateScreenBuffer()
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue