emit metadata in output
[#76848252] Signed-off-by: Chris Brown <cbrown@pivotal.io>
This commit is contained in:
@@ -94,11 +94,7 @@ func (c *InCommand) Run(destDir string, request InRequest) (InResponse, error) {
|
|||||||
Version: Version{
|
Version: Version{
|
||||||
Tag: *foundRelease.TagName,
|
Tag: *foundRelease.TagName,
|
||||||
},
|
},
|
||||||
Metadata: []MetadataPair{
|
Metadata: metadataFromRelease(foundRelease),
|
||||||
{Name: "name", Value: *foundRelease.Name, URL: *foundRelease.HTMLURL},
|
|
||||||
{Name: "url", Value: *foundRelease.HTMLURL},
|
|
||||||
{Name: "body", Value: *foundRelease.Body, Markdown: true},
|
|
||||||
},
|
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -55,25 +55,19 @@ var _ = Describe("In Command", func() {
|
|||||||
})
|
})
|
||||||
|
|
||||||
buildRelease := func(id int, tag string) github.RepositoryRelease {
|
buildRelease := func(id int, tag string) github.RepositoryRelease {
|
||||||
url := "http://google.com"
|
|
||||||
name := "release-name"
|
|
||||||
body := "*markdown*"
|
|
||||||
|
|
||||||
return github.RepositoryRelease{
|
return github.RepositoryRelease{
|
||||||
ID: &id,
|
ID: github.Int(id),
|
||||||
TagName: &tag,
|
TagName: github.String(tag),
|
||||||
HTMLURL: &url,
|
HTMLURL: github.String("http://google.com"),
|
||||||
Name: &name,
|
Name: github.String("release-name"),
|
||||||
Body: &body,
|
Body: github.String("*markdown*"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
buildAsset := func(name string) github.ReleaseAsset {
|
buildAsset := func(name string) github.ReleaseAsset {
|
||||||
url := server.URL() + "/" + name
|
|
||||||
|
|
||||||
return github.ReleaseAsset{
|
return github.ReleaseAsset{
|
||||||
Name: &name,
|
Name: &name,
|
||||||
BrowserDownloadURL: &url,
|
BrowserDownloadURL: github.String(server.URL() + "/" + name),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -158,6 +152,14 @@ var _ = Describe("In Command", func() {
|
|||||||
Ω(inResponse.Version).Should(Equal(resource.Version{Tag: "v0.35.0"}))
|
Ω(inResponse.Version).Should(Equal(resource.Version{Tag: "v0.35.0"}))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
It("has some sweet metadata", func() {
|
||||||
|
Ω(inResponse.Metadata).Should(ConsistOf(
|
||||||
|
resource.MetadataPair{Name: "url", Value: "http://google.com"},
|
||||||
|
resource.MetadataPair{Name: "name", Value: "release-name", URL: "http://google.com"},
|
||||||
|
resource.MetadataPair{Name: "body", Value: "*markdown*", Markdown: true},
|
||||||
|
))
|
||||||
|
})
|
||||||
|
|
||||||
It("downloads all of the files", func() {
|
It("downloads all of the files", func() {
|
||||||
_, err := os.Stat(filepath.Join(destDir, "example.txt"))
|
_, err := os.Stat(filepath.Join(destDir, "example.txt"))
|
||||||
Ω(err).ShouldNot(HaveOccurred())
|
Ω(err).ShouldNot(HaveOccurred())
|
||||||
@@ -196,6 +198,14 @@ var _ = Describe("In Command", func() {
|
|||||||
Ω(inResponse.Version).Should(Equal(resource.Version{Tag: "v0.35.0"}))
|
Ω(inResponse.Version).Should(Equal(resource.Version{Tag: "v0.35.0"}))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
It("has some sweet metadata", func() {
|
||||||
|
Ω(inResponse.Metadata).Should(ConsistOf(
|
||||||
|
resource.MetadataPair{Name: "url", Value: "http://google.com"},
|
||||||
|
resource.MetadataPair{Name: "name", Value: "release-name", URL: "http://google.com"},
|
||||||
|
resource.MetadataPair{Name: "body", Value: "*markdown*", Markdown: true},
|
||||||
|
))
|
||||||
|
})
|
||||||
|
|
||||||
It("fetches from the latest release", func() {
|
It("fetches from the latest release", func() {
|
||||||
_, err := os.Stat(filepath.Join(destDir, "example.txt"))
|
_, err := os.Stat(filepath.Join(destDir, "example.txt"))
|
||||||
Ω(err).ShouldNot(HaveOccurred())
|
Ω(err).ShouldNot(HaveOccurred())
|
||||||
|
37
metadata.go
Normal file
37
metadata.go
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
package resource
|
||||||
|
|
||||||
|
import "github.com/google/go-github/github"
|
||||||
|
|
||||||
|
func metadataFromRelease(release *github.RepositoryRelease) []MetadataPair {
|
||||||
|
metadata := []MetadataPair{}
|
||||||
|
|
||||||
|
if release.Name != nil {
|
||||||
|
nameMeta := MetadataPair{
|
||||||
|
Name: "name",
|
||||||
|
Value: *release.Name,
|
||||||
|
}
|
||||||
|
|
||||||
|
if release.HTMLURL != nil {
|
||||||
|
nameMeta.URL = *release.HTMLURL
|
||||||
|
}
|
||||||
|
|
||||||
|
metadata = append(metadata, nameMeta)
|
||||||
|
}
|
||||||
|
|
||||||
|
if release.HTMLURL != nil {
|
||||||
|
metadata = append(metadata, MetadataPair{
|
||||||
|
Name: "url",
|
||||||
|
Value: *release.HTMLURL,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
if release.Body != nil {
|
||||||
|
metadata = append(metadata, MetadataPair{
|
||||||
|
Name: "body",
|
||||||
|
Value: *release.Body,
|
||||||
|
Markdown: true,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
return metadata
|
||||||
|
}
|
@@ -45,6 +45,7 @@ func (c *OutCommand) Run(sourceDir string, request OutRequest) (OutResponse, err
|
|||||||
TagName: github.String(tag),
|
TagName: github.String(tag),
|
||||||
Body: github.String(body),
|
Body: github.String(body),
|
||||||
}
|
}
|
||||||
|
|
||||||
createdRelease, err := c.github.CreateRelease(release)
|
createdRelease, err := c.github.CreateRelease(release)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return OutResponse{}, err
|
return OutResponse{}, err
|
||||||
@@ -76,6 +77,7 @@ func (c *OutCommand) Run(sourceDir string, request OutRequest) (OutResponse, err
|
|||||||
Version: Version{
|
Version: Version{
|
||||||
Tag: tag,
|
Tag: tag,
|
||||||
},
|
},
|
||||||
|
Metadata: metadataFromRelease(createdRelease),
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -30,6 +30,15 @@ var _ = Describe("Out Command", func() {
|
|||||||
|
|
||||||
sourcesDir, err = ioutil.TempDir("", "github-release")
|
sourcesDir, err = ioutil.TempDir("", "github-release")
|
||||||
Ω(err).ShouldNot(HaveOccurred())
|
Ω(err).ShouldNot(HaveOccurred())
|
||||||
|
|
||||||
|
githubClient.CreateReleaseStub = func(gh *github.RepositoryRelease) (*github.RepositoryRelease, error) {
|
||||||
|
createdRel := *gh
|
||||||
|
createdRel.ID = github.Int(112)
|
||||||
|
createdRel.HTMLURL = github.String("http://google.com")
|
||||||
|
createdRel.Name = github.String("release-name")
|
||||||
|
createdRel.Body = github.String("*markdown*")
|
||||||
|
return &createdRel, nil
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
AfterEach(func() {
|
AfterEach(func() {
|
||||||
@@ -105,8 +114,9 @@ var _ = Describe("Out Command", func() {
|
|||||||
file(globNotMatching, "not matching")
|
file(globNotMatching, "not matching")
|
||||||
|
|
||||||
githubClient.CreateReleaseStub = func(gh *github.RepositoryRelease) (*github.RepositoryRelease, error) {
|
githubClient.CreateReleaseStub = func(gh *github.RepositoryRelease) (*github.RepositoryRelease, error) {
|
||||||
gh.ID = github.Int(112)
|
createdRel := *gh
|
||||||
return gh, nil
|
createdRel.ID = github.Int(112)
|
||||||
|
return &createdRel, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
request := resource.OutRequest{
|
request := resource.OutRequest{
|
||||||
@@ -131,6 +141,33 @@ var _ = Describe("Out Command", func() {
|
|||||||
Ω(name).Should(Equal("great-file.tgz"))
|
Ω(name).Should(Equal("great-file.tgz"))
|
||||||
Ω(file.Name()).Should(Equal(filepath.Join(sourcesDir, "great-file.tgz")))
|
Ω(file.Name()).Should(Equal(filepath.Join(sourcesDir, "great-file.tgz")))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
It("has some sweet metadata", func() {
|
||||||
|
namePath := filepath.Join(sourcesDir, "name")
|
||||||
|
bodyPath := filepath.Join(sourcesDir, "body")
|
||||||
|
tagPath := filepath.Join(sourcesDir, "tag")
|
||||||
|
|
||||||
|
file(namePath, "v0.3.12")
|
||||||
|
file(bodyPath, "this is a great release")
|
||||||
|
file(tagPath, "0.3.12")
|
||||||
|
|
||||||
|
request := resource.OutRequest{
|
||||||
|
Params: resource.OutParams{
|
||||||
|
NamePath: "name",
|
||||||
|
BodyPath: "body",
|
||||||
|
TagPath: "tag",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
outResponse, err := command.Run(sourcesDir, request)
|
||||||
|
Ω(err).ShouldNot(HaveOccurred())
|
||||||
|
|
||||||
|
Ω(outResponse.Metadata).Should(ConsistOf(
|
||||||
|
resource.MetadataPair{Name: "url", Value: "http://google.com"},
|
||||||
|
resource.MetadataPair{Name: "name", Value: "release-name", URL: "http://google.com"},
|
||||||
|
resource.MetadataPair{Name: "body", Value: "*markdown*", Markdown: true},
|
||||||
|
))
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
func file(path, contents string) {
|
func file(path, contents string) {
|
||||||
|
Reference in New Issue
Block a user