Get Netrc machine from clone url (#800)

We previously got the machine hostname for Netrc from the url of the remote, but in cases where the clone-url does not match the api url this can lead to errors.
This commit is contained in:
Anbraten
2022-02-26 02:54:15 +01:00
committed by GitHub
parent 8ae124d5e6
commit 52d8097290
14 changed files with 97 additions and 85 deletions

View File

@@ -27,6 +27,7 @@ import (
"github.com/woodpecker-ci/woodpecker/server/model"
"github.com/woodpecker-ci/woodpecker/server/remote"
"github.com/woodpecker-ci/woodpecker/server/remote/common"
)
// Opts defines configuration options.
@@ -40,7 +41,6 @@ type Opts struct {
type client struct {
URL string
Machine string
Username string
Password string
PrivateMode bool
@@ -60,7 +60,6 @@ func New(opts Opts) (remote.Remote, error) {
}
return &client{
URL: opts.URL,
Machine: u.Host,
Username: opts.Username,
Password: opts.Password,
PrivateMode: opts.PrivateMode,
@@ -217,17 +216,22 @@ func (c *client) Status(ctx context.Context, u *model.User, r *model.Repo, b *mo
// cloning Gogs repositories. The netrc will use the global machine account
// when configured.
func (c *client) Netrc(u *model.User, r *model.Repo) (*model.Netrc, error) {
host, err := common.ExtractHostFromCloneURL(r.Clone)
if err != nil {
return nil, err
}
if c.Password != "" {
return &model.Netrc{
Login: c.Username,
Password: c.Password,
Machine: c.Machine,
Machine: host,
}, nil
}
return &model.Netrc{
Login: u.Token,
Password: "x-oauth-basic",
Machine: c.Machine,
Machine: host,
}, nil
}