Skip to content

Commit

Permalink
Merge pull request #115 from concourse/in-timestamp
Browse files Browse the repository at this point in the history
Create `timestamp` file on `in` operations
  • Loading branch information
chenbh authored Jan 20, 2022
2 parents 5fcc3a5 + 8a18a40 commit 3aded06
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 13 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ Also creates the following files:
* `tag` containing the git tag name of the release being fetched.
* `version` containing the version determined by the git tag of the release being fetched.
* `body` containing the body text of the release.
* `timestamp` containing the publish or creation timestamp for the release in RFC 3339 format.
* `commit_sha` containing the commit SHA the tag is pointing to.
* `url` containing the HTMLURL for the release being fetched.

Expand Down
15 changes: 14 additions & 1 deletion in_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ package resource
import (
"errors"
"fmt"
"github.com/google/go-github/v39/github"
"io"
"io/ioutil"
"net/http"
"os"
"path/filepath"
"strconv"

"github.com/google/go-github/v39/github"
)

type InCommand struct {
Expand Down Expand Up @@ -95,6 +96,18 @@ func (c *InCommand) Run(destDir string, request InRequest) (InResponse, error) {
return InResponse{}, err
}
}

if foundRelease.PublishedAt != nil || foundRelease.CreatedAt != nil {
timestampPath := filepath.Join(destDir, "timestamp")
timestamp, err := getTimestamp(foundRelease).MarshalText()
if err != nil {
return InResponse{}, err
}
err = ioutil.WriteFile(timestampPath, timestamp, 0644)
if err != nil {
return InResponse{}, err
}
}
}

assets, err := c.github.ListReleaseAssets(*foundRelease)
Expand Down
31 changes: 19 additions & 12 deletions in_command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,15 @@ var _ = Describe("In Command", func() {

buildRelease := func(id int64, tag string, draft bool) *github.RepositoryRelease {
return &github.RepositoryRelease{
ID: github.Int64(id),
TagName: github.String(tag),
HTMLURL: github.String("http://google.com"),
Name: github.String("release-name"),
Body: github.String("*markdown*"),
Draft: github.Bool(draft),
Prerelease: github.Bool(false),
ID: github.Int64(id),
TagName: github.String(tag),
HTMLURL: github.String("http://google.com"),
Name: github.String("release-name"),
Body: github.String("*markdown*"),
CreatedAt: &github.Timestamp{Time: exampleTimeStamp(1)},
PublishedAt: &github.Timestamp{Time: exampleTimeStamp(1)},
Draft: github.Bool(draft),
Prerelease: github.Bool(false),
}
}

Expand All @@ -74,6 +76,7 @@ var _ = Describe("In Command", func() {
HTMLURL: github.String("http://google.com"),
Name: github.String("release-name"),
Body: github.String("*markdown*"),
CreatedAt: &github.Timestamp{Time: exampleTimeStamp(1)},
Draft: github.Bool(true),
Prerelease: github.Bool(false),
}
Expand Down Expand Up @@ -120,7 +123,7 @@ var _ = Describe("In Command", func() {
It("returns the fetched version", func() {
inResponse, inErr = command.Run(destDir, inRequest)

Ω(inResponse.Version).Should(Equal(resource.Version{ID: "1", Tag: "v0.35.0"}))
Ω(inResponse.Version).Should(Equal(newVersionWithTimestamp(1, "v0.35.0", 1)))
})

It("has some sweet metadata", func() {
Expand Down Expand Up @@ -168,6 +171,10 @@ var _ = Describe("In Command", func() {
Ω(err).ShouldNot(HaveOccurred())
Ω(string(contents)).Should(Equal("*markdown*"))

contents, err = ioutil.ReadFile(path.Join(destDir, "timestamp"))
Ω(err).ShouldNot(HaveOccurred())
Ω(string(contents)).Should(Equal("2018-01-01T00:00:00Z"))

contents, err = ioutil.ReadFile(path.Join(destDir, "url"))
Ω(err).ShouldNot(HaveOccurred())
Ω(string(contents)).Should(Equal("http://google.com"))
Expand Down Expand Up @@ -378,7 +385,7 @@ var _ = Describe("In Command", func() {
})

It("returns the fetched version", func() {
Ω(inResponse.Version).Should(Equal(resource.Version{ID: "1", Tag: "v0.35.0"}))
Ω(inResponse.Version).Should(Equal(newVersionWithTimestamp(1, "v0.35.0", 1)))
})

It("has some sweet metadata", func() {
Expand Down Expand Up @@ -471,7 +478,7 @@ var _ = Describe("In Command", func() {
})

It("returns the fetched version", func() {
Ω(inResponse.Version).Should(Equal(resource.Version{ID: "1", Tag: "v0.35.0"}))
Ω(inResponse.Version).Should(Equal(newVersionWithTimestamp(1, "v0.35.0", 1)))
})

It("has some sweet metadata", func() {
Expand Down Expand Up @@ -512,7 +519,7 @@ var _ = Describe("In Command", func() {
})

It("returns the fetched version", func() {
Ω(inResponse.Version).Should(Equal(resource.Version{ID: "1"}))
Ω(inResponse.Version).Should(Equal(newVersionWithTimestamp(1, "", 1)))
})

It("has some sweet metadata", func() {
Expand Down Expand Up @@ -551,7 +558,7 @@ var _ = Describe("In Command", func() {
})

It("returns the fetched version", func() {
Ω(inResponse.Version).Should(Equal(resource.Version{ID: "1"}))
Ω(inResponse.Version).Should(Equal(newVersionWithTimestamp(1, "", 1)))
})

It("has some sweet metadata", func() {
Expand Down

0 comments on commit 3aded06

Please sign in to comment.