Add SHA to versions

This commit is contained in:
Ed
2018-12-18 12:56:09 -05:00
parent b747989d43
commit 6f0e6ea3ca
6 changed files with 24 additions and 15 deletions

View File

@@ -1,8 +1,10 @@
# GitLab Releases Resource # GitLab Releases Resource
Fetches and creates versioned GitLab resources. GitLab resources are metadata attached to tags. Fetches and creates versioned GitLab resources. GitLab resources are metadata attached to tags. Note that `check` will skip tags that do not have associated resources.
Note that this is still in development, and is still undergoing changes. It may or may not work properly at the moment, but should hopefully somewhat more stable soon. Note that this is still in development, and is still undergoing changes. It may or may not work properly at the moment, but should hopefully be somewhat more stable soon.
You may want to clean up your uploads folder over time if you re-run a put step with the same inputs, as this will simply re-upload the files under a new hash.
## Source Configuration ## Source Configuration

View File

@@ -74,9 +74,7 @@ func (c *CheckCommand) Run(request CheckRequest) ([]Version, error) {
latestTag := filteredTags[len(filteredTags)-1] latestTag := filteredTags[len(filteredTags)-1]
if (request.Version == Version{}) { if (request.Version == Version{}) {
return []Version{ return []Version{versionFromTag(latestTag)}, nil
Version{Tag: latestTag.Name},
}, nil
} }
if latestTag.Name == request.Version.Tag { if latestTag.Name == request.Version.Tag {
@@ -84,11 +82,11 @@ func (c *CheckCommand) Run(request CheckRequest) ([]Version, error) {
// https://github.com/concourse/github-release-resource/blob/master/check_command.go#L87 // https://github.com/concourse/github-release-resource/blob/master/check_command.go#L87
// but documentation says to return current item? // but documentation says to return current item?
// https://concourse-ci.org/implementing-resources.html#section_resource-check // https://concourse-ci.org/implementing-resources.html#section_resource-check
return []Version{Version{Tag: latestTag.Name}}, nil return []Version{versionFromTag(latestTag)}, nil
} }
upToLatest := false upToLatest := false
reversedVersions := []Version{} nextVersions := []Version{} // contains the requested version and all newer ones
for _, release := range filteredTags { for _, release := range filteredTags {
if !upToLatest { if !upToLatest {
@@ -97,17 +95,17 @@ func (c *CheckCommand) Run(request CheckRequest) ([]Version, error) {
} }
if upToLatest { if upToLatest {
reversedVersions = append(reversedVersions, Version{Tag: release.Name}) nextVersions = append(nextVersions, Version{Tag: release.Name})
} }
} }
if !upToLatest { if !upToLatest {
// current version was removed; start over from latest // current version was removed; start over from latest
reversedVersions = append( nextVersions = append(
reversedVersions, nextVersions,
Version{Tag: filteredTags[len(filteredTags)-1].Name}, versionFromTag(filteredTags[len(filteredTags)-1]),
) )
} }
return reversedVersions, nil return nextVersions, nil
} }

View File

@@ -115,7 +115,7 @@ func (c *InCommand) Run(destDir string, request InRequest) (InResponse, error) {
} }
return InResponse{ return InResponse{
Version: Version{Tag: foundTag.Name}, Version: versionFromTag(foundTag),
Metadata: metadataFromTag(foundTag), Metadata: metadataFromTag(foundTag),
}, nil }, nil
} }

View File

@@ -99,7 +99,7 @@ func (c *OutCommand) Run(sourceDir string, request OutRequest) (OutResponse, err
} }
return OutResponse{ return OutResponse{
Version: Version{Tag: tag_name}, Version: versionFromTag(tag),
Metadata: metadataFromTag(tag), Metadata: metadataFromTag(tag),
}, nil }, nil
} }

View File

@@ -69,7 +69,7 @@ type OutResponse struct {
type Version struct { type Version struct {
Tag string `json:"tag,omitempty"` Tag string `json:"tag,omitempty"`
Commitish string `json:"commitish,omitempty"` CommitSHA string `json:"commit_sha,omitempty"`
} }
type MetadataPair struct { type MetadataPair struct {

View File

@@ -2,6 +2,8 @@ package resource
import ( import (
"regexp" "regexp"
"github.com/xanzy/go-gitlab"
) )
var defaultTagFilter = "^v?([^v].*)" var defaultTagFilter = "^v?([^v].*)"
@@ -28,3 +30,10 @@ func (vp *versionParser) parse(tag string) string {
} }
return "" return ""
} }
func versionFromTag(tag *gitlab.Tag) Version {
return Version{
Tag: tag.Name,
CommitSHA: tag.Commit.ID,
}
}