diff --git a/README.md b/README.md index 8b5e1c76..6aaa33a4 100644 --- a/README.md +++ b/README.md @@ -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) diff --git a/chglog.go b/chglog.go index 968b65cf..5a3427d3 100644 --- a/chglog.go +++ b/chglog.go @@ -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 diff --git a/cmd/git-chglog/config.go b/cmd/git-chglog/config.go index d2e4844d..2410b68c 100644 --- a/cmd/git-chglog/config.go +++ b/cmd/git-chglog/config.go @@ -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, diff --git a/cmd/git-chglog/context.go b/cmd/git-chglog/context.go index 3f2e1aa8..a086cf15 100644 --- a/cmd/git-chglog/context.go +++ b/cmd/git-chglog/context.go @@ -23,6 +23,7 @@ type CLIContext struct { JiraUsername string JiraToken string JiraUrl string + Paths []string } // InitContext ... diff --git a/cmd/git-chglog/main.go b/cmd/git-chglog/main.go index 28005207..c8a61bd8 100644 --- a/cmd/git-chglog/main.go +++ b/cmd/git-chglog/main.go @@ -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(), diff --git a/commit_parser.go b/commit_parser.go index 83d38a45..f3cc7a8b 100644 --- a/commit_parser.go +++ b/commit_parser.go @@ -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