diff options
| author | Ophestra <cat@gensokyo.uk> | 2026-03-12 23:14:12 +0900 |
|---|---|---|
| committer | Ophestra <cat@gensokyo.uk> | 2026-03-13 10:31:14 +0900 |
| commit | 0130f8ea6d88b451ac218f97b07d10eb11ee2f71 (patch) | |
| tree | 6f2af99c25030c6b4ea3a116fc060bb47d115547 /internal/rosa/all.go | |
| parent | faac5c4a839e81323760a9a6cd09407f769eef10 (diff) | |
internal/rosa: represent runtime dependencies
This also resolves indirect dependencies, reducing noise.
Signed-off-by: Ophestra <cat@gensokyo.uk>
Diffstat (limited to 'internal/rosa/all.go')
| -rw-r--r-- | internal/rosa/all.go | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/internal/rosa/all.go b/internal/rosa/all.go index d1116e88..49f0ada6 100644 --- a/internal/rosa/all.go +++ b/internal/rosa/all.go @@ -4,6 +4,7 @@ import ( "context" "encoding/json" "errors" + "fmt" "net/http" "strconv" "sync" @@ -167,6 +168,36 @@ const ( PresetEnd ) +// P represents multiple [PArtifact] and is stable through JSON. +type P []PArtifact + +// MarshalJSON represents [PArtifact] by their [Metadata.Name]. +func (s P) MarshalJSON() ([]byte, error) { + names := make([]string, len(s)) + for i, p := range s { + names[i] = GetMetadata(p).Name + } + return json.Marshal(names) +} + +// UnmarshalJSON resolves the value created by MarshalJSON back to [P]. +func (s *P) UnmarshalJSON(data []byte) error { + var names []string + if err := json.Unmarshal(data, &names); err != nil { + return err + } + + *s = make(P, len(names)) + for i, name := range names { + if p, ok := ResolveName(name); !ok { + return fmt.Errorf("unknown artifact %q", name) + } else { + (*s)[i] = p + } + } + return nil +} + // Metadata is stage-agnostic information of a [PArtifact] not directly // representable in the resulting [pkg.Artifact]. type Metadata struct { @@ -179,6 +210,9 @@ type Metadata struct { // Project home page. Website string `json:"website,omitempty"` + // Runtime dependencies. + Dependencies P `json:"dependencies"` + // Project identifier on [Anitya]. // // [Anitya]: https://release-monitoring.org/ |
