Skip to content

Commit

Permalink
presenter/github: Improve handling of moved repos.
Browse files Browse the repository at this point in the history
Use Repositories.Get method to fetch the owner avatar URL, instead of
relying the github owner name. This works better when the repository
has moved, since redirection works on Repositories.Get endpoint.
  • Loading branch information
dmitshur committed Feb 25, 2017
1 parent 7557da9 commit 2196978
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions presenter/github/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,12 @@ func presentGitHubRepo(ctx context.Context, gh *github.Client, repo *gps.Repo, g
}

// Use the repo owner avatar image.
if user, _, err := gh.Users.Get(ctx, ghOwner); err == nil && user.AvatarURL != nil {
p.ImageURL = *user.AvatarURL
if repo, _, err := gh.Repositories.Get(ctx, ghOwner, ghRepo); err == nil && repo.Owner != nil && repo.Owner.AvatarURL != nil {
p.ImageURL = *repo.Owner.AvatarURL
} else if rateLimitErr, ok := err.(*github.RateLimitError); ok {
setFirstError(p, rateLimitError{rateLimitErr})
} else {
setFirstError(p, fmt.Errorf("gh.Users.Get: %v", err))
setFirstError(p, fmt.Errorf("gh.Repositories.Get: %v", err))
}

return p
Expand Down

0 comments on commit 2196978

Please sign in to comment.