users can provide commitish
when creating a release
[finishes #99189274] Signed-off-by: Chris Walter <cwalter@pivotal.io>
This commit is contained in:
committed by
Chris Walter
parent
bd263fd89d
commit
3d99be0bca
@@ -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
|
* `tag`: *Required.* A path to a file containing the name of the Git tag to use
|
||||||
for the release.
|
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.
|
* `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
|
* `globs`: *Optional.* A list of globs for files that will be uploaded alongside
|
||||||
|
@@ -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{
|
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),
|
||||||
|
TargetCommitish: github.String(targetCommitish),
|
||||||
}
|
}
|
||||||
|
|
||||||
existingReleases, err := c.github.ListReleases()
|
existingReleases, err := c.github.ListReleases()
|
||||||
@@ -66,6 +75,7 @@ func (c *OutCommand) Run(sourceDir string, request OutRequest) (OutResponse, err
|
|||||||
if existingRelease != nil {
|
if existingRelease != nil {
|
||||||
existingRelease.Name = github.String(name)
|
existingRelease.Name = github.String(name)
|
||||||
existingRelease.Body = github.String(body)
|
existingRelease.Body = github.String(body)
|
||||||
|
existingRelease.TargetCommitish = github.String(targetCommitish)
|
||||||
|
|
||||||
for _, asset := range existingRelease.Assets {
|
for _, asset := range existingRelease.Assets {
|
||||||
fmt.Fprintf(c.writer, "clearing existing asset: %s\n", *asset.Name)
|
fmt.Fprintf(c.writer, "clearing existing asset: %s\n", *asset.Name)
|
||||||
|
@@ -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() {
|
It("deletes the existing assets", func() {
|
||||||
Ω(githubClient.DeleteReleaseAssetCallCount()).Should(Equal(2))
|
Ω(githubClient.DeleteReleaseAssetCallCount()).Should(Equal(2))
|
||||||
|
|
||||||
Ω(githubClient.DeleteReleaseAssetArgsForCall(0)).Should(Equal(existingAssets[0]))
|
Ω(githubClient.DeleteReleaseAssetArgsForCall(0)).Should(Equal(existingAssets[0]))
|
||||||
Ω(githubClient.DeleteReleaseAssetArgsForCall(1)).Should(Equal(existingAssets[1]))
|
Ω(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() {
|
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() {
|
Context("with a body", func() {
|
||||||
BeforeEach(func() {
|
BeforeEach(func() {
|
||||||
bodyPath := filepath.Join(sourcesDir, "body")
|
bodyPath := filepath.Join(sourcesDir, "body")
|
||||||
|
@@ -34,9 +34,10 @@ type OutRequest struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type OutParams struct {
|
type OutParams struct {
|
||||||
NamePath string `json:"name"`
|
NamePath string `json:"name"`
|
||||||
BodyPath string `json:"body"`
|
BodyPath string `json:"body"`
|
||||||
TagPath string `json:"tag"`
|
TagPath string `json:"tag"`
|
||||||
|
CommitishPath string `json:"commitsh"`
|
||||||
|
|
||||||
Globs []string `json:"globs"`
|
Globs []string `json:"globs"`
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user