Skip to content

Commit

Permalink
Merge pull request #112 from chelnak/convert_changelog_datastructure
Browse files Browse the repository at this point in the history
Convert changelog datastructure
  • Loading branch information
chelnak authored Nov 13, 2022
2 parents 2d0076b + 0590070 commit 5143363
Show file tree
Hide file tree
Showing 13 changed files with 557 additions and 201 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@ jobs:
version: "latest"

- name: "test"
run: go test -v ./...
run: go test -race -covermode=atomic -v ./...
35 changes: 18 additions & 17 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,33 @@ require (
github.com/Masterminds/semver/v3 v3.1.1
github.com/alecthomas/chroma v0.10.0
github.com/charmbracelet/bubbles v0.14.0
github.com/charmbracelet/bubbletea v0.22.1
github.com/charmbracelet/glamour v0.5.1-0.20220727184942-e70ff2d969da
github.com/charmbracelet/bubbletea v0.23.0
github.com/charmbracelet/glamour v0.6.0
github.com/charmbracelet/lipgloss v0.6.0
github.com/chelnak/ysmrr v0.2.0
github.com/cli/go-gh v0.1.1
github.com/chelnak/ysmrr v0.2.1
github.com/cli/go-gh v0.1.2
github.com/fatih/color v1.13.0
github.com/gomarkdown/markdown v0.0.0-20221013030248-663e2500819c
github.com/jarcoal/httpmock v1.2.0
github.com/rs/zerolog v1.28.0
github.com/shurcooL/githubv4 v0.0.0-20220922232305-70b4d362a8cb
github.com/spf13/cobra v1.5.0
github.com/spf13/viper v1.13.0
github.com/stretchr/testify v1.8.0
github.com/shurcooL/githubv4 v0.0.0-20221021030919-a134b1472cc7
github.com/spf13/cobra v1.6.1
github.com/spf13/viper v1.14.0
github.com/stretchr/testify v1.8.1
golang.org/x/text v0.4.0
gopkg.in/h2non/gock.v1 v1.1.2
gopkg.in/yaml.v2 v2.4.0
)

