Use FlexVer to sort by tag instead of date

Implements: https://todo.sr.ht/~amolith/willow/24
This commit is contained in:
Amolith 2023-11-28 19:19:14 -05:00
parent b2c5dbed1c
commit b1af277fa8
Signed by: Amolith
GPG Key ID: 8AE30347CE28D101
4 changed files with 14 additions and 9 deletions

View File

@ -10,7 +10,6 @@ import (
"io" "io"
"net/url" "net/url"
"os" "os"
"sort"
"strings" "strings"
"time" "time"
@ -104,8 +103,6 @@ func GetReleases(gitURI, forge string) ([]Release, error) {
return nil, err return nil, err
} }
sort.Slice(releases, func(i, j int) bool { return releases[i].Date.After(releases[j].Date) })
return releases, nil return releases, nil
} }

1
go.mod
View File

@ -48,6 +48,7 @@ require (
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
github.com/sergi/go-diff v1.3.1 // indirect github.com/sergi/go-diff v1.3.1 // indirect
github.com/skeema/knownhosts v1.2.1 // indirect github.com/skeema/knownhosts v1.2.1 // indirect
github.com/unascribed/FlexVer/go/flexver v1.0.0 // indirect
github.com/xanzy/ssh-agent v0.3.3 // indirect github.com/xanzy/ssh-agent v0.3.3 // indirect
golang.org/x/mod v0.14.0 // indirect golang.org/x/mod v0.14.0 // indirect
golang.org/x/net v0.19.0 // indirect golang.org/x/net v0.19.0 // indirect

2
go.sum
View File

@ -118,6 +118,8 @@ github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UV
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk= github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/unascribed/FlexVer/go/flexver v1.0.0 h1:eaAAWwaT8TiGK75wfEgQRPRVJc1ZIiLTLGUKXxpcs0c=
github.com/unascribed/FlexVer/go/flexver v1.0.0/go.mod h1:OkWZGfmV3DV2ADlgoS7W1+dD1OOci4mEracZCi3ulBk=
github.com/xanzy/ssh-agent v0.3.3 h1:+/15pJfg/RsTxqYcX6fHqOXZwwMP+2VyYWJeWM2qQFM= github.com/xanzy/ssh-agent v0.3.3 h1:+/15pJfg/RsTxqYcX6fHqOXZwwMP+2VyYWJeWM2qQFM=
github.com/xanzy/ssh-agent v0.3.3/go.mod h1:6dzNDKs0J9rVPHPhaGCukekBHKqfl+L3KghI1Bc68Uw= github.com/xanzy/ssh-agent v0.3.3/go.mod h1:6dzNDKs0J9rVPHPhaGCukekBHKqfl+L3KghI1Bc68Uw=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=

View File

@ -13,6 +13,8 @@ import (
"strings" "strings"
"time" "time"
"github.com/unascribed/FlexVer/go/flexver"
"git.sr.ht/~amolith/willow/db" "git.sr.ht/~amolith/willow/db"
"git.sr.ht/~amolith/willow/git" "git.sr.ht/~amolith/willow/git"
"git.sr.ht/~amolith/willow/rss" "git.sr.ht/~amolith/willow/rss"
@ -52,9 +54,7 @@ func GetReleases(dbConn *sql.DB, proj Project) (Project, error) {
Date: time.Time{}, Date: time.Time{},
}) })
} }
sort.Slice(proj.Releases, func(i, j int) bool { proj.Releases = SortReleases(proj.Releases)
return proj.Releases[i].Date.After(proj.Releases[j].Date)
})
return proj, nil return proj, nil
} }
@ -100,12 +100,17 @@ func fetchReleases(dbConn *sql.DB, p Project) (Project, error) {
} }
} }
} }
sort.Slice(p.Releases, func(i, j int) bool { p.Releases = SortReleases(p.Releases)
return p.Releases[i].Date.After(p.Releases[j].Date)
})
return p, err return p, err
} }
func SortReleases(releases []Release) []Release {
sort.Slice(releases, func(i, j int) bool {
return !flexver.Less(releases[i].Tag, releases[j].Tag)
})
return releases
}
// upsert updates or inserts a project release into the database // upsert updates or inserts a project release into the database
func upsert(dbConn *sql.DB, url string, releases []Release) error { func upsert(dbConn *sql.DB, url string, releases []Release) error {
for _, release := range releases { for _, release := range releases {