Sort projects alphabetically

This commit is contained in:
Amolith 2024-02-24 10:08:13 -05:00
parent 753b2acf2c
commit ecd3635be7
Signed by: Amolith
SSH Key Fingerprint: SHA256:JBKEeoO/72Fz03rtlzeO49PATFT2maMancH3opcT0h0
1 changed files with 9 additions and 2 deletions

View File

@ -130,6 +130,13 @@ func SortReleases(releases []Release) []Release {
return releases return releases
} }
func SortProjects(projects []Project) []Project {
sort.Slice(projects, func(i, j int) bool {
return strings.ToLower(projects[i].Name) < strings.ToLower(projects[j].Name)
})
return projects
}
// upsertReleases updates or inserts a release in the database // upsertReleases updates or inserts a release in the database
func upsertReleases(dbConn *sql.DB, mu *sync.Mutex, projID string, releases []Release) error { func upsertReleases(dbConn *sql.DB, mu *sync.Mutex, projID string, releases []Release) error {
for _, release := range releases { for _, release := range releases {
@ -268,7 +275,7 @@ func GetProjects(dbConn *sql.DB) ([]Project, error) {
} }
} }
return projects, nil return SortProjects(projects), nil
} }
// GetProjectsWithReleases returns a list of all projects and all their releases // GetProjectsWithReleases returns a list of all projects and all their releases
@ -287,5 +294,5 @@ func GetProjectsWithReleases(dbConn *sql.DB, mu *sync.Mutex) ([]Project, error)
projects[i].Releases = SortReleases(projects[i].Releases) projects[i].Releases = SortReleases(projects[i].Releases)
} }
return projects, nil return SortProjects(projects), nil
} }