feat(flag): --path filtering - refs (#62). Closes #35

* Argument: --path filtering - refs #35
* Minor documentation additions for Paths option
This commit is contained in:
Mikael Fridh 2021-03-12 13:57:00 +01:00 committed by GitHub
parent a1c84d7a0d
commit 9d62af2943
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 28 additions and 5 deletions

View file

@ -182,6 +182,7 @@ USAGE:
OPTIONS:
--init generate the git-chglog configuration file in interactive
--path value Filter commits by path(s). Can use multiple times.
--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)

View file

@ -40,6 +40,7 @@ type Options struct {
JiraUrl string
JiraTypeMaps map[string]string
JiraIssueDescriptionPattern string
Paths []string // Path filter
}
// Info is metadata related to CHANGELOG

View file

@ -292,6 +292,7 @@ func (config *Config) Convert(ctx *CLIContext) *chglog.Config {
NextTag: ctx.NextTag,
TagFilterPattern: ctx.TagFilterPattern,
NoCaseSensitive: ctx.NoCaseSensitive,
Paths: ctx.Paths,
CommitFilters: opts.Commits.Filters,
CommitSortBy: opts.Commits.SortBy,
CommitGroupBy: opts.CommitGroups.GroupBy,

View file

@ -23,6 +23,7 @@ type CLIContext struct {
JiraUsername string
JiraToken string
JiraUrl string
Paths []string
}
// InitContext ...

View file

@ -53,7 +53,11 @@ func CreateApp(actionFunc cli.ActionFunc) *cli.App {
$ {{.Name}} --config custom/dir/config.yml
The above is a command that uses a configuration file placed other than ".chglog/config.yml".
The above is a command that uses a configuration file placed other than ".chglog/config.yml".
$ {{.Name}} --path path/to/my/component --output CHANGELOG.component.md
Filter commits by specific paths or files in git and output to a component specific changelog.
`,
ttl("USAGE:"),
ttl("OPTIONS:"),
@ -76,6 +80,12 @@ func CreateApp(actionFunc cli.ActionFunc) *cli.App {
Usage: "generate the git-chglog configuration file in interactive",
},
// path
&cli.StringSliceFlag{
Name: "path",
Usage: "Filter commits by path(s). Can use multiple times.",
},
// config
&cli.StringFlag{
Name: "config, c",
@ -216,6 +226,7 @@ func AppAction(c *cli.Context) error {
JiraUsername: c.String("jira-username"),
JiraToken: c.String("jira-token"),
JiraUrl: c.String("jira-url"),
Paths: c.StringSlice("path"),
},
fs,
NewConfigLoader(),

View file

@ -86,12 +86,20 @@ func newCommitParser(logger *Logger, client gitcmd.Client, jiraClient JiraClient
}
func (p *commitParser) Parse(rev string) ([]*Commit, error) {
out, err := p.client.Exec(
"log",
paths := p.config.Options.Paths
args := []string{
rev,
"--no-decorate",
"--pretty="+logFormat,
)
"--pretty=" + logFormat,
}
if len(paths) > 0 {
args = append(args, "--")
args = append(args, paths...)
}
out, err := p.client.Exec("log", args...)
if err != nil {
return nil, err