Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --ancestors-only and --filter flags + some much needed maintenance #156

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
9 changes: 8 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@ linters:
enable:
- dogsled
- dupl
- errcheck
- gocritic
- gofmt
- goimports
- gosec
- gosimple
- govet
- misspell
- nakedret
- stylecheck
Expand All @@ -17,5 +21,8 @@ linters:
- ineffassign
- unused
- staticcheck
- typecheck
- usestdlibvars
- exportloopref
issues:
exclude-use-default: false
exclude-use-default: false
17 changes: 17 additions & 0 deletions .mockery.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
with-expecter: true
filename: "mock_{{.InterfaceName}}.go"
dir: "mocks/{{.PackageName}}"
mockname: "Mock{{.InterfaceName}}"
outpkg: "{{.PackageName}}"

packages:
github.com/chelnak/gh-changelog/pkg/builder:
interfaces:
Git:
GitHub:
github.com/chelnak/gh-changelog/internal/githubclient:
interfaces:
GitHubClient:
github.com/chelnak/gh-changelog/internal/gitclient:
interfaces:
GitClient:
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,23 @@ This option can work well with `--next-version`.
gh changelog new --latest
```

#### --filter

Filter the results by tag name. This flag supports regular expressions.
Regular expressions used should follow RE2 syntax as described [here](https://golang.org/s/re2syntax).

```bash
gh changelog new --filter v1.*
```

#### --ancestors-only

Builds the changelog with tags that are ancestors of the current branch.

```bash
gh changelog new --ancestors-only
```

#### Console output

You can switch between two `spinner` and `console`.
Expand Down
2 changes: 1 addition & 1 deletion cmd/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ This command is useful for creating and updating Release notes in GitHub.
RunE: func(command *cobra.Command, args []string) error {
fileName := configuration.Config.FileName

var changelog changelog.Changelog
var changelog *changelog.Changelog
var err error

if printLatest {
Expand Down
54 changes: 40 additions & 14 deletions cmd/new.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,37 +5,61 @@ package cmd
import (
"os"
"path/filepath"
"regexp"

"github.com/chelnak/gh-changelog/internal/configuration"
"github.com/chelnak/gh-changelog/internal/log"
"github.com/chelnak/gh-changelog/internal/writer"
"github.com/chelnak/gh-changelog/pkg/builder"
"github.com/spf13/cobra"
)

var nextVersion string
var fromVersion string
var latestVersion bool
var logger string
var (
nextVersion string
fromVersion string
latestVersion bool
filter string
ancestorsOnly bool
logger string
)

// newCmd is the entry point for creating a new changelog
var newCmd = &cobra.Command{
Use: "new",
Short: "Creates a new changelog from activity in the current repository",
Long: "Creates a new changelog from activity in the current repository.",
RunE: func(command *cobra.Command, args []string) error {
opts := builder.BuilderOptions{
Logger: logger,
NextVersion: nextVersion,
FromVersion: fromVersion,
LatestVersion: latestVersion,
}

builder, err := builder.NewBuilder(opts)
log.SetupLogging(log.GetLoggerType(logger))
builder, err := builder.NewBuilder()
if err != nil {
return err
}

changelog, err := builder.BuildChangelog()
if nextVersion != "" {
builder.NextVersion(nextVersion)
}

if fromVersion != "" {
builder.FromVersion(fromVersion)
}

if latestVersion {
builder.LatestVersion()
}

if filter != "" {
fil, err := regexp.Compile(filter)
if err != nil {
return err
}
builder.Filter(fil)
}

if ancestorsOnly {
builder.AncestorsOnly()
}

changelog, err := builder.Build()
if err != nil {
return err
}
Expand Down Expand Up @@ -70,7 +94,9 @@ func init() {
"Build the changelog starting from the latest tag. Using this flag will result in a changelog with one entry.\nIt can be useful for generating a changelog to be used in release notes.",
)

newCmd.Flags().StringVar(&logger, "logger", "", "The type of logger to use. Valid values are 'spinner' and 'console'. The default is 'spinner'.")
newCmd.Flags().StringVar(&filter, "filter", "", "Filter the results by tag name. This flag supports regular expressions.")
newCmd.Flags().BoolVar(&ancestorsOnly, "ancestors-only", false, "Builds the changelog with tags that are ancestor of the current branch.")
newCmd.Flags().StringVar(&logger, "logger", "spinner", "The type of logger to use. Valid values are 'spinner' and 'console'. The default is 'spinner'.")

newCmd.MarkFlagsMutuallyExclusive("from-version", "latest")
newCmd.Flags().SortFlags = false
Expand Down
8 changes: 4 additions & 4 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"os"

"github.com/chelnak/gh-changelog/internal/configuration"
"github.com/chelnak/gh-changelog/internal/utils"
"github.com/chelnak/gh-changelog/internal/update"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -55,7 +55,7 @@ Issues or feature requests can be opened at:
Run: nil,
PersistentPostRun: func(cmd *cobra.Command, args []string) {
if configuration.Config.CheckForUpdates {
utils.CheckForUpdate(version)
update.CheckForUpdate(version)
}
},
}
Expand Down Expand Up @@ -83,15 +83,15 @@ func init() {
func formatError(err error) {
fmt.Print("\n❌ It looks like something went wrong!\n")
fmt.Println("\nReported errors:")
fmt.Fprintln(os.Stderr, fmt.Errorf("• %s", err))
_, _ = fmt.Fprintln(os.Stderr, fmt.Errorf("• %s", err))
fmt.Println()
}

// Execute is called from main and is responsible for processing
// requests to the application and handling exit codes appropriately
func Execute() int {
if err := rootCmd.Execute(); err != nil {
if err != errSilent {
if !errors.Is(err, errSilent) {
formatError(err)
}
return 1
Expand Down
64 changes: 33 additions & 31 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,33 @@ go 1.21
require (
github.com/Masterminds/semver/v3 v3.2.1
github.com/alecthomas/chroma v0.10.0
github.com/charmbracelet/bubbles v0.15.0
github.com/charmbracelet/bubbletea v0.23.2
github.com/charmbracelet/glamour v0.6.0
github.com/charmbracelet/lipgloss v0.6.0
github.com/chelnak/ysmrr v0.2.1
github.com/cli/go-gh v1.2.1
github.com/fatih/color v1.15.0
github.com/charmbracelet/bubbles v0.18.0
github.com/charmbracelet/bubbletea v0.25.0
github.com/charmbracelet/glamour v0.7.0
github.com/charmbracelet/lipgloss v0.10.0
github.com/chelnak/ysmrr v0.4.0
github.com/cli/go-gh/v2 v2.8.0
github.com/cli/shurcooL-graphql v0.0.4
github.com/fatih/color v1.16.0
github.com/gomarkdown/markdown v0.0.0-20240419095408-642f0ee99ae2
github.com/jarcoal/httpmock v1.2.0
github.com/rs/zerolog v1.29.1
github.com/shurcooL/githubv4 v0.0.0-20240429030203-be2daab69064
github.com/spf13/cobra v1.6.1
github.com/spf13/viper v1.15.0
github.com/stretchr/testify v1.8.4
github.com/rs/zerolog v1.32.0
github.com/spf13/cobra v1.8.0
github.com/spf13/viper v1.18.2
github.com/stretchr/testify v1.9.0
golang.org/x/text v0.14.0
gopkg.in/h2non/gock.v1 v1.1.2
gopkg.in/yaml.v2 v2.4.0
)

require (
github.com/aymanbagabas/go-osc52 v1.2.2 // indirect
github.com/alecthomas/chroma/v2 v2.13.0 // indirect
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
github.com/aymerick/douceur v0.2.0 // indirect
github.com/cli/safeexec v1.0.1 // indirect
github.com/cli/shurcooL-graphql v0.0.4 // indirect
github.com/containerd/console v1.0.4 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/dlclark/regexp2 v1.8.1 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/dlclark/regexp2 v1.11.0 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/gorilla/css v1.0.1 // indirect
github.com/h2non/parth v0.0.0-20190131123155-b4df798d6542 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
Expand All @@ -49,25 +48,28 @@ require (
github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 // indirect
github.com/muesli/cancelreader v0.2.2 // indirect
github.com/muesli/reflow v0.3.0 // indirect
github.com/muesli/termenv v0.14.0 // indirect
github.com/muesli/termenv v0.15.2 // indirect
github.com/olekukonko/tablewriter v0.0.5 // indirect
github.com/pelletier/go-toml/v2 v2.0.9 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/pelletier/go-toml/v2 v2.2.1 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/rivo/uniseg v0.4.7 // indirect
github.com/shurcooL/graphql v0.0.0-20230722043721-ed46e5a46466 // indirect
github.com/spf13/afero v1.9.5 // indirect
github.com/spf13/cast v1.5.1 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/sagikazarmark/locafero v0.4.0 // indirect
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
github.com/sourcegraph/conc v0.3.0 // indirect
github.com/spf13/afero v1.11.0 // indirect
github.com/spf13/cast v1.6.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/stretchr/objx v0.5.2 // indirect
github.com/subosito/gotenv v1.4.2 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
github.com/thlib/go-timezone-local v0.0.0-20210907160436-ef149e42d28e // indirect
github.com/yuin/goldmark v1.5.6 // indirect
github.com/yuin/goldmark v1.7.1 // indirect
github.com/yuin/goldmark-emoji v1.0.2 // indirect
golang.org/x/net v0.23.0 // indirect
golang.org/x/sync v0.1.0 // indirect
golang.org/x/sys v0.18.0 // indirect
golang.org/x/term v0.18.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/exp v0.0.0-20240416160154-fe59bbe5cc7f // indirect
golang.org/x/net v0.24.0 // indirect
golang.org/x/sync v0.7.0 // indirect
golang.org/x/sys v0.19.0 // indirect
golang.org/x/term v0.19.0 // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
Expand Down
Loading
Loading