hook honors branch filter
This commit is contained in:
parent
543a46a755
commit
371a64ef6a
3 changed files with 18 additions and 5 deletions
|
@ -78,6 +78,9 @@ func (c *Condition) MatchBranch(branch string) bool {
|
|||
if len(c.Branch) == 0 {
|
||||
return true
|
||||
}
|
||||
if strings.HasPrefix(branch, "refs/heads/") {
|
||||
branch = branch[11:]
|
||||
}
|
||||
match, _ := filepath.Match(c.Branch, branch)
|
||||
return match
|
||||
}
|
||||
|
|
|
@ -92,3 +92,11 @@ func ParseSingle(raw string, opts *Opts) (*common.Config, error) {
|
|||
}
|
||||
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
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ import (
|
|||
|
||||
log "github.com/Sirupsen/logrus"
|
||||
"github.com/drone/drone/common"
|
||||
"github.com/drone/drone/parser"
|
||||
"github.com/drone/drone/parser/inject"
|
||||
"github.com/drone/drone/parser/matrix"
|
||||
"github.com/drone/drone/queue"
|
||||
|
@ -122,11 +123,12 @@ func PostHook(c *gin.Context) {
|
|||
}
|
||||
|
||||
// verify the branches can be built vs skipped
|
||||
// s, _ := script.ParseBuild(string(yml))
|
||||
// if len(hook.PullRequest) == 0 && !s.MatchBranch(hook.Branch) {
|
||||
// w.WriteHeader(http.StatusOK)
|
||||
// return
|
||||
// }
|
||||
when, _ := parser.ParseCondition(string(raw))
|
||||
if build.Commit != nil && when != nil && !when.MatchBranch(build.Commit.Ref) {
|
||||
log.Infof("ignoring hook. yaml file excludes repo and branch %s %s", repo.FullName, build.Commit.Ref)
|
||||
c.AbortWithStatus(200)
|
||||
return
|
||||
}
|
||||
|
||||
err = store.SetBuild(repo.FullName, build)
|
||||
if err != nil {
|
||||
|
|
Loading…
Reference in a new issue