Skip to content

Commit

Permalink
chore(changefinder): support nested commit format (#8998)
Browse files Browse the repository at this point in the history
  • Loading branch information
noahdietz authored Nov 13, 2023
1 parent 7a46b54 commit 9af7e85
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
4 changes: 3 additions & 1 deletion internal/actions/cmd/changefinder/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@ The available flags are as follows:
* `-q`: Enables quiet mode with no logging. In the event of an error while in
quiet mode, all logs that were surpressed are dumped with the error. Defaults
to `false` (i.e. "verbose").
* `-format=[plain|github]`: The `stdout` output format. Default is `plain`.
* `-format=[plain|github|commit]`: The `stdout` output format. Default is `plain`.
* `-gh-var=[variable name]`: The variabe name to set output for in `github`
format mode. Defaults to `submodules`.
* `-base=[ref name]`: The base ref to compare `HEAD` to. Default is
`origin/main`.
* `-path-filter=[path filter]`: The path filter to diff for.
* `-content-pattern=[regex]`: A regex to match on diff contents.
* `-commit-message=[commit message]`: Message to use in the nested commit block
* `-commit-scope=[conventional commit scope]`: Scope to use for the commit e.g. `fix`

Example usages from this repo root:

Expand Down
13 changes: 12 additions & 1 deletion internal/actions/cmd/changefinder/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,23 @@ import (

var (
dir = flag.String("dir", "", "the root directory to evaluate")
format = flag.String("format", "plain", "output format, one of [plain|github], defaults to 'plain'")
format = flag.String("format", "plain", "output format, one of [plain|github|commit], defaults to 'plain'")
ghVarName = flag.String("gh-var", "submodules", "github format's variable name to set output for, defaults to 'submodules'.")
base = flag.String("base", "origin/main", "the base ref to compare to, defaults to 'origin/main'")
// See https://git-scm.com/docs/git-diff#Documentation/git-diff.txt---diff-filterACDMRTUXB82308203
filter = flag.String("diff-filter", "", "the git diff filter to apply [A|C|D|M|R|T|U|X|B] - lowercase to exclude")
pathFilter = flag.String("path-filter", "", "filter commits by changes to target path(s)")
contentPattern = flag.String("content-regex", "", "regular expression to execute against contents of diff")
commitMessage = flag.String("commit-message", "", "message to use with the module in nested commit format")
commitScope = flag.String("commit-scope", "", "scope to use in commit message - only for format=commit")
)

func main() {
flag.BoolVar(&logg.Quiet, "q", false, "quiet mode, minimal logging")
flag.Parse()
if *format == "commit" && (*commitMessage == "" || *commitScope == "") {
logg.Fatalf("requested format=commit and missing commit-message or commit-scope")
}
rootDir, err := os.Getwd()
if err != nil {
logg.Fatal(err)
Expand Down Expand Up @@ -88,6 +93,12 @@ func output(s []string) error {
logg.Fatalf("unable to marshal submodules: %v", err)
}
fmt.Printf("::set-output name=%s::%s", *ghVarName, b)
case "commit":
for _, m := range s {
fmt.Println("BEGIN_NESTED_COMMIT")
fmt.Printf("%s(%s):%s\n", *commitScope, m, *commitMessage)
fmt.Println("END_NESTED_COMMIT")
}
case "plain":
fallthrough
default:
Expand Down

0 comments on commit 9af7e85

Please sign in to comment.