From 77b5c6246d8650d82c2b51000dd05db2b53ff8b3 Mon Sep 17 00:00:00 2001 From: glaszig Date: Fri, 11 Dec 2015 01:44:14 +0100 Subject: [PATCH] skip build with any combination of "skip" and "ci" a commit message containing any case-insensitive variant of the above two words wrapped in square brackets will skip the build. examples: [ci skip], [skip CI] this reintroduces pr #1134 and additionally logs the matched skip instruction. --- controller/hook.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/controller/hook.go b/controller/hook.go index f761bf0f6..569e29805 100644 --- a/controller/hook.go +++ b/controller/hook.go @@ -6,6 +6,7 @@ import ( "os" "path/filepath" "strings" + "regexp" log "github.com/Sirupsen/logrus" "github.com/drone/drone/engine" @@ -38,10 +39,12 @@ func PostHook(c *gin.Context) { return } - // a build may be skipped if the text [CI SKIP] - // is found inside the commit message - if strings.Contains(build.Message, "[CI SKIP]") { - log.Infof("ignoring hook. [ci skip] found for %s") + // skip the build if any case-insensitive combination of the words "skip" and "ci" + // wrapped in square brackets appear in the commit message + skipRe := regexp.MustCompile(`\[(?i:ci *skip|skip *ci)\]`) + skipMatches := skipRe.FindStringSubmatch(build.Message) + if len(skipMatches) > 0 { + log.Infof("ignoring hook. %s found in %s", skipMatches[0], build.Commit) c.Writer.WriteHeader(204) return }