Skip to content

Commit

Permalink
Merge pull request #153 from antham/enable-gofumpt
Browse files Browse the repository at this point in the history
Enable gofumpt, upgrade vendors
  • Loading branch information
antham authored May 3, 2024
2 parents 99d671f + ca49c5c commit c811657
Show file tree
Hide file tree
Showing 43 changed files with 80 additions and 111 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@ permissions:
jobs:
call-workflow:
uses: antham/go-workflow-github-action/.github/workflows/build.yml@master
secrets:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
3 changes: 3 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
linters:
enable:
- gofumpt
7 changes: 2 additions & 5 deletions chyle/apih/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package apih

import (
"fmt"
"io/ioutil"
"io"
"log"
"net/http"
)
Expand All @@ -29,21 +29,18 @@ func SetHeaders(request *http.Request, headers map[string]string) {
// SendRequest picks a request and send it with given client
func SendRequest(client *http.Client, request *http.Request) (int, []byte, error) {
response, err := client.Do(request)

if err != nil {
return 0, []byte{}, err
}

defer func() {
err = response.Body.Close()

if err != nil {
log.Fatal(err)
}
}()

b, err := ioutil.ReadAll(response.Body)

b, err := io.ReadAll(response.Body)
if err != nil {
return response.StatusCode, b, errResponse{request, response, b}
}
Expand Down
2 changes: 0 additions & 2 deletions chyle/chyle.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ var EnableDebugging = false
// BuildChangelog creates a changelog from defined configuration
func BuildChangelog(envConfig *envh.EnvTree) error {
conf, err := config.Create(envConfig)

if err != nil {
return err
}
Expand All @@ -32,7 +31,6 @@ func BuildChangelog(envConfig *envh.EnvTree) error {
}

commits, err := git.FetchCommits(conf.GIT.REPOSITORY.PATH, conf.GIT.REFERENCE.FROM, conf.GIT.REFERENCE.TO)

if err != nil {
return err
}
Expand Down
14 changes: 2 additions & 12 deletions chyle/chyle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package chyle
import (
"bytes"
"encoding/json"
"io/ioutil"
"log"
"os"
"testing"
Expand All @@ -16,7 +15,6 @@ import (
func TestBuildChangelog(t *testing.T) {
restoreEnvs()
p, err := os.Getwd()

if err != nil {
log.Fatal(err)
}
Expand All @@ -30,8 +28,7 @@ func TestBuildChangelog(t *testing.T) {
setenv("CHYLE_EXTRACTORS_MESSAGE_REG", "(.{1,50})")
setenv("CHYLE_SENDERS_STDOUT_FORMAT", "json")

f, err := ioutil.TempFile(p+"/testing-repository", "test")

f, err := os.CreateTemp(p+"/testing-repository", "test")
if err != nil {
log.Fatal(err)
}
Expand All @@ -43,7 +40,6 @@ func TestBuildChangelog(t *testing.T) {
}()

config, err := envh.NewEnvTree("CHYLE", "_")

if err != nil {
log.Fatal(err)
}
Expand All @@ -57,7 +53,7 @@ func TestBuildChangelog(t *testing.T) {

assert.NoError(t, err)

b, err := ioutil.ReadFile(f.Name())
b, err := os.ReadFile(f.Name())

assert.NoError(t, err)

Expand Down Expand Up @@ -120,7 +116,6 @@ func TestBuildChangelog(t *testing.T) {
func TestBuildChangelogWithAnErrorFromGitPackage(t *testing.T) {
restoreEnvs()
p, err := os.Getwd()

if err != nil {
log.Fatal(err)
}
Expand All @@ -135,7 +130,6 @@ func TestBuildChangelogWithAnErrorFromGitPackage(t *testing.T) {
setenv("CHYLE_SENDERS_STDOUT_FORMAT", "json")

config, err := envh.NewEnvTree("CHYLE", "_")

if err != nil {
log.Fatal(err)
}
Expand All @@ -149,7 +143,6 @@ func TestBuildChangelogWithAnErrorFromGitPackage(t *testing.T) {
func TestBuildChangelogWithAnErrorFromConfigPackage(t *testing.T) {
restoreEnvs()
p, err := os.Getwd()

if err != nil {
log.Fatal(err)
}
Expand All @@ -160,7 +153,6 @@ func TestBuildChangelogWithAnErrorFromConfigPackage(t *testing.T) {
setenv("CHYLE_SENDERS_STDOUT_FORMAT", "whatever")

config, err := envh.NewEnvTree("CHYLE", "_")

if err != nil {
log.Fatal(err)
}
Expand All @@ -174,7 +166,6 @@ func TestBuildChangelogWithAnErrorFromConfigPackage(t *testing.T) {
func TestBuildChangelogWithDebuggingEnabled(t *testing.T) {
restoreEnvs()
p, err := os.Getwd()

if err != nil {
log.Fatal(err)
}
Expand All @@ -190,7 +181,6 @@ func TestBuildChangelogWithDebuggingEnabled(t *testing.T) {
setenv("CHYLE_EXTRACTORS_MESSAGE_REG", "(.{1,50})")

config, err := envh.NewEnvTree("CHYLE", "_")

if err != nil {
log.Fatal(err)
}
Expand Down
1 change: 0 additions & 1 deletion chyle/config/api_decorator.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@ func (a *apiDecoratorConfigurator) applyCustomValidators(keyChains *[][]string)
// validateKeys checks key mapping between fields extracted from api and fields added to final struct
func (a *apiDecoratorConfigurator) validateKeys() error {
keys, err := a.config.FindChildrenKeys("CHYLE", "DECORATORS", a.decoratorKey, "KEYS")

if err != nil {
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"}, "_")}
}
Expand Down
2 changes: 0 additions & 2 deletions chyle/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ func saveExistingEnvs() {
env := envh.NewEnv()

envs, err = env.FindEntries(".*")

if err != nil {
fmt.Println(err)
os.Exit(1)
Expand All @@ -46,7 +45,6 @@ func restoreEnvs() {

func setenv(key string, value string) {
err := os.Setenv(key, value)

if err != nil {
fmt.Println(err)
os.Exit(1)
Expand Down
1 change: 0 additions & 1 deletion chyle/config/extractors.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ func (e *extractorsConfigurator) setExtractors(config *CHYLE) {
DESTKEY string
REG *regexp.Regexp
}{

e.config.FindStringUnsecured("CHYLE", "EXTRACTORS", key, "ORIGKEY"),
e.config.FindStringUnsecured("CHYLE", "EXTRACTORS", key, "DESTKEY"),
regexp.MustCompile(e.config.FindStringUnsecured("CHYLE", "EXTRACTORS", key, "REG")),
Expand Down
2 changes: 0 additions & 2 deletions chyle/config/matchers.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ func (m *matchersConfigurator) isDisabled() bool {
func (m *matchersConfigurator) validateRegexpMatchers() error {
for _, key := range []string{"MESSAGE", "COMMITTER", "AUTHOR"} {
_, err := m.config.FindString("CHYLE", "MATCHERS", key)

if err != nil {
continue
}
Expand All @@ -55,7 +54,6 @@ func (m *matchersConfigurator) validateRegexpMatchers() error {

func (m *matchersConfigurator) validateTypeMatcher() error {
_, err := m.config.FindString("CHYLE", "MATCHERS", "TYPE")

if err != nil {
return nil
}
Expand Down
1 change: 0 additions & 1 deletion chyle/config/primitives.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ func validateTemplate(fullconfig *envh.EnvTree, keyChain []string) error {
val := fullconfig.FindStringUnsecured(keyChain...)

_, err := tmplh.Parse("test", val)

if err != nil {
return EnvValidationError{fmt.Sprintf(`provide a valid template string for "%s" : "%s", "%s" given`, strings.Join(keyChain, "_"), err.Error(), val), strings.Join(keyChain, "_")}
}
Expand Down
1 change: 0 additions & 1 deletion chyle/config/shell_decorator.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,4 @@ func (s *shellDecoratorConfigurator) setShellConfigs(config *CHYLE) {
s.config.FindStringUnsecured("CHYLE", "DECORATORS", "SHELL", key, "DESTKEY"),
}
}

}
2 changes: 0 additions & 2 deletions chyle/decorators/decorator.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ func Decorate(decorators *map[string][]Decorater, changelog *types.Changelog) (*

for _, decorator := range (*decorators)["datas"] {
result, err = decorator.Decorate(&d)

if err != nil {
return nil, err
}
Expand All @@ -35,7 +34,6 @@ func Decorate(decorators *map[string][]Decorater, changelog *types.Changelog) (*

for _, decorator := range (*decorators)["metadatas"] {
m, err := decorator.Decorate(&metadatas)

if err != nil {
return nil, err
}
Expand Down
6 changes: 4 additions & 2 deletions chyle/decorators/decorator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ func TestDecorator(t *testing.T) {
{
"test": "test2",
"jiraIssueId": "ABC-123",
}},
},
},
Metadatas: map[string]interface{}{},
}

Expand All @@ -71,7 +72,8 @@ func TestDecorator(t *testing.T) {
"test": "test2",
"jiraIssueId": "ABC-123",
"jiraIssueKey": "ABC-123",
}},
},
},
Metadatas: map[string]interface{}{},
}

Expand Down
1 change: 0 additions & 1 deletion chyle/decorators/github_issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ func (g githubIssue) Decorate(commitMap *map[string]interface{}) (*map[string]in
}

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)

if err != nil {
return commitMap, err
}
Expand Down
6 changes: 3 additions & 3 deletions chyle/decorators/github_issue_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package decorators

import (
"io/ioutil"
"net/http"
"os"
"testing"

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

defer gock.Off()

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

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

Expand Down Expand Up @@ -62,7 +62,7 @@ func TestGithubIssue(t *testing.T) {
func TestGithubWithNoGithubIssueIdDefined(t *testing.T) {
defer gock.Off()

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

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

Expand Down
1 change: 0 additions & 1 deletion chyle/decorators/jira_issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ func (j jiraIssue) Decorate(commitMap *map[string]interface{}) (*map[string]inte
}

req, err := http.NewRequest("GET", fmt.Sprintf("%s/rest/api/2/issue/%s", j.config.ENDPOINT.URL, ID), nil)

if err != nil {
return commitMap, err
}
Expand Down
6 changes: 0 additions & 6 deletions chyle/git/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ func resolveRef(refCommit string, repository *git.Repository) (*object.Commit, e
}

iter, err := repository.References()

if err != nil {
return &object.Commit{}, errReferenceNotFound{refCommit}
}
Expand Down Expand Up @@ -90,19 +89,16 @@ func resolveRef(refCommit string, repository *git.Repository) (*object.Commit, e
// FetchCommits retrieves commits in a reference range
func FetchCommits(repoPath string, fromRef string, toRef string) (*[]object.Commit, error) {
rep, err := git.PlainOpen(repoPath)

if err != nil {
return nil, errRepositoryPath{repoPath}
}

fromCommit, err := resolveRef(fromRef, rep)

if err != nil {
return &[]object.Commit{}, err
}

toCommit, err := resolveRef(toRef, rep)

if err != nil {
return &[]object.Commit{}, err
}
Expand All @@ -111,7 +107,6 @@ func FetchCommits(repoPath string, fromRef string, toRef string) (*[]object.Comm
var commits *[]object.Commit

exclusionList, err := buildOriginCommitList(fromCommit)

if err != nil {
return nil, err
}
Expand All @@ -121,7 +116,6 @@ func FetchCommits(repoPath string, fromRef string, toRef string) (*[]object.Comm
}

commits, err = findDiffCommits(toCommit, &exclusionList)

if err != nil {
return nil, err
}
Expand Down
9 changes: 4 additions & 5 deletions chyle/git/git_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,19 @@ import (
"gopkg.in/src-d/go-git.v4/plumbing/object"
)

var repo *git.Repository
var gitRepositoryPath = "testing-repository"
var (
repo *git.Repository
gitRepositoryPath = "testing-repository"
)

func setup() {
path, err := os.Getwd()

if err != nil {
fmt.Println(err)
os.Exit(1)
}

repo, err = git.PlainOpen(path + "/" + gitRepositoryPath)

if err != nil {
fmt.Println(err)
os.Exit(1)
Expand All @@ -45,7 +45,6 @@ func getCommitFromRef(ref string) *object.Commit {
}

c, err := repo.CommitObject(plumbing.NewHash(string(ID)))

if err != nil {
logrus.WithField("ID", ID).Fatal(err)
}
Expand Down
6 changes: 2 additions & 4 deletions chyle/matchers/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,14 @@ const (
)

// mergeCommit match merge commit message
type mergeCommit struct {
}
type mergeCommit struct{}

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

// regularCommit match regular commit message
type regularCommit struct {
}
type regularCommit struct{}

func (r regularCommit) Match(commit *object.Commit) bool {
return commit.NumParents() == 1 || commit.NumParents() == 0
Expand Down
1 change: 0 additions & 1 deletion chyle/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ func proceed(process *process, commits *[]object.Commit) error {
changelog, err := decorators.Decorate(process.decorators,
extractors.Extract(process.extractors,
matchers.Filter(process.matchers, commits)))

if err != nil {
return err
}
Expand Down
Loading

0 comments on commit c811657

Please sign in to comment.