fetchPRHeadSHA fetches the head commit SHA for a given PR.
(repoOverride string, prNumber string)
| 196 | |
| 197 | // fetchPRHeadSHA fetches the head commit SHA for a given PR. |
| 198 | func fetchPRHeadSHA(repoOverride string, prNumber string) (string, error) { |
| 199 | output, err := execGHAPI(repoOverride, prNumber, |
| 200 | "api", "repos/{owner}/{repo}/pulls/"+prNumber, "--jq", ".head.sha") |
| 201 | if err != nil { |
| 202 | return "", err |
| 203 | } |
| 204 | |
| 205 | sha := strings.TrimSpace(string(output)) |
| 206 | if sha == "" { |
| 207 | return "", errors.New(console.FormatErrorWithSuggestions( |
| 208 | "PR #"+prNumber+" returned an empty SHA", |
| 209 | []string{ |
| 210 | "Verify that PR #" + prNumber + " exists and is accessible", |
| 211 | "Check that the --repo flag points to the correct repository", |
| 212 | }, |
| 213 | )) |
| 214 | } |
| 215 | return sha, nil |
| 216 | } |
| 217 | |
| 218 | // classifyGHAPIError converts a gh API exit error into a user-friendly, pre-formatted error. |
| 219 | func classifyGHAPIError(exitCode int, stderr string, prNumber string, repo string) error { |
no test coverage detected