Skip to content

Commit

Permalink
fix CI (#208)
Browse files Browse the repository at this point in the history
* test ci

* update go version & golangci-lint to latest

* fix linting issues and update lint config

* revert uncapitalizing letter in err message
  • Loading branch information
preslavmihaylov committed Oct 14, 2023
1 parent f4d225e commit 92eca9e
Show file tree
Hide file tree
Showing 11 changed files with 35 additions and 35 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/master.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- name: golangci-lint
uses: golangci/golangci-lint-action@v2
with:
version: v1.47.3
version: v1.54.2
build:
runs-on: ubuntu-latest
needs: lint
Expand Down
12 changes: 8 additions & 4 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
linters-settings:
revive:
rules:
- name: unused-parameter
severity: warning
disabled: true
linters:
enable:
- deadcode
- errcheck
- unused
- gosimple
- govet
- ineffassign
- staticcheck
- structcheck
- typecheck
- unused
- varcheck
- gofmt
- revive
- revive
Empty file added aaa
Empty file.
5 changes: 2 additions & 3 deletions authmanager/authstore/authstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package authstore

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

Expand All @@ -21,7 +20,7 @@ type Config struct {

// FromFile extracts the tokens configuration from the given file
func FromFile(filename string) (*Config, error) {
bs, err := ioutil.ReadFile(filename)
bs, err := os.ReadFile(filename)
if err != nil {
return nil, fmt.Errorf("couldn't open %s: %w", filename, err)
}
Expand All @@ -47,7 +46,7 @@ func (cfg *Config) SaveWithPerms(filename string, perms os.FileMode) error {
return fmt.Errorf("failed to marshal tokens config: %w", err)
}

err = ioutil.WriteFile(filename, bs, perms)
err = os.WriteFile(filename, bs, perms)
if err != nil {
return fmt.Errorf("failed to save marshaled tokens config: %w", err)
}
Expand Down
5 changes: 2 additions & 3 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package config

import (
"fmt"
"io/ioutil"
"os"
"regexp"
"strings"
Expand Down Expand Up @@ -64,7 +63,7 @@ func NewLocal(cfgPath, basepath string) (*Local, error) {
}

func fromFile(cfgPath string) (*Local, error) {
bs, err := ioutil.ReadFile(cfgPath)
bs, err := os.ReadFile(cfgPath)
if err != nil {
return nil, fmt.Errorf("couldn't open local configuration (%s): %w", cfgPath, err)
}
Expand All @@ -79,7 +78,7 @@ func fromFile(cfgPath string) (*Local, error) {
}

func autoDetect(basepath string) (*Local, error) {
bs, err := ioutil.ReadFile(basepath + "/.git/config")
bs, err := os.ReadFile(basepath + "/.git/config")
if err != nil {
return nil, err
}
Expand Down
14 changes: 7 additions & 7 deletions fetcher/fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package fetcher
import (
"encoding/json"
"fmt"
"io/ioutil"
"io"
"net/http"

"github.com/preslavmihaylov/todocheck/issuetracker"
Expand All @@ -12,8 +12,8 @@ import (

// Fetcher for task statuses by contacting task management web apps' rest api
type Fetcher struct {
issuetracker.IssueTracker
sendRequest func(req *http.Request) (*http.Response, error)
issueTracker issuetracker.IssueTracker
sendRequest func(req *http.Request) (*http.Response, error)
}

// NewFetcher instance
Expand All @@ -24,12 +24,12 @@ func NewFetcher(issueTracker issuetracker.IssueTracker) *Fetcher {

// Fetch a task's status based on task ID
func (f *Fetcher) Fetch(taskID string) (taskstatus.TaskStatus, error) {
req, err := http.NewRequest("GET", f.IssueTracker.IssueURLFor(taskID), nil)
req, err := http.NewRequest("GET", f.issueTracker.IssueURLFor(taskID), nil)
if err != nil {
return taskstatus.None, fmt.Errorf("failed creating new GET request: %w", err)
}

err = f.IssueTracker.InstrumentMiddleware(req)
err = f.issueTracker.InstrumentMiddleware(req)
if err != nil {
return taskstatus.None, fmt.Errorf("couldn't instrument authentication middleware: %w", err)
}
Expand All @@ -40,7 +40,7 @@ func (f *Fetcher) Fetch(taskID string) (taskstatus.TaskStatus, error) {
}
defer resp.Body.Close()

body, err := ioutil.ReadAll(resp.Body)
body, err := io.ReadAll(resp.Body)
if err != nil {
return taskstatus.None, fmt.Errorf("couldn't read response body: %w", err)
} else if resp.StatusCode == http.StatusNotFound {
Expand All @@ -49,7 +49,7 @@ func (f *Fetcher) Fetch(taskID string) (taskstatus.TaskStatus, error) {
return taskstatus.None, fmt.Errorf("bad status code upon fetching task: %d - %s", resp.StatusCode, string(body))
}

task := f.IssueTracker.TaskModel()
task := f.issueTracker.TaskModel()
err = json.Unmarshal(body, &task)
if err != nil {
return taskstatus.None, fmt.Errorf("couldn't unmarshal response task JSON: %w", err)
Expand Down
9 changes: 7 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
module github.com/preslavmihaylov/todocheck

go 1.14
go 1.21

require (
github.com/bmatcuk/doublestar v1.3.1
github.com/fatih/color v1.9.0
github.com/mitchellh/go-homedir v1.1.0
golang.org/x/crypto v0.0.0-20200510223506-06a226fb4e37
golang.org/x/sys v0.0.0-20220915200043-7b5979e65e41 // indirect
gopkg.in/yaml.v2 v2.2.8
)

require (
github.com/mattn/go-colorable v0.1.4 // indirect
github.com/mattn/go-isatty v0.0.11 // indirect
golang.org/x/sys v0.0.0-20220915200043-7b5979e65e41 // indirect
)
1 change: 0 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037 h1:YyJpGZS1sBuBCzLAR1VEpK193GlqGZbnPFnPV/5Rsb4=
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20220915200043-7b5979e65e41 h1:ohgcoMbSofXygzo6AD2I1kz3BFmW1QArPYTtwEM3UXc=
golang.org/x/sys v0.0.0-20220915200043-7b5979e65e41/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
Expand Down
9 changes: 4 additions & 5 deletions testing/scenariobuilder/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package scenariobuilder
import (
"bytes"
"fmt"
"io/ioutil"
"net/http"
"net/http/httptest"
"os"
Expand Down Expand Up @@ -127,7 +126,7 @@ func (s *TodocheckScenario) setupGitConfig() error {
}
}

return ioutil.WriteFile(filepath.Join(gitDir, "config"), []byte(gitConfig), 0644)
return os.WriteFile(filepath.Join(gitDir, "config"), []byte(gitConfig), 0644)
}

func (s *TodocheckScenario) teardownGitConfig() {
Expand Down Expand Up @@ -373,20 +372,20 @@ func (s *TodocheckScenario) setupMockIssueTrackerServer() (teardownFunc, error)

func setupMockIssueTrackerCfg(cfgPath string, mockOrigin string) (teardownFunc, error) {
patt := regexp.MustCompile("origin: \"?[a-zA-Z0-9._:/]+\"?")
origBs, err := ioutil.ReadFile(cfgPath)
origBs, err := os.ReadFile(cfgPath)
if err != nil {
return nil, fmt.Errorf("couldn't read config file %s: %w", cfgPath, err)
}

mockBs := patt.ReplaceAll(origBs, []byte(fmt.Sprintf("origin: %s", mockOrigin)))

err = ioutil.WriteFile(cfgPath, mockBs, 0755)
err = os.WriteFile(cfgPath, mockBs, 0755)
if err != nil {
return nil, fmt.Errorf("couldn't writeback mock issue tracker origin in file %s: %w", cfgPath, err)
}

return func() {
err := ioutil.WriteFile(cfgPath, origBs, 0755)
err := os.WriteFile(cfgPath, origBs, 0755)
if err != nil {
panic("couldn't teardown mock issue tracker: " + err.Error())
}
Expand Down
4 changes: 2 additions & 2 deletions testing/scenariobuilder/validations.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"os"
"strings"

"github.com/preslavmihaylov/todocheck/authmanager/authstore"
Expand Down Expand Up @@ -89,7 +89,7 @@ func validateAuthTokensCache(tokensCache string, url, expectedToken string) vali
return errors.New("tokens_cache is not set in the configuration. It must be set for auth token scenarios")
}

authTokensBs, err := ioutil.ReadFile(tokensCache)
authTokensBs, err := os.ReadFile(tokensCache)
if err != nil {
return fmt.Errorf("couldn't read auth tokens config file %s: %w", tokensCache, err)
}
Expand Down
9 changes: 2 additions & 7 deletions traverser/lines/lines.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"bytes"
"fmt"
"io"
"io/ioutil"
"log"
"os"
"path/filepath"
Expand Down Expand Up @@ -45,7 +44,7 @@ func TraversePath(path string, ignoredPaths, supportedFileExtensions []string, c
}

func traverseFile(filename string, callback lineCallback) error {
buf, err := ioutil.ReadFile(filename)
buf, err := os.ReadFile(filename)
if err != nil {
return fmt.Errorf("failed to open file %s: %w", filename, err)
}
Expand All @@ -55,11 +54,7 @@ func traverseFile(filename string, callback lineCallback) error {
linecnt := 0

reader := bufio.NewReader(bytes.NewReader(buf))
for {
if err == io.EOF {
break
}

for err != io.EOF {
linecnt++
line, err = reader.ReadString('\n')

Expand Down

0 comments on commit 92eca9e

Please sign in to comment.