misc cleanup

This commit is contained in:
vaindil 2023-06-30 20:01:17 -04:00
parent e4aa5ba84c
commit 77df68e11a
4 changed files with 8 additions and 114 deletions

View file

@ -10,7 +10,6 @@ import (
"github.com/cli/cli/v2/internal/browser"
"github.com/cli/cli/v2/internal/config"
"github.com/cli/cli/v2/internal/ghrepo"
"github.com/cli/cli/v2/internal/run"
"github.com/cli/cli/v2/pkg/cmdutil"
"github.com/cli/cli/v2/pkg/httpmock"
"github.com/cli/cli/v2/pkg/iostreams"
@ -137,76 +136,6 @@ func Test_NewCmdList(t *testing.T) {
}
}
func Test_RulesetList_Web(t *testing.T) {
tests := []struct {
name string
stdoutTTY bool
wantStdout string
wantBrowse string
}{
{
name: "repo tty",
stdoutTTY: true,
wantStdout: "Opening github.com/OWNER/REPO in your browser.\n",
wantBrowse: "https://github.com/OWNER/REPO",
},
{
name: "org tty",
stdoutTTY: true,
wantStdout: "Opening github.com/OWNER/REPO in your browser.\n",
wantBrowse: "https://github.com/OWNER/REPO",
},
{
name: "repo non-tty",
stdoutTTY: false,
wantStdout: "",
wantBrowse: "https://github.com/OWNER/REPO",
},
{
name: "org non-tty",
stdoutTTY: false,
wantStdout: "",
wantBrowse: "https://github.com/OWNER/REPO",
},
}
for _, tt := range tests {
reg := &httpmock.Registry{}
reg.StubRepoInfoResponse("OWNER", "REPO", "main")
browser := &browser.Stub{}
opts := &ListOptions{
WebMode: true,
HttpClient: func() (*http.Client, error) {
return &http.Client{Transport: reg}, nil
},
BaseRepo: func() (ghrepo.Interface, error) {
return ghrepo.New("OWNER", "REPO"), nil
},
Browser: browser,
}
io, _, stdout, _ := iostreams.Test()
opts.IO = io
t.Run(tt.name, func(t *testing.T) {
io.SetStdoutTTY(tt.stdoutTTY)
_, teardown := run.Stub()
defer teardown(t)
if err := listRun(opts); err != nil {
t.Errorf("listRun() error = %v", err)
}
assert.Equal(t, "", stdout.String())
assert.Equal(t, tt.wantStdout, stdout.String())
reg.Verify(t)
browser.Verify(t, tt.wantBrowse)
})
}
}
func Test_listRun(t *testing.T) {
tests := []struct {
name string

View file

@ -1,39 +0,0 @@
package ruleset
type RuleType string
type Enforcement string
type MatchingOperator string
const (
RuleTypeCommitAuthorEmailPattern RuleType = "commit_author_email_pattern"
RuleTypePullRequest RuleType = "pull_request"
// TODO others
EnforcementEnabled Enforcement = "enabled"
EnforcementDisabled Enforcement = "disabled"
MatchingOperatorStartsWith MatchingOperator = "starts_with"
MatchingOperatorEndsWith MatchingOperator = "ends_with"
MatchingOperatorContains MatchingOperator = "contains"
MatchingOperatorRegex MatchingOperator = "regex"
)
type ConfigurationPullRequest struct {
DissmissStaleReviewsOnPush bool
RequireCodeOwnerReview bool
RequestLastPushApproval bool
RequiredApprovingReviewCount int
}
type BranchNamePattern struct {
Name string
Negate bool
Operator MatchingOperator
}
type Rule struct {
ID string
Type RuleType
Enforcement Enforcement
Configuration interface{}
}

View file

@ -12,12 +12,17 @@ import (
func NewCmdRuleset(f *cmdutil.Factory) *cobra.Command {
cmd := &cobra.Command{
Use: "ruleset <command>",
Short: "Manage repository and organization rulesets",
Short: "View info about repo rulesets",
Long: heredoc.Doc(`
TODO
Repository rulesets are a way to define a set of rules that apply to a repository.
These commands allow you to view information about them.
`),
Aliases: []string{"rs"},
Example: "TODO",
Example: heredoc.Doc(`
$ gh ruleset list
$ gh ruleset view --repo OWNER/REPO --web
$ gh ruleset check branch-name
`),
}
cmdutil.EnableRepoOverride(cmd, f)

View file

@ -34,7 +34,6 @@ type RulesetREST struct {
BypassMode string `json:"bypass_mode"`
} `json:"bypass_actors"`
Conditions map[string]map[string]interface{}
// TODO is this source field used?
SourceType string `json:"source_type"`
Source string
Rules []RulesetRule