Fix version formatting in releases widget

This commit is contained in:
Svilen Markov 2024-08-30 16:19:20 +01:00
parent 725d0da15d
commit b9bf8c6c96
3 changed files with 12 additions and 14 deletions

View File

@ -38,16 +38,10 @@ func fetchLatestGithubRelease(request *ReleaseRequest) (*AppRelease, error) {
return nil, err return nil, err
} }
version := response.TagName
if len(version) > 0 && version[0] != 'v' {
version = "v" + version
}
return &AppRelease{ return &AppRelease{
Source: ReleaseSourceGithub, Source: ReleaseSourceGithub,
Name: request.Repository, Name: request.Repository,
Version: version, Version: normalizeVersionFormat(response.TagName),
NotesUrl: response.HtmlUrl, NotesUrl: response.HtmlUrl,
TimeReleased: parseRFC3339Time(response.PublishedAt), TimeReleased: parseRFC3339Time(response.PublishedAt),
Downvotes: response.Reactions.Downvotes, Downvotes: response.Reactions.Downvotes,

View File

@ -38,16 +38,10 @@ func fetchLatestGitLabRelease(request *ReleaseRequest) (*AppRelease, error) {
return nil, err return nil, err
} }
version := response.TagName
if len(version) > 0 && version[0] != 'v' {
version = "v" + version
}
return &AppRelease{ return &AppRelease{
Source: ReleaseSourceGitlab, Source: ReleaseSourceGitlab,
Name: request.Repository, Name: request.Repository,
Version: version, Version: normalizeVersionFormat(response.TagName),
NotesUrl: response.Links.Self, NotesUrl: response.Links.Self,
TimeReleased: parseRFC3339Time(response.ReleasedAt), TimeReleased: parseRFC3339Time(response.ReleasedAt),
}, nil }, nil

View File

@ -105,3 +105,13 @@ func parseRFC3339Time(t string) time.Time {
return parsed return parsed
} }
func normalizeVersionFormat(version string) string {
version = strings.ToLower(strings.TrimSpace(version))
if len(version) > 0 && version[0] != 'v' {
return "v" + version
}
return version
}