Pass on github client error, do not create empty commit_sha file

This commit is contained in:
Christoph Sassenberg
2018-01-21 11:03:06 +01:00
parent dae25957fc
commit 5819c61aa6

View File

@@ -63,11 +63,17 @@ func (c *InCommand) Run(destDir string, request InRequest) (InResponse, error) {
}
commitPath := filepath.Join(destDir, "commit_sha")
commitSHA = c.resolveTagToCommitSHA(*foundRelease.TagName)
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
@@ -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
}