1
0
Fork 0
mirror of https://github.com/Luzifer/git-changerelease.git synced 2024-12-20 19:11:17 +00:00

Replace error concat with wrapping

Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
Knut Ahlers 2020-08-07 16:05:08 +02:00
parent 24cac8d4ee
commit afbd9fef7f
Signed by: luzifer
GPG key ID: DC2729FDD34BE99E
4 changed files with 18 additions and 15 deletions

View file

@ -112,8 +112,8 @@ func bindataAssetsGitchangereleaseyaml() (*asset, error) {
name: "assets/git_changerelease.yaml", name: "assets/git_changerelease.yaml",
size: 834, size: 834,
md5checksum: "", md5checksum: "",
mode: os.FileMode(436), mode: os.FileMode(420),
modTime: time.Unix(1537952066, 0), modTime: time.Unix(1537952886, 0),
} }
a := &asset{bytes: bytes, info: info} a := &asset{bytes: bytes, info: info}

1
go.mod
View file

@ -5,6 +5,7 @@ go 1.14
require ( require (
github.com/Luzifer/rconfig/v2 v2.2.1 github.com/Luzifer/rconfig/v2 v2.2.1
github.com/mitchellh/go-homedir v1.1.0 github.com/mitchellh/go-homedir v1.1.0
github.com/pkg/errors v0.9.1
github.com/sirupsen/logrus v1.6.0 github.com/sirupsen/logrus v1.6.0
gopkg.in/yaml.v2 v2.3.0 gopkg.in/yaml.v2 v2.3.0
) )

2
go.sum
View file

@ -6,6 +6,8 @@ github.com/konsorten/go-windows-terminal-sequences v1.0.3 h1:CE8S1cTafDpPvMhIxNJ
github.com/konsorten/go-windows-terminal-sequences v1.0.3/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/konsorten/go-windows-terminal-sequences v1.0.3/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y= github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y=
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/sirupsen/logrus v1.6.0 h1:UBcNElsrwanuuMsnGSlYmtmgbb23qDR5dG+6X6Oo89I= github.com/sirupsen/logrus v1.6.0 h1:UBcNElsrwanuuMsnGSlYmtmgbb23qDR5dG+6X6Oo89I=
github.com/sirupsen/logrus v1.6.0/go.mod h1:7uNnSEd1DgxDLC74fIahvMZmmYsHGZGEOFrfsX/uA88= github.com/sirupsen/logrus v1.6.0/go.mod h1:7uNnSEd1DgxDLC74fIahvMZmmYsHGZGEOFrfsX/uA88=

26
main.go
View file

