delete assets that failed to upload
[#121455813] Signed-off-by: Yucheng Tu <ytu@pivotal.io>
This commit is contained in:
@@ -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)
|
||||||
|
@@ -69,24 +69,29 @@ var _ = Describe("Out Command", func() {
|
|||||||
Name: github.String("unicorns.txt"),
|
Name: github.String("unicorns.txt"),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
ID: github.Int(3450798),
|
ID: github.Int(3450798),
|
||||||
Name: github.String("rainbows.txt"),
|
Name: github.String("rainbows.txt"),
|
||||||
|
State: github.String("new"),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
existingReleases := []github.RepositoryRelease{
|
||||||
|
{
|
||||||
|
ID: github.Int(1),
|
||||||
|
Draft: github.Bool(true),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
ID: github.Int(112),
|
||||||
|
TagName: github.String("some-tag-name"),
|
||||||
|
Assets: []github.ReleaseAsset{existingAssets[0]},
|
||||||
|
Draft: github.Bool(false),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
BeforeEach(func() {
|
BeforeEach(func() {
|
||||||
githubClient.ListReleasesReturns([]github.RepositoryRelease{
|
githubClient.ListReleasesReturns(existingReleases, nil)
|
||||||
{
|
|
||||||
ID: github.Int(1),
|
githubClient.ListReleaseAssetsReturns(existingAssets, nil)
|
||||||
Draft: github.Bool(true),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
ID: github.Int(112),
|
|
||||||
TagName: github.String("some-tag-name"),
|
|
||||||
Assets: existingAssets,
|
|
||||||
Draft: github.Bool(false),
|
|
||||||
},
|
|
||||||
}, 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]))
|
||||||
|
Reference in New Issue
Block a user