mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2025-02-02 12:42:21 +00:00
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
|
// Netrc returns a .netrc file that can be used to clone
|
||||||
// private repositories from a remote system.
|
// 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)
|
url_, err := url.Parse(g.URL)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
|
@ -31,7 +31,7 @@ type Remote interface {
|
||||||
|
|
||||||
// Netrc returns a .netrc file that can be used to clone
|
// Netrc returns a .netrc file that can be used to clone
|
||||||
// private repositories from a remote system.
|
// 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
|
// Activate activates a repository by creating the post-commit hook and
|
||||||
// adding the SSH deploy key, if applicable.
|
// adding the SSH deploy key, if applicable.
|
||||||
|
|
|
@ -5,6 +5,7 @@ import (
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"github.com/drone/drone/common"
|
"github.com/drone/drone/common"
|
||||||
|
"github.com/drone/drone/parser/inject"
|
||||||
"github.com/drone/drone/queue"
|
"github.com/drone/drone/queue"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/gin-gonic/gin/binding"
|
"github.com/gin-gonic/gin/binding"
|
||||||
|
@ -102,6 +103,7 @@ func PostBuildStatus(c *gin.Context) {
|
||||||
// POST /api/builds/:owner/:name/builds/:number
|
// POST /api/builds/:owner/:name/builds/:number
|
||||||
//
|
//
|
||||||
func RunBuild(c *gin.Context) {
|
func RunBuild(c *gin.Context) {
|
||||||
|
remote := ToRemote(c)
|
||||||
store := ToDatastore(c)
|
store := ToDatastore(c)
|
||||||
queue_ := ToQueue(c)
|
queue_ := ToQueue(c)
|
||||||
repo := ToRepo(c)
|
repo := ToRepo(c)
|
||||||
|
@ -152,18 +154,32 @@ func RunBuild(c *gin.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// params, _ := store.RepoParams(repo.FullName)
|
netrc, err := remote.Netrc(user)
|
||||||
// if params != nil && len(params) != 0 {
|
if err != nil {
|
||||||
// raw = []byte(inject.InjectSafe(string(raw), params))
|
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{
|
queue_.Publish(&queue.Work{
|
||||||
User: user,
|
User: user,
|
||||||
Repo: repo,
|
Repo: repo,
|
||||||
Build: build,
|
Build: build,
|
||||||
Keys: keys,
|
Keys: keys,
|
||||||
Netrc: &common.Netrc{}, //TODO create netrc
|
Netrc: netrc,
|
||||||
Yaml: nil, // TODO fetch yaml
|
Yaml: raw,
|
||||||
})
|
})
|
||||||
|
|
||||||
c.JSON(202, build)
|
c.JSON(202, build)
|
||||||
|
|
|
@ -115,6 +115,12 @@ func PostHook(c *gin.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
netrc, err := remote.Netrc(user)
|
||||||
|
if err != nil {
|
||||||
|
c.Fail(500, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// verify the branches can be built vs skipped
|
// verify the branches can be built vs skipped
|
||||||
// s, _ := script.ParseBuild(string(yml))
|
// s, _ := script.ParseBuild(string(yml))
|
||||||
// if len(hook.PullRequest) == 0 && !s.MatchBranch(hook.Branch) {
|
// if len(hook.PullRequest) == 0 && !s.MatchBranch(hook.Branch) {
|
||||||
|
@ -133,7 +139,7 @@ func PostHook(c *gin.Context) {
|
||||||
Repo: repo,
|
Repo: repo,
|
||||||
Build: build,
|
Build: build,
|
||||||
Keys: keys,
|
Keys: keys,
|
||||||
Netrc: &common.Netrc{}, // TODO
|
Netrc: netrc,
|
||||||
Yaml: raw,
|
Yaml: raw,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue