MCPcopy Index your code
hub / github.com/coder/coder / FetchBranchDiff

Method FetchBranchDiff

coderd/externalauth/gitprovider/github.go:348–385  ·  view source on GitHub ↗
(
	ctx context.Context,
	token string,
	ref BranchRef,
)

Source from the content-addressed store, hash-verified

346}
347
348func (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
387func (g *githubProvider) decodeJSON(
388 ctx context.Context,

Callers

nothing calls this directly

Calls 3

decodeJSONMethod · 0.95
fetchDiffMethod · 0.95
NewMethod · 0.65

Tested by

no test coverage detected