feat: Add --tag-filter-pattern flag.

This flag specifies a regular expression and only matched tags will
be included in change log.

Closes #43
This commit is contained in:
Chao Li 2019-07-04 11:40:48 +08:00
parent 63a4e63702
commit 1198e283de
10 changed files with 222 additions and 65 deletions

View file

@ -2,6 +2,7 @@ package chglog
import (
"fmt"
"regexp"
"sort"
"strings"
"time"
@ -13,12 +14,14 @@ type tagReader struct {
client gitcmd.Client
format string
separator string
reFilter *regexp.Regexp
}
func newTagReader(client gitcmd.Client) *tagReader {
func newTagReader(client gitcmd.Client, filterPattern string) *tagReader {
return &tagReader{
client: client,
separator: "@@__CHGLOG__@@",
reFilter: regexp.MustCompile(filterPattern),
}
}
@ -56,6 +59,12 @@ func (r *tagReader) ReadAll() ([]*Tag, error) {
date = t
}
if r.reFilter != nil {
if !r.reFilter.MatchString(name) {
continue
}
}
tags = append(tags, &Tag{
Name: name,
Subject: subject,