From 9af7e853088b69e875c1be4a517d0168ee493244 Mon Sep 17 00:00:00 2001 From: Noah Dietz Date: Mon, 13 Nov 2023 10:46:22 -0800 Subject: [PATCH] chore(changefinder): support nested commit format (#8998) --- internal/actions/cmd/changefinder/README.md | 4 +++- internal/actions/cmd/changefinder/main.go | 13 ++++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/internal/actions/cmd/changefinder/README.md b/internal/actions/cmd/changefinder/README.md index 6cd43655d585..d9f29857af4d 100644 --- a/internal/actions/cmd/changefinder/README.md +++ b/internal/actions/cmd/changefinder/README.md @@ -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: diff --git a/internal/actions/cmd/changefinder/main.go b/internal/actions/cmd/changefinder/main.go index 30d095f35cb8..80962a420775 100644 --- a/internal/actions/cmd/changefinder/main.go +++ b/internal/actions/cmd/changefinder/main.go @@ -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) @@ -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: