1
0
mirror of https://github.com/woodpecker-ci/woodpecker.git synced 2025-11-23 21:44:44 +02:00

Add Forge Metadata (#1789)

close  #1787
This commit is contained in:
6543
2023-05-31 18:30:41 +02:00
committed by GitHub
parent a1943aa49e
commit 524611cf00
16 changed files with 149 additions and 55 deletions

View File

@@ -57,22 +57,22 @@ type Opts struct {
func New(opts Opts) (forge.Forge, error) {
r := &client{
API: defaultAPI,
URL: defaultURL,
url: defaultURL,
Client: opts.Client,
Secret: opts.Secret,
SkipVerify: opts.SkipVerify,
MergeRef: opts.MergeRef,
}
if opts.URL != defaultURL {
r.URL = strings.TrimSuffix(opts.URL, "/")
r.API = r.URL + "/api/v3/"
r.url = strings.TrimSuffix(opts.URL, "/")
r.API = r.url + "/api/v3/"
}
return r, nil
}
type client struct {
URL string
url string
API string
Client string
Secret string
@@ -85,6 +85,11 @@ func (c *client) Name() string {
return "github"
}
// URL returns the root url of a configured forge
func (c *client) URL() string {
return c.url
}
// Login authenticates the session and returns the forge user details.
func (c *client) Login(ctx context.Context, res http.ResponseWriter, req *http.Request) (*model.User, error) {
config := c.newConfig(req)
@@ -380,8 +385,8 @@ func (c *client) newConfig(req *http.Request) *oauth2.Config {
ClientSecret: c.Secret,
Scopes: []string{"repo", "repo:status", "user:email", "read:org"},
Endpoint: oauth2.Endpoint{
AuthURL: fmt.Sprintf("%s/login/oauth/authorize", c.URL),
TokenURL: fmt.Sprintf("%s/login/oauth/access_token", c.URL),
AuthURL: fmt.Sprintf("%s/login/oauth/authorize", c.url),
TokenURL: fmt.Sprintf("%s/login/oauth/access_token", c.url),
},
RedirectURL: redirect,
}