get netrc data when hook is triggering
This commit is contained in:
parent
67a4e302c7
commit
b84943222b
4 changed files with 31 additions and 9 deletions
|
@ -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
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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,
|
||||
})
|
||||
|
||||
|
|
Loading…
Reference in a new issue