From e95c7d6c986c486db5253accbea8190957acc49f Mon Sep 17 00:00:00 2001 From: Gabe Cook Date: Wed, 13 Mar 2024 19:03:32 -0500 Subject: [PATCH] feat(cmd): Add `--repo` flag --- README.md | 3 ++- action.yml | 8 ++++++-- cmd/cmd.go | 12 +++++++++++- docs/changelog-generator.md | 1 + 4 files changed, 20 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index ddb02aa..50b2b98 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,8 @@ Generated changelogs look similar to the changelogs generated by [GoReleaser](ht | Name | Description | Default | |----------|--------------------------------------------|-----------------------------| -| `path` | Generated changelog path. | `` | +| `output` | Generated changelog path. | ` ` | +| `path` | Path to the local git repository | `"."` | | `config` | Path to the config file. | `.changelog-generator.yaml` | | `token` | GitHub token used to fetch release assets. | `${{ github.token }}` | diff --git a/action.yml b/action.yml index b657453..543fa6c 100644 --- a/action.yml +++ b/action.yml @@ -8,6 +8,9 @@ inputs: description: Path to the config file default: ${{ github.workspace }}/.changelog-generator.yaml path: + description: Path to the local git repository + default: . + output: description: Generated changelog path token: description: GitHub token @@ -84,9 +87,10 @@ runs: - id: changelog shell: bash env: - output: ${{ inputs.path }} + repo: ${{ inputs.path }} + output: ${{ inputs.output }} run: | - changelog="$(changelog-generator)" + changelog="$(changelog-generator --repo="$repo")" echo '::group::Generated Changelog' echo "$changelog" echo '::endgroup::' diff --git a/cmd/cmd.go b/cmd/cmd.go index 13fd4ec..4509e46 100644 --- a/cmd/cmd.go +++ b/cmd/cmd.go @@ -27,6 +27,11 @@ func New() *cobra.Command { return []string{"yaml"}, cobra.ShellCompDirectiveFilterFileExt }) + cmd.PersistentFlags().String("repo", ".", `Path to the git repo root. Parent directories will be walked until .git is found.`) + _ = cmd.RegisterFlagCompletionFunc("repo", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { + return []string{}, cobra.ShellCompDirectiveFilterDirs + }) + return cmd } @@ -44,9 +49,14 @@ func run(cmd *cobra.Command, args []string) error { return err } + repoPath, err := cmd.Flags().GetString("repo") + if err != nil { + return err + } + cmd.SilenceUsage = true - repo, err := git.PlainOpenWithOptions(".", &git.PlainOpenOptions{DetectDotGit: true}) + repo, err := git.PlainOpenWithOptions(repoPath, &git.PlainOpenOptions{DetectDotGit: true}) if err != nil { return err } diff --git a/docs/changelog-generator.md b/docs/changelog-generator.md index 3f5b24f..d372dc6 100644 --- a/docs/changelog-generator.md +++ b/docs/changelog-generator.md @@ -12,5 +12,6 @@ changelog-generator [flags] --completion string Output command-line completion code for the specified shell. Can be 'bash', 'zsh', 'fish', or 'powershell'. --config string Config file (default ".changelog-generator.yaml") -h, --help help for changelog-generator + --repo string Path to the git repo root. Parent directories will be walked until .git is found. (default ".") ```