Skip to content

Commit

Permalink
fix: fix typo in the getDeb function (#30)
Browse files Browse the repository at this point in the history
* fix: fix typo in the getDeb function that prevented the deb distributions from being used when chglog is being used as a cli

* fix: fix lint issues
  • Loading branch information
Dj Gilcrease authored Nov 9, 2020
1 parent f4b552e commit 9c6b268
Show file tree
Hide file tree
Showing 15 changed files with 88 additions and 65 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ dist
bin
coverage.out
chglog
!chglog/
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ linters:
- wsl
- testpackage
- gofumpt
- exhaustivestruct
linters-settings:
maligned:
# print struct with more effective memory layout or not, false by default
Expand Down
6 changes: 3 additions & 3 deletions add.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,20 @@ func AddEntry(
)

if ref, err = gitRepo.Head(); err != nil {
return nil, err
return nil, fmt.Errorf("error adding entry: %w", err)
}
from = ref.Hash()

to = plumbing.ZeroHash
if len(current) > 0 {
if to, err = GitHashFotTag(gitRepo, current[0].Semver); err != nil {
return nil, err
return nil, fmt.Errorf("error adding entry: %w", err)
}
}

cle = append(cle, current...)
if commits, err = CommitsBetween(gitRepo, to, from); err != nil {
return nil, err
return nil, fmt.Errorf("error adding entry: %w", err)
}

if len(commits) == 0 {
Expand Down
9 changes: 0 additions & 9 deletions cmd/chglog/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,8 @@ func main() {
}
cwd, _ := os.Getwd()
cfgFile := path.Join(cwd, fmt.Sprintf(".%s.yml", pkgName))
debug := false
config := setupConfig(cfgFile)

cmdRoot.PersistentFlags().BoolVarP(
&debug,
"debug",
"",
debug,
``)
config.BindPFlag("debug", cmdRoot.PersistentFlags().Lookup("debug"))

cmdRoot.PersistentFlags().StringVarP(
&cfgFile,
"config-file",
Expand Down
2 changes: 1 addition & 1 deletion conventional_commits.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"strings"
)

// nolint: gochecknoglobals,gocritic
// nolint:gocritic
var expectedFormatRegex = regexp.MustCompile(`(?s)^(?P<category>\S+?)?(?P<scope>\(\S+\))?(?P<breaking>!?)?: (?P<description>[^\n\r]+)?([\n\r]{2}(?P<body>.*))?`)

// ParseConventionalCommit takes a commits message and parses it into usable blocks.
Expand Down
9 changes: 6 additions & 3 deletions files.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package chglog

import (
"fmt"
"io/ioutil"
"os"

Expand All @@ -17,12 +18,14 @@ func Parse(file string) (entries ChangeLogEntries, err error) {
case os.IsNotExist(err):
return make(ChangeLogEntries, 0), nil
case err != nil:
return nil, err
return nil, fmt.Errorf("error parsing %s: %w", file, err)
}

err = yaml.Unmarshal(body, &entries)
if err = yaml.Unmarshal(body, &entries); err != nil {
return entries, fmt.Errorf("error parsing %s: %w", file, err)
}

return entries, err
return entries, nil
}

// Save save ChangeLogEntries to a yml file.
Expand Down
7 changes: 5 additions & 2 deletions format.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@ package chglog

import (
"bytes"
"fmt"
"text/template"
)

// FormatChangelog format pkgLogs from a text/template.
func FormatChangelog(pkgLogs *PackageChangeLog, tpl *template.Template) (string, error) {
var data bytes.Buffer
err := tpl.Execute(&data, pkgLogs)
if err := tpl.Execute(&data, pkgLogs); err != nil {
return data.String(), fmt.Errorf("error formatting: %w", err)
}

return data.String(), err
return data.String(), nil
}
1 change: 1 addition & 0 deletions format_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ func TestFormatChangelog(t *testing.T) {
gitRepo *git.Repository
testCLE ChangeLogEntries
)
t.Parallel()
if gitRepo, err = GitRepo("./testdata/init-repo", false); err != nil {
log.Fatal(err)
}
Expand Down
8 changes: 5 additions & 3 deletions git.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package chglog

import (
"errors"
"fmt"
"strings"

"github.com/go-git/go-git/v5"
"github.com/go-git/go-git/v5/plumbing"
Expand All @@ -21,11 +23,11 @@ func GitRepo(gitPath string, detectDotGit bool) (*git.Repository, error) {
func GitHashFotTag(gitRepo *git.Repository, tagName string) (hash plumbing.Hash, err error) {
var ref *plumbing.Reference
ref, err = gitRepo.Tag(tagName)
if errors.Is(err, git.ErrTagNotFound) {
if errors.Is(err, git.ErrTagNotFound) && !strings.HasPrefix(tagName, "v") {
ref, err = gitRepo.Tag("v" + tagName)
}
if err != nil {
return plumbing.ZeroHash, err
return plumbing.ZeroHash, fmt.Errorf("error getting commit for tag %s: %w", tagName, err)
}

return ref.Hash(), nil
Expand All @@ -52,7 +54,7 @@ func CommitsBetween(gitRepo *git.Repository, start, end plumbing.Hash) (commits
})

if err != nil && !errors.Is(err, errReachedToCommit) {
return nil, err
return nil, fmt.Errorf("error getting commits between %v & %v: %w", start, end, err)
}

return commits, nil
Expand Down
23 changes: 14 additions & 9 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,29 @@ require (
github.com/Masterminds/semver v1.5.0
github.com/Masterminds/semver/v3 v3.1.0
github.com/Masterminds/sprig v2.22.0+incompatible
github.com/Microsoft/go-winio v0.4.15 // indirect
github.com/fsnotify/fsnotify v1.4.9 // indirect
github.com/go-git/go-git/v5 v5.2.0
github.com/google/go-cmp v0.5.2
github.com/google/uuid v1.1.1 // indirect
github.com/google/uuid v1.1.2 // indirect
github.com/huandu/xstrings v1.3.2 // indirect
github.com/imdario/mergo v0.3.11 // indirect
github.com/kevinburke/ssh_config v0.0.0-20201106050909-4977a11b4351 // indirect
github.com/magiconair/properties v1.8.4 // indirect
github.com/mitchellh/copystructure v1.0.0 // indirect
github.com/mitchellh/mapstructure v1.3.2 // indirect
github.com/mitchellh/mapstructure v1.3.3 // indirect
github.com/mitchellh/reflectwalk v1.0.1 // indirect
github.com/pelletier/go-toml v1.8.0 // indirect
github.com/spf13/afero v1.3.2 // indirect
github.com/pelletier/go-toml v1.8.1 // indirect
github.com/spf13/afero v1.4.1 // indirect
github.com/spf13/cast v1.3.1 // indirect
github.com/spf13/cobra v1.1.1
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/viper v1.7.1
golang.org/x/crypto v0.0.0-20200709230013-948cd5f35899 // indirect
golang.org/x/net v0.0.0-20200707034311-ab3426394381 // indirect
golang.org/x/sys v0.0.0-20200625212154-ddb9806d33ae // indirect
golang.org/x/text v0.3.3 // indirect
gopkg.in/ini.v1 v1.57.0 // indirect
github.com/xanzy/ssh-agent v0.3.0 // indirect
golang.org/x/crypto v0.0.0-20201016220609-9e8e0b390897 // indirect
golang.org/x/net v0.0.0-20201031054903-ff519b6c9102 // indirect
golang.org/x/sys v0.0.0-20201109165425-215b40eba54c // indirect
golang.org/x/text v0.3.4 // indirect
gopkg.in/ini.v1 v1.62.0 // indirect
gopkg.in/yaml.v2 v2.3.0
)
Loading

0 comments on commit 9c6b268

Please sign in to comment.