From 5819c61aa633a58527d59ed714f963c47be0e1ed Mon Sep 17 00:00:00 2001 From: Christoph Sassenberg Date: Sun, 21 Jan 2018 11:03:06 +0100 Subject: [PATCH] Pass on github client error, do not create empty commit_sha file --- in_command.go | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/in_command.go b/in_command.go index f5f9a3d..634ec82 100644 --- a/in_command.go +++ b/in_command.go @@ -63,12 +63,18 @@ func (c *InCommand) Run(destDir string, request InRequest) (InResponse, error) { } commitPath := filepath.Join(destDir, "commit_sha") - commitSHA = c.resolveTagToCommitSHA(*foundRelease.TagName) - err = ioutil.WriteFile(commitPath, []byte(commitSHA), 0644) + commitSHA, err = c.resolveTagToCommitSHA(*foundRelease.TagName) if err != nil { return InResponse{}, err } + if commitSHA != "" { + err = ioutil.WriteFile(commitPath, []byte(commitSHA), 0644) + if err != nil { + return InResponse{}, err + } + } + if foundRelease.Body != nil && *foundRelease.Body != "" { body := *foundRelease.Body bodyPath := filepath.Join(destDir, "body") @@ -191,18 +197,13 @@ func (c *InCommand) downloadFile(url, destPath string) error { return nil } -func (c *InCommand) resolveTagToCommitSHA(tag string) string { +func (c *InCommand) resolveTagToCommitSHA(tag string) (string, error) { reference, err := c.github.GetRef(tag) - if err != nil { - fmt.Fprintln(c.writer, "could not resolve tag '%s' to commit: %v", tag, err) - return "" + if err != nil && *reference.Object.Type != "commit" { + fmt.Fprintln(c.writer, "could not resolve tag '%s' to commit: returned type is not 'commit' - only lightweight tags are supported") + return "", nil } - if *reference.Object.Type != "commit" { - fmt.Fprintln(c.writer, "could not resolve tag '%s' to commit: returned type is not 'commit' - only lightweight tags are supported", tag) - return "" - } - - return *reference.Object.SHA + return *reference.Object.SHA, err }