Skip to content

Commit

Permalink
Merge 4c86963 into 63a4e63
Browse files Browse the repository at this point in the history
  • Loading branch information
evanchaoli committed Jul 4, 2019
2 parents 63a4e63 + 4c86963 commit a798842
Show file tree
Hide file tree
Showing 8 changed files with 87 additions and 37 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
*.dll
*.so
*.dylib
git-chglog

# Test binary, build with `go test -c`
*.test
Expand All @@ -31,6 +32,10 @@ Icon
# Thumbnails
._*

# Intellij IDEA
*.iml
.idea

# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
Expand Down
30 changes: 20 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,15 +166,16 @@ USAGE:
4. <name> - Commit contained in <name>.

OPTIONS:
--init generate the git-chglog configuration file in interactive
--config value, -c value specifies a different configuration file to pick up (default: ".chglog/config.yml")
--output value, -o value output path and filename for the changelogs. If not specified, output to stdout
--next-tag value treat unreleased commits as specified tags (EXPERIMENTAL)
--silent disable stdout output
--no-color disable color output [$NO_COLOR]
--no-emoji disable emoji output [$NO_EMOJI]
--help, -h show help
--version, -v print the version
--init generate the git-chglog configuration file in interactive
--config value, -c value specifies a different configuration file to pick up (default: ".chglog/config.yml")
--output value, -o value output path and filename for the changelogs. If not specified, output to stdout
--next-tag value treat unreleased commits as specified tags (EXPERIMENTAL)
--silent disable stdout output
--no-color disable color output [$NO_COLOR]
--no-emoji disable emoji output [$NO_EMOJI]
--tag-filter-pattern value, -p value regular expression of tag filter. Is specified, only matched tags will be picked
--help, -h show help
--version, -v print the version

EXAMPLE:

Expand Down Expand Up @@ -512,7 +513,16 @@ See godoc [RenderData][doc-render-data] for available variables.
This is a step that is necessary for project operation in many cases.
</details>


<details>
<summary>Can I generated CHANGELOG based on certain tags?</summary>

Yes, it can be solved by use the `--tag-filter-pattern` flag.

For example, the following command will only include tags starting with "v":
```bash
$ git-chglog --tag-filter-pattern '^v'
```
</details>


## TODO
Expand Down
13 changes: 7 additions & 6 deletions chglog.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
type Options struct {
Processor Processor
NextTag string // Treat unreleased commits as specified tags (EXPERIMENTAL)
TagFilterPattern string // Filter tag by regexp
CommitFilters map[string][]string // Filter by using `Commit` properties and values. Filtering is not done by specifying an empty value
CommitSortBy string // Property name to use for sorting `Commit` (e.g. `Scope`)
CommitGroupBy string // Property name of `Commit` to be grouped into `CommitGroup` (e.g. `Type`)
Expand Down Expand Up @@ -49,11 +50,11 @@ type RenderData struct {

// Config for generating CHANGELOG
type Config struct {
Bin string // Git execution command
WorkingDir string // Working directory
Template string // Path for template file. If a relative path is specified, it depends on the value of `WorkingDir`.
Info *Info
Options *Options
Bin string // Git execution command
WorkingDir string // Working directory
Template string // Path for template file. If a relative path is specified, it depends on the value of `WorkingDir`.
Info *Info
Options *Options
}

func normalizeConfig(config *Config) {
Expand Down Expand Up @@ -108,7 +109,7 @@ func NewGenerator(config *Config) *Generator {
return &Generator{
client: client,
config: config,
tagReader: newTagReader(client),
tagReader: newTagReader(client, config.Options.TagFilterPattern),
tagSelector: newTagSelector(),
commitParser: newCommitParser(client, config),
commitExtractor: newCommitExtractor(config.Options),
Expand Down
21 changes: 12 additions & 9 deletions cmd/git-chglog/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,13 @@ type Options struct {

// Config ...
type Config struct {
Bin string `yaml:"bin"`
Template string `yaml:"template"`
Style string `yaml:"style"`
Info Info `yaml:"info"`
Options Options `yaml:"options"`
Bin string `yaml:"bin"`
Template string `yaml:"template"`
Style string `yaml:"style"`
TagFilterPattern string `yaml:tag_filter_pattern`
Info Info `yaml:"info"`
Options Options `yaml:"options"`
//TagFilterPattern string `yaml:tag_filter_pattern`
}

// Normalize ...
Expand Down Expand Up @@ -249,15 +251,16 @@ func (config *Config) Convert(ctx *CLIContext) *chglog.Config {
opts := config.Options

return &chglog.Config{
Bin: config.Bin,
WorkingDir: ctx.WorkingDir,
Template: config.Template,
Info: &chglog.Info{
Bin: config.Bin,
WorkingDir: ctx.WorkingDir,
Template: config.Template,
Info: &chglog.Info{
Title: info.Title,
RepositoryURL: info.RepositoryURL,
},
Options: &chglog.Options{
NextTag: ctx.NextTag,
TagFilterPattern: ctx.TagFilterPattern,
CommitFilters: opts.Commits.Filters,
CommitSortBy: opts.Commits.SortBy,
CommitGroupBy: opts.CommitGroups.GroupBy,
Expand Down
21 changes: 11 additions & 10 deletions cmd/git-chglog/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,17 @@ import (

// CLIContext ...
type CLIContext struct {
WorkingDir string
Stdout io.Writer
Stderr io.Writer
ConfigPath string
OutputPath string
Silent bool
NoColor bool
NoEmoji bool
Query string
NextTag string
WorkingDir string
Stdout io.Writer
Stderr io.Writer
ConfigPath string
OutputPath string
Silent bool
NoColor bool
NoEmoji bool
Query string
NextTag string
TagFilterPattern string
}

// InitContext ...
Expand Down
6 changes: 6 additions & 0 deletions cmd/git-chglog/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,11 @@ func main() {
EnvVar: "NO_EMOJI",
},

cli.StringFlag{
Name: "tag-filter-pattern, p",
Usage: "Regular expression of tag filter. Is specified, only matched tags will be picked",
},

// help & version
cli.HelpFlag,
cli.VersionFlag,
Expand Down Expand Up @@ -161,6 +166,7 @@ func main() {
NoEmoji: c.Bool("no-emoji"),
Query: c.Args().First(),
NextTag: c.String("next-tag"),
TagFilterPattern: c.String("tag-filter-pattern"),
},
fs,
NewConfigLoader(),
Expand Down
11 changes: 10 additions & 1 deletion tag_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package chglog

import (
"fmt"
"regexp"
"sort"
"strings"
"time"
Expand All @@ -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),
}
}

Expand Down Expand Up @@ -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,
Expand Down
17 changes: 16 additions & 1 deletion tag_reader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func TestTagReader(t *testing.T) {
},
}

actual, err := newTagReader(client).ReadAll()
actual, err := newTagReader(client, "").ReadAll()
assert.Nil(err)

assert.Equal(
Expand Down Expand Up @@ -103,4 +103,19 @@ func TestTagReader(t *testing.T) {
},
actual,
)

actual_filtered, err_filtered := newTagReader(client, "^v").ReadAll()
assert.Nil(err_filtered)
assert.Equal(
[]*Tag{
&Tag{
Name: "v2.0.4-beta.1",
Subject: "Release v2.0.4-beta.1",
Date: time.Date(2018, 2, 1, 0, 0, 0, 0, time.UTC),
Next: nil,
Previous: nil,
},
},
actual_filtered,
)
}

0 comments on commit a798842

Please sign in to comment.