mirror of
https://github.com/git-chglog/git-chglog.git
synced 2026-01-23 02:15:12 +00:00
feat: First implement
This commit is contained in:
parent
a44743ef3f
commit
6caf676beb
105 changed files with 20966 additions and 0 deletions
65
tag_reader.go
Normal file
65
tag_reader.go
Normal 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
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue