1
1
Fork 0
mirror of https://github.com/joshdk/drone-skip-pipeline synced 2024-04-26 14:54:59 +02:00

ci: lint code with golangci-lint (#11)

This commit is contained in:
Josh Komoroske 2021-11-14 18:27:59 -08:00 committed by GitHub
parent d6844517de
commit eaad6116e5
Signed by: GitHub
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 6 deletions

View File

@ -15,6 +15,11 @@ jobs:
- name: Run commitlint
uses: wagoid/commitlint-github-action@v4
- name: Run golangci-lint
uses: golangci/golangci-lint-action@v2
with:
version: v1.42.0
docker:
name: Docker
runs-on: ubuntu-latest

8
.golangci.yml Normal file
View File

@ -0,0 +1,8 @@
linters:
enable-all: true
disable:
- goerr113
- wrapcheck
issues:
exclude-use-default: false

14
main.go
View File

@ -30,9 +30,10 @@ const exitCodeDroneSkipPipeline = 78
var errDroneSkipPipeline = errors.New("skipping pipeline")
func main() {
switch err := mainCmd(); err {
switch err := mainCmd(); err { // nolint:errorlint
case nil:
log.Println("continuing pipeline")
return
case errDroneSkipPipeline:
log.Println("skipping pipeline")
@ -58,10 +59,11 @@ func mainCmd() error {
if cfg.GithubToken != "" {
httpClient = oauth2.NewClient(ctx,
oauth2.StaticTokenSource(
&oauth2.Token{AccessToken: cfg.GithubToken},
&oauth2.Token{AccessToken: cfg.GithubToken}, // nolint:exhaustivestruct
),
)
}
client := github.NewClient(httpClient)
// Get a list of all files (added, deleted, modified) that are a part of
@ -73,15 +75,15 @@ func mainCmd() error {
matcher := ignore.CompileIgnoreLines(cfg.Rules...)
skip := true
// Examine every file in the current pull request, and try to match it
// against the set of configured plugin rules.
skip := true
for _, commitFile := range commitFiles {
filename := commitFile.GetFilename()
if matched, how := matcher.MatchesPathHow(filename); matched {
if matched, how := matcher.MatchesPathHow(filename); matched { // nolint:gocritic
skip = false
// File was matched by a rule.
log.Printf("file %s matched by rule %q\n", filename, how.Line)
skip = false
} else if how != nil {
// File was matched by a rule, but then negated by another.
log.Printf("file %s not matched by negated rule %q\n", filename, how.Line)
@ -112,8 +114,8 @@ type config struct {
}
func loadConfig() (*config, error) {
// Load plugin configuration from current working environment.
var cfg config
// Load plugin configuration from current working environment.
err := envconfig.Process("", &cfg)
if err != nil {
return nil, err