File: http.go

package info (click to toggle)
gh 2.46.0-4
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 15,548 kB
  • sloc: sh: 227; makefile: 117
file content (32 lines) | stat: -rw-r--r-- 980 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package view

import (
	"fmt"
	"net/http"

	"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(), 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", orgLogin, 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
}