2016-07-14 11:44:21 +00:00
|
|
|
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
|
2016-07-21 15:51:08 +00:00
|
|
|
BumpType semVerBump
|
2016-07-14 11:44:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func parseCommit(line string) (*commit, error) {
|
|
|
|
t := strings.Split(line, "\t")
|
|
|
|
if len(t) != 4 {
|
|
|
|
return nil, errors.New("Unexpected line format")
|
|
|
|
}
|
2016-07-21 15:51:08 +00:00
|
|
|
|
|
|
|
c := &commit{
|
2016-07-14 11:44:21 +00:00
|
|
|
ShortHash: t[0],
|
|
|
|
Subject: t[1],
|
|
|
|
AuthorName: t[2],
|
|
|
|
AuthorEmail: t[3],
|
2016-07-21 15:51:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
2016-07-14 11:44:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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...)
|
|
|
|
}
|