From 2ab978b6ea0dd8c2269ccb471e1fbdb4491306a1 Mon Sep 17 00:00:00 2001 From: Alex Suraci Date: Fri, 20 Feb 2015 14:38:49 -0800 Subject: [PATCH] add logging to /out Signed-off-by: Chris Brown --- cmd/out/out.go | 2 +- in_command.go | 1 + out_command.go | 13 ++++++++++++- out_command_test.go | 2 +- 4 files changed, 15 insertions(+), 3 deletions(-) diff --git a/cmd/out/out.go b/cmd/out/out.go index 43fa2f8..b8a15c1 100644 --- a/cmd/out/out.go +++ b/cmd/out/out.go @@ -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) diff --git a/in_command.go b/in_command.go index 2a08f04..963961f 100644 --- a/in_command.go +++ b/in_command.go @@ -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 diff --git a/out_command.go b/out_command.go index fe3f5bd..b1381b2 100644 --- a/out_command.go +++ b/out_command.go @@ -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 { diff --git a/out_command_test.go b/out_command_test.go index 7541291..63b8dad 100644 --- a/out_command_test.go +++ b/out_command_test.go @@ -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())