ghAPIGetArray calls the GitHub REST API and returns a JSON array.
(endpoint string, repo string)
| 246 | |
| 247 | // ghAPIGetArray calls the GitHub REST API and returns a JSON array. |
| 248 | func ghAPIGetArray(endpoint string, repo string) ([]map[string]any, error) { |
| 249 | ownerRepo, host := repoutil.NormalizeRepoForAPI(repo) |
| 250 | args := []string{"api", fmt.Sprintf("repos/%s/%s", ownerRepo, endpoint)} |
| 251 | var output []byte |
| 252 | var err error |
| 253 | if host != "" { |
| 254 | output, err = workflow.RunGHWithHost("Checking outcome...", host, args...) |
| 255 | } else { |
| 256 | output, err = workflow.RunGH("Checking outcome...", args...) |
| 257 | } |
| 258 | if err != nil { |
| 259 | return nil, fmt.Errorf("gh api %s: %w", endpoint, err) |
| 260 | } |
| 261 | var result []map[string]any |
| 262 | if err := json.Unmarshal(output, &result); err != nil { |
| 263 | return nil, fmt.Errorf("parsing response for %s: %w", endpoint, err) |
| 264 | } |
| 265 | return result, nil |
| 266 | } |
| 267 | |
| 268 | // ghAPIGraphQL calls the GitHub GraphQL API via gh cli and returns the parsed JSON. |
| 269 | func ghAPIGraphQL(query string, repo string) (map[string]any, error) { |
no test coverage detected