( ctx context.Context, token string, ref BranchRef, )
| 346 | } |
| 347 | |
| 348 | func (g *githubProvider) FetchBranchDiff( |
| 349 | ctx context.Context, |
| 350 | token string, |
| 351 | ref BranchRef, |
| 352 | ) (string, error) { |
| 353 | if ref.Owner == "" || ref.Repo == "" || ref.Branch == "" { |
| 354 | return "", nil |
| 355 | } |
| 356 | |
| 357 | var repository struct { |
| 358 | DefaultBranch string `json:"default_branch"` |
| 359 | } |
| 360 | |
| 361 | repositoryURL := fmt.Sprintf( |
| 362 | "%s/repos/%s/%s", |
| 363 | g.apiBaseURL, |
| 364 | url.PathEscape(ref.Owner), |
| 365 | url.PathEscape(ref.Repo), |
| 366 | ) |
| 367 | if err := g.decodeJSON(ctx, repositoryURL, token, &repository); err != nil { |
| 368 | return "", err |
| 369 | } |
| 370 | defaultBranch := strings.TrimSpace(repository.DefaultBranch) |
| 371 | if defaultBranch == "" { |
| 372 | return "", xerrors.New("github repository default branch is empty") |
| 373 | } |
| 374 | |
| 375 | requestURL := fmt.Sprintf( |
| 376 | "%s/repos/%s/%s/compare/%s...%s", |
| 377 | g.apiBaseURL, |
| 378 | url.PathEscape(ref.Owner), |
| 379 | url.PathEscape(ref.Repo), |
| 380 | url.PathEscape(defaultBranch), |
| 381 | url.PathEscape(ref.Branch), |
| 382 | ) |
| 383 | |
| 384 | return g.fetchDiff(ctx, requestURL, token) |
| 385 | } |
| 386 | |
| 387 | func (g *githubProvider) decodeJSON( |
| 388 | ctx context.Context, |
nothing calls this directly
no test coverage detected