From 87fabebb68984c4e6d5ac9447a244191975d83c3 Mon Sep 17 00:00:00 2001 From: vilmibm Date: Mon, 6 Feb 2023 15:31:36 -0800 Subject: [PATCH] start on gh rs --- pkg/cmd/ruleset/check/check.go | 65 ++++++++++++++++++++++++++++++++++ pkg/cmd/ruleset/ruleset.go | 26 ++++++++++++++ 2 files changed, 91 insertions(+) create mode 100644 pkg/cmd/ruleset/check/check.go create mode 100644 pkg/cmd/ruleset/ruleset.go diff --git a/pkg/cmd/ruleset/check/check.go b/pkg/cmd/ruleset/check/check.go new file mode 100644 index 000000000..a143981b1 --- /dev/null +++ b/pkg/cmd/ruleset/check/check.go @@ -0,0 +1,65 @@ +package check + +import ( + "net/http" + + "github.com/MakeNowJust/heredoc" + "github.com/cli/cli/v2/internal/config" + "github.com/cli/cli/v2/internal/ghrepo" + "github.com/cli/cli/v2/pkg/cmdutil" + "github.com/cli/cli/v2/pkg/iostreams" + "github.com/spf13/cobra" +) + +type CheckOptions struct { + HttpClient func() (*http.Client, error) + IO *iostreams.IOStreams + Config func() (config.Config, error) + BaseRepo func() (ghrepo.Interface, error) + + Branch string +} + +func NewCmdCheck(f *cmdutil.Factory, runF func(*CheckOptions) error) *cobra.Command { + opts := &CheckOptions{ + IO: f.IOStreams, + Config: f.Config, + HttpClient: f.HttpClient, + } + cmd := &cobra.Command{ + Use: "check []", + Short: "Print rules that would apply to a given branch", + Long: heredoc.Doc(` + TODO + `), + Example: "TODO", + Args: cobra.MaximumNArgs(1), + RunE: func(cmd *cobra.Command, args []string) error { + // support `-R, --repo` override + opts.BaseRepo = f.BaseRepo + + // TODO flag to do a push + + if len(args) > 0 { + opts.Branch = args[0] + } + + if runF != nil { + return runF(opts) + } + + return checkRun(opts) + }, + } + + return cmd +} + +func checkRun(opts *CheckOptions) error { + // TODO sniff local branch if opts.Branch is empty + // TODO ask about pushing (if interactive) + // TODO error if not interactive and --push not specified + + // is the --push redundant? like, it needs to be specified every time for scripted use. can i tell if a branch is up to date with remote without a push? i could figure that out i think and then would know a push wasn't needed (but it will require a fetch per invocation. that seems fine?) + return nil +} diff --git a/pkg/cmd/ruleset/ruleset.go b/pkg/cmd/ruleset/ruleset.go new file mode 100644 index 000000000..2fa86684c --- /dev/null +++ b/pkg/cmd/ruleset/ruleset.go @@ -0,0 +1,26 @@ +package ruleset + +import ( + "github.com/MakeNowJust/heredoc" + "github.com/cli/cli/v2/pkg/cmdutil" + "github.com/spf13/cobra" +) + +func NewCmdRuleset(f *cmdutil.Factory) *cobra.Command { + cmd := &cobra.Command{ + Use: "ruleset ", + Short: "Manage repository and organization rulesets", + Long: heredoc.Doc(` + TODO + `), + Aliases: []string{"rs"}, + Example: "TODO", + } + + cmdutil.EnableRepoOverride(cmd, f) + // cmd.AddCommand(cmdList.NewCmdList(f, nil) + // cmd.AddCommand(cmdList.NewCmdView(f, nil) + // cmd.AddCommand(cmdCheck.NewCmdCheck(f, nil) + + return cmd +}