mirror of
https://github.com/Luzifer/git-changerelease.git
synced 2024-12-20 19:11:17 +00:00
Knut Ahlers
fa7cfd9e9e
In previous versions the bump type was not calculated correctly when a minor commit and a patch type commit were included in a release. Instead of using the minor-bump it used the patch-bump because minor was the default and patch overruled minor.
78 lines
1.3 KiB
Go
78 lines
1.3 KiB
Go
package main
|
|
|
|
import (
|
|
"bytes"
|
|
"errors"
|
|
"os"
|
|
"os/exec"
|
|
"strings"
|
|
)
|
|
|
|
var (
|
|
gitLogFormat string
|
|
gitLogFormatParts = []string{
|
|
`%h`, // ShortHash
|
|
`%s`, // Subject
|
|
`%an`, // AuthorName
|
|
`%ae`, // AuthorEmail
|
|
}
|
|
)
|
|
|
|
func init() {
|
|
gitLogFormat = strings.Join(gitLogFormatParts, `%x09`)
|
|
}
|
|
|
|
type commit struct {
|
|
ShortHash string
|
|
Subject string
|
|
AuthorName string
|
|
AuthorEmail string
|
|
BumpType semVerBump
|
|
}
|
|
|
|
func parseCommit(line string) (*commit, error) {
|
|
t := strings.Split(line, "\t")
|
|
if len(t) != 4 {
|
|
return nil, errors.New("Unexpected line format")
|
|
}
|
|
|
|
c := &commit{
|
|
ShortHash: t[0],
|
|
Subject: t[1],
|
|
AuthorName: t[2],
|
|
AuthorEmail: t[3],
|
|
}
|
|
|
|
for rex, bt := range matchers {
|
|
if rex.MatchString(c.Subject) && bt > c.BumpType {
|
|
c.BumpType = bt
|
|
}
|
|
}
|
|
|
|
if c.BumpType == semVerBumpUndecided {
|
|
c.BumpType = semVerBumpMinor
|
|
}
|
|
|
|
return c, nil
|
|
}
|
|
|
|
func git(stderrEnabled bool, args ...string) (string, error) {
|
|
buf := bytes.NewBuffer([]byte{})
|
|
|
|
cmd := exec.Command("git", args...)
|
|
cmd.Stdout = buf
|
|
if stderrEnabled {
|
|
cmd.Stderr = os.Stderr
|
|
}
|
|
err := cmd.Run()
|
|
|
|
return strings.TrimSpace(buf.String()), err
|
|
}
|
|
|
|
func gitErr(args ...string) (string, error) {
|
|
return git(true, args...)
|
|
}
|
|
|
|
func gitSilent(args ...string) (string, error) {
|
|
return git(false, args...)
|
|
}
|