users can provide commitish when creating a release

[finishes #99189274]

Signed-off-by: Chris Walter <cwalter@pivotal.io>
This commit is contained in:
Chris Brown
2015-07-23 14:50:59 -07:00
committed by Chris Walter
parent bd263fd89d
commit 3d99be0bca
4 changed files with 73 additions and 14 deletions

View File

@@ -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

View File

@@ -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),
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)

View File

@@ -100,19 +100,39 @@ var _ = Describe("Out Command", func() {
}
})
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("")))
})
})
It("deletes the existing assets", func() {
Ω(githubClient.DeleteReleaseAssetCallCount()).Should(Equal(2))
Context("when a commitish is supplied", func() {
BeforeEach(func() {
commitishPath := filepath.Join(sourcesDir, "commitish")
file(commitishPath, "1z22f1")
request.Params.CommitishPath = "commitish"
})
Ω(githubClient.DeleteReleaseAssetArgsForCall(0)).Should(Equal(existingAssets[0]))
Ω(githubClient.DeleteReleaseAssetArgsForCall(1)).Should(Equal(existingAssets[1]))
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")))
})
})
})
@@ -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")

View File

@@ -37,6 +37,7 @@ type OutParams struct {
NamePath string `json:"name"`
BodyPath string `json:"body"`
TagPath string `json:"tag"`
CommitishPath string `json:"commitsh"`
Globs []string `json:"globs"`
}