@@ -19,7 +19,7 @@ func main() {
|
||||
sourceDir := os.Args[1]
|
||||
|
||||
github := resource.NewGitHubClient(request.Source)
|
||||
command := resource.NewOutCommand(github)
|
||||
command := resource.NewOutCommand(github, os.Stderr)
|
||||
response, err := command.Run(sourceDir, request)
|
||||
if err != nil {
|
||||
resource.Fatal("running command", err)
|
||||
|
@@ -84,6 +84,7 @@ func (c *InCommand) Run(destDir string, request InRequest) (InResponse, error) {
|
||||
}
|
||||
|
||||
fmt.Fprintf(c.writer, "downloading asset: %s\n", *asset.Name)
|
||||
|
||||
err := c.downloadFile(url, path)
|
||||
if err != nil {
|
||||
return InResponse{}, nil
|
||||
|
@@ -1,6 +1,8 @@
|
||||
package resource
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
@@ -11,11 +13,13 @@ import (
|
||||
|
||||
type OutCommand struct {
|
||||
github GitHub
|
||||
writer io.Writer
|
||||
}
|
||||
|
||||
func NewOutCommand(github GitHub) *OutCommand {
|
||||
func NewOutCommand(github GitHub, writer io.Writer) *OutCommand {
|
||||
return &OutCommand{
|
||||
github: github,
|
||||
writer: writer,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -64,14 +68,19 @@ func (c *OutCommand) Run(sourceDir string, request OutRequest) (OutResponse, err
|
||||
existingRelease.Body = github.String(body)
|
||||
|
||||
for _, asset := range existingRelease.Assets {
|
||||
fmt.Fprintf(c.writer, "clearing existing asset: %s\n", asset.Name)
|
||||
|
||||
err := c.github.DeleteReleaseAsset(asset)
|
||||
if err != nil {
|
||||
return OutResponse{}, err
|
||||
}
|
||||
}
|
||||
|
||||
fmt.Fprintf(c.writer, "updating release %s\n", name)
|
||||
|
||||
release, err = c.github.UpdateRelease(existingRelease)
|
||||
} else {
|
||||
fmt.Fprintf(c.writer, "creating release %s\n", name)
|
||||
release, err = c.github.CreateRelease(release)
|
||||
}
|
||||
|
||||
@@ -91,6 +100,8 @@ func (c *OutCommand) Run(sourceDir string, request OutRequest) (OutResponse, err
|
||||
return OutResponse{}, err
|
||||
}
|
||||
|
||||
fmt.Fprintf(c.writer, "uploading %s\n", filePath)
|
||||
|
||||
name := filepath.Base(filePath)
|
||||
err = c.github.UploadReleaseAsset(release, name, file)
|
||||
if err != nil {
|
||||
|
@@ -33,7 +33,7 @@ var _ = Describe("Out Command", func() {
|
||||
var err error
|
||||
|
||||
githubClient = &fakes.FakeGitHub{}
|
||||
command = resource.NewOutCommand(githubClient)
|
||||
command = resource.NewOutCommand(githubClient, ioutil.Discard)
|
||||
|
||||
sourcesDir, err = ioutil.TempDir("", "github-release")
|
||||
Ω(err).ShouldNot(HaveOccurred())
|
||||
|
Reference in New Issue
Block a user