hook honors branch filter

This commit is contained in:
Brad Rydzewski 2015-04-30 10:39:16 -07:00
parent 543a46a755
commit 371a64ef6a
3 changed files with 18 additions and 5 deletions

View file

@ -78,6 +78,9 @@ func (c *Condition) MatchBranch(branch string) bool {
if len(c.Branch) == 0 { if len(c.Branch) == 0 {
return true return true
} }
if strings.HasPrefix(branch, "refs/heads/") {
branch = branch[11:]
}
match, _ := filepath.Match(c.Branch, branch) match, _ := filepath.Match(c.Branch, branch)
return match return match
} }

View file

@ -92,3 +92,11 @@ func ParseSingle(raw string, opts *Opts) (*common.Config, error) {
} }
return conf, err return conf, err
} }
func ParseCondition(raw string) (*common.Condition, error) {
c := struct {
Condition *common.Condition `yaml:"when"`
}{}
err := yaml.Unmarshal([]byte(raw), c)
return c.Condition, err
}

View file

@ -5,6 +5,7 @@ import (
log "github.com/Sirupsen/logrus" log "github.com/Sirupsen/logrus"
"github.com/drone/drone/common" "github.com/drone/drone/common"
"github.com/drone/drone/parser"
"github.com/drone/drone/parser/inject" "github.com/drone/drone/parser/inject"
"github.com/drone/drone/parser/matrix" "github.com/drone/drone/parser/matrix"
"github.com/drone/drone/queue" "github.com/drone/drone/queue"
@ -122,11 +123,12 @@ func PostHook(c *gin.Context) {
} }
// verify the branches can be built vs skipped // verify the branches can be built vs skipped
// s, _ := script.ParseBuild(string(yml)) when, _ := parser.ParseCondition(string(raw))
// if len(hook.PullRequest) == 0 && !s.MatchBranch(hook.Branch) { if build.Commit != nil && when != nil && !when.MatchBranch(build.Commit.Ref) {
// w.WriteHeader(http.StatusOK) log.Infof("ignoring hook. yaml file excludes repo and branch %s %s", repo.FullName, build.Commit.Ref)
// return c.AbortWithStatus(200)
// } return
}
err = store.SetBuild(repo.FullName, build) err = store.SetBuild(repo.FullName, build)
if err != nil { if err != nil {