Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 3 additions & 12 deletions server/model/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package model

import (
"fmt"
"slices"
"strings"

"go.woodpecker-ci.org/woodpecker/v3/pipeline"
Expand Down Expand Up @@ -83,23 +84,13 @@ func (t *Task) ShouldRun() bool {
}

func (t *Task) runsOnFailure() bool {
for _, status := range t.RunOn {
if status == string(StatusFailure) {
return true
}
}
return false
return slices.Contains(t.RunOn, string(StatusFailure))
}

func (t *Task) runsOnSuccess() bool {
if len(t.RunOn) == 0 {
return true
}

for _, status := range t.RunOn {
if status == string(StatusSuccess) {
return true
}
}
return false
return slices.Contains(t.RunOn, string(StatusSuccess))
}
9 changes: 2 additions & 7 deletions server/pipeline/cancel.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package pipeline
import (
"context"
"fmt"
"slices"

"github.com/rs/zerolog/log"

Expand Down Expand Up @@ -108,13 +109,7 @@ func cancelPreviousPipelines(
user *model.User,
) error {
// check this event should cancel previous pipelines
eventIncluded := false
for _, ev := range repo.CancelPreviousPipelineEvents {
if ev == pipeline.Event {
eventIncluded = true
break
}
}
eventIncluded := slices.Contains(repo.CancelPreviousPipelineEvents, pipeline.Event)
if !eventIncluded {
return nil
}
Expand Down
7 changes: 3 additions & 4 deletions server/queue/fifo.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"container/list"
"context"
"fmt"
"slices"
"sync"
"time"

Expand Down Expand Up @@ -362,10 +363,8 @@ func (q *fifo) depsInQueue(task *model.Task) bool {
}
for possibleDepID := range q.running {
log.Debug().Msgf("queue: running right now: %v", possibleDepID)
for _, dep := range task.Dependencies {
if possibleDepID == dep {
return true
}
if slices.Contains(task.Dependencies, possibleDepID) {
return true
}
}
return false
Expand Down
9 changes: 2 additions & 7 deletions shared/token/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package token
import (
"fmt"
"net/http"
"slices"

"github.com/golang-jwt/jwt/v5"
"github.com/rs/zerolog/log"
Expand Down Expand Up @@ -55,13 +56,7 @@ func Parse(allowedTypes []Type, raw string, fn SecretFunc) (*Token, error) {
return nil, jwt.ErrTokenUnverifiable
}

hasAllowedType := false
for _, k := range allowedTypes {
if k == token.Type {
hasAllowedType = true
break
}
}
hasAllowedType := slices.Contains(allowedTypes, token.Type)

if !hasAllowedType {
return nil, jwt.ErrInvalidType
Expand Down