diff --git a/api/client.go b/api/client.go index 0d2690378..e32856554 100644 --- a/api/client.go +++ b/api/client.go @@ -19,7 +19,7 @@ const ( authorization = "Authorization" cacheTTL = "X-GH-CACHE-TTL" graphqlFeatures = "GraphQL-Features" - features = "merge_queue,push_policies" + features = "merge_queue" userAgent = "User-Agent" ) diff --git a/pkg/cmd/ruleset/list/list.go b/pkg/cmd/ruleset/list/list.go index e49710ba8..ee13afeef 100644 --- a/pkg/cmd/ruleset/list/list.go +++ b/pkg/cmd/ruleset/list/list.go @@ -149,7 +149,7 @@ func listRun(opts *ListOptions) error { tp.HeaderRow("ID", "NAME", "SOURCE", "STATUS", "TARGET", "RULES") for _, rs := range result.Rulesets { - tp.AddField(strconv.Itoa(rs.Id)) + tp.AddField(strconv.Itoa(rs.DatabaseId)) tp.AddField(rs.Name, tableprinter.WithColor(cs.Bold)) var ownerString string if rs.Source.RepoOwner != "" { @@ -162,7 +162,7 @@ func listRun(opts *ListOptions) error { tp.AddField(ownerString) tp.AddField(strings.ToLower(rs.Enforcement)) tp.AddField(strings.ToLower(rs.Target)) - tp.AddField(strconv.Itoa(rs.RulesGql.TotalCount)) + tp.AddField(strconv.Itoa(rs.Rules.TotalCount)) tp.EndRow() } diff --git a/pkg/cmd/ruleset/shared/http.go b/pkg/cmd/ruleset/shared/http.go index 9dae0d7e6..2276f8989 100644 --- a/pkg/cmd/ruleset/shared/http.go +++ b/pkg/cmd/ruleset/shared/http.go @@ -12,7 +12,7 @@ type RulesetResponse struct { Level struct { Rulesets struct { TotalCount int - Nodes []Ruleset + Nodes []RulesetGraphQL PageInfo struct { HasNextPage bool EndCursor string @@ -23,7 +23,7 @@ type RulesetResponse struct { type RulesetList struct { TotalCount int - Rulesets []Ruleset + Rulesets []RulesetGraphQL } func ListRepoRulesets(httpClient *http.Client, repo ghrepo.Interface, limit int, includeParents bool) (*RulesetList, error) { @@ -49,7 +49,7 @@ func listRulesets(httpClient *http.Client, query string, variables map[string]in pageLimit := min(limit, 100) res := RulesetList{ - Rulesets: []Ruleset{}, + Rulesets: []RulesetGraphQL{}, } client := api.NewClientFromHTTP(httpClient) @@ -97,7 +97,7 @@ func rulesetsQuery(org bool) string { rulesets(first: $limit, after: $endCursor, includeParents: $includeParents) { totalCount nodes { - id: databaseId + databaseId name target enforcement @@ -105,18 +105,7 @@ func rulesetsQuery(org bool) string { ... on Repository { repoOwner: nameWithOwner } ... on Organization { orgOwner: login } } - # conditions { - # refName { - # include - # exclude - # } - # repositoryName { - # include - # exclude - # protected - # } - # } - rulesGql: rules { + rules { totalCount } } diff --git a/pkg/cmd/ruleset/shared/shared.go b/pkg/cmd/ruleset/shared/shared.go index fa5f2e30f..090d3d989 100644 --- a/pkg/cmd/ruleset/shared/shared.go +++ b/pkg/cmd/ruleset/shared/shared.go @@ -1,6 +1,20 @@ package shared -type Ruleset struct { +type RulesetGraphQL struct { + DatabaseId int + Name string + Target string + Enforcement string + Source struct { + RepoOwner string + OrgOwner string + } + Rules struct { + TotalCount int + } +} + +type RulesetREST struct { Id int Name string Target string @@ -10,23 +24,9 @@ type Ruleset struct { ActorId int `json:"actor_id"` ActorType string `json:"actor_type"` } `json:"bypass_actors"` - Conditions map[string]map[string]interface { - // RefName struct { - // Include []string - // Exclude []string - // } `json:"ref_name"` - // RepositoryName struct { - // Include []string - // Exclude []string - // Protected bool - // } `json:"repository_name"` - } - Source struct { - RepoOwner string - OrgOwner string - } - RulesGql struct { - TotalCount int - } - Rules []interface{} + Conditions map[string]map[string]interface{} + // TODO is this source field used? + SourceType string `json:"source_type"` + Source string + Rules []struct{} } diff --git a/pkg/cmd/ruleset/view/http.go b/pkg/cmd/ruleset/view/http.go index bd56c3cf6..d0b26f530 100644 --- a/pkg/cmd/ruleset/view/http.go +++ b/pkg/cmd/ruleset/view/http.go @@ -9,19 +9,19 @@ import ( "github.com/cli/cli/v2/pkg/cmd/ruleset/shared" ) -func viewRepoRuleset(httpClient *http.Client, repo ghrepo.Interface, databaseId string) (*shared.Ruleset, error) { +func viewRepoRuleset(httpClient *http.Client, repo ghrepo.Interface, databaseId string) (*shared.RulesetREST, error) { path := fmt.Sprintf("repos/%s/%s/rulesets/%s", repo.RepoOwner(), repo.RepoName(), databaseId) return viewRuleset(httpClient, repo.RepoHost(), path) } -func viewOrgRuleset(httpClient *http.Client, orgLogin string, databaseId string, host string) (*shared.Ruleset, error) { +func viewOrgRuleset(httpClient *http.Client, orgLogin string, databaseId string, host string) (*shared.RulesetREST, error) { path := fmt.Sprintf("orgs/%s/rulesets/%s", orgLogin, databaseId) return viewRuleset(httpClient, host, path) } -func viewRuleset(httpClient *http.Client, hostname string, path string) (*shared.Ruleset, error) { +func viewRuleset(httpClient *http.Client, hostname string, path string) (*shared.RulesetREST, error) { apiClient := api.NewClientFromHTTP(httpClient) - result := shared.Ruleset{} + result := shared.RulesetREST{} err := apiClient.REST(hostname, "GET", path, nil, &result) if err != nil { diff --git a/pkg/cmd/ruleset/view/view.go b/pkg/cmd/ruleset/view/view.go index 6d0005909..7569d3e62 100644 --- a/pkg/cmd/ruleset/view/view.go +++ b/pkg/cmd/ruleset/view/view.go @@ -104,7 +104,7 @@ func viewRun(opts *ViewOptions) error { hostname, _ := cfg.DefaultHost() - var rs *shared.Ruleset + var rs *shared.RulesetREST if opts.Organization != "" { rs, err = viewOrgRuleset(httpClient, opts.Organization, opts.ID, hostname) } else {