MCPcopy Create free account
hub / github.com/cli/cli / RepoExists

Function RepoExists

api/queries_repo.go:1676–1701  ·  view source on GitHub ↗
(client *Client, repo ghrepo.Interface)

Source from the content-addressed store, hash-verified

1674}
1675
1676func RepoExists(client *Client, repo ghrepo.Interface) (bool, error) {
1677 path, err := safeurl.JoinPath("repos", repo.RepoOwner(), repo.RepoName())
1678 if err != nil {
1679 return false, err
1680 }
1681
1682 // A HEAD request has no body to decode, so Request is used rather than REST. Existence is
1683 // decided by the status alone.
1684 resp, err := client.Request(repo.RepoHost(), http.MethodHead, path.String(), nil)
1685 if err != nil {
1686 if httpErr, ok := errors.AsType[HTTPError](err); ok && httpErr.StatusCode == http.StatusNotFound {
1687 return false, nil
1688 }
1689 return false, err
1690 }
1691
1692 defer resp.Body.Close()
1693
1694 // Only 200 means the repository exists. Any other success status is unexpected here and is
1695 // reported as an error rather than being taken as existence.
1696 if resp.StatusCode != http.StatusOK {
1697 return false, UnexpectedStatusError(resp)
1698 }
1699
1700 return true, nil
1701}
1702
1703// RepoLicenses fetches available repository licenses.
1704// It uses API v3 because licenses are not supported by GraphQL.

Callers 2

runBrowseFunction · 0.92
TestRepoExistsFunction · 0.85

Calls 8

JoinPathFunction · 0.92
UnexpectedStatusErrorFunction · 0.85
RequestMethod · 0.80
RepoOwnerMethod · 0.65
RepoNameMethod · 0.65
RepoHostMethod · 0.65
StringMethod · 0.65
CloseMethod · 0.65

Tested by 1

TestRepoExistsFunction · 0.68