delete assets that failed to upload

[#121455813]

Signed-off-by: Yucheng Tu <ytu@pivotal.io>
This commit is contained in:
Evan Short
2016-06-13 17:45:11 -07:00
committed by Yucheng Tu
parent de0080906a
commit b0114ca8b4
2 changed files with 28 additions and 15 deletions

View File

@@ -81,6 +81,11 @@ func (c *OutCommand) Run(sourceDir string, request OutRequest) (OutResponse, err
} }
if existingRelease != nil { if existingRelease != nil {
releaseAssets, err := c.github.ListReleaseAssets(*existingRelease)
if err != nil {
return OutResponse{}, err
}
existingRelease.Name = github.String(name) existingRelease.Name = github.String(name)
existingRelease.TargetCommitish = github.String(targetCommitish) existingRelease.TargetCommitish = github.String(targetCommitish)
existingRelease.Draft = github.Bool(draft) existingRelease.Draft = github.Bool(draft)
@@ -89,7 +94,7 @@ func (c *OutCommand) Run(sourceDir string, request OutRequest) (OutResponse, err
existingRelease.Body = github.String(body) existingRelease.Body = github.String(body)
} }
for _, asset := range existingRelease.Assets { for _, asset := range releaseAssets {
fmt.Fprintf(c.writer, "clearing existing asset: %s\n", *asset.Name) fmt.Fprintf(c.writer, "clearing existing asset: %s\n", *asset.Name)
err := c.github.DeleteReleaseAsset(asset) err := c.github.DeleteReleaseAsset(asset)

View File

@@ -71,11 +71,11 @@ var _ = Describe("Out Command", func() {
{ {
ID: github.Int(3450798), ID: github.Int(3450798),
Name: github.String("rainbows.txt"), Name: github.String("rainbows.txt"),
State: github.String("new"),
}, },
} }
BeforeEach(func() { existingReleases := []github.RepositoryRelease{
githubClient.ListReleasesReturns([]github.RepositoryRelease{
{ {
ID: github.Int(1), ID: github.Int(1),
Draft: github.Bool(true), Draft: github.Bool(true),
@@ -83,10 +83,15 @@ var _ = Describe("Out Command", func() {
{ {
ID: github.Int(112), ID: github.Int(112),
TagName: github.String("some-tag-name"), TagName: github.String("some-tag-name"),
Assets: existingAssets, Assets: []github.ReleaseAsset{existingAssets[0]},
Draft: github.Bool(false), Draft: github.Bool(false),
}, },
}, nil) }
BeforeEach(func() {
githubClient.ListReleasesReturns(existingReleases, nil)
githubClient.ListReleaseAssetsReturns(existingAssets, nil)
namePath := filepath.Join(sourcesDir, "name") namePath := filepath.Join(sourcesDir, "name")
bodyPath := filepath.Join(sourcesDir, "body") bodyPath := filepath.Join(sourcesDir, "body")
@@ -106,6 +111,9 @@ var _ = Describe("Out Command", func() {
}) })
It("deletes the existing assets", func() { It("deletes the existing assets", func() {
Ω(githubClient.ListReleaseAssetsCallCount()).Should(Equal(1))
Ω(githubClient.ListReleaseAssetsArgsForCall(0)).Should(Equal(existingReleases[1]))
Ω(githubClient.DeleteReleaseAssetCallCount()).Should(Equal(2)) Ω(githubClient.DeleteReleaseAssetCallCount()).Should(Equal(2))
Ω(githubClient.DeleteReleaseAssetArgsForCall(0)).Should(Equal(existingAssets[0])) Ω(githubClient.DeleteReleaseAssetArgsForCall(0)).Should(Equal(existingAssets[0]))