require (
github.com/aymanbagabas/go-osc52 v1.0.3 // indirect
github.com/aymanbagabas/go-osc52 v1.2.1 // indirect
github.com/aymerick/douceur v0.2.0 // indirect
github.com/cli/safeexec v1.0.0 // indirect
github.com/cli/shurcooL-graphql v0.0.2 // indirect
github.com/containerd/console v1.0.3 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/dlclark/regexp2 v1.7.0 // indirect
github.com/fsnotify/fsnotify v1.5.4 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/gorilla/css v1.0.0 // indirect
github.com/h2non/parth v0.0.0-20190131123155-b4df798d6542 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
Expand All @@ -44,7 +46,7 @@ require (
github.com/mattn/go-runewidth v0.0.14 // indirect
github.com/microcosm-cc/bluemonday v1.0.21 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/muesli/ansi v0.0.0-20211031195517-c9f0611b6c70 // indirect
github.com/muesli/ansi v0.0.0-20221106050444-61f0cd9a192a // indirect
github.com/muesli/cancelreader v0.2.2 // indirect
github.com/muesli/reflow v0.3.0 // indirect
github.com/muesli/termenv v0.13.0 // indirect
Expand All @@ -58,15 +60,14 @@ require (
github.com/spf13/cast v1.5.0 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/stretchr/objx v0.4.0 // indirect
github.com/stretchr/objx v0.5.0 // indirect
github.com/subosito/gotenv v1.4.1 // indirect
github.com/thlib/go-timezone-local v0.0.0-20210907160436-ef149e42d28e // indirect
github.com/yuin/goldmark v1.5.2 // indirect
github.com/yuin/goldmark v1.5.3 // indirect
github.com/yuin/goldmark-emoji v1.0.1 // indirect
golang.org/x/net v0.0.0-20221004154528-8021a29435af // indirect
golang.org/x/sys v0.0.0-20221006211917-84dc82d7e875 // indirect
golang.org/x/term v0.0.0-20220919170432-7a66f970e087 // indirect
golang.org/x/text v0.3.7 // indirect
golang.org/x/net v0.2.0 // indirect
golang.org/x/sys v0.2.0 // indirect
golang.org/x/term v0.2.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
81 changes: 42 additions & 39 deletions go.sum

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion internal/show/viewport.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func start(content string) error {
tea.WithMouseCellMotion(),
)

if err := p.Start(); err != nil {
if _, err := p.Run(); err != nil {
return err
}

Expand Down
28 changes: 23 additions & 5 deletions internal/writer/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ package writer

import (
"io"
"os/exec"
"text/template"

"github.com/chelnak/gh-changelog/internal/gitclient"
"github.com/chelnak/gh-changelog/pkg/changelog"
)

Expand All @@ -16,17 +18,20 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org).
{{- $unreleased := .GetUnreleased }}
{{- if $unreleased }}
{{if $unreleased }}
## Unreleased
{{range $unreleased }}
- {{.}}
{{- end}}
{{- end -}}
{{range .GetEntries}}
## [{{.CurrentTag}}](https://github.com/{{$.GetRepoOwner}}/{{$.GetRepoName}}/tree/{{.CurrentTag}}) - {{.Date.Format "2006-01-02"}}
## [{{.Tag}}](https://github.com/{{$.GetRepoOwner}}/{{$.GetRepoName}}/tree/{{.Tag}}) - {{.Date.Format "2006-01-02"}}
{{ if .Previous }}
[Full Changelog](https://github.com/{{$.GetRepoOwner}}/{{$.GetRepoName}}/compare/{{.Previous.Tag}}...{{.Tag}})
{{else}}
[Full Changelog](https://github.com/{{$.GetRepoOwner}}/{{$.GetRepoName}}/compare/{{getFirstCommit}}...{{.Tag}})
{{- end -}}
[Full Changelog](https://github.com/{{$.GetRepoOwner}}/{{$.GetRepoName}}/compare/{{.PreviousTag}}...{{.CurrentTag}})
{{if .Added }}
### Added
{{range .Added}}
Expand Down Expand Up @@ -77,6 +82,19 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
{{- end}}`

func Write(writer io.Writer, changelog changelog.Changelog) error {
tmpl := template.Must(template.New("changelog").Parse(tmplSrc))
tmpl, err := template.New("changelog").Funcs(template.FuncMap{
"getFirstCommit": func() string {
git := gitclient.NewGitClient(exec.Command)
commit, err := git.GetFirstCommit()
if err != nil {
return ""
}
return commit
},
}).Parse(tmplSrc)
if err != nil {
return err
}

return tmpl.Execute(writer, changelog)
}
24 changes: 12 additions & 12 deletions internal/writer/writer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

"github.com/chelnak/gh-changelog/internal/writer"
"github.com/chelnak/gh-changelog/pkg/changelog"
"github.com/chelnak/gh-changelog/pkg/entry"
"github.com/stretchr/testify/assert"
)

Expand All @@ -19,20 +20,19 @@ const (
func Test_ItWritesOutAChangelogInTheCorrectFormat(t *testing.T) {
mockChangelog := changelog.NewChangelog(repoName, repoOwner)

entry := changelog.Entry{
CurrentTag: "v1.0.0",
PreviousTag: "v0.0.0",
Date: time.Now(),
Added: []string{"Added 1", "Added 2"},
Changed: []string{"Changed 1", "Changed 2"},
Deprecated: []string{"Deprecated 1", "Deprecated 2"},
Removed: []string{"Removed 1", "Removed 2"},
Fixed: []string{"Fixed 1", "Fixed 2"},
Security: []string{"Security 1", "Security 2"},
Other: []string{"Other 1", "Other 2"},
entry := entry.Entry{
Tag: "v1.0.0",
Date: time.Now(),
Added: []string{"Added 1", "Added 2"},
Changed: []string{"Changed 1", "Changed 2"},
Deprecated: []string{"Deprecated 1", "Deprecated 2"},
Removed: []string{"Removed 1", "Removed 2"},
Fixed: []string{"Fixed 1", "Fixed 2"},
Security: []string{"Security 1", "Security 2"},
Other: []string{"Other 1", "Other 2"},
}

mockChangelog.AddEntry(entry)
mockChangelog.Insert(entry)
mockChangelog.AddUnreleased([]string{"Unreleased 1", "Unreleased 2"})

var buf bytes.Buffer
Expand Down
52 changes: 42 additions & 10 deletions mocks/Changelog.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

63 changes: 63 additions & 0 deletions mocks/Logger.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 5143363

Please sign in to comment.