MCPcopy Index your code
hub / github.com/cli/cli / FindRepoBranchID

Function FindRepoBranchID

api/queries_branch_issue_reference.go:112–148  ·  view source on GitHub ↗
(client *Client, repo ghrepo.Interface, ref string)

Source from the content-addressed store, hash-verified

110}
111
112func FindRepoBranchID(client *Client, repo ghrepo.Interface, ref string) (string, string, error) {
113 var query struct {
114 Repository struct {
115 Id string
116 DefaultBranchRef struct {
117 Target struct {
118 Oid string
119 }
120 }
121 Ref struct {
122 Target struct {
123 Oid string
124 }
125 } `graphql:"ref(qualifiedName: $ref)"`
126 } `graphql:"repository(owner: $owner, name: $name)"`
127 }
128
129 variables := map[string]interface{}{
130 "ref": githubv4.String(ref),
131 "owner": githubv4.String(repo.RepoOwner()),
132 "name": githubv4.String(repo.RepoName()),
133 }
134
135 if err := client.Query(repo.RepoHost(), "FindRepoBranchID", &query, variables); err != nil {
136 return "", "", err
137 }
138
139 branchID := query.Repository.Ref.Target.Oid
140 if branchID == "" {
141 if ref != "" {
142 return "", "", fmt.Errorf("could not find branch %q in %s", ref, ghrepo.FullName(repo))
143 }
144 branchID = query.Repository.DefaultBranchRef.Target.Oid
145 }
146
147 return query.Repository.Id, branchID, nil
148}

Callers 1

developRunCreateFunction · 0.92

Calls 7

FullNameFunction · 0.92
RepoOwnerMethod · 0.65
RepoNameMethod · 0.65
QueryMethod · 0.65
RepoHostMethod · 0.65
ErrorfMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected