From 6f0e6ea3caa932c6902e15399d9c71bc32dee5e9 Mon Sep 17 00:00:00 2001 From: Ed Date: Tue, 18 Dec 2018 12:56:09 -0500 Subject: [PATCH] Add SHA to versions --- README.md | 6 ++++-- check_command.go | 18 ++++++++---------- in_command.go | 2 +- out_command.go | 2 +- resources.go | 2 +- versions.go | 9 +++++++++ 6 files changed, 24 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 025acd8..70e3168 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,10 @@ # 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 diff --git a/check_command.go b/check_command.go index e6db930..14d6814 100644 --- a/check_command.go +++ b/check_command.go @@ -74,9 +74,7 @@ func (c *CheckCommand) Run(request CheckRequest) ([]Version, error) { latestTag := filteredTags[len(filteredTags)-1] if (request.Version == Version{}) { - return []Version{ - Version{Tag: latestTag.Name}, - }, nil + return []Version{versionFromTag(latestTag)}, nil } 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 // but documentation says to return current item? // https://concourse-ci.org/implementing-resources.html#section_resource-check - return []Version{Version{Tag: latestTag.Name}}, nil + return []Version{versionFromTag(latestTag)}, nil } upToLatest := false - reversedVersions := []Version{} + nextVersions := []Version{} // contains the requested version and all newer ones for _, release := range filteredTags { if !upToLatest { @@ -97,17 +95,17 @@ func (c *CheckCommand) Run(request CheckRequest) ([]Version, error) { } if upToLatest { - reversedVersions = append(reversedVersions, Version{Tag: release.Name}) + nextVersions = append(nextVersions, Version{Tag: release.Name}) } } if !upToLatest { // current version was removed; start over from latest - reversedVersions = append( - reversedVersions, - Version{Tag: filteredTags[len(filteredTags)-1].Name}, + nextVersions = append( + nextVersions, + versionFromTag(filteredTags[len(filteredTags)-1]), ) } - return reversedVersions, nil + return nextVersions, nil } diff --git a/in_command.go b/in_command.go index 3c46d22..622204c 100644 --- a/in_command.go +++ b/in_command.go @@ -115,7 +115,7 @@ func (c *InCommand) Run(destDir string, request InRequest) (InResponse, error) { } return InResponse{ - Version: Version{Tag: foundTag.Name}, + Version: versionFromTag(foundTag), Metadata: metadataFromTag(foundTag), }, nil } diff --git a/out_command.go b/out_command.go index c3c80a9..eec0c60 100644 --- a/out_command.go +++ b/out_command.go @@ -99,7 +99,7 @@ func (c *OutCommand) Run(sourceDir string, request OutRequest) (OutResponse, err } return OutResponse{ - Version: Version{Tag: tag_name}, + Version: versionFromTag(tag), Metadata: metadataFromTag(tag), }, nil } diff --git a/resources.go b/resources.go index 0ed1ef4..435030c 100644 --- a/resources.go +++ b/resources.go @@ -69,7 +69,7 @@ type OutResponse struct { type Version struct { Tag string `json:"tag,omitempty"` - Commitish string `json:"commitish,omitempty"` + CommitSHA string `json:"commit_sha,omitempty"` } type MetadataPair struct { diff --git a/versions.go b/versions.go index e4fa1b9..4568195 100644 --- a/versions.go +++ b/versions.go @@ -2,6 +2,8 @@ package resource import ( "regexp" + + "github.com/xanzy/go-gitlab" ) var defaultTagFilter = "^v?([^v].*)" @@ -28,3 +30,10 @@ func (vp *versionParser) parse(tag string) string { } return "" } + +func versionFromTag(tag *gitlab.Tag) Version { + return Version{ + Tag: tag.Name, + CommitSHA: tag.Commit.ID, + } +}