diff --git a/remote/github/github.go b/remote/github/github.go index 439ca0d63..800d4a63c 100644 --- a/remote/github/github.go +++ b/remote/github/github.go @@ -152,7 +152,7 @@ func (g *GitHub) Script(u *common.User, r *common.Repo, b *common.Build) ([]byte // Netrc returns a .netrc file that can be used to clone // private repositories from a remote system. -func (g *GitHub) Netrc(u *common.User, r *common.Repo) (*common.Netrc, error) { +func (g *GitHub) Netrc(u *common.User) (*common.Netrc, error) { url_, err := url.Parse(g.URL) if err != nil { return nil, err diff --git a/remote/remote.go b/remote/remote.go index b1cb210be..a1b15498d 100644 --- a/remote/remote.go +++ b/remote/remote.go @@ -31,7 +31,7 @@ type Remote interface { // Netrc returns a .netrc file that can be used to clone // private repositories from a remote system. - Netrc(u *common.User, r *common.Repo) (*common.Netrc, error) + Netrc(u *common.User) (*common.Netrc, error) // Activate activates a repository by creating the post-commit hook and // adding the SSH deploy key, if applicable. diff --git a/server/builds.go b/server/builds.go index ddb231a28..052af5802 100644 --- a/server/builds.go +++ b/server/builds.go @@ -5,6 +5,7 @@ import ( "strconv" "github.com/drone/drone/common" + "github.com/drone/drone/parser/inject" "github.com/drone/drone/queue" "github.com/gin-gonic/gin" "github.com/gin-gonic/gin/binding" @@ -102,6 +103,7 @@ func PostBuildStatus(c *gin.Context) { // POST /api/builds/:owner/:name/builds/:number // func RunBuild(c *gin.Context) { + remote := ToRemote(c) store := ToDatastore(c) queue_ := ToQueue(c) repo := ToRepo(c) @@ -152,18 +154,32 @@ func RunBuild(c *gin.Context) { return } - // params, _ := store.RepoParams(repo.FullName) - // if params != nil && len(params) != 0 { - // raw = []byte(inject.InjectSafe(string(raw), params)) - // } + netrc, err := remote.Netrc(user) + if err != nil { + c.Fail(500, err) + return + } + + // featch the .drone.yml file from the database + raw, err := remote.Script(user, repo, build) + if err != nil { + c.Fail(404, err) + return + } + + // inject any private parameters into the .drone.yml + params, _ := store.RepoParams(repo.FullName) + if params != nil && len(params) != 0 { + raw = []byte(inject.InjectSafe(string(raw), params)) + } queue_.Publish(&queue.Work{ User: user, Repo: repo, Build: build, Keys: keys, - Netrc: &common.Netrc{}, //TODO create netrc - Yaml: nil, // TODO fetch yaml + Netrc: netrc, + Yaml: raw, }) c.JSON(202, build) diff --git a/server/hooks.go b/server/hooks.go index 250ab0934..3ceb69444 100644 --- a/server/hooks.go +++ b/server/hooks.go @@ -115,6 +115,12 @@ func PostHook(c *gin.Context) { return } + netrc, err := remote.Netrc(user) + if err != nil { + c.Fail(500, err) + return + } + // verify the branches can be built vs skipped // s, _ := script.ParseBuild(string(yml)) // if len(hook.PullRequest) == 0 && !s.MatchBranch(hook.Branch) { @@ -133,7 +139,7 @@ func PostHook(c *gin.Context) { Repo: repo, Build: build, Keys: keys, - Netrc: &common.Netrc{}, // TODO + Netrc: netrc, Yaml: raw, })