Skip to content

Commit

Permalink
Merge d330bce into a94e3f9
Browse files Browse the repository at this point in the history
  • Loading branch information
barryib committed Apr 10, 2020
2 parents a94e3f9 + d330bce commit fd56057
Show file tree
Hide file tree
Showing 9 changed files with 99 additions and 37 deletions.
25 changes: 13 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
[![Coverage Status](https://img.shields.io/coveralls/github/git-chglog/git-chglog.svg?style=flat-square)](https://coveralls.io/github/git-chglog/git-chglog?branch=master)
[![MIT License](http://img.shields.io/badge/license-MIT-blue.svg?style=flat-square)](https://github.com/git-chglog/git-chglog/blob/master/LICENSE)

> CHANGELOG generator implemented in Go (Golang).
> CHANGELOG generator implemented in Go (Golang).
> _Anytime, anywhere, Write your CHANGELOG._

Expand Down Expand Up @@ -54,7 +54,7 @@

## How it works

`git-chglog` internally uses the `git` command to get data to include in the CHANGELOG.
`git-chglog` internally uses the `git` command to get data to include in the CHANGELOG.
The basic steps are as follows.

1. Get all the tags.
Expand Down Expand Up @@ -105,7 +105,7 @@ $ git-chglog --version

### Quick Start

`git-chglog` requires configuration files and templates to generate a CHANGELOG.
`git-chglog` requires configuration files and templates to generate a CHANGELOG.

However, it is a waste of time to create configuration files and templates from scratch.

Expand All @@ -121,7 +121,7 @@ $ git-chglog --init

You are now ready for configuration files and templates!

Let's immediately generate a CHANGELOG of your project.
Let's immediately generate a CHANGELOG of your project.
By doing the following simple command, Markdown for your CHANGELOG is displayed on stdout.

```bash
Expand Down Expand Up @@ -163,7 +163,8 @@ OPTIONS:
--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
--no-case disable case sensitive filters
--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

Expand Down Expand Up @@ -464,7 +465,7 @@ See the godoc [RenderData][doc-render-data] documentation for available variable
It is ideal to describe everything included in CHANGELOG in your commits. But actually it is very difficult to do it perfectly.
There are times when you need to edit the generated output to write a great CHANGELOG.
There are times when you need to edit the generated output to write a great CHANGELOG.
By displaying it on the standard output, it makes it easy to change the contents.
</details>
Expand All @@ -474,7 +475,7 @@ See the godoc [RenderData][doc-render-data] documentation for available variable
Yes, it can be solved by using the `--next-tag` flag.
For example, let's say you want to upgrade your project to `2.0.0`.
For example, let's say you want to upgrade your project to `2.0.0`.
You can create CHANGELOG containing `2.0.0` as follows.
```bash
Expand All @@ -490,9 +491,9 @@ See the godoc [RenderData][doc-render-data] documentation for available variable
<details>
<summary>Can I generate a 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'
Expand Down Expand Up @@ -527,10 +528,10 @@ Bugs, feature requests and comments are more than welcome in the [issues](https:
### Feedback
I would like to make `git-chglog` a better tool.
I would like to make `git-chglog` a better tool.
The goal is to be able to use in various projects.
Therefore, your feedback is very useful.
Therefore, your feedback is very useful.
I am very happy to tell you your opinions on Issues and PR :heart:
## CHANGELOG
Expand All @@ -548,4 +549,4 @@ See [CHANGELOG.md](./CHANGELOG.md)
[doc-commit]: https://godoc.org/github.com/git-chglog/git-chglog#Commit
[doc-commit-group]: https://godoc.org/github.com/git-chglog/git-chglog#Commit
[doc-ref]: https://godoc.org/github.com/git-chglog/git-chglog#Ref
[doc-render-data]: https://godoc.org/github.com/git-chglog/git-chglog#RenderData
[doc-render-data]: https://godoc.org/github.com/git-chglog/git-chglog#RenderData
1 change: 1 addition & 0 deletions chglog.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ type Options struct {
Processor Processor
NextTag string // Treat unreleased commits as specified tags (EXPERIMENTAL)
TagFilterPattern string // Filter tag by regexp
NoCaseSensitive bool // Filter commits in a case insensitive way
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
1 change: 1 addition & 0 deletions cmd/git-chglog/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ func (config *Config) Convert(ctx *CLIContext) *chglog.Config {
Options: &chglog.Options{
NextTag: ctx.NextTag,
TagFilterPattern: ctx.TagFilterPattern,
NoCaseSensitive: ctx.NoCaseSensitive,
CommitFilters: opts.Commits.Filters,
CommitSortBy: opts.Commits.SortBy,
CommitGroupBy: opts.CommitGroups.GroupBy,
Expand Down
1 change: 1 addition & 0 deletions cmd/git-chglog/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ type CLIContext struct {
Silent bool
NoColor bool
NoEmoji bool
NoCaseSensitive bool
Query string
NextTag string
TagFilterPattern string
Expand Down
31 changes: 19 additions & 12 deletions cmd/git-chglog/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,16 @@ func CreateApp(actionFunc cli.ActionFunc) *cli.App {
EnvVar: "NO_EMOJI",
},

// no-case
cli.BoolFlag{
Name: "no-case",
Usage: "disable case sensitive filters",
},

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

// help & version
Expand Down Expand Up @@ -162,16 +168,17 @@ func AppAction(c *cli.Context) error {
// chglog
chglogCLI := NewCLI(
&CLIContext{
WorkingDir: wd,
Stdout: colorable.NewColorableStdout(),
Stderr: colorable.NewColorableStderr(),
ConfigPath: c.String("config"),
OutputPath: c.String("output"),
Silent: c.Bool("silent"),
NoColor: c.Bool("no-color"),
NoEmoji: c.Bool("no-emoji"),
Query: c.Args().First(),
NextTag: c.String("next-tag"),
WorkingDir: wd,
Stdout: colorable.NewColorableStdout(),
Stderr: colorable.NewColorableStderr(),
ConfigPath: c.String("config"),
OutputPath: c.String("output"),
Silent: c.Bool("silent"),
NoColor: c.Bool("no-color"),
NoEmoji: c.Bool("no-emoji"),
NoCaseSensitive: c.Bool("no-case"),
Query: c.Args().First(),
NextTag: c.String("next-tag"),
TagFilterPattern: c.String("tag-filter-pattern"),
},
fs,
Expand Down
2 changes: 1 addition & 1 deletion cmd/git-chglog/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func TestCreateApp(t *testing.T) {
gAssert = assert

app := CreateApp(mock_app_action)
args := []string {
args := []string{
"git-chglog",
"--silent",
"--no-color",
Expand Down
17 changes: 13 additions & 4 deletions commit_extractor.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func (e *commitExtractor) Extract(commits []*Commit) ([]*CommitGroup, []*Commit,
mergeCommits := []*Commit{}
revertCommits := []*Commit{}

filteredCommits := commitFilter(commits, e.opts.CommitFilters)
filteredCommits := commitFilter(commits, e.opts.CommitFilters, e.opts.NoCaseSensitive)

for _, commit := range commits {
if commit.Merge != nil {
Expand All @@ -37,7 +37,7 @@ func (e *commitExtractor) Extract(commits []*Commit) ([]*CommitGroup, []*Commit,

for _, commit := range filteredCommits {
if commit.Merge == nil && commit.Revert == nil {
e.processCommitGroups(&commitGroups, commit)
e.processCommitGroups(&commitGroups, commit, e.opts.NoCaseSensitive)
}

e.processNoteGroups(&noteGroups, commit)
Expand All @@ -49,14 +49,23 @@ func (e *commitExtractor) Extract(commits []*Commit) ([]*CommitGroup, []*Commit,
return commitGroups, mergeCommits, revertCommits, noteGroups
}

func (e *commitExtractor) processCommitGroups(groups *[]*CommitGroup, commit *Commit) {
func (e *commitExtractor) processCommitGroups(groups *[]*CommitGroup, commit *Commit, noCaseSensitive bool) {
var group *CommitGroup

// commit group
raw, ttl := e.commitGroupTitle(commit)

for _, g := range *groups {
if g.RawTitle == raw {
rawTitleTmp := g.RawTitle
if noCaseSensitive {
rawTitleTmp = strings.ToLower(g.RawTitle)
}

rawTmp := raw
if noCaseSensitive {
rawTmp = strings.ToLower(raw)
}
if rawTitleTmp == rawTmp {
group = g
}
}
Expand Down
14 changes: 13 additions & 1 deletion commit_filter.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package chglog

func commitFilter(commits []*Commit, filters map[string][]string) []*Commit {
import (
"strings"
)

func commitFilter(commits []*Commit, filters map[string][]string, noCaseSensitive bool) []*Commit {
res := []*Commit{}

for _, commit := range commits {
Expand All @@ -23,9 +27,17 @@ func commitFilter(commits []*Commit, filters map[string][]string) []*Commit {
break
}

if noCaseSensitive {
str = strings.ToLower(str)
}

exist := false

for _, val := range values {
if noCaseSensitive {
val = strings.ToLower(val)
}

if str == val {
exist = true
}
Expand Down
44 changes: 37 additions & 7 deletions commit_filter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,34 @@ func TestCommitFilter(t *testing.T) {
Scope: "fuga",
Subject: "4",
},
&Commit{
Type: "Bar",
Scope: "hogera",
Subject: "5",
},
}

assert.Equal(
[]string{
"1",
"2",
"3",
"4",
"5",
},
pickCommitSubjects(commitFilter(fixtures, map[string][]string{}, false)),
)

assert.Equal(
[]string{
"1",
"2",
"3",
"4",
},
pickCommitSubjects(commitFilter(fixtures, map[string][]string{})),
pickCommitSubjects(commitFilter(fixtures, map[string][]string{
"Type": {"foo", "bar"},
}, false)),
)

assert.Equal(
Expand All @@ -56,10 +74,11 @@ func TestCommitFilter(t *testing.T) {
"2",
"3",
"4",
"5",
},
pickCommitSubjects(commitFilter(fixtures, map[string][]string{
"Type": {"foo", "bar"},
})),
}, true)),
)

assert.Equal(
Expand All @@ -69,17 +88,28 @@ func TestCommitFilter(t *testing.T) {
},
pickCommitSubjects(commitFilter(fixtures, map[string][]string{
"Type": {"foo"},
})),
}, false)),
)

assert.Equal(
[]string{
"3",
"4",
},
pickCommitSubjects(commitFilter(fixtures, map[string][]string{
"Type": {"bar"},
}, false)),
)

assert.Equal(
[]string{
"3",
"4",
"5",
},
pickCommitSubjects(commitFilter(fixtures, map[string][]string{
"Type": {"bar"},
})),
}, true)),
)

assert.Equal(
Expand All @@ -89,7 +119,7 @@ func TestCommitFilter(t *testing.T) {
},
pickCommitSubjects(commitFilter(fixtures, map[string][]string{
"Scope": {"fuga"},
})),
}, false)),
)

assert.Equal(
Expand All @@ -99,7 +129,7 @@ func TestCommitFilter(t *testing.T) {
pickCommitSubjects(commitFilter(fixtures, map[string][]string{
"Type": {"bar"},
"Scope": {"hoge"},
})),
}, false)),
)

assert.Equal(
Expand All @@ -110,6 +140,6 @@ func TestCommitFilter(t *testing.T) {
pickCommitSubjects(commitFilter(fixtures, map[string][]string{
"Type": {"foo"},
"Scope": {"fuga", "hoge"},
})),
}, false)),
)
}

0 comments on commit fd56057

Please sign in to comment.