aboutsummaryrefslogtreecommitdiffhomepage
path: root/internal
diff options
context:
space:
mode:
authorOphestra <cat@gensokyo.uk>2026-03-05 20:55:45 +0900
committerOphestra <cat@gensokyo.uk>2026-03-05 20:57:05 +0900
commita36b3ece165ab1008141a1a8b927776e77122068 (patch)
treeedc6fcfc22006383660aa8626d4d495e784b28e4 /internal
parent75970a5650808feaaee2fb4d77aad14756349755 (diff)
internal/rosa: release monitoring via Anitya
This is much more sustainable than manual package flagging. Signed-off-by: Ophestra <cat@gensokyo.uk>
Diffstat (limited to 'internal')
-rw-r--r--internal/rosa/all.go51
1 files changed, 51 insertions, 0 deletions
diff --git a/internal/rosa/all.go b/internal/rosa/all.go
index 8b2aec14..da1e3655 100644
--- a/internal/rosa/all.go
+++ b/internal/rosa/all.go
@@ -1,6 +1,11 @@
package rosa
import (
+ "context"
+ "encoding/json"
+ "errors"
+ "net/http"
+ "strconv"
"sync"
"hakurei.app/internal/pkg"
@@ -152,11 +157,57 @@ type Metadata struct {
Description string `json:"description"`
// Project home page.
Website string `json:"website,omitempty"`
+
+ // Project identifier on [Anitya].
+ //
+ // [Anitya]: https://release-monitoring.org/
+ ID int `json:"-"`
}
// Unversioned denotes an unversioned [PArtifact].
const Unversioned = "\x00"
+// UnpopulatedIDError is returned by [Metadata.GetLatest] for an instance of
+// [Metadata] where ID is not populated.
+type UnpopulatedIDError struct{}
+
+func (UnpopulatedIDError) Unwrap() error { return errors.ErrUnsupported }
+func (UnpopulatedIDError) Error() string { return "Anitya ID is not populated" }
+
+// Versions are package versions returned by Anitya.
+type Versions struct {
+ // The latest version for the project, as determined by the version sorting algorithm.
+ Latest string `json:"latest_version"`
+ // List of all versions that aren’t flagged as pre-release.
+ Stable []string `json:"stable_versions"`
+ // List of all versions stored, sorted from newest to oldest.
+ All []string `json:"versions"`
+}
+
+// GetVersions returns versions fetched from Anitya.
+func (meta *Metadata) GetVersions(ctx context.Context) (*Versions, error) {
+ if meta.ID == 0 {
+ return nil, UnpopulatedIDError{}
+ }
+
+ var resp *http.Response
+ if req, err := http.NewRequestWithContext(
+ ctx,
+ http.MethodGet,
+ "https://release-monitoring.org/api/v2/versions/?project_id="+
+ strconv.Itoa(meta.ID),
+ nil,
+ ); err != nil {
+ return nil, err
+ } else if resp, err = http.DefaultClient.Do(req); err != nil {
+ return nil, err
+ }
+
+ var v Versions
+ err := json.NewDecoder(resp.Body).Decode(&v)
+ return &v, errors.Join(err, resp.Body.Close())
+}
+
var (
// artifactsM is an array of [PArtifact] metadata.
artifactsM [PresetEnd]Metadata