support draft releases for in and out
* in will pull in the latest release, even if draft. It will not create the files `tag` and `version`, if no tag is defined on the draft release. * out will push a release in a draft state when provided as a param [#102513822] Signed-off-by: David Morhovich <dmorhovich@pivotal.io>
This commit is contained in:
committed by
David Morhovich
parent
a7eb775171
commit
b2eee37237
@@ -41,6 +41,7 @@ func (c *InCommand) Run(destDir string, request InRequest) (InResponse, error) {
|
|||||||
return InResponse{}, errors.New("no releases")
|
return InResponse{}, errors.New("no releases")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if *foundRelease.TagName != "" {
|
||||||
tagPath := filepath.Join(destDir, "tag")
|
tagPath := filepath.Join(destDir, "tag")
|
||||||
err = ioutil.WriteFile(tagPath, []byte(*foundRelease.TagName), 0644)
|
err = ioutil.WriteFile(tagPath, []byte(*foundRelease.TagName), 0644)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -53,6 +54,7 @@ func (c *InCommand) Run(destDir string, request InRequest) (InResponse, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return InResponse{}, err
|
return InResponse{}, err
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
assets, err := c.github.ListReleaseAssets(*foundRelease)
|
assets, err := c.github.ListReleaseAssets(*foundRelease)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@@ -5,6 +5,7 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
|
"path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
. "github.com/onsi/ginkgo"
|
. "github.com/onsi/ginkgo"
|
||||||
@@ -50,13 +51,14 @@ var _ = Describe("In Command", func() {
|
|||||||
Ω(os.RemoveAll(tmpDir)).Should(Succeed())
|
Ω(os.RemoveAll(tmpDir)).Should(Succeed())
|
||||||
})
|
})
|
||||||
|
|
||||||
buildRelease := func(id int, tag string) *github.RepositoryRelease {
|
buildRelease := func(id int, tag string, draft bool) *github.RepositoryRelease {
|
||||||
return &github.RepositoryRelease{
|
return &github.RepositoryRelease{
|
||||||
ID: github.Int(id),
|
ID: github.Int(id),
|
||||||
TagName: github.String(tag),
|
TagName: github.String(tag),
|
||||||
HTMLURL: github.String("http://google.com"),
|
HTMLURL: github.String("http://google.com"),
|
||||||
Name: github.String("release-name"),
|
Name: github.String("release-name"),
|
||||||
Body: github.String("*markdown*"),
|
Body: github.String("*markdown*"),
|
||||||
|
Draft: github.Bool(draft),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -70,7 +72,7 @@ var _ = Describe("In Command", func() {
|
|||||||
Context("when there is a tagged release", func() {
|
Context("when there is a tagged release", func() {
|
||||||
Context("when a present version is specified", func() {
|
Context("when a present version is specified", func() {
|
||||||
BeforeEach(func() {
|
BeforeEach(func() {
|
||||||
githubClient.GetReleaseByTagReturns(buildRelease(1, "v0.35.0"), nil)
|
githubClient.GetReleaseByTagReturns(buildRelease(1, "v0.35.0", false), nil)
|
||||||
|
|
||||||
githubClient.ListReleaseAssetsReturns([]github.ReleaseAsset{
|
githubClient.ListReleaseAssetsReturns([]github.ReleaseAsset{
|
||||||
buildAsset(0, "example.txt"),
|
buildAsset(0, "example.txt"),
|
||||||
@@ -112,6 +114,16 @@ var _ = Describe("In Command", func() {
|
|||||||
Ω(githubClient.DownloadReleaseAssetArgsForCall(0)).Should(Equal(buildAsset(0, "example.txt")))
|
Ω(githubClient.DownloadReleaseAssetArgsForCall(0)).Should(Equal(buildAsset(0, "example.txt")))
|
||||||
Ω(githubClient.DownloadReleaseAssetArgsForCall(1)).Should(Equal(buildAsset(1, "example.rtf")))
|
Ω(githubClient.DownloadReleaseAssetArgsForCall(1)).Should(Equal(buildAsset(1, "example.rtf")))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
It("does create the tag and version files", func() {
|
||||||
|
contents, err := ioutil.ReadFile(path.Join(destDir, "tag"))
|
||||||
|
Ω(err).ShouldNot(HaveOccurred())
|
||||||
|
Ω(string(contents)).Should(Equal("v0.35.0"))
|
||||||
|
|
||||||
|
contents, err = ioutil.ReadFile(path.Join(destDir, "version"))
|
||||||
|
Ω(err).ShouldNot(HaveOccurred())
|
||||||
|
Ω(string(contents)).Should(Equal("0.35.0"))
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
Context("when an invalid asset filename glob is given", func() {
|
Context("when an invalid asset filename glob is given", func() {
|
||||||
@@ -215,4 +227,71 @@ var _ = Describe("In Command", func() {
|
|||||||
Ω(inErr).Should(Equal(disaster))
|
Ω(inErr).Should(Equal(disaster))
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
Context("when there is a draft release", func() {
|
||||||
|
Context("which has a tag", func() {
|
||||||
|
BeforeEach(func() {
|
||||||
|
githubClient.GetReleaseByTagReturns(buildRelease(1, "v0.35.0", true), nil)
|
||||||
|
|
||||||
|
inRequest.Version = &resource.Version{Tag: "v0.35.0"}
|
||||||
|
inResponse, inErr = command.Run(destDir, inRequest)
|
||||||
|
})
|
||||||
|
|
||||||
|
It("succeeds", func() {
|
||||||
|
Ω(inErr).ShouldNot(HaveOccurred())
|
||||||
|
})
|
||||||
|
|
||||||
|
It("returns the fetched version", 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("does create the tag and version files", func() {
|
||||||
|
contents, err := ioutil.ReadFile(path.Join(destDir, "tag"))
|
||||||
|
Ω(err).ShouldNot(HaveOccurred())
|
||||||
|
Ω(string(contents)).Should(Equal("v0.35.0"))
|
||||||
|
|
||||||
|
contents, err = ioutil.ReadFile(path.Join(destDir, "version"))
|
||||||
|
Ω(err).ShouldNot(HaveOccurred())
|
||||||
|
Ω(string(contents)).Should(Equal("0.35.0"))
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
Context("which doesn't have a tag", func() {
|
||||||
|
BeforeEach(func() {
|
||||||
|
githubClient.GetReleaseByTagReturns(buildRelease(1, "", true), nil)
|
||||||
|
|
||||||
|
inRequest.Version = &resource.Version{}
|
||||||
|
inResponse, inErr = command.Run(destDir, inRequest)
|
||||||
|
})
|
||||||
|
|
||||||
|
It("succeeds", func() {
|
||||||
|
Ω(inErr).ShouldNot(HaveOccurred())
|
||||||
|
})
|
||||||
|
|
||||||
|
It("returns the fetched version", func() {
|
||||||
|
Ω(inResponse.Version).Should(Equal(resource.Version{Tag: ""}))
|
||||||
|
})
|
||||||
|
|
||||||
|
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("does not create the tag and version files", func() {
|
||||||
|
Ω(path.Join(destDir, "tag")).ShouldNot(BeAnExistingFile())
|
||||||
|
Ω(path.Join(destDir, "version")).ShouldNot(BeAnExistingFile())
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
@@ -52,10 +52,13 @@ func (c *OutCommand) Run(sourceDir string, request OutRequest) (OutResponse, err
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
draft := request.Params.Draft
|
||||||
|
|
||||||
release := &github.RepositoryRelease{
|
release := &github.RepositoryRelease{
|
||||||
Name: github.String(name),
|
Name: github.String(name),
|
||||||
TagName: github.String(tag),
|
TagName: github.String(tag),
|
||||||
Body: github.String(body),
|
Body: github.String(body),
|
||||||
|
Draft: github.Bool(draft),
|
||||||
TargetCommitish: github.String(targetCommitish),
|
TargetCommitish: github.String(targetCommitish),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -205,6 +205,31 @@ var _ = Describe("Out Command", func() {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
It("always defaults to non-draft mode", func() {
|
||||||
|
Ω(githubClient.CreateReleaseCallCount()).Should(Equal(1))
|
||||||
|
release := githubClient.CreateReleaseArgsForCall(0)
|
||||||
|
|
||||||
|
Ω(*release.Draft).Should(Equal(false))
|
||||||
|
})
|
||||||
|
|
||||||
|
Context("when set as a draft release", func() {
|
||||||
|
BeforeEach(func() {
|
||||||
|
bodyPath := filepath.Join(sourcesDir, "body")
|
||||||
|
file(bodyPath, "this is a great release")
|
||||||
|
request.Params.Draft = true
|
||||||
|
})
|
||||||
|
|
||||||
|
It("creates a release on GitHub in draft mode", func() {
|
||||||
|
Ω(githubClient.CreateReleaseCallCount()).Should(Equal(1))
|
||||||
|
release := githubClient.CreateReleaseArgsForCall(0)
|
||||||
|
|
||||||
|
Ω(*release.Name).Should(Equal("v0.3.12"))
|
||||||
|
Ω(*release.TagName).Should(Equal("0.3.12"))
|
||||||
|
Ω(*release.Body).Should(Equal(""))
|
||||||
|
Ω(*release.Draft).Should(Equal(true))
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
Context("with file globs", func() {
|
Context("with file globs", func() {
|
||||||
BeforeEach(func() {
|
BeforeEach(func() {
|
||||||
globMatching := filepath.Join(sourcesDir, "great-file.tgz")
|
globMatching := filepath.Join(sourcesDir, "great-file.tgz")
|
||||||
|
@@ -40,6 +40,7 @@ type OutParams struct {
|
|||||||
BodyPath string `json:"body"`
|
BodyPath string `json:"body"`
|
||||||
TagPath string `json:"tag"`
|
TagPath string `json:"tag"`
|
||||||
CommitishPath string `json:"commitish"`
|
CommitishPath string `json:"commitish"`
|
||||||
|
Draft bool `json:"draft"`
|
||||||
|
|
||||||
Globs []string `json:"globs"`
|
Globs []string `json:"globs"`
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user