@ -4,7 +4,6 @@ package main
import ( import (
"bytes" "bytes"
"errors"
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"os" "os"
@ -16,6 +15,7 @@ import (
"time" "time"
"github.com/mitchellh/go-homedir" "github.com/mitchellh/go-homedir"
"github.com/pkg/errors"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
"github.com/Luzifer/rconfig/v2" "github.com/Luzifer/rconfig/v2"
@ -44,7 +44,7 @@ var (
func filenameToGitRoot(fn string) (string, error) { func filenameToGitRoot(fn string) (string, error) {
root, err := git(false, "rev-parse", "--show-toplevel") root, err := git(false, "rev-parse", "--show-toplevel")
if err != nil { if err != nil {
return "", fmt.Errorf("Unable to fetch root dir: %s", err) return "", errors.Wrap(err, "Unable to fetch root dir")
} }
return path.Join(root, fn), nil return path.Join(root, fn), nil
@ -108,7 +108,7 @@ func loadMatcherRegex(matches []string, bump semVerBump) error {
for _, match := range matches { for _, match := range matches {
r, err := regexp.Compile(match) r, err := regexp.Compile(match)
if err != nil { if err != nil {
return fmt.Errorf("Unable to parse regex '%s': %s", match, err) return errors.Wrapf(err, "Unable to parse regex '%s'", match)
} }
matchers[r] = bump matchers[r] = bump
} }
@ -181,17 +181,17 @@ func main() {
func applyTag(stringVersion string) error { func applyTag(stringVersion string) error {
var err error var err error
if _, err = gitErr("add", cfg.ChangelogFile); err != nil { if _, err = gitErr("add", cfg.ChangelogFile); err != nil {
return fmt.Errorf("Unable to add changelog file: %s", err) return errors.Wrap(err, "Unable to add changelog file")
} }
commitMessage, err := quickTemplate("commitMessage", []byte(config.ReleaseCommitMessage), map[string]interface{}{ commitMessage, err := quickTemplate("commitMessage", []byte(config.ReleaseCommitMessage), map[string]interface{}{
"Version": stringVersion, "Version": stringVersion,
}) })
if err != nil { if err != nil {
return fmt.Errorf("Unable to compile commit message: %s", err) return errors.Wrap(err, "Unable to compile commit message")
} }
if _, err := gitErr("commit", "-m", string(commitMessage)); err != nil { if _, err := gitErr("commit", "-m", string(commitMessage)); err != nil {
return fmt.Errorf("Unable to commit changelog: %s", err) return errors.Wrap(err, "Unable to commit changelog")
} }
tagType := "-s" // By default use signed tags tagType := "-s" // By default use signed tags
@ -200,7 +200,7 @@ func applyTag(stringVersion string) error {
} }
if _, err := gitErr("tag", tagType, "-m", stringVersion, stringVersion); err != nil { if _, err := gitErr("tag", tagType, "-m", stringVersion, stringVersion); err != nil {
return fmt.Errorf("Unable to tag release: %s", err) return errors.Wrap(err, "Unable to tag release")
} }
return nil return nil
@ -216,7 +216,7 @@ func fetchGitLogs(since string, fetchAll bool) ([]commit, error) {
rawLogs, err := gitErr(logArgs...) rawLogs, err := gitErr(logArgs...)
if err != nil { if err != nil {
return nil, fmt.Errorf("Unable to read git log entries: %s", err) return nil, errors.Wrap(err, "Unable to read git log entries")
} }
logs := []commit{} logs := []commit{}
@ -255,11 +255,11 @@ func renderLog(newVersion *semVer, logs []commit) (*semVer, error) {
"OldLog": readChangelog(), "OldLog": readChangelog(),
}) })
if err != nil { if err != nil {
return nil, fmt.Errorf("Unable to compile log: %s", err) return nil, errors.Wrap(err, "Unable to compile log")
} }
if err = ioutil.WriteFile(cfg.ChangelogFile, bytes.TrimSpace(c), 0644); err != nil { if err = ioutil.WriteFile(cfg.ChangelogFile, bytes.TrimSpace(c), 0644); err != nil {
return nil, fmt.Errorf("Unable to write new changelog: %s", err) return nil, errors.Wrap(err, "Unable to write new changelog")
} }
// Spawning editor // Spawning editor
@ -280,7 +280,7 @@ func renderLog(newVersion *semVer, logs []commit) (*semVer, error) {
} }
newVersion, err = parseSemVer(strings.Split(changelog[0], " ")[1]) newVersion, err = parseSemVer(strings.Split(changelog[0], " ")[1])
if err != nil { if err != nil {
return nil, fmt.Errorf("Unable to parse new version from log: %s", err) return nil, errors.Wrap(err, "Unable to parse new version from log")
} }
return newVersion, nil return newVersion, nil
@ -290,13 +290,13 @@ func newVersionFromLogs(lastTag string, logs []commit) (*semVer, error) {
// Tetermine increase type // Tetermine increase type
semVerBumpType, err := selectBumpType(logs) semVerBumpType, err := selectBumpType(logs)
if err != nil { if err != nil {
return nil, fmt.Errorf("Could not determine how to increase the version: %s", err) return nil, errors.Wrap(err, "Could not determine how to increase the version")
} }
// Generate new version // Generate new version
newVersion, err := parseSemVer(lastTag) newVersion, err := parseSemVer(lastTag)
if err != nil { if err != nil {
return nil, fmt.Errorf("Was unable to parse previous version: %s", err) return nil, errors.Wrap(err, "Was unable to parse previous version")
} }
if newVersion.PreReleaseInformation == "" && cfg.PreRelease == "" { if newVersion.PreReleaseInformation == "" && cfg.PreRelease == "" {
newVersion.Bump(semVerBumpType) newVersion.Bump(semVerBumpType)