Skip to content

Commit

Permalink
Move changelog generation to root command and update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
hskiba committed Aug 15, 2023
1 parent 958b700 commit ec48bfe
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 28 deletions.
58 changes: 58 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,61 @@
# gotaglog

[![Go Report Card](https://goreportcard.com/badge/github.com/frgrisk/gotaglog)](https://goreportcard.com/report/github.com/frgrisk/gotaglog)

GoTagLog is a simple command-line application to automatically generate a
changelog from git tags based on the semantic versioning. It categorizes
commits into groups and outputs them in a formatted markdown file or
directly to the terminal with highlighting.

## Prerequisites

To use GoTagLog, you'll need to have:

- [Go](https://golang.org/dl/) installed on your local machine.

## Installation

```bash
go install github.com/frgrisk/gotaglog@latest
```

## Usage

To generate a changelog, use the following command:

```bash
gotaglog
```

### Flags

The application accepts several flags:

- `--config`: path to configuration file (default is `$HOME/.gotaglog.yaml`).
- `-o, --output`: path to output file (default if to print to stdout).
- `-r, --repo`: repo to generate changelog for (default is current directory).
- `--unreleased`: show only unreleased changes.

### Environment variables

In addition to flags and the configuration file, you can also use
environment variables to set parameters. The application will automatically
look for any environment variables beginning with `GOTAGLOG_`. For
instance, to set the repo, you could use the following command:

```bash
export GOTAGLOG_REPO=/path/to/repo
```

## License

GoTagLog is released under the MIT License. See the [LICENSE](./LICENSE)
file for more details.

## Acknowledgments

- Inspired by [git-cliff](https://github.com/orhun/git-cliff)
- Built with [go-git](https://github.com/go-git/go-git)
- Command line interface powered by [cobra](https://github.com/spf13/cobra)
- Configuration management using [viper](https://github.com/spf13/viper)
- Markdown rendering by [glamour](https://github.com/charmbracelet/glamour)
30 changes: 6 additions & 24 deletions cmd/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,35 +15,12 @@ import (
"github.com/go-git/go-git/v5/plumbing/object"
"github.com/go-git/go-git/v5/plumbing/storer"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"golang.org/x/term"
"golang.org/x/text/cases"
"golang.org/x/text/language"
)

// generateCmd represents the generate command
var generateCmd = &cobra.Command{
Use: "generate",
Short: "Generate a changelog from git tags",
Run: func(cmd *cobra.Command, args []string) {
getChangeLog()
},
}

func init() {
rootCmd.AddCommand(generateCmd)
generateCmd.Flags().StringP("output", "o", "", "output file")
err := generateCmd.MarkFlagFilename("output", "md")
if err != nil {
panic(err)
}
err = viper.BindPFlags(generateCmd.Flags())
if err != nil {
panic(err)
}
}

type CommitGroup struct {
Message string
Group string
Expand Down Expand Up @@ -113,8 +90,13 @@ func getChangeLog() {
prevTag = tag
if ver == semverTags[len(semverTags)-1] {
entry = getTagEntryDetails(repo, tag, nil)
unreleasedEntry := []string{"## [unreleased]", entry}
if entry != "" {
changelog = append([]string{"## [unreleased]", entry}, changelog...)
if viper.GetBool("unreleased") {
changelog = unreleasedEntry
} else {
changelog = append(unreleasedEntry, changelog...)
}
}
}
}
Expand Down
16 changes: 12 additions & 4 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ var cfgFile string
var rootCmd = &cobra.Command{
Use: "gotaglog",
Short: "Generate a changelog from git tags",
// Run: func(cmd *cobra.Command, args []string) { },
Run: func(cmd *cobra.Command, args []string) {
getChangeLog()
},
}

// Execute adds all child commands to the root command and sets flags appropriately.
Expand All @@ -38,10 +40,16 @@ func init() {
panic(err)
}

// Cobra also supports local flags, which will only run
// when this action is called directly.
rootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
rootCmd.Flags().Bool("unreleased", false, "show only unreleased changes")
rootCmd.Flags().StringP("output", "o", "", "output file")
err = rootCmd.MarkFlagFilename("output", "md")
if err != nil {
panic(err)
}
err = viper.BindPFlags(rootCmd.Flags())
if err != nil {
panic(err)
}
err = viper.BindPFlags(rootCmd.PersistentFlags())
if err != nil {
panic(err)
Expand Down

0 comments on commit ec48bfe

Please sign in to comment.