Skip to content

Commit

Permalink
add logging to /out
Browse files Browse the repository at this point in the history
Signed-off-by: Chris Brown <[email protected]>
  • Loading branch information
vito authored and Chris Brown committed Feb 20, 2015
1 parent 330d632 commit 2ab978b
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion cmd/out/out.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions in_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 12 additions & 1 deletion out_command.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package resource

import (
"fmt"
"io"
"io/ioutil"
"os"
"path/filepath"
Expand All @@ -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,
}
}

Expand Down Expand Up @@ -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)
}

Expand All @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion out_command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down

0 comments on commit 2ab978b

Please sign in to comment.