Skip to content

Commit 4d68c58

Browse files
authored
changelog-entry: allow customizing allowed types (#33)
1 parent 974418b commit 4d68c58

File tree

2 files changed

+38
-6
lines changed

2 files changed

+38
-6
lines changed

cmd/changelog-entry/README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,25 @@ $ changelog-entry -type improvement -subcategory monitoring -description "optimi
2323

2424
If parameters are missing the command will prompt to fill them, the pull request number is optional and if not provided the command will try to guess it based on the current branch name and remote if the current directory is in a git repository.
2525

26+
### Customizing the allowed types
27+
28+
To customize the types that will be displayed in the prompt, create a line
29+
delimited file with the types are allow and pass it as the `-allowed-types-file`
30+
flag.
31+
32+
As an example, to allow only `bug` and `enhancement` types, create a file with the following content:
33+
34+
```sh
35+
bug
36+
enhancement
37+
```
38+
39+
Then pass it to the command:
40+
41+
```sh
42+
$ changelog-entry -allowed-types-file=types.txt
43+
```
44+
2645
## Output
2746

2847
``````markdown

cmd/changelog-entry/main.go

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,16 @@ import (
1010
"errors"
1111
"flag"
1212
"fmt"
13-
"github.com/go-git/go-git/v5"
14-
"github.com/google/go-github/github"
15-
"github.com/hashicorp/go-changelog"
16-
"github.com/manifoldco/promptui"
1713
"os"
1814
"path"
1915
"regexp"
2016
"strings"
2117
"text/template"
18+
19+
"github.com/go-git/go-git/v5"
20+
"github.com/google/go-github/github"
21+
"github.com/hashicorp/go-changelog"
22+
"github.com/manifoldco/promptui"
2223
)
2324

2425
//go:embed changelog-entry.tmpl
@@ -43,7 +44,7 @@ func main() {
4344
fmt.Fprintln(os.Stderr, err)
4445
os.Exit(1)
4546
}
46-
var subcategory, changeType, description, changelogTmpl, dir, url string
47+
var subcategory, changeType, description, changelogTmpl, dir, url, allowedTypes string
4748
var pr int
4849
var Url bool
4950
flag.BoolVar(&Url, "add-url", false, "add GitHub issue URL (omitted by default due to formatting in changelog-build)")
@@ -53,6 +54,7 @@ func main() {
5354
flag.StringVar(&description, "description", "", "the changelog entry content")
5455
flag.StringVar(&changelogTmpl, "changelog-template", "", "the path of the file holding the template to use for the changelog entries")
5556
flag.StringVar(&dir, "dir", "", "the relative path from the current directory of where the changelog entry file should be written")
57+
flag.StringVar(&allowedTypes, "allowed-types-file", "", "the relative path from the current directory to a line separated file of allowed types. If not provided, default types are used")
5658
flag.Parse()
5759

5860
if pr == -1 {
@@ -66,10 +68,21 @@ func main() {
6668
}
6769
fmt.Fprintln(os.Stderr, "Found matching pull request:", url)
6870

71+
promptTypes := changelog.TypeValues
72+
if allowedTypes != "" {
73+
file, err := os.ReadFile(allowedTypes)
74+
if err != nil {
75+
fmt.Fprintf(os.Stderr, "Failed to read allowed types file: %s\n", err)
76+
os.Exit(1)
77+
}
78+
79+
promptTypes = strings.Split(strings.TrimSpace(string(file)), "\n")
80+
}
81+
6982
if changeType == "" {
7083
prompt := promptui.Select{
7184
Label: "Select a change type",
72-
Items: changelog.TypeValues,
85+
Items: promptTypes,
7386
}
7487

7588
_, changeType, err = prompt.Run()

0 commit comments

Comments
 (0)