feat: First implement

This commit is contained in:
tsuyoshiwada 2018-02-10 18:11:50 +09:00
parent a44743ef3f
commit 6caf676beb
105 changed files with 20966 additions and 0 deletions

65
tag_reader.go Normal file
View file

@ -0,0 +1,65 @@
package chglog
import (
"regexp"
"strconv"
"strings"
"time"
gitcmd "github.com/tsuyoshiwada/go-gitcmd"
)
type tagReader struct {
client gitcmd.Client
format string
reTag *regexp.Regexp
}
func newTagReader(client gitcmd.Client) *tagReader {
return &tagReader{
client: client,
reTag: regexp.MustCompile("tag: ([\\w\\.\\-_]+),?"),
}
}
func (r *tagReader) ReadAll() ([]*Tag, error) {
out, err := r.client.Exec(
"log",
"--tags",
"--simplify-by-decoration",
"--pretty=%D\t%at",
)
tags := []*Tag{}
if err != nil {
return tags, err
}
lines := strings.Split(out, "\n")
for _, line := range lines {
if line == "" {
continue
}
tokens := strings.Split(line, "\t")
res := r.reTag.FindAllStringSubmatch(tokens[0], -1)
if len(res) == 0 {
continue
}
ts, err := strconv.Atoi(tokens[1])
if err != nil {
continue
}
tags = append(tags, &Tag{
Name: res[0][1],
Date: time.Unix(int64(ts), 0),
})
}
return tags, nil
}