cli/pkg/cmd/ruleset/view/http.go
copilot-swe-agent[bot] 0c1c1bdab3
fix: apply url.PathEscape to databaseId in ruleset view HTTP functions
Agent-Logs-Url: https://github.com/cli/cli/sessions/e09c6964-46ba-4baf-a486-f8dce8c7ac48

Co-authored-by: babakks <36728931+babakks@users.noreply.github.com>
2026-04-23 10:36:18 +00:00

33 lines
1 KiB
Go

package view
import (
"fmt"
"net/http"
"net/url"
"github.com/cli/cli/v2/api"
"github.com/cli/cli/v2/internal/ghrepo"
"github.com/cli/cli/v2/pkg/cmd/ruleset/shared"
)
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(), url.PathEscape(databaseId))
return viewRuleset(httpClient, repo.RepoHost(), path)
}
func viewOrgRuleset(httpClient *http.Client, orgLogin string, databaseId string, host string) (*shared.RulesetREST, error) {
path := fmt.Sprintf("orgs/%s/rulesets/%s", url.PathEscape(orgLogin), url.PathEscape(databaseId))
return viewRuleset(httpClient, host, path)
}
func viewRuleset(httpClient *http.Client, hostname string, path string) (*shared.RulesetREST, error) {
apiClient := api.NewClientFromHTTP(httpClient)
result := shared.RulesetREST{}
err := apiClient.REST(hostname, "GET", path, nil, &result)
if err != nil {
return nil, err
}
return &result, nil
}