1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-07-03 00:57:43 +02:00

refactor: turned changelog generation into a pipe

I turned myself into a pipe morty!

PipeRick!!!

refs #284
This commit is contained in:
Carlos Alexandro Becker
2017-10-15 20:21:35 -02:00
committed by Carlos Alexandro Becker
parent b585ac8b0e
commit 87d269dc45
8 changed files with 163 additions and 123 deletions

View File

@ -4,7 +4,6 @@ package git
import (
"bytes"
"fmt"
"regexp"
"strings"
"text/template"
@ -39,9 +38,6 @@ func (Pipe) Run(ctx *context.Context) (err error) {
Commit: commit,
}
log.Infof("releasing %s, commit %s", tag, commit)
if err = setLog(ctx, tag, commit); err != nil {
return
}
if err = setVersion(ctx, tag, commit); err != nil {
return
}
@ -65,23 +61,6 @@ func setVersion(ctx *context.Context, tag, commit string) (err error) {
return
}
func setLog(ctx *context.Context, tag, commit string) (err error) {
if ctx.ReleaseNotes != "" {
return
}
var log string
if tag == "" {
log, err = getChangelog(commit)
} else {
log, err = getChangelog(tag)
}
if err != nil {
return err
}
ctx.ReleaseNotes = fmt.Sprintf("## Changelog\n\n%v", log)
return nil
}
type snapshotNameData struct {
Commit string
Tag string
@ -114,50 +93,18 @@ func validate(ctx *context.Context, commit, tag string) error {
if !regexp.MustCompile("^[0-9.]+").MatchString(ctx.Version) {
return ErrInvalidVersionFormat{ctx.Version}
}
_, err = cleanGit("describe", "--exact-match", "--tags", "--match", tag)
_, err = git.Clean(git.Run("describe", "--exact-match", "--tags", "--match", tag))
if err != nil {
return ErrWrongRef{commit, tag}
}
return nil
}
func getChangelog(tag string) (string, error) {
prev, err := previous(tag)
if err != nil {
return "", err
}
if !prev.Tag {
return gitLog(prev.SHA, tag)
}
return gitLog(fmt.Sprintf("%v..%v", prev.SHA, tag))
}
func gitLog(refs ...string) (string, error) {
var args = []string{"log", "--pretty=oneline", "--abbrev-commit"}
args = append(args, refs...)
return git.Run(args...)
}
func getInfo() (tag, commit string, err error) {
tag, err = cleanGit("describe", "--tags", "--abbrev=0")
tag, err = git.Clean(git.Run("describe", "--tags", "--abbrev=0"))
if err != nil {
log.WithError(err).Info("failed to retrieve current tag")
}
commit, err = cleanGit("show", "--format='%H'", "HEAD")
commit, err = git.Clean(git.Run("show", "--format='%H'", "HEAD"))
return
}
func previous(tag string) (result ref, err error) {
result.Tag = true
result.SHA, err = cleanGit("describe", "--tags", "--abbrev=0", tag+"^")
if err != nil {
result.Tag = false
result.SHA, err = cleanGit("rev-list", "--max-parents=0", "HEAD")
}
return
}
type ref struct {
Tag bool
SHA string
}