Skip to content

Commit

Permalink
Return an empty string when a repo has no avatar in the repo API (go-…
Browse files Browse the repository at this point in the history
…gitea#31187)

Backport go-gitea#31187

Resolves go-gitea#31167.

go-gitea#30885 changed the behavior of
`repo.AvatarLink()` where it can now take the empty string and append it
to the app data URL. This does not point to a valid avatar image URL,
and, as the issue mentions, previous Gitea versions returned the empty
string.

---------

Co-authored-by: wxiaoguang <[email protected]>
  • Loading branch information
2 people authored and jpraet committed Jul 5, 2024
1 parent 6486c8b commit d27ddbf
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions models/repo/avatar.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,13 @@ func (repo *Repository) relAvatarLink(ctx context.Context) string {
return setting.AppSubURL + "/repo-avatars/" + url.PathEscape(repo.Avatar)
}

// AvatarLink returns the full avatar url with http host. TODO: refactor it to a relative URL, but it is still used in API response at the moment
// AvatarLink returns the full avatar url with http host or the empty string if the repo doesn't have an avatar.
//
// TODO: refactor it to a relative URL, but it is still used in API response at the moment
func (repo *Repository) AvatarLink(ctx context.Context) string {
return httplib.MakeAbsoluteURL(ctx, repo.relAvatarLink(ctx))
relLink := repo.relAvatarLink(ctx)
if relLink != "" {
return httplib.MakeAbsoluteURL(ctx, relLink)
}
return ""
}

0 comments on commit d27ddbf

Please sign in to comment.