Use FlexVer to sort by tag instead of date
Implements: https://todo.sr.ht/~amolith/willow/24
This commit is contained in:
		
							parent
							
								
									b2c5dbed1c
								
							
						
					
					
						commit
						b1af277fa8
					
				| 
						 | 
				
			
			@ -10,7 +10,6 @@ import (
 | 
			
		|||
	"io"
 | 
			
		||||
	"net/url"
 | 
			
		||||
	"os"
 | 
			
		||||
	"sort"
 | 
			
		||||
	"strings"
 | 
			
		||||
	"time"
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -104,8 +103,6 @@ func GetReleases(gitURI, forge string) ([]Release, error) {
 | 
			
		|||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	sort.Slice(releases, func(i, j int) bool { return releases[i].Date.After(releases[j].Date) })
 | 
			
		||||
 | 
			
		||||
	return releases, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										1
									
								
								go.mod
								
								
								
								
							
							
						
						
									
										1
									
								
								go.mod
								
								
								
								
							| 
						 | 
				
			
			@ -48,6 +48,7 @@ require (
 | 
			
		|||
	github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
 | 
			
		||||
	github.com/sergi/go-diff v1.3.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
 | 
			
		||||
	golang.org/x/mod v0.14.0 // indirect
 | 
			
		||||
	golang.org/x/net v0.19.0 // indirect
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										2
									
								
								go.sum
								
								
								
								
							
							
						
						
									
										2
									
								
								go.sum
								
								
								
								
							| 
						 | 
				
			
			@ -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.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
 | 
			
		||||
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/go.mod h1:6dzNDKs0J9rVPHPhaGCukekBHKqfl+L3KghI1Bc68Uw=
 | 
			
		||||
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -13,6 +13,8 @@ import (
 | 
			
		|||
	"strings"
 | 
			
		||||
	"time"
 | 
			
		||||
 | 
			
		||||
	"github.com/unascribed/FlexVer/go/flexver"
 | 
			
		||||
 | 
			
		||||
	"git.sr.ht/~amolith/willow/db"
 | 
			
		||||
	"git.sr.ht/~amolith/willow/git"
 | 
			
		||||
	"git.sr.ht/~amolith/willow/rss"
 | 
			
		||||
| 
						 | 
				
			
			@ -52,9 +54,7 @@ func GetReleases(dbConn *sql.DB, proj Project) (Project, error) {
 | 
			
		|||
			Date:    time.Time{},
 | 
			
		||||
		})
 | 
			
		||||
	}
 | 
			
		||||
	sort.Slice(proj.Releases, func(i, j int) bool {
 | 
			
		||||
		return proj.Releases[i].Date.After(proj.Releases[j].Date)
 | 
			
		||||
	})
 | 
			
		||||
	proj.Releases = SortReleases(proj.Releases)
 | 
			
		||||
	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 {
 | 
			
		||||
		return p.Releases[i].Date.After(p.Releases[j].Date)
 | 
			
		||||
	})
 | 
			
		||||
	p.Releases = SortReleases(p.Releases)
 | 
			
		||||
	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
 | 
			
		||||
func upsert(dbConn *sql.DB, url string, releases []Release) error {
 | 
			
		||||
	for _, release := range releases {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue