Skip to content

Commit 9c6b268

Browse files
author
Dj Gilcrease
authored
fix: fix typo in the getDeb function (#30)
* 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
1 parent f4b552e commit 9c6b268

15 files changed

+88
-65
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ dist
66
bin
77
coverage.out
88
chglog
9+
!chglog/

.golangci.yml

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ linters:
55
- wsl
66
- testpackage
77
- gofumpt
8+
- exhaustivestruct
89
linters-settings:
910
maligned:
1011
# print struct with more effective memory layout or not, false by default

add.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -32,20 +32,20 @@ func AddEntry(
3232
)
3333

3434
if ref, err = gitRepo.Head(); err != nil {
35-
return nil, err
35+
return nil, fmt.Errorf("error adding entry: %w", err)
3636
}
3737
from = ref.Hash()
3838

3939
to = plumbing.ZeroHash
4040
if len(current) > 0 {
4141
if to, err = GitHashFotTag(gitRepo, current[0].Semver); err != nil {
42-
return nil, err
42+
return nil, fmt.Errorf("error adding entry: %w", err)
4343
}
4444
}
4545

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

5151
if len(commits) == 0 {

cmd/chglog/main.go

-9
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,8 @@ func main() {
2525
}
2626
cwd, _ := os.Getwd()
2727
cfgFile := path.Join(cwd, fmt.Sprintf(".%s.yml", pkgName))
28-
debug := false
2928
config := setupConfig(cfgFile)
3029

31-
cmdRoot.PersistentFlags().BoolVarP(
32-
&debug,
33-
"debug",
34-
"",
35-
debug,
36-
``)
37-
config.BindPFlag("debug", cmdRoot.PersistentFlags().Lookup("debug"))
38-
3930
cmdRoot.PersistentFlags().StringVarP(
4031
&cfgFile,
4132
"config-file",

conventional_commits.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"strings"
66
)
77

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

1111
// ParseConventionalCommit takes a commits message and parses it into usable blocks.

files.go

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package chglog
22

33
import (
4+
"fmt"
45
"io/ioutil"
56
"os"
67

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

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

25-
return entries, err
28+
return entries, nil
2629
}
2730

2831
// Save save ChangeLogEntries to a yml file.

format.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,16 @@ package chglog
22

33
import (
44
"bytes"
5+
"fmt"
56
"text/template"
67
)
78

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

13-
return data.String(), err
16+
return data.String(), nil
1417
}

format_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ func TestFormatChangelog(t *testing.T) {
1919
gitRepo *git.Repository
2020
testCLE ChangeLogEntries
2121
)
22+
t.Parallel()
2223
if gitRepo, err = GitRepo("./testdata/init-repo", false); err != nil {
2324
log.Fatal(err)
2425
}

git.go

+5-3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package chglog
22

33
import (
44
"errors"
5+
"fmt"
6+
"strings"
57

68
"github.com/go-git/go-git/v5"
79
"github.com/go-git/go-git/v5/plumbing"
@@ -21,11 +23,11 @@ func GitRepo(gitPath string, detectDotGit bool) (*git.Repository, error) {
2123
func GitHashFotTag(gitRepo *git.Repository, tagName string) (hash plumbing.Hash, err error) {
2224
var ref *plumbing.Reference
2325
ref, err = gitRepo.Tag(tagName)
24-
if errors.Is(err, git.ErrTagNotFound) {
26+
if errors.Is(err, git.ErrTagNotFound) && !strings.HasPrefix(tagName, "v") {
2527
ref, err = gitRepo.Tag("v" + tagName)
2628
}
2729
if err != nil {
28-
return plumbing.ZeroHash, err
30+
return plumbing.ZeroHash, fmt.Errorf("error getting commit for tag %s: %w", tagName, err)
2931
}
3032

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

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

5860
return commits, nil

go.mod

+14-9
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,29 @@ require (
77
github.com/Masterminds/semver v1.5.0
88
github.com/Masterminds/semver/v3 v3.1.0
99
github.com/Masterminds/sprig v2.22.0+incompatible
10+
github.com/Microsoft/go-winio v0.4.15 // indirect
1011
github.com/fsnotify/fsnotify v1.4.9 // indirect
1112
github.com/go-git/go-git/v5 v5.2.0
1213
github.com/google/go-cmp v0.5.2
13-
github.com/google/uuid v1.1.1 // indirect
14+
github.com/google/uuid v1.1.2 // indirect
1415
github.com/huandu/xstrings v1.3.2 // indirect
16+
github.com/imdario/mergo v0.3.11 // indirect
17+
github.com/kevinburke/ssh_config v0.0.0-20201106050909-4977a11b4351 // indirect
18+
github.com/magiconair/properties v1.8.4 // indirect
1519
github.com/mitchellh/copystructure v1.0.0 // indirect
16-
github.com/mitchellh/mapstructure v1.3.2 // indirect
20+
github.com/mitchellh/mapstructure v1.3.3 // indirect
1721
github.com/mitchellh/reflectwalk v1.0.1 // indirect
18-
github.com/pelletier/go-toml v1.8.0 // indirect
19-
github.com/spf13/afero v1.3.2 // indirect
22+
github.com/pelletier/go-toml v1.8.1 // indirect
23+
github.com/spf13/afero v1.4.1 // indirect
2024
github.com/spf13/cast v1.3.1 // indirect
2125
github.com/spf13/cobra v1.1.1
2226
github.com/spf13/jwalterweatherman v1.1.0 // indirect
2327
github.com/spf13/viper v1.7.1
24-
golang.org/x/crypto v0.0.0-20200709230013-948cd5f35899 // indirect
25-
golang.org/x/net v0.0.0-20200707034311-ab3426394381 // indirect
26-
golang.org/x/sys v0.0.0-20200625212154-ddb9806d33ae // indirect
27-
golang.org/x/text v0.3.3 // indirect
28-
gopkg.in/ini.v1 v1.57.0 // indirect
28+
github.com/xanzy/ssh-agent v0.3.0 // indirect
29+
golang.org/x/crypto v0.0.0-20201016220609-9e8e0b390897 // indirect
30+
golang.org/x/net v0.0.0-20201031054903-ff519b6c9102 // indirect
31+
golang.org/x/sys v0.0.0-20201109165425-215b40eba54c // indirect
32+
golang.org/x/text v0.3.4 // indirect
33+
gopkg.in/ini.v1 v1.62.0 // indirect
2934
gopkg.in/yaml.v2 v2.3.0
3035
)

0 commit comments

Comments
 (0)