Skip to content

Commit c811657

Browse files
authored
Merge pull request #153 from antham/enable-gofumpt
Enable gofumpt, upgrade vendors
2 parents 99d671f + ca49c5c commit c811657

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+80
-111
lines changed

.github/workflows/build.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,5 @@ permissions:
1414
jobs:
1515
call-workflow:
1616
uses: antham/go-workflow-github-action/.github/workflows/build.yml@master
17+
secrets:
18+
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

.golangci.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
linters:
2+
enable:
3+
- gofumpt

chyle/apih/http.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package apih
22

33
import (
44
"fmt"
5-
"io/ioutil"
5+
"io"
66
"log"
77
"net/http"
88
)
@@ -29,21 +29,18 @@ func SetHeaders(request *http.Request, headers map[string]string) {
2929
// SendRequest picks a request and send it with given client
3030
func SendRequest(client *http.Client, request *http.Request) (int, []byte, error) {
3131
response, err := client.Do(request)
32-
3332
if err != nil {
3433
return 0, []byte{}, err
3534
}
3635

3736
defer func() {
3837
err = response.Body.Close()
39-
4038
if err != nil {
4139
log.Fatal(err)
4240
}
4341
}()
4442

45-
b, err := ioutil.ReadAll(response.Body)
46-
43+
b, err := io.ReadAll(response.Body)
4744
if err != nil {
4845
return response.StatusCode, b, errResponse{request, response, b}
4946
}

chyle/chyle.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ var EnableDebugging = false
2222
// BuildChangelog creates a changelog from defined configuration
2323
func BuildChangelog(envConfig *envh.EnvTree) error {
2424
conf, err := config.Create(envConfig)
25-
2625
if err != nil {
2726
return err
2827
}
@@ -32,7 +31,6 @@ func BuildChangelog(envConfig *envh.EnvTree) error {
3231
}
3332

3433
commits, err := git.FetchCommits(conf.GIT.REPOSITORY.PATH, conf.GIT.REFERENCE.FROM, conf.GIT.REFERENCE.TO)
35-
3634
if err != nil {
3735
return err
3836
}

chyle/chyle_test.go

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package chyle
33
import (
44
"bytes"
55
"encoding/json"
6-
"io/ioutil"
76
"log"
87
"os"
98
"testing"
@@ -16,7 +15,6 @@ import (
1615
func TestBuildChangelog(t *testing.T) {
1716
restoreEnvs()
1817
p, err := os.Getwd()
19-
2018
if err != nil {
2119
log.Fatal(err)
2220
}
@@ -30,8 +28,7 @@ func TestBuildChangelog(t *testing.T) {
3028
setenv("CHYLE_EXTRACTORS_MESSAGE_REG", "(.{1,50})")
3129
setenv("CHYLE_SENDERS_STDOUT_FORMAT", "json")
3230

33-
f, err := ioutil.TempFile(p+"/testing-repository", "test")
34-
31+
f, err := os.CreateTemp(p+"/testing-repository", "test")
3532
if err != nil {
3633
log.Fatal(err)
3734
}
@@ -43,7 +40,6 @@ func TestBuildChangelog(t *testing.T) {
4340
}()
4441

4542
config, err := envh.NewEnvTree("CHYLE", "_")
46-
4743
if err != nil {
4844
log.Fatal(err)
4945
}
@@ -57,7 +53,7 @@ func TestBuildChangelog(t *testing.T) {
5753

5854
assert.NoError(t, err)
5955

60-
b, err := ioutil.ReadFile(f.Name())
56+
b, err := os.ReadFile(f.Name())
6157

6258
assert.NoError(t, err)
6359

@@ -120,7 +116,6 @@ func TestBuildChangelog(t *testing.T) {
120116
func TestBuildChangelogWithAnErrorFromGitPackage(t *testing.T) {
121117
restoreEnvs()
122118
p, err := os.Getwd()
123-
124119
if err != nil {
125120
log.Fatal(err)
126121
}
@@ -135,7 +130,6 @@ func TestBuildChangelogWithAnErrorFromGitPackage(t *testing.T) {
135130
setenv("CHYLE_SENDERS_STDOUT_FORMAT", "json")
136131

137132
config, err := envh.NewEnvTree("CHYLE", "_")
138-
139133
if err != nil {
140134
log.Fatal(err)
141135
}
@@ -149,7 +143,6 @@ func TestBuildChangelogWithAnErrorFromGitPackage(t *testing.T) {
149143
func TestBuildChangelogWithAnErrorFromConfigPackage(t *testing.T) {
150144
restoreEnvs()
151145
p, err := os.Getwd()
152-
153146
if err != nil {
154147
log.Fatal(err)
155148
}
@@ -160,7 +153,6 @@ func TestBuildChangelogWithAnErrorFromConfigPackage(t *testing.T) {
160153
setenv("CHYLE_SENDERS_STDOUT_FORMAT", "whatever")
161154

162155
config, err := envh.NewEnvTree("CHYLE", "_")
163-
164156
if err != nil {
165157
log.Fatal(err)
166158
}
@@ -174,7 +166,6 @@ func TestBuildChangelogWithAnErrorFromConfigPackage(t *testing.T) {
174166
func TestBuildChangelogWithDebuggingEnabled(t *testing.T) {
175167
restoreEnvs()
176168
p, err := os.Getwd()
177-
178169
if err != nil {
179170
log.Fatal(err)
180171
}
@@ -190,7 +181,6 @@ func TestBuildChangelogWithDebuggingEnabled(t *testing.T) {
190181
setenv("CHYLE_EXTRACTORS_MESSAGE_REG", "(.{1,50})")
191182

192183
config, err := envh.NewEnvTree("CHYLE", "_")
193-
194184
if err != nil {
195185
log.Fatal(err)
196186
}

chyle/config/api_decorator.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,6 @@ func (a *apiDecoratorConfigurator) applyCustomValidators(keyChains *[][]string)
141141
// validateKeys checks key mapping between fields extracted from api and fields added to final struct
142142
func (a *apiDecoratorConfigurator) validateKeys() error {
143143
keys, err := a.config.FindChildrenKeys("CHYLE", "DECORATORS", a.decoratorKey, "KEYS")
144-
145144
if err != nil {
146145
return EnvValidationError{fmt.Sprintf(`define at least one environment variable couple "CHYLE_DECORATORS_%s_KEYS_*_DESTKEY" and "CHYLE_DECORATORS_%s_KEYS_*_FIELD", replace "*" with your own naming`, a.decoratorKey, a.decoratorKey), strings.Join([]string{"CHYLE", "DECORATORS", a.decoratorKey, "KEYS"}, "_")}
147146
}

chyle/config/config_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ func saveExistingEnvs() {
2727
env := envh.NewEnv()
2828

2929
envs, err = env.FindEntries(".*")
30-
3130
if err != nil {
3231
fmt.Println(err)
3332
os.Exit(1)
@@ -46,7 +45,6 @@ func restoreEnvs() {
4645

4746
func setenv(key string, value string) {
4847
err := os.Setenv(key, value)
49-
5048
if err != nil {
5149
fmt.Println(err)
5250
os.Exit(1)

chyle/config/extractors.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ func (e *extractorsConfigurator) setExtractors(config *CHYLE) {
6161
DESTKEY string
6262
REG *regexp.Regexp
6363
}{
64-
6564
e.config.FindStringUnsecured("CHYLE", "EXTRACTORS", key, "ORIGKEY"),
6665
e.config.FindStringUnsecured("CHYLE", "EXTRACTORS", key, "DESTKEY"),
6766
regexp.MustCompile(e.config.FindStringUnsecured("CHYLE", "EXTRACTORS", key, "REG")),

chyle/config/matchers.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ func (m *matchersConfigurator) isDisabled() bool {
4040
func (m *matchersConfigurator) validateRegexpMatchers() error {
4141
for _, key := range []string{"MESSAGE", "COMMITTER", "AUTHOR"} {
4242
_, err := m.config.FindString("CHYLE", "MATCHERS", key)
43-
4443
if err != nil {
4544
continue
4645
}
@@ -55,7 +54,6 @@ func (m *matchersConfigurator) validateRegexpMatchers() error {
5554

5655
func (m *matchersConfigurator) validateTypeMatcher() error {
5756
_, err := m.config.FindString("CHYLE", "MATCHERS", "TYPE")
58-
5957
if err != nil {
6058
return nil
6159
}

chyle/config/primitives.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@ func validateTemplate(fullconfig *envh.EnvTree, keyChain []string) error {
9090
val := fullconfig.FindStringUnsecured(keyChain...)
9191

9292
_, err := tmplh.Parse("test", val)
93-
9493
if err != nil {
9594
return EnvValidationError{fmt.Sprintf(`provide a valid template string for "%s" : "%s", "%s" given`, strings.Join(keyChain, "_"), err.Error(), val), strings.Join(keyChain, "_")}
9695
}

chyle/config/shell_decorator.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,5 +63,4 @@ func (s *shellDecoratorConfigurator) setShellConfigs(config *CHYLE) {
6363
s.config.FindStringUnsecured("CHYLE", "DECORATORS", "SHELL", key, "DESTKEY"),
6464
}
6565
}
66-
6766
}

chyle/decorators/decorator.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ func Decorate(decorators *map[string][]Decorater, changelog *types.Changelog) (*
2020

2121
for _, decorator := range (*decorators)["datas"] {
2222
result, err = decorator.Decorate(&d)
23-
2423
if err != nil {
2524
return nil, err
2625
}
@@ -35,7 +34,6 @@ func Decorate(decorators *map[string][]Decorater, changelog *types.Changelog) (*
3534

3635
for _, decorator := range (*decorators)["metadatas"] {
3736
m, err := decorator.Decorate(&metadatas)
38-
3937
if err != nil {
4038
return nil, err
4139
}

chyle/decorators/decorator_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ func TestDecorator(t *testing.T) {
5454
{
5555
"test": "test2",
5656
"jiraIssueId": "ABC-123",
57-
}},
57+
},
58+
},
5859
Metadatas: map[string]interface{}{},
5960
}
6061

@@ -71,7 +72,8 @@ func TestDecorator(t *testing.T) {
7172
"test": "test2",
7273
"jiraIssueId": "ABC-123",
7374
"jiraIssueKey": "ABC-123",
74-
}},
75+
},
76+
},
7577
Metadatas: map[string]interface{}{},
7678
}
7779

chyle/decorators/github_issue.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ func (g githubIssue) Decorate(commitMap *map[string]interface{}) (*map[string]in
3636
}
3737

3838
req, err := http.NewRequest("GET", fmt.Sprintf("https://api.github.com/repos/%s/%s/issues/%d", g.config.CREDENTIALS.OWNER, g.config.REPOSITORY.NAME, ID), nil)
39-
4039
if err != nil {
4140
return commitMap, err
4241
}

chyle/decorators/github_issue_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package decorators
22

33
import (
4-
"io/ioutil"
54
"net/http"
5+
"os"
66
"testing"
77

88
"github.com/stretchr/testify/assert"
@@ -30,7 +30,7 @@ func TestGithubIssue(t *testing.T) {
3030

3131
defer gock.Off()
3232

33-
issueResponse, err := ioutil.ReadFile("fixtures/github-issue-fetch-response.json")
33+
issueResponse, err := os.ReadFile("fixtures/github-issue-fetch-response.json")
3434

3535
assert.NoError(t, err, "Must read json fixture file")
3636

@@ -62,7 +62,7 @@ func TestGithubIssue(t *testing.T) {
6262
func TestGithubWithNoGithubIssueIdDefined(t *testing.T) {
6363
defer gock.Off()
6464

65-
issueResponse, err := ioutil.ReadFile("fixtures/github-issue-fetch-response.json")
65+
issueResponse, err := os.ReadFile("fixtures/github-issue-fetch-response.json")
6666

6767
assert.NoError(t, err, "Must read json fixture file")
6868

chyle/decorators/jira_issue.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ func (j jiraIssue) Decorate(commitMap *map[string]interface{}) (*map[string]inte
4242
}
4343

4444
req, err := http.NewRequest("GET", fmt.Sprintf("%s/rest/api/2/issue/%s", j.config.ENDPOINT.URL, ID), nil)
45-
4645
if err != nil {
4746
return commitMap, err
4847
}

chyle/git/git.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ func resolveRef(refCommit string, repository *git.Repository) (*object.Commit, e
6161
}
6262

6363
iter, err := repository.References()
64-
6564
if err != nil {
6665
return &object.Commit{}, errReferenceNotFound{refCommit}
6766
}
@@ -90,19 +89,16 @@ func resolveRef(refCommit string, repository *git.Repository) (*object.Commit, e
9089
// FetchCommits retrieves commits in a reference range
9190
func FetchCommits(repoPath string, fromRef string, toRef string) (*[]object.Commit, error) {
9291
rep, err := git.PlainOpen(repoPath)
93-
9492
if err != nil {
9593
return nil, errRepositoryPath{repoPath}
9694
}
9795

9896
fromCommit, err := resolveRef(fromRef, rep)
99-
10097
if err != nil {
10198
return &[]object.Commit{}, err
10299
}
103100

104101
toCommit, err := resolveRef(toRef, rep)
105-
106102
if err != nil {
107103
return &[]object.Commit{}, err
108104
}
@@ -111,7 +107,6 @@ func FetchCommits(repoPath string, fromRef string, toRef string) (*[]object.Comm
111107
var commits *[]object.Commit
112108

113109
exclusionList, err := buildOriginCommitList(fromCommit)
114-
115110
if err != nil {
116111
return nil, err
117112
}
@@ -121,7 +116,6 @@ func FetchCommits(repoPath string, fromRef string, toRef string) (*[]object.Comm
121116
}
122117

123118
commits, err = findDiffCommits(toCommit, &exclusionList)
124-
125119
if err != nil {
126120
return nil, err
127121
}

chyle/git/git_test.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,19 @@ import (
1414
"gopkg.in/src-d/go-git.v4/plumbing/object"
1515
)
1616

17-
var repo *git.Repository
18-
var gitRepositoryPath = "testing-repository"
17+
var (
18+
repo *git.Repository
19+
gitRepositoryPath = "testing-repository"
20+
)
1921

2022
func setup() {
2123
path, err := os.Getwd()
22-
2324
if err != nil {
2425
fmt.Println(err)
2526
os.Exit(1)
2627
}
2728

2829
repo, err = git.PlainOpen(path + "/" + gitRepositoryPath)
29-
3030
if err != nil {
3131
fmt.Println(err)
3232
os.Exit(1)
@@ -45,7 +45,6 @@ func getCommitFromRef(ref string) *object.Commit {
4545
}
4646

4747
c, err := repo.CommitObject(plumbing.NewHash(string(ID)))
48-
4948
if err != nil {
5049
logrus.WithField("ID", ID).Fatal(err)
5150
}

chyle/matchers/type.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,14 @@ const (
1010
)
1111

1212
// mergeCommit match merge commit message
13-
type mergeCommit struct {
14-
}
13+
type mergeCommit struct{}
1514

1615
func (m mergeCommit) Match(commit *object.Commit) bool {
1716
return commit.NumParents() == 2
1817
}
1918

2019
// regularCommit match regular commit message
21-
type regularCommit struct {
22-
}
20+
type regularCommit struct{}
2321

2422
func (r regularCommit) Match(commit *object.Commit) bool {
2523
return commit.NumParents() == 1 || commit.NumParents() == 0

chyle/process.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ func proceed(process *process, commits *[]object.Commit) error {
3434
changelog, err := decorators.Decorate(process.decorators,
3535
extractors.Extract(process.extractors,
3636
matchers.Filter(process.matchers, commits)))
37-
3837
if err != nil {
3938
return err
4039
}

0 commit comments

Comments
 (0)