mirror of
https://github.com/edgelesssys/constellation.git
synced 2024-12-25 07:29:38 -05:00
pseudo-version: allow tags that are only references
This commit is contained in:
parent
cce2611e2a
commit
d1d24ca587
@ -11,7 +11,10 @@ import (
|
|||||||
"github.com/go-git/go-git/v5/plumbing/storer"
|
"github.com/go-git/go-git/v5/plumbing/storer"
|
||||||
)
|
)
|
||||||
|
|
||||||
var versionRegex = regexp.MustCompile(`^v\d+\.\d+\.\d+$`)
|
var (
|
||||||
|
versionRegex = regexp.MustCompile(`^v\d+\.\d+\.\d+$`)
|
||||||
|
tagReference = regexp.MustCompile(`^refs/tags/([^/]+)$`)
|
||||||
|
)
|
||||||
|
|
||||||
type Git struct {
|
type Git struct {
|
||||||
repo *git.Repository
|
repo *git.Repository
|
||||||
@ -87,19 +90,24 @@ func (g *Git) tagsByRevisionHash() (map[string][]string, error) {
|
|||||||
switch err {
|
switch err {
|
||||||
case nil:
|
case nil:
|
||||||
// Tag object present
|
// Tag object present
|
||||||
case plumbing.ErrObjectNotFound:
|
|
||||||
// Not a tag object
|
|
||||||
return nil
|
|
||||||
default:
|
|
||||||
// Some other error
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
commit, err := tag.Commit()
|
commit, err := tag.Commit()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
commitHash := commit.Hash.String()
|
commitHash := commit.Hash.String()
|
||||||
tags[commitHash] = append(tags[commitHash], tag.Name)
|
tags[commitHash] = append(tags[commitHash], tag.Name)
|
||||||
|
case plumbing.ErrObjectNotFound:
|
||||||
|
// Not a tag object
|
||||||
|
message, err := tagRefToMessage(ref)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
tags[ref.Hash().String()] = append(tags[ref.Hash().String()], message)
|
||||||
|
default:
|
||||||
|
// Some other error
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
); err != nil {
|
); err != nil {
|
||||||
@ -117,3 +125,11 @@ func (g *Git) findVersionTag(tags []string) *string {
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func tagRefToMessage(tagRef *plumbing.Reference) (string, error) {
|
||||||
|
matches := tagReference.FindStringSubmatch(tagRef.Name().String())
|
||||||
|
if len(matches) != 2 {
|
||||||
|
return "", errors.New("invalid tag reference")
|
||||||
|
}
|
||||||
|
return matches[1], nil
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user