Skip to content

Commit

Permalink
Merge pull request #67 from laszlocph/surface-parsing-errors
Browse files Browse the repository at this point in the history
Surface parsing error in branch filter
  • Loading branch information
laszlocph authored Sep 9, 2019
2 parents 41cb4e6 + 1c306dd commit 45877a7
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions server/hook.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,12 @@ func PostHook(c *gin.Context) {
return
}

if branchFiltered(build, remoteYamlConfigs) {
filtered, err := branchFiltered(build, remoteYamlConfigs)
if err != nil {
logrus.Errorf("failure to parse yaml from hook for %s. %s", repo.FullName, err)
c.AbortWithError(400, err)
}
if filtered {
c.String(200, "Branch does not match restrictions defined in yaml")
return
}
Expand Down Expand Up @@ -286,17 +291,19 @@ func PostHook(c *gin.Context) {
queueBuild(build, repo, buildItems)
}

func branchFiltered(build *model.Build, remoteYamlConfigs []*remote.FileMeta) bool {
func branchFiltered(build *model.Build, remoteYamlConfigs []*remote.FileMeta) (bool, error) {
for _, remoteYamlConfig := range remoteYamlConfigs {
parsedPipelineConfig, err := yaml.ParseString(string(remoteYamlConfig.Data))
if err == nil {
if !parsedPipelineConfig.Branches.Match(build.Branch) && build.Event != model.EventTag && build.Event != model.EventDeploy {
} else {
return false
}
if err != nil {
return false, err
}

if !parsedPipelineConfig.Branches.Match(build.Branch) && build.Event != model.EventTag && build.Event != model.EventDeploy {
} else {
return false, nil
}
}
return true
return true, nil
}

func zeroSteps(build *model.Build, remoteYamlConfigs []*remote.FileMeta) bool {
Expand Down

0 comments on commit 45877a7

Please sign in to comment.