| 110 | } |
| 111 | |
| 112 | func 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 | } |