From 3d99be0bca74294fc32ac1010088e9fa8e785074 Mon Sep 17 00:00:00 2001 From: Chris Brown Date: Thu, 23 Jul 2015 14:50:59 -0700 Subject: [PATCH] users can provide `commitish` when creating a release [finishes #99189274] Signed-off-by: Chris Walter --- README.md | 3 +++ out_command.go | 16 +++++++++--- out_command_test.go | 61 +++++++++++++++++++++++++++++++++++++++------ resources.go | 7 +++--- 4 files changed, 73 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 84ae43e..dd3e844 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,9 @@ matching the patterns in `globs` to the release. * `tag`: *Required.* A path to a file containing the name of the Git tag to use for the release. +* `commitish`: *Optional.* A path to a file containing the commitish (SHA, tag, + branch name) that the release should be associated with. + * `body`: *Optional.* A path to a file containing the body text of the release. * `globs`: *Optional.* A list of globs for files that will be uploaded alongside diff --git a/out_command.go b/out_command.go index 14352eb..a86333a 100644 --- a/out_command.go +++ b/out_command.go @@ -44,10 +44,19 @@ func (c *OutCommand) Run(sourceDir string, request OutRequest) (OutResponse, err } } + targetCommitish := "" + if request.Params.CommitishPath != "" { + targetCommitish, err = c.fileContents(filepath.Join(sourceDir, request.Params.CommitishPath)) + if err != nil { + return OutResponse{}, err + } + } + release := &github.RepositoryRelease{ - Name: github.String(name), - TagName: github.String(tag), - Body: github.String(body), + Name: github.String(name), + TagName: github.String(tag), + Body: github.String(body), + TargetCommitish: github.String(targetCommitish), } existingReleases, err := c.github.ListReleases() @@ -66,6 +75,7 @@ func (c *OutCommand) Run(sourceDir string, request OutRequest) (OutResponse, err if existingRelease != nil { existingRelease.Name = github.String(name) existingRelease.Body = github.String(body) + existingRelease.TargetCommitish = github.String(targetCommitish) for _, asset := range existingRelease.Assets { fmt.Fprintf(c.writer, "clearing existing asset: %s\n", *asset.Name) diff --git a/out_command_test.go b/out_command_test.go index f5d026d..6db7825 100644 --- a/out_command_test.go +++ b/out_command_test.go @@ -100,20 +100,40 @@ var _ = Describe("Out Command", func() { } }) - It("updates the existing release", func() { - Ω(githubClient.UpdateReleaseCallCount()).Should(Equal(1)) - - updatedRelease := githubClient.UpdateReleaseArgsForCall(0) - Ω(*updatedRelease.Name).Should(Equal("v0.3.12")) - Ω(*updatedRelease.Body).Should(Equal("this is a great release")) - }) - It("deletes the existing assets", func() { Ω(githubClient.DeleteReleaseAssetCallCount()).Should(Equal(2)) Ω(githubClient.DeleteReleaseAssetArgsForCall(0)).Should(Equal(existingAssets[0])) Ω(githubClient.DeleteReleaseAssetArgsForCall(1)).Should(Equal(existingAssets[1])) }) + + Context("when a commitish is not supplied", func() { + It("updates the existing release", func() { + Ω(githubClient.UpdateReleaseCallCount()).Should(Equal(1)) + + updatedRelease := githubClient.UpdateReleaseArgsForCall(0) + Ω(*updatedRelease.Name).Should(Equal("v0.3.12")) + Ω(*updatedRelease.Body).Should(Equal("this is a great release")) + Ω(updatedRelease.TargetCommitish).Should(Equal(github.String(""))) + }) + }) + + Context("when a commitish is supplied", func() { + BeforeEach(func() { + commitishPath := filepath.Join(sourcesDir, "commitish") + file(commitishPath, "1z22f1") + request.Params.CommitishPath = "commitish" + }) + + It("updates the existing release", func() { + Ω(githubClient.UpdateReleaseCallCount()).Should(Equal(1)) + + updatedRelease := githubClient.UpdateReleaseArgsForCall(0) + Ω(*updatedRelease.Name).Should(Equal("v0.3.12")) + Ω(*updatedRelease.Body).Should(Equal("this is a great release")) + Ω(updatedRelease.TargetCommitish).Should(Equal(github.String("1z22f1"))) + }) + }) }) Context("when the release has not already been created", func() { @@ -132,6 +152,31 @@ var _ = Describe("Out Command", func() { } }) + Context("with a commitish", func() { + BeforeEach(func() { + commitishPath := filepath.Join(sourcesDir, "commitish") + file(commitishPath, "a2f4a3") + request.Params.CommitishPath = "commitish" + }) + + It("creates a release on GitHub with the commitish", func() { + Ω(githubClient.CreateReleaseCallCount()).Should(Equal(1)) + release := githubClient.CreateReleaseArgsForCall(0) + + Ω(release.TargetCommitish).Should(Equal(github.String("a2f4a3"))) + }) + }) + + Context("without a commitish", func() { + It("creates a release on GitHub without the commitish", func() { + Ω(githubClient.CreateReleaseCallCount()).Should(Equal(1)) + release := githubClient.CreateReleaseArgsForCall(0) + + // GitHub treats empty string the same as not suppying the field. + Ω(release.TargetCommitish).Should(Equal(github.String(""))) + }) + }) + Context("with a body", func() { BeforeEach(func() { bodyPath := filepath.Join(sourcesDir, "body") diff --git a/resources.go b/resources.go index fbb194a..a5b1c52 100644 --- a/resources.go +++ b/resources.go @@ -34,9 +34,10 @@ type OutRequest struct { } type OutParams struct { - NamePath string `json:"name"` - BodyPath string `json:"body"` - TagPath string `json:"tag"` + NamePath string `json:"name"` + BodyPath string `json:"body"` + TagPath string `json:"tag"` + CommitishPath string `json:"commitsh"` Globs []string `json:"globs"` }