From 433159e990161d7e4e45048b185436cfae998a40 Mon Sep 17 00:00:00 2001 From: Brad Rydzewski Date: Thu, 16 Apr 2015 00:24:53 -0700 Subject: [PATCH] hook now calculates build matrix and creates appropriate tasks --- server/hooks.go | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/server/hooks.go b/server/hooks.go index f236c1659..70b3120b4 100644 --- a/server/hooks.go +++ b/server/hooks.go @@ -5,6 +5,7 @@ import ( log "github.com/Sirupsen/logrus" "github.com/drone/drone/common" + "github.com/drone/drone/parser/matrix" // "github.com/bradrydzewski/drone/worker" "github.com/gin-gonic/gin" ) @@ -77,13 +78,30 @@ func PostHook(c *gin.Context) { build.PullRequest = hook.PullRequest // featch the .drone.yml file from the database - _, err = remote.Script(user, repo, build) + raw, err := remote.Script(user, repo, build) if err != nil { log.Errorf("failure to get .drone.yml for %s. %s", repo.FullName, err) c.Fail(404, err) return } + axes, err := matrix.Parse(string(raw)) + if err != nil { + log.Errorf("failure to calculate matrix for %s. %s", repo.FullName, err) + c.Fail(404, err) + return + } + if len(axes) == 0 { + axes = append(axes, matrix.Axis{}) + } + for num, axis := range axes { + build.Tasks = append(build.Tasks, &common.Task{ + Number: num + 1, + State: common.StatePending, + Environment: axis, + }) + } + err = store.SetBuild(repo.FullName, build) if err != nil { c.Fail(500, err)