mvoe ID generation logic to helper function

This commit is contained in:
Amolith 2023-12-20 14:18:12 -05:00
parent 54c05b42c9
commit 89f122b75b
Signed by: Amolith
SSH Key Fingerprint: SHA256:JBKEeoO/72Fz03rtlzeO49PATFT2maMancH3opcT0h0
1 changed files with 6 additions and 2 deletions

View File

@ -115,8 +115,7 @@ func SortReleases(releases []Release) []Release {
func upsert(dbConn *sql.DB, url string, releases []Release) error {
for _, release := range releases {
date := release.Date.Format("2006-01-02 15:04:05")
idByte := sha256.Sum256([]byte(url + release.URL + release.Tag + date))
id := fmt.Sprintf("%x", idByte)
id := genReleaseID(url, release.URL, release.Tag)
err := db.UpsertRelease(dbConn, id, url, release.URL, release.Tag, release.Content, date)
if err != nil {
log.Printf("Error upserting release: %v", err)
@ -126,6 +125,11 @@ func upsert(dbConn *sql.DB, url string, releases []Release) error {
return nil
}
func genReleaseID(projectURL, releaseURL, tag string) string {
idByte := sha256.Sum256([]byte(projectURL + releaseURL + tag))
return fmt.Sprintf("%x", idByte)
}
func Track(dbConn *sql.DB, manualRefresh *chan struct{}, name, url, forge, release string) {
err := db.UpsertProject(dbConn, url, name, forge, release)
if err != nil {