Skip to content

Commit

Permalink
Merge pull request #12 from chelnak/show_command
Browse files Browse the repository at this point in the history
Add show command
  • Loading branch information
chelnak authored Apr 15, 2022
2 parents 25fbbd8 + 9b76108 commit 0baab7d
Show file tree
Hide file tree
Showing 8 changed files with 296 additions and 29 deletions.
27 changes: 18 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,29 +1,38 @@
# Make your changelogs ✨

[![ci](https://github.com/chelnak/gh-changelog/actions/workflows/ci.yml/badge.svg)](https://github.com/chelnak/gh-changelog/actions/workflows/ci.yml) [![Release](https://img.shields.io/github/release/chelnak/gh-changelog.svg)](https://github.com/chelnak/gh-changelog/releases/latest)
[![ci](https://github.com/chelnak/gh-changelog/actions/workflows/ci.yml/badge.svg)](https://github.com/chelnak/gh-changelog/actions/workflows/ci.yml)
[![Release](https://img.shields.io/github/release/chelnak/gh-changelog.svg)](https://github.com/chelnak/gh-changelog/releases/latest)

An opinionated [GitHub Cli](https://github.com/cli/cli) extension for creating changelogs that adhere to the [keep a changelog](https://keepachangelog.com/en/1.0.0/) specification.

## Installation and Usage

Before you start make sure that:

- GitHub Cli is [installed](https://cli.github.com/manual/installation) and [authenticated](https://cli.github.com/manual/gh_auth_login)
- You are inside a git repository
- The repository contains commits and has been pushed to GitHub

### Install

```bash
# Install
gh extension install chelnak/gh-changelog
```

### Upgrade

```bash
# Upgrade
gh extension upgrade chelnak/gh-changelog
```

Before you start make sure that:
### Create a new changelog

- GitHub Cli is [installed](https://cli.github.com/manual/installation) and [authenticated](https://cli.github.com/manual/gh_auth_login)
- You are inside a git repository
- The repository contains commits and has been pushed to GitHub
```bash
gh changelog new
```

Basic usage is simple. Just run the following command:
### View your changelog in the terminal

```bash
gh changelog
gh changelog show
```
31 changes: 31 additions & 0 deletions cmd/new.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package cmd

import (
"fmt"
"time"

"github.com/briandowns/spinner"
"github.com/chelnak/gh-changelog/internal/pkg/changelog"
"github.com/chelnak/gh-changelog/internal/pkg/writer"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)

var newCmd = &cobra.Command{
Use: "new",
Short: "Creates a new changelog from activity in the current repository",
Long: "Creates a new changelog from activity the current repository.",
RunE: func(command *cobra.Command, args []string) error {
s := spinner.New(spinner.CharSets[11], 100*time.Millisecond)
_ = s.Color("green")
s.FinalMSG = fmt.Sprintf("✅ Open %s or run 'gh changelog show' to view your changelog.\n", viper.GetString("fileName"))

changeLog, err := changelog.MakeFullChangelog(s)
if err != nil {
return err
}

s.Stop()
return writer.Write(changeLog)
},
}
25 changes: 5 additions & 20 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,8 @@ import (
"errors"
"fmt"
"os"
"time"

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

Expand All @@ -18,27 +14,13 @@ var ErrSilent = errors.New("ErrSilent")

// RootCmd represents the base command when called without any subcommands
var rootCmd = &cobra.Command{
Use: "changelog",
Use: "changelog [command]",
Short: "Create a changelog that adheres to the [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) format",
Long: "Create a changelog that adheres to the [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) format",
Version: version,
SilenceUsage: true,
SilenceErrors: true,
RunE: func(command *cobra.Command, args []string) error {

s := spinner.New(spinner.CharSets[11], 100*time.Millisecond)
_ = s.Color("green")
s.FinalMSG = "✅ Done!\n"

changeLog, err := changelog.MakeFullChangelog(s)
if err != nil {
return err
}

s.Stop()

return writer.Write(changeLog)
},
Run: nil,
}

func init() {
Expand All @@ -53,6 +35,9 @@ func init() {
cmd.Println(cmd.UsageString())
return ErrSilent
})

rootCmd.AddCommand(newCmd)
rootCmd.AddCommand(showCmd)
}

func Execute() int {
Expand Down
18 changes: 18 additions & 0 deletions cmd/show.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package cmd

import (
"github.com/chelnak/gh-changelog/internal/pkg/markdown"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)

var showCmd = &cobra.Command{
Use: "show",
Short: "Renders a changelog in the terminal",
Long: "Renders the changelog in the terminal",
RunE: func(command *cobra.Command, args []string) error {

changelog := viper.GetString("fileName")
return markdown.Render(changelog)
},
}
20 changes: 20 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,55 @@ go 1.18

require (
github.com/briandowns/spinner v1.18.1
github.com/charmbracelet/bubbles v0.10.3
github.com/charmbracelet/bubbletea v0.20.0
github.com/charmbracelet/glamour v0.5.0
github.com/charmbracelet/lipgloss v0.5.0
github.com/cli/go-gh v0.0.3
github.com/google/go-github/v43 v43.0.0
github.com/spf13/cobra v1.4.0
github.com/spf13/viper v1.11.0
)

require (
github.com/alecthomas/chroma v0.10.0 // indirect
github.com/aymerick/douceur v0.2.0 // indirect
github.com/cli/safeexec v1.0.0 // indirect
github.com/cli/shurcooL-graphql v0.0.1 // indirect
github.com/containerd/console v1.0.3 // indirect
github.com/dlclark/regexp2 v1.4.0 // indirect
github.com/fatih/color v1.13.0 // indirect
github.com/fsnotify/fsnotify v1.5.1 // indirect
github.com/google/go-querystring v1.1.0 // indirect
github.com/gorilla/css v1.0.0 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/henvic/httpretty v0.0.6 // indirect
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
github.com/magiconair/properties v1.8.6 // indirect
github.com/mattn/go-colorable v0.1.12 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect
github.com/mattn/go-runewidth v0.0.13 // indirect
github.com/microcosm-cc/bluemonday v1.0.17 // indirect
github.com/mitchellh/mapstructure v1.4.3 // indirect
github.com/muesli/ansi v0.0.0-20211018074035-2e021307bc4b // indirect
github.com/muesli/reflow v0.3.0 // indirect
github.com/muesli/termenv v0.11.1-0.20220212125758-44cd13922739 // indirect
github.com/olekukonko/tablewriter v0.0.5 // indirect
github.com/pelletier/go-toml v1.9.4 // indirect
github.com/pelletier/go-toml/v2 v2.0.0-beta.8 // indirect
github.com/rivo/uniseg v0.2.0 // indirect
github.com/spf13/afero v1.8.2 // indirect
github.com/spf13/cast v1.4.1 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/subosito/gotenv v1.2.0 // indirect
github.com/yuin/goldmark v1.4.4 // indirect
github.com/yuin/goldmark-emoji v1.0.1 // indirect
golang.org/x/crypto v0.0.0-20220411220226-7b82a4e95df4 // indirect
golang.org/x/net v0.0.0-20220412020605-290c469a71a5 // indirect
golang.org/x/sys v0.0.0-20220412211240-33da011f77ad // indirect
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect
golang.org/x/text v0.3.7 // indirect
gopkg.in/ini.v1 v1.66.4 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
Expand Down
Loading

0 comments on commit 0baab7d

Please sign in to comment.