From 60f4183057f7091fc0290e04ba3be02d3c0aa388 Mon Sep 17 00:00:00 2001 From: micash Date: Sun, 8 Sep 2024 16:59:24 +0200 Subject: [PATCH] add codeberg releases --- docs/configuration.md | 8 +++-- internal/assets/static/icons/codeberg.svg | 1 + internal/feed/codeberg.go | 39 +++++++++++++++++++++++ internal/feed/releases.go | 3 ++ internal/widget/releases.go | 6 +++- 5 files changed, 53 insertions(+), 4 deletions(-) create mode 100644 internal/assets/static/icons/codeberg.svg create mode 100644 internal/feed/codeberg.go diff --git a/docs/configuration.md b/docs/configuration.md index 944019e..fb119a5 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -1114,7 +1114,7 @@ Whether to ignore invalid/self-signed certificates. Whether to open the link in the same or a new tab. ### Releases -Display a list of latest releases for specific repositories on Github, GitLab or Docker Hub. +Display a list of latest releases for specific repositories on Github, GitLab, Codeberg or Docker Hub. Example: @@ -1125,6 +1125,7 @@ Example: - go-gitea/gitea - jellyfin/jellyfin - glanceapp/glance + - codeberg:redict/redict - gitlab:fdroid/fdroidclient - dockerhub:gotify/server ``` @@ -1145,12 +1146,13 @@ Preview: | collapse-after | integer | no | 5 | ##### `repositories` -A list of repositores to fetch the latest release for. Only the name/repo is required, not the full URL. A prefix can be specified for repositories hosted elsewhere such as GitLab and Docker Hub. Example: +A list of repositores to fetch the latest release for. Only the name/repo is required, not the full URL. A prefix can be specified for repositories hosted elsewhere such as GitLab, Codeberg and Docker Hub. Example: ```yaml repositories: - gitlab:inkscape/inkscape - dockerhub:glanceapp/glance + - codeberg:redict/redict ``` Official images on Docker Hub can be specified by ommiting the owner: @@ -1172,7 +1174,7 @@ repositories: ##### `show-source-icon` -Shows an icon of the source (GitHub/GitLab/Docker Hub) next to the repository name when set to `true`. +Shows an icon of the source (GitHub/GitLab/Codeberg/Docker Hub) next to the repository name when set to `true`. ##### `token` Without authentication Github allows for up to 60 requests per hour. You can easily exceed this limit and start seeing errors if you're tracking lots of repositories or your cache time is low. To circumvent this you can [create a read only token from your Github account](https://github.com/settings/personal-access-tokens/new) and provide it here. diff --git a/internal/assets/static/icons/codeberg.svg b/internal/assets/static/icons/codeberg.svg new file mode 100644 index 0000000..a87790e --- /dev/null +++ b/internal/assets/static/icons/codeberg.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/internal/feed/codeberg.go b/internal/feed/codeberg.go new file mode 100644 index 0000000..edd83d7 --- /dev/null +++ b/internal/feed/codeberg.go @@ -0,0 +1,39 @@ +package feed + +import ( + "fmt" + "net/http" +) + +type codebergReleaseResponseJson struct { + TagName string `json:"tag_name"` + PublishedAt string `json:"published_at"` + HtmlUrl string `json:"html_url"` +} + +func FetchLatestCodebergRelease(request *ReleaseRequest) (*AppRelease, error) { + httpRequest, err := http.NewRequest( + "GET", + fmt.Sprintf( + "https://codeberg.org/api/v1/repos/%s/releases/latest", + request.Repository, + ), + nil, + ) + if err != nil { + return nil, err + } + + response, err := decodeJsonFromRequest[codebergReleaseResponseJson](defaultClient, httpRequest) + + if err != nil { + return nil, err + } + return &AppRelease{ + Source: ReleaseSourceCodeberg, + Name: request.Repository, + Version: normalizeVersionFormat(response.TagName), + NotesUrl: response.HtmlUrl, + TimeReleased: parseRFC3339Time(response.PublishedAt), + }, nil +} diff --git a/internal/feed/releases.go b/internal/feed/releases.go index 516801e..596d1be 100644 --- a/internal/feed/releases.go +++ b/internal/feed/releases.go @@ -9,6 +9,7 @@ import ( type ReleaseSource string const ( + ReleaseSourceCodeberg ReleaseSource = "codeberg" ReleaseSourceGithub ReleaseSource = "github" ReleaseSourceGitlab ReleaseSource = "gitlab" ReleaseSourceDockerHub ReleaseSource = "dockerhub" @@ -57,6 +58,8 @@ func FetchLatestReleases(requests []*ReleaseRequest) (AppReleases, error) { func fetchLatestReleaseTask(request *ReleaseRequest) (*AppRelease, error) { switch request.Source { + case ReleaseSourceCodeberg: + return FetchLatestCodebergRelease(request) case ReleaseSourceGithub: return fetchLatestGithubRelease(request) case ReleaseSourceGitlab: diff --git a/internal/widget/releases.go b/internal/widget/releases.go index c7831cb..74b5af7 100644 --- a/internal/widget/releases.go +++ b/internal/widget/releases.go @@ -40,7 +40,6 @@ func (widget *Releases) Initialize() error { for _, repository := range widget.Repositories { parts := strings.SplitN(repository, ":", 2) var request *feed.ReleaseRequest - if len(parts) == 1 { request = &feed.ReleaseRequest{ Source: feed.ReleaseSourceGithub, @@ -65,6 +64,11 @@ func (widget *Releases) Initialize() error { Source: feed.ReleaseSourceDockerHub, Repository: parts[1], } + } else if parts[0] == string(feed.ReleaseSourceCodeberg) { + request = &feed.ReleaseRequest{ + Source: feed.ReleaseSourceCodeberg, + Repository: parts[1], + } } else { return errors.New("invalid repository source " + parts[0]) }