Implement cache migrations

This commit is contained in:
2024-12-31 20:12:02 -05:00
parent 30d86d72ed
commit 2f0e1b0d46
3 changed files with 60 additions and 18 deletions

View File

@ -9,6 +9,8 @@ import (
"github.com/go-git/go-git/v5"
)
// Git project metadata
// Do not use Project.ID directly (remotes may conflict), use Project.GetID()
type Project struct {
ID int
Description string
@ -44,19 +46,30 @@ func (pl *ProjectLanguages) AddLanguage(lang *ProjectLanguage) {
*pl = append(*pl, lang)
}
// Gets a unique ID using a short-sha of the http repo URL
// Gets a unique ID using a short-sha of the http repo
// along with the numerical ID of the project.
// Uses SSH URL and then Remote if previous is empty
func (p *Project) GetID() string {
shaText := p.HTTPURLToRepo
if shaText == "" && p.SSHURLToRepo != "" {
shaText = p.SSHURLToRepo
} else if shaText == "" {
shaText = p.Remote
return fmt.Sprintf("%s||%d", p.GetRemoteSha(), p.ID)
}
func MakeID(remote string, projectID int) string {
return fmt.Sprintf("%s||%d", GetRemoteSha(remote), projectID)
}
func (p *Project) GetRemoteSha() string {
remote := p.Remote
if remote == "" && p.HTTPURLToRepo != "" {
remote = p.HTTPURLToRepo
} else if remote == "" && p.WebURL != "" {
remote = p.WebURL
}
shortSha := fmt.Sprintf("%x", sha1.Sum([]byte(shaText)))[:12]
return fmt.Sprintf("%s||%d", shortSha, p.ID)
return GetRemoteSha(remote)
}
func GetRemoteSha(remote string) string {
return fmt.Sprintf("%x", sha1.Sum([]byte(remote)))[:12]
}
func (p *Project) String() string {