add logging to /out

Signed-off-by: Chris Brown <cbrown@pivotal.io>
This commit is contained in:
Alex Suraci
2015-02-20 14:38:49 -08:00
committed by Chris Brown
parent 330d632d62
commit 2ab978b6ea
4 changed files with 15 additions and 3 deletions

View File

@@ -19,7 +19,7 @@ func main() {
sourceDir := os.Args[1] sourceDir := os.Args[1]
github := resource.NewGitHubClient(request.Source) github := resource.NewGitHubClient(request.Source)
command := resource.NewOutCommand(github) command := resource.NewOutCommand(github, os.Stderr)
response, err := command.Run(sourceDir, request) response, err := command.Run(sourceDir, request)
if err != nil { if err != nil {
resource.Fatal("running command", err) resource.Fatal("running command", err)

View File

@@ -84,6 +84,7 @@ func (c *InCommand) Run(destDir string, request InRequest) (InResponse, error) {
} }
fmt.Fprintf(c.writer, "downloading asset: %s\n", *asset.Name) fmt.Fprintf(c.writer, "downloading asset: %s\n", *asset.Name)
err := c.downloadFile(url, path) err := c.downloadFile(url, path)
if err != nil { if err != nil {
return InResponse{}, nil return InResponse{}, nil

View File

@@ -1,6 +1,8 @@
package resource package resource
import ( import (
"fmt"
"io"
"io/ioutil" "io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
@@ -11,11 +13,13 @@ import (
type OutCommand struct { type OutCommand struct {
github GitHub github GitHub
writer io.Writer
} }
func NewOutCommand(github GitHub) *OutCommand { func NewOutCommand(github GitHub, writer io.Writer) *OutCommand {
return &OutCommand{ return &OutCommand{
github: github, github: github,
writer: writer,
} }
} }
@@ -64,14 +68,19 @@ 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 existingRelease.Assets {
fmt.Fprintf(c.writer, "clearing existing asset: %s\n", asset.Name)
err := c.github.DeleteReleaseAsset(asset) err := c.github.DeleteReleaseAsset(asset)
if err != nil { if err != nil {
return OutResponse{}, err return OutResponse{}, err
} }
} }
fmt.Fprintf(c.writer, "updating release %s\n", name)
release, err = c.github.UpdateRelease(existingRelease) release, err = c.github.UpdateRelease(existingRelease)
} else { } else {
fmt.Fprintf(c.writer, "creating release %s\n", name)
release, err = c.github.CreateRelease(release) release, err = c.github.CreateRelease(release)
} }
@@ -91,6 +100,8 @@ func (c *OutCommand) Run(sourceDir string, request OutRequest) (OutResponse, err
return OutResponse{}, err return OutResponse{}, err
} }
fmt.Fprintf(c.writer, "uploading %s\n", filePath)
name := filepath.Base(filePath) name := filepath.Base(filePath)
err = c.github.UploadReleaseAsset(release, name, file) err = c.github.UploadReleaseAsset(release, name, file)
if err != nil { if err != nil {

View File

@@ -33,7 +33,7 @@ var _ = Describe("Out Command", func() {
var err error var err error
githubClient = &fakes.FakeGitHub{} githubClient = &fakes.FakeGitHub{}
command = resource.NewOutCommand(githubClient) command = resource.NewOutCommand(githubClient, ioutil.Discard)
sourcesDir, err = ioutil.TempDir("", "github-release") sourcesDir, err = ioutil.TempDir("", "github-release")
Ω(err).ShouldNot(HaveOccurred()) Ω(err).ShouldNot(HaveOccurred())