Skip to content

Commit

Permalink
Revert "Move "skip ci" logic into global pipeline conditions (woodpec…
Browse files Browse the repository at this point in the history
…ker-ci#2216)"

This reverts commit a5ef372.
  • Loading branch information
anbraten committed Sep 11, 2023
1 parent 9eb3efa commit 54b590b
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 41 deletions.
1 change: 0 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
"prettier.configPath": "./web/.prettierrc.js",
"prettier.ignorePath": "./web/.prettierignore",
"cSpell.words": [
"Curr",
"doublestar",
"multierr"
]
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ test-server-datastore-coverage: ## Test server datastore with coverage report

test-ui: ui-dependencies ## Test UI code
(cd web/; pnpm run lint)
(cd web/; pnpm run format:check)
(cd web/; pnpm run formatcheck)
(cd web/; pnpm run typecheck)
(cd web/; pnpm run test)

Expand Down
14 changes: 0 additions & 14 deletions pipeline/frontend/yaml/constraint/constraint.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,17 @@ import (
"errors"
"fmt"
"path"
"regexp"
"strings"

"github.com/antonmedv/expr"
"github.com/bmatcuk/doublestar/v4"
"github.com/rs/zerolog/log"
"golang.org/x/exp/maps"
"gopkg.in/yaml.v3"

"github.com/woodpecker-ci/woodpecker/pipeline/frontend/metadata"
yaml_base_types "github.com/woodpecker-ci/woodpecker/pipeline/frontend/yaml/types/base"
)

var skipRe = regexp.MustCompile(`\[(?i:ci *skip|skip *ci)\]`)

type (
// When defines a set of runtime constraints.
When struct {
Expand Down Expand Up @@ -82,16 +78,6 @@ func (when *When) IsEmpty() bool {

// Returns true if at least one of the internal constraints is true.
func (when *When) Match(metadata metadata.Metadata, global bool, env map[string]string) (bool, error) {
if global {
// skip the whole workflow if any case-insensitive combination of the words "skip" and "ci"
// wrapped in square brackets appear in the commit message
skipMatch := skipRe.FindString(metadata.Curr.Commit.Message)
if len(skipMatch) > 0 {
log.Debug().Msgf("skip workflow as keyword to do so was detected in commit message '%s'", metadata.Curr.Commit.Message)
return false, nil
}
}

for _, c := range when.Constraints {
match, err := c.Match(metadata, global, env)
if err != nil {
Expand Down
18 changes: 18 additions & 0 deletions server/api/hook.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"errors"
"fmt"
"net/http"
"regexp"

"github.com/gin-gonic/gin"
"github.com/rs/zerolog/log"
Expand All @@ -34,6 +35,8 @@ import (
"github.com/woodpecker-ci/woodpecker/shared/token"
)

var skipRe = regexp.MustCompile(`\[(?i:ci *skip|skip *ci)\]`)

// GetQueueInfo
//
// @Summary Get pipeline queue information
Expand Down Expand Up @@ -137,6 +140,21 @@ func PostHook(c *gin.Context) {
return
}

//
// Skip if commit message contains skip-ci
// TODO: move into global pipeline conditions logic
//

// skip the tmpPipeline if any case-insensitive combination of the words "skip" and "ci"
// wrapped in square brackets appear in the commit message
skipMatch := skipRe.FindString(tmpPipeline.Message)
if len(skipMatch) > 0 {
msg := fmt.Sprintf("ignoring hook: %s found in %s", skipMatch, tmpPipeline.Commit)
log.Debug().Msg(msg)
c.String(http.StatusNoContent, msg)
return
}

//
// 2. Get related repo from store and take repo renaming into account
//
Expand Down
2 changes: 1 addition & 1 deletion server/pipeline/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func Create(ctx context.Context, _store store.Store, repo *model.Repo, pipeline
filtered, parseErr = checkIfFiltered(repo, pipeline, forgeYamlConfigs)
if parseErr == nil {
if filtered {
err := ErrFiltered{Msg: "global when filter of all workflows do skip this pipeline"}
err := ErrFiltered{Msg: "branch does not match restrictions defined in yaml"}
log.Debug().Str("repo", repo.FullName).Msgf("%v", err)
return nil, err
}
Expand Down
24 changes: 0 additions & 24 deletions server/pipeline/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,6 @@ func (e ErrNotFound) Error() string {
return e.Msg
}

func (e ErrNotFound) Is(target error) bool {
_, ok := target.(ErrNotFound) //nolint:errorlint
if !ok {
_, ok = target.(*ErrNotFound) //nolint:errorlint
}
return ok
}

type ErrBadRequest struct {
Msg string
}
Expand All @@ -38,26 +30,10 @@ func (e ErrBadRequest) Error() string {
return e.Msg
}

func (e ErrBadRequest) Is(target error) bool {
_, ok := target.(ErrBadRequest) //nolint:errorlint
if !ok {
_, ok = target.(*ErrBadRequest) //nolint:errorlint
}
return ok
}

type ErrFiltered struct {
Msg string
}

func (e ErrFiltered) Error() string {
return "ignoring hook: " + e.Msg
}

func (e *ErrFiltered) Is(target error) bool {
_, ok := target.(ErrFiltered) //nolint:errorlint
if !ok {
_, ok = target.(*ErrFiltered) //nolint:errorlint
}
return ok
}

0 comments on commit 54b590b

Please sign in to comment.