mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2025-02-17 11:55:14 +00:00
commit
f723e8f84c
2 changed files with 46 additions and 15 deletions
|
@ -95,7 +95,7 @@ func (a *Agent) prep(w *queue.Work) (*yaml.Config, error) {
|
||||||
envs := toEnv(w)
|
envs := toEnv(w)
|
||||||
w.Yaml = expander.ExpandString(w.Yaml, envs)
|
w.Yaml = expander.ExpandString(w.Yaml, envs)
|
||||||
|
|
||||||
// inject the netrc file into the clone plugin if the repositroy is
|
// inject the netrc file into the clone plugin if the repository is
|
||||||
// private and requires authentication.
|
// private and requires authentication.
|
||||||
var secrets []*model.Secret
|
var secrets []*model.Secret
|
||||||
if w.Verified {
|
if w.Verified {
|
||||||
|
|
|
@ -17,6 +17,7 @@ import (
|
||||||
"github.com/drone/drone/model"
|
"github.com/drone/drone/model"
|
||||||
"github.com/drone/drone/remote"
|
"github.com/drone/drone/remote"
|
||||||
"github.com/mrjones/oauth"
|
"github.com/mrjones/oauth"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Opts defines configuration options.
|
// Opts defines configuration options.
|
||||||
|
@ -115,16 +116,26 @@ func (c *client) Login(res http.ResponseWriter, req *http.Request) (*model.User,
|
||||||
|
|
||||||
// TODO errors should never be ignored like this
|
// TODO errors should never be ignored like this
|
||||||
response1, err := client.Get(fmt.Sprintf("%s/rest/api/1.0/users/%s", c.URL, login))
|
response1, err := client.Get(fmt.Sprintf("%s/rest/api/1.0/users/%s", c.URL, login))
|
||||||
contents, err := ioutil.ReadAll(response1.Body)
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
defer response1.Body.Close()
|
defer response1.Body.Close()
|
||||||
var mUser User // TODO prefixing with m* is not a common convention in Go
|
|
||||||
json.Unmarshal(contents, &mUser) // TODO should not ignore error
|
|
||||||
|
|
||||||
|
contents, err := ioutil.ReadAll(response1.Body)
|
||||||
|
if err !=nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var user User
|
||||||
|
err = json.Unmarshal(contents, &user)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
return &model.User{
|
return &model.User{
|
||||||
Login: login,
|
Login: login,
|
||||||
Email: mUser.EmailAddress,
|
Email: user.EmailAddress,
|
||||||
Token: accessToken.Token,
|
Token: accessToken.Token,
|
||||||
Avatar: avatarLink(mUser.EmailAddress),
|
Avatar: avatarLink(user.EmailAddress),
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -143,29 +154,36 @@ func (c *client) Repo(u *model.User, owner, name string) (*model.Repo, error) {
|
||||||
|
|
||||||
client := NewClientWithToken(&c.Consumer, u.Token)
|
client := NewClientWithToken(&c.Consumer, u.Token)
|
||||||
|
|
||||||
url := fmt.Sprintf("%s/rest/api/1.0/projects/%s/repos/%s", c.URL, owner, name)
|
urlString := fmt.Sprintf("%s/rest/api/1.0/projects/%s/repos/%s", c.URL, owner, name)
|
||||||
|
|
||||||
response, err := client.Get(url)
|
response, err := client.Get(urlString)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error(err)
|
log.Error(err)
|
||||||
}
|
}
|
||||||
defer response.Body.Close()
|
defer response.Body.Close()
|
||||||
contents, err := ioutil.ReadAll(response.Body)
|
contents, err := ioutil.ReadAll(response.Body)
|
||||||
bsRepo := BSRepo{}
|
bsRepo := BSRepo{}
|
||||||
json.Unmarshal(contents, &bsRepo)
|
err = json.Unmarshal(contents, &bsRepo)
|
||||||
|
if err !=nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
repo := &model.Repo{
|
repo := &model.Repo{
|
||||||
Name: bsRepo.Slug,
|
Name: bsRepo.Slug,
|
||||||
Owner: bsRepo.Project.Key,
|
Owner: bsRepo.Project.Key,
|
||||||
Branch: "master",
|
Branch: "master",
|
||||||
Kind: model.RepoGit,
|
Kind: model.RepoGit,
|
||||||
IsPrivate: !bsRepo.Project.Public, // TODO(josmo) verify this is corrrect
|
IsPrivate: true, // TODO(josmo) possibly set this as a setting - must always be private to use netrc
|
||||||
FullName: fmt.Sprintf("%s/%s", bsRepo.Project.Key, bsRepo.Slug),
|
FullName: fmt.Sprintf("%s/%s", bsRepo.Project.Key, bsRepo.Slug),
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, item := range bsRepo.Links.Clone {
|
for _, item := range bsRepo.Links.Clone {
|
||||||
if item.Name == "http" {
|
if item.Name == "http" {
|
||||||
repo.Clone = item.Href
|
uri, err := url.Parse(item.Href)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
uri.User = nil
|
||||||
|
repo.Clone = uri.String()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for _, item := range bsRepo.Links.Self {
|
for _, item := range bsRepo.Links.Self {
|
||||||
|
@ -189,8 +207,14 @@ func (c *client) Repos(u *model.User) ([]*model.RepoLite, error) {
|
||||||
}
|
}
|
||||||
defer response.Body.Close()
|
defer response.Body.Close()
|
||||||
contents, err := ioutil.ReadAll(response.Body)
|
contents, err := ioutil.ReadAll(response.Body)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
var repoResponse Repos
|
var repoResponse Repos
|
||||||
json.Unmarshal(contents, &repoResponse)
|
err = json.Unmarshal(contents, &repoResponse)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
for _, repo := range repoResponse.Values {
|
for _, repo := range repoResponse.Values {
|
||||||
repos = append(repos, &model.RepoLite{
|
repos = append(repos, &model.RepoLite{
|
||||||
|
@ -240,12 +264,19 @@ func (*client) Status(*model.User, *model.Repo, *model.Build, string) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *client) Netrc(user *model.User, r *model.Repo) (*model.Netrc, error) {
|
func (c *client) Netrc(user *model.User, r *model.Repo) (*model.Netrc, error) {
|
||||||
u, err := url.Parse(c.URL) // TODO strip port from url
|
u, err := url.Parse(c.URL)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
//remove the port
|
||||||
|
tmp := strings.Split(u.Host, ":")
|
||||||
|
var host = tmp[0]
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return &model.Netrc{
|
return &model.Netrc{
|
||||||
Machine: u.Host,
|
Machine: host,
|
||||||
Login: c.GitUserName,
|
Login: c.GitUserName,
|
||||||
Password: c.GitPassword,
|
Password: c.GitPassword,
|
||||||
}, nil
|
}, nil
|
||||||
|
|
Loading…
Reference in a new issue