Begin move to project/alias by unique ID

This commit is contained in:
2024-12-30 16:42:45 -05:00
parent 11a2ca434c
commit 70027a9880
7 changed files with 51 additions and 25 deletions

View File

@ -1,6 +1,7 @@
package projects
import (
"crypto/sha1"
"fmt"
"strings"
"time"
@ -35,8 +36,7 @@ type ProjectLanguage struct {
}
func NewProjectLanguages() *ProjectLanguages {
var pLangs ProjectLanguages
pLangs = make([]*ProjectLanguage, 0)
var pLangs ProjectLanguages = make([]*ProjectLanguage, 0)
return &pLangs
}
@ -44,6 +44,21 @@ func (pl *ProjectLanguages) AddLanguage(lang *ProjectLanguage) {
*pl = append(*pl, lang)
}
// Gets a unique ID using a short-sha of the http repo URL
// 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
}
shortSha := fmt.Sprintf("%x", sha1.Sum([]byte(shaText)))[:12]
return fmt.Sprintf("%s||%d", shortSha, p.ID)
}
func (p *Project) String() string {
var projectString string
if p != nil {

View File

@ -20,9 +20,7 @@ const (
GitProtoHTTP
)
var (
ErrUnknownHost error = errors.New("No addresses found for host")
)
var ErrUnknownHost error = errors.New("no addresses found for host")
func (p *Project) CheckHost(proto GitProto) error {
switch proto {
@ -31,7 +29,7 @@ func (p *Project) CheckHost(proto GitProto) error {
case GitProtoSSH:
return p.checkSSHRemote()
}
return errors.New("Unknown git protocol")
return errors.New("unknown git protocol")
}
func (p *Project) checkHTTPRemote() error {