Skip to content

Commit

Permalink
feat(cmd): Add --repo flag
Browse files Browse the repository at this point in the history
  • Loading branch information
gabe565 committed Mar 14, 2024
1 parent a9c4e8f commit e95c7d6
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 4 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}` |

Expand Down
8 changes: 6 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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::'
Expand Down
12 changes: 11 additions & 1 deletion cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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
}
Expand Down
1 change: 1 addition & 0 deletions docs/changelog-generator.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 ".")
```

0 comments on commit e95c7d6

Please sign in to comment.