emit metadata in output

[#76848252]

Signed-off-by: Chris Brown <cbrown@pivotal.io>
This commit is contained in:
Alex Suraci
2015-02-18 10:06:04 -08:00
committed by Chris Brown
parent 3dc650adc8
commit c4436c0350
5 changed files with 101 additions and 19 deletions

View File

@@ -94,11 +94,7 @@ func (c *InCommand) Run(destDir string, request InRequest) (InResponse, error) {
Version: Version{
Tag: *foundRelease.TagName,
},
Metadata: []MetadataPair{
{Name: "name", Value: *foundRelease.Name, URL: *foundRelease.HTMLURL},
{Name: "url", Value: *foundRelease.HTMLURL},
{Name: "body", Value: *foundRelease.Body, Markdown: true},
},
Metadata: metadataFromRelease(foundRelease),
}, nil
}

View File

@@ -55,25 +55,19 @@ var _ = Describe("In Command", func() {
})
buildRelease := func(id int, tag string) github.RepositoryRelease {
url := "http://google.com"
name := "release-name"
body := "*markdown*"
return github.RepositoryRelease{
ID: &id,
TagName: &tag,
HTMLURL: &url,
Name: &name,
Body: &body,
ID: github.Int(id),
TagName: github.String(tag),
HTMLURL: github.String("http://google.com"),
Name: github.String("release-name"),
Body: github.String("*markdown*"),
}
}
buildAsset := func(name string) github.ReleaseAsset {
url := server.URL() + "/" + name
return github.ReleaseAsset{
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"}))
})
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() {
_, err := os.Stat(filepath.Join(destDir, "example.txt"))
Ω(err).ShouldNot(HaveOccurred())
@@ -196,6 +198,14 @@ var _ = Describe("In Command", func() {
Ω(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() {
_, err := os.Stat(filepath.Join(destDir, "example.txt"))
Ω(err).ShouldNot(HaveOccurred())

37
metadata.go Normal file
View 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
}

View File

@@ -45,6 +45,7 @@ func (c *OutCommand) Run(sourceDir string, request OutRequest) (OutResponse, err
TagName: github.String(tag),
Body: github.String(body),
}
createdRelease, err := c.github.CreateRelease(release)
if err != nil {
return OutResponse{}, err
@@ -76,6 +77,7 @@ func (c *OutCommand) Run(sourceDir string, request OutRequest) (OutResponse, err
Version: Version{
Tag: tag,
},
Metadata: metadataFromRelease(createdRelease),
}, nil
}

View File

@@ -30,6 +30,15 @@ var _ = Describe("Out Command", func() {
sourcesDir, err = ioutil.TempDir("", "github-release")
Ω(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() {
@@ -105,8 +114,9 @@ var _ = Describe("Out Command", func() {
file(globNotMatching, "not matching")
githubClient.CreateReleaseStub = func(gh *github.RepositoryRelease) (*github.RepositoryRelease, error) {
gh.ID = github.Int(112)
return gh, nil
createdRel := *gh
createdRel.ID = github.Int(112)
return &createdRel, nil
}
request := resource.OutRequest{
@@ -131,6 +141,33 @@ var _ = Describe("Out Command", func() {
Ω(name).Should(Equal("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) {