Rename oauth variables (#5435)

Co-authored-by: Anton Bracke <anton.bracke@fastleansmart.com>
This commit is contained in:
Anbraten 2025-08-20 22:47:43 +02:00 committed by GitHub
parent 88b926c9dd
commit 24ebcb8cf8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
17 changed files with 197 additions and 196 deletions

View File

@ -125,12 +125,12 @@ func PatchForge(c *gin.Context) {
} }
forge.URL = in.URL forge.URL = in.URL
forge.Type = in.Type forge.Type = in.Type
forge.Client = in.Client forge.OAuthClientID = in.OAuthClientID
forge.OAuthHost = in.OAuthHost forge.OAuthHost = in.OAuthHost
forge.SkipVerify = in.SkipVerify forge.SkipVerify = in.SkipVerify
forge.AdditionalOptions = in.AdditionalOptions forge.AdditionalOptions = in.AdditionalOptions
if in.ClientSecret != "" { if in.ClientSecret != "" {
forge.ClientSecret = in.ClientSecret forge.OAuthClientSecret = in.ClientSecret
} }
err = _store.ForgeUpdate(forge) err = _store.ForgeUpdate(forge)
@ -163,8 +163,8 @@ func PostForge(c *gin.Context) {
forge := &model.Forge{ forge := &model.Forge{
URL: in.URL, URL: in.URL,
Type: in.Type, Type: in.Type,
Client: in.Client, OAuthClientID: in.OAuthClientID,
ClientSecret: in.ClientSecret, OAuthClientSecret: in.OAuthClientSecret,
OAuthHost: in.OAuthHost, OAuthHost: in.OAuthHost,
SkipVerify: in.SkipVerify, SkipVerify: in.SkipVerify,
AdditionalOptions: in.AdditionalOptions, AdditionalOptions: in.AdditionalOptions,

View File

@ -44,25 +44,25 @@ const (
// Opts are forge options for bitbucket. // Opts are forge options for bitbucket.
type Opts struct { type Opts struct {
Client string OAuthClientID string
Secret string OAuthClientSecret string
} }
type config struct { type config struct {
API string api string
url string url string
Client string oAuthClientID string
Secret string oAuthSecret string
} }
// New returns a new forge Configuration for integrating with the Bitbucket // New returns a new forge Configuration for integrating with the Bitbucket
// repository hosting service at https://bitbucket.org // repository hosting service at https://bitbucket.org
func New(opts *Opts) (forge.Forge, error) { func New(opts *Opts) (forge.Forge, error) {
return &config{ return &config{
API: DefaultAPI, api: DefaultAPI,
url: DefaultURL, url: DefaultURL,
Client: opts.Client, oAuthClientID: opts.OAuthClientID,
Secret: opts.Secret, oAuthSecret: opts.OAuthClientSecret,
}, nil }, nil
// TODO: add checks // TODO: add checks
} }
@ -93,7 +93,7 @@ func (c *config) Login(ctx context.Context, req *forge_types.OAuthRequest) (*mod
return nil, redirectURL, err return nil, redirectURL, err
} }
client := internal.NewClient(ctx, c.API, config.Client(ctx, token)) client := internal.NewClient(ctx, c.api, config.Client(ctx, token))
curr, err := client.FindCurrent() curr, err := client.FindCurrent()
if err != nil { if err != nil {
return nil, redirectURL, err return nil, redirectURL, err
@ -448,15 +448,15 @@ func (c *config) newClient(ctx context.Context, u *model.User) *internal.Client
} }
// helper function to return the bitbucket oauth2 client. // helper function to return the bitbucket oauth2 client.
func (c *config) newClientToken(ctx context.Context, token, secret string) *internal.Client { func (c *config) newClientToken(ctx context.Context, accessToken, refreshToken string) *internal.Client {
return internal.NewClientToken( return internal.NewClientToken(
ctx, ctx,
c.API, c.api,
c.Client, accessToken,
c.Secret, refreshToken,
&oauth2.Token{ &oauth2.Token{
AccessToken: token, AccessToken: accessToken,
RefreshToken: secret, RefreshToken: refreshToken,
}, },
) )
} }
@ -464,8 +464,8 @@ func (c *config) newClientToken(ctx context.Context, token, secret string) *inte
// helper function to return the bitbucket oauth2 config. // helper function to return the bitbucket oauth2 config.
func (c *config) newOAuth2Config() *oauth2.Config { func (c *config) newOAuth2Config() *oauth2.Config {
return &oauth2.Config{ return &oauth2.Config{
ClientID: c.Client, ClientID: c.oAuthClientID,
ClientSecret: c.Secret, ClientSecret: c.oAuthSecret,
Endpoint: oauth2.Endpoint{ Endpoint: oauth2.Endpoint{
AuthURL: fmt.Sprintf("%s/site/oauth2/authorize", c.url), AuthURL: fmt.Sprintf("%s/site/oauth2/authorize", c.url),
TokenURL: fmt.Sprintf("%s/site/oauth2/access_token", c.url), TokenURL: fmt.Sprintf("%s/site/oauth2/access_token", c.url),

View File

@ -34,13 +34,13 @@ import (
) )
func TestNew(t *testing.T) { func TestNew(t *testing.T) {
forge, _ := New(&Opts{Client: "4vyW6b49Z", Secret: "a5012f6c6"}) forge, _ := New(&Opts{OAuthClientID: "4vyW6b49Z", OAuthClientSecret: "a5012f6c6"})
f, _ := forge.(*config) f, _ := forge.(*config)
assert.Equal(t, DefaultURL, f.url) assert.Equal(t, DefaultURL, f.url)
assert.Equal(t, DefaultAPI, f.API) assert.Equal(t, DefaultAPI, f.api)
assert.Equal(t, "4vyW6b49Z", f.Client) assert.Equal(t, "4vyW6b49Z", f.oAuthClientID)
assert.Equal(t, "a5012f6c6", f.Secret) assert.Equal(t, "a5012f6c6", f.oAuthSecret)
} }
func TestBitbucket(t *testing.T) { func TestBitbucket(t *testing.T) {
@ -48,7 +48,7 @@ func TestBitbucket(t *testing.T) {
s := httptest.NewServer(fixtures.Handler()) s := httptest.NewServer(fixtures.Handler())
defer s.Close() defer s.Close()
c := &config{url: s.URL, API: s.URL} c := &config{url: s.URL, api: s.URL}
ctx := t.Context() ctx := t.Context()

View File

@ -38,12 +38,12 @@ const listLimit = 250
// Opts defines configuration options. // Opts defines configuration options.
type Opts struct { type Opts struct {
URL string // Bitbucket server url for API access. URL string // Bitbucket server url for API access.
Username string // Git machine account username. Username string // Git machine account username.
Password string // Git machine account password. Password string // Git machine account password.
ClientID string // OAuth 2.0 client id OAuthClientID string // OAuth 2.0 client id
ClientSecret string // OAuth 2.0 client secret OAuthClientSecret string // OAuth 2.0 client secret
OAuthHost string // OAuth 2.0 host OAuthHost string // OAuth 2.0 host
} }
type client struct { type client struct {
@ -62,8 +62,8 @@ func New(opts Opts) (forge.Forge, error) {
config := &client{ config := &client{
url: opts.URL, url: opts.URL,
urlAPI: fmt.Sprintf("%s/rest", opts.URL), urlAPI: fmt.Sprintf("%s/rest", opts.URL),
clientID: opts.ClientID, clientID: opts.OAuthClientID,
clientSecret: opts.ClientSecret, clientSecret: opts.OAuthClientSecret,
oauthHost: opts.OAuthHost, oauthHost: opts.OAuthHost,
username: opts.Username, username: opts.Username,
password: opts.Password, password: opts.Password,
@ -74,9 +74,9 @@ func New(opts Opts) (forge.Forge, error) {
return nil, fmt.Errorf("must have a git machine account username") return nil, fmt.Errorf("must have a git machine account username")
case opts.Password == "": case opts.Password == "":
return nil, fmt.Errorf("must have a git machine account password") return nil, fmt.Errorf("must have a git machine account password")
case opts.ClientID == "": case opts.OAuthClientID == "":
return nil, fmt.Errorf("must have an oauth 2.0 client id") return nil, fmt.Errorf("must have an oauth 2.0 client id")
case opts.ClientSecret == "": case opts.OAuthClientSecret == "":
return nil, fmt.Errorf("must have an oauth 2.0 client secret") return nil, fmt.Errorf("must have an oauth 2.0 client secret")
} }

View File

@ -27,11 +27,11 @@ import (
func TestNew(t *testing.T) { func TestNew(t *testing.T) {
forge, err := New(Opts{ forge, err := New(Opts{
URL: "http://localhost:8080", URL: "http://localhost:8080",
Username: "0ZXh0IjoiI", Username: "0ZXh0IjoiI",
Password: "I1NiIsInR5", Password: "I1NiIsInR5",
ClientID: "client-id", OAuthClientID: "client-id",
ClientSecret: "client-secret", OAuthClientSecret: "client-secret",
}) })
assert.NoError(t, err) assert.NoError(t, err)
assert.NotNil(t, forge) assert.NotNil(t, forge)

View File

@ -45,21 +45,21 @@ const (
) )
type Forgejo struct { type Forgejo struct {
url string url string
oauth2URL string oauth2URL string
ClientID string oAuthClientID string
ClientSecret string oAuthClientSecret string
SkipVerify bool skipVerify bool
pageSize int pageSize int
} }
// Opts defines configuration options. // Opts defines configuration options.
type Opts struct { type Opts struct {
URL string // Forgejo server url. URL string // Forgejo server url.
OAuth2URL string // User-facing Forgejo server url for OAuth2. OAuth2URL string // User-facing Forgejo server url for OAuth2.
Client string // OAuth2 Client ID OAuthClientID string // OAuth2 Client ID
Secret string // OAuth2 Client Secret OAuthClientSecret string // OAuth2 Client Secret
SkipVerify bool // Skip ssl verification. SkipVerify bool // Skip ssl verification.
} }
// New returns a Forge implementation that integrates with Forgejo, // New returns a Forge implementation that integrates with Forgejo,
@ -70,11 +70,11 @@ func New(opts Opts) (forge.Forge, error) {
} }
return &Forgejo{ return &Forgejo{
url: opts.URL, url: opts.URL,
oauth2URL: opts.OAuth2URL, oauth2URL: opts.OAuth2URL,
ClientID: opts.Client, oAuthClientID: opts.OAuthClientID,
ClientSecret: opts.Secret, oAuthClientSecret: opts.OAuthClientSecret,
SkipVerify: opts.SkipVerify, skipVerify: opts.SkipVerify,
}, nil }, nil
} }
@ -90,8 +90,8 @@ func (c *Forgejo) URL() string {
func (c *Forgejo) oauth2Config(ctx context.Context) (*oauth2.Config, context.Context) { func (c *Forgejo) oauth2Config(ctx context.Context) (*oauth2.Config, context.Context) {
return &oauth2.Config{ return &oauth2.Config{
ClientID: c.ClientID, ClientID: c.oAuthClientID,
ClientSecret: c.ClientSecret, ClientSecret: c.oAuthClientSecret,
Endpoint: oauth2.Endpoint{ Endpoint: oauth2.Endpoint{
AuthURL: fmt.Sprintf(authorizeTokenURL, c.oauth2URL), AuthURL: fmt.Sprintf(authorizeTokenURL, c.oauth2URL),
TokenURL: fmt.Sprintf(accessTokenURL, c.oauth2URL), TokenURL: fmt.Sprintf(accessTokenURL, c.oauth2URL),
@ -100,7 +100,7 @@ func (c *Forgejo) oauth2Config(ctx context.Context) (*oauth2.Config, context.Con
}, },
context.WithValue(ctx, oauth2.HTTPClient, &http.Client{Transport: &http.Transport{ context.WithValue(ctx, oauth2.HTTPClient, &http.Client{Transport: &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: c.SkipVerify}, TLSClientConfig: &tls.Config{InsecureSkipVerify: c.skipVerify},
Proxy: http.ProxyFromEnvironment, Proxy: http.ProxyFromEnvironment,
}}) }})
} }
@ -568,7 +568,7 @@ func (c *Forgejo) Org(ctx context.Context, u *model.User, owner string) (*model.
// newClientToken returns a Forgejo client with token. // newClientToken returns a Forgejo client with token.
func (c *Forgejo) newClientToken(ctx context.Context, token string) (*forgejo.Client, error) { func (c *Forgejo) newClientToken(ctx context.Context, token string) (*forgejo.Client, error) {
httpClient := &http.Client{} httpClient := &http.Client{}
if c.SkipVerify { if c.skipVerify {
httpClient.Transport = &http.Transport{ httpClient.Transport = &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
} }

View File

@ -38,7 +38,7 @@ func TestNew(t *testing.T) {
f, _ := forge.(*Forgejo) f, _ := forge.(*Forgejo)
assert.Equal(t, "http://localhost:8080", f.url) assert.Equal(t, "http://localhost:8080", f.url)
assert.True(t, f.SkipVerify) assert.True(t, f.skipVerify)
} }
func Test_forgejo(t *testing.T) { func Test_forgejo(t *testing.T) {

View File

@ -47,32 +47,32 @@ const (
) )
type Gitea struct { type Gitea struct {
url string url string
ClientID string oAuthClientID string
ClientSecret string oAuthClientSecret string
OAuthHost string oAuthHost string
SkipVerify bool skipVerify bool
pageSize int pageSize int
} }
// Opts defines configuration options. // Opts defines configuration options.
type Opts struct { type Opts struct {
URL string // Gitea server url. URL string // Gitea server url.
Client string // OAuth2 Client ID OAuthClientID string // OAuth2 Client ID
Secret string // OAuth2 Client Secret OAuthClientSecret string // OAuth2 Client Secret
OAuthHost string // OAuth2 Host OAuthHost string // OAuth2 Host
SkipVerify bool // Skip ssl verification. SkipVerify bool // Skip ssl verification.
} }
// New returns a Forge implementation that integrates with Gitea, // New returns a Forge implementation that integrates with Gitea,
// an open source Git service written in Go. See https://gitea.io/ // an open source Git service written in Go. See https://gitea.io/
func New(opts Opts) (forge.Forge, error) { func New(opts Opts) (forge.Forge, error) {
return &Gitea{ return &Gitea{
url: opts.URL, url: opts.URL,
ClientID: opts.Client, oAuthClientID: opts.OAuthClientID,
ClientSecret: opts.Secret, oAuthClientSecret: opts.OAuthClientSecret,
OAuthHost: opts.OAuthHost, oAuthHost: opts.OAuthHost,
SkipVerify: opts.SkipVerify, skipVerify: opts.SkipVerify,
}, nil }, nil
} }
@ -87,13 +87,13 @@ func (c *Gitea) URL() string {
} }
func (c *Gitea) oauth2Config(ctx context.Context) (*oauth2.Config, context.Context) { func (c *Gitea) oauth2Config(ctx context.Context) (*oauth2.Config, context.Context) {
publicOAuthURL := c.OAuthHost publicOAuthURL := c.oAuthHost
if publicOAuthURL == "" { if publicOAuthURL == "" {
publicOAuthURL = c.url publicOAuthURL = c.url
} }
return &oauth2.Config{ return &oauth2.Config{
ClientID: c.ClientID, ClientID: c.oAuthClientID,
ClientSecret: c.ClientSecret, ClientSecret: c.oAuthClientSecret,
Endpoint: oauth2.Endpoint{ Endpoint: oauth2.Endpoint{
AuthURL: fmt.Sprintf(authorizeTokenURL, publicOAuthURL), AuthURL: fmt.Sprintf(authorizeTokenURL, publicOAuthURL),
TokenURL: fmt.Sprintf(accessTokenURL, c.url), TokenURL: fmt.Sprintf(accessTokenURL, c.url),
@ -102,7 +102,7 @@ func (c *Gitea) oauth2Config(ctx context.Context) (*oauth2.Config, context.Conte
}, },
context.WithValue(ctx, oauth2.HTTPClient, &http.Client{Transport: &http.Transport{ context.WithValue(ctx, oauth2.HTTPClient, &http.Client{Transport: &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: c.SkipVerify}, TLSClientConfig: &tls.Config{InsecureSkipVerify: c.skipVerify},
Proxy: http.ProxyFromEnvironment, Proxy: http.ProxyFromEnvironment,
}}) }})
} }
@ -575,7 +575,7 @@ func (c *Gitea) Org(ctx context.Context, u *model.User, owner string) (*model.Or
// newClientToken returns the Gitea client with Token. // newClientToken returns the Gitea client with Token.
func (c *Gitea) newClientToken(ctx context.Context, token string) (*gitea.Client, error) { func (c *Gitea) newClientToken(ctx context.Context, token string) (*gitea.Client, error) {
httpClient := &http.Client{} httpClient := &http.Client{}
if c.SkipVerify { if c.skipVerify {
httpClient.Transport = &http.Transport{ httpClient.Transport = &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
} }

View File

@ -39,7 +39,7 @@ func TestNew(t *testing.T) {
f, _ := forge.(*Gitea) f, _ := forge.(*Gitea)
assert.Equal(t, "http://localhost:8080", f.url) assert.Equal(t, "http://localhost:8080", f.url)
assert.True(t, f.SkipVerify) assert.True(t, f.skipVerify)
} }
func Test_gitea(t *testing.T) { func Test_gitea(t *testing.T) {

View File

@ -47,13 +47,13 @@ const (
// Opts defines configuration options. // Opts defines configuration options.
type Opts struct { type Opts struct {
URL string // GitHub server url. URL string // GitHub server url.
Client string // GitHub oauth client id. OAuthClientID string // GitHub oauth client id.
Secret string // GitHub oauth client secret. OAuthClientSecret string // GitHub oauth client secret.
SkipVerify bool // Skip ssl verification. SkipVerify bool // Skip ssl verification.
MergeRef bool // Clone pull requests using the merge ref. MergeRef bool // Clone pull requests using the merge ref.
OnlyPublic bool // Only obtain OAuth tokens with access to public repos. OnlyPublic bool // Only obtain OAuth tokens with access to public repos.
OAuthHost string // Public url for oauth if different from url. OAuthHost string // Public url for oauth if different from url.
} }
// New returns a Forge implementation that integrates with a GitHub Cloud or // New returns a Forge implementation that integrates with a GitHub Cloud or
@ -62,8 +62,8 @@ func New(opts Opts) (forge.Forge, error) {
r := &client{ r := &client{
API: defaultAPI, API: defaultAPI,
url: defaultURL, url: defaultURL,
Client: opts.Client, Client: opts.OAuthClientID,
Secret: opts.Secret, Secret: opts.OAuthClientSecret,
oAuthHost: opts.OAuthHost, oAuthHost: opts.OAuthHost,
SkipVerify: opts.SkipVerify, SkipVerify: opts.SkipVerify,
MergeRef: opts.MergeRef, MergeRef: opts.MergeRef,

View File

@ -28,10 +28,10 @@ import (
func TestNew(t *testing.T) { func TestNew(t *testing.T) {
forge, _ := New(Opts{ forge, _ := New(Opts{
URL: "http://localhost:8080/", URL: "http://localhost:8080/",
Client: "0ZXh0IjoiI", OAuthClientID: "0ZXh0IjoiI",
Secret: "I1NiIsInR5", OAuthClientSecret: "I1NiIsInR5",
SkipVerify: true, SkipVerify: true,
}) })
f, _ := forge.(*client) f, _ := forge.(*client)
assert.Equal(t, "http://localhost:8080", f.url) assert.Equal(t, "http://localhost:8080", f.url)

View File

@ -47,34 +47,34 @@ const (
// Opts defines configuration options. // Opts defines configuration options.
type Opts struct { type Opts struct {
URL string // Gitlab server url. URL string // Gitlab server url.
ClientID string // Oauth2 client id. OAuthClientID string // Oauth2 client id.
ClientSecret string // Oauth2 client secret. OAuthClientSecret string // Oauth2 client secret.
SkipVerify bool // Skip ssl verification. SkipVerify bool // Skip ssl verification.
OAuthHost string // Public url for oauth if different from url. OAuthHost string // Public url for oauth if different from url.
} }
// Gitlab implements "Forge" interface. // Gitlab implements "Forge" interface.
type GitLab struct { type GitLab struct {
url string url string
ClientID string oAuthClientID string
ClientSecret string oAuthClientSecret string
SkipVerify bool skipVerify bool
HideArchives bool hideArchives bool
Search bool search bool
oAuthHost string oAuthHost string
} }
// New returns a Forge implementation that integrates with Gitlab, an open // New returns a Forge implementation that integrates with Gitlab, an open
// source Git service. See https://gitlab.com // source Git service. See https://gitlab.com
func New(opts Opts) (forge.Forge, error) { func New(opts Opts) (forge.Forge, error) {
return &GitLab{ return &GitLab{
url: opts.URL, url: opts.URL,
ClientID: opts.ClientID, oAuthClientID: opts.OAuthClientID,
ClientSecret: opts.ClientSecret, oAuthClientSecret: opts.OAuthClientSecret,
oAuthHost: opts.OAuthHost, oAuthHost: opts.OAuthHost,
SkipVerify: opts.SkipVerify, skipVerify: opts.SkipVerify,
HideArchives: true, hideArchives: true,
}, nil }, nil
} }
@ -95,8 +95,8 @@ func (g *GitLab) oauth2Config(ctx context.Context) (*oauth2.Config, context.Cont
} }
return &oauth2.Config{ return &oauth2.Config{
ClientID: g.ClientID, ClientID: g.oAuthClientID,
ClientSecret: g.ClientSecret, ClientSecret: g.oAuthClientSecret,
Endpoint: oauth2.Endpoint{ Endpoint: oauth2.Endpoint{
AuthURL: fmt.Sprintf("%s/oauth/authorize", publicOAuthURL), AuthURL: fmt.Sprintf("%s/oauth/authorize", publicOAuthURL),
TokenURL: fmt.Sprintf("%s/oauth/token", g.url), TokenURL: fmt.Sprintf("%s/oauth/token", g.url),
@ -106,7 +106,7 @@ func (g *GitLab) oauth2Config(ctx context.Context) (*oauth2.Config, context.Cont
}, },
context.WithValue(ctx, oauth2.HTTPClient, &http.Client{Transport: &http.Transport{ context.WithValue(ctx, oauth2.HTTPClient, &http.Client{Transport: &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: g.SkipVerify}, TLSClientConfig: &tls.Config{InsecureSkipVerify: g.skipVerify},
Proxy: http.ProxyFromEnvironment, Proxy: http.ProxyFromEnvironment,
}}) }})
} }
@ -127,7 +127,7 @@ func (g *GitLab) Login(ctx context.Context, req *forge_types.OAuthRequest) (*mod
return nil, redirectURL, fmt.Errorf("error exchanging token: %w", err) return nil, redirectURL, fmt.Errorf("error exchanging token: %w", err)
} }
client, err := newClient(g.url, token.AccessToken, g.SkipVerify) client, err := newClient(g.url, token.AccessToken, g.skipVerify)
if err != nil { if err != nil {
return nil, redirectURL, err return nil, redirectURL, err
} }
@ -178,7 +178,7 @@ func (g *GitLab) Refresh(ctx context.Context, user *model.User) (bool, error) {
// Auth authenticates the session and returns the forge user login for the given token. // Auth authenticates the session and returns the forge user login for the given token.
func (g *GitLab) Auth(ctx context.Context, token, _ string) (string, error) { func (g *GitLab) Auth(ctx context.Context, token, _ string) (string, error) {
client, err := newClient(g.url, token, g.SkipVerify) client, err := newClient(g.url, token, g.skipVerify)
if err != nil { if err != nil {
return "", err return "", err
} }
@ -192,7 +192,7 @@ func (g *GitLab) Auth(ctx context.Context, token, _ string) (string, error) {
// Teams fetches a list of team memberships from the forge. // Teams fetches a list of team memberships from the forge.
func (g *GitLab) Teams(ctx context.Context, user *model.User) ([]*model.Team, error) { func (g *GitLab) Teams(ctx context.Context, user *model.User) ([]*model.Team, error) {
client, err := newClient(g.url, user.AccessToken, g.SkipVerify) client, err := newClient(g.url, user.AccessToken, g.skipVerify)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -261,7 +261,7 @@ func (g *GitLab) getInheritedProjectMember(ctx context.Context, client *gitlab.C
// Repo fetches the repository from the forge. // Repo fetches the repository from the forge.
func (g *GitLab) Repo(ctx context.Context, user *model.User, remoteID model.ForgeRemoteID, owner, name string) (*model.Repo, error) { func (g *GitLab) Repo(ctx context.Context, user *model.User, remoteID model.ForgeRemoteID, owner, name string) (*model.Repo, error) {
client, err := newClient(g.url, user.AccessToken, g.SkipVerify) client, err := newClient(g.url, user.AccessToken, g.skipVerify)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -286,7 +286,7 @@ func (g *GitLab) Repo(ctx context.Context, user *model.User, remoteID model.Forg
// Repos fetches a list of repos from the forge. // Repos fetches a list of repos from the forge.
func (g *GitLab) Repos(ctx context.Context, user *model.User) ([]*model.Repo, error) { func (g *GitLab) Repos(ctx context.Context, user *model.User) ([]*model.Repo, error) {
client, err := newClient(g.url, user.AccessToken, g.SkipVerify) client, err := newClient(g.url, user.AccessToken, g.skipVerify)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -296,7 +296,7 @@ func (g *GitLab) Repos(ctx context.Context, user *model.User) ([]*model.Repo, er
ListOptions: gitlab.ListOptions{PerPage: perPage}, ListOptions: gitlab.ListOptions{PerPage: perPage},
MinAccessLevel: gitlab.Ptr(gitlab.DeveloperPermissions), // TODO: check what's best here MinAccessLevel: gitlab.Ptr(gitlab.DeveloperPermissions), // TODO: check what's best here
} }
if g.HideArchives { if g.hideArchives {
opts.Archived = gitlab.Ptr(false) opts.Archived = gitlab.Ptr(false)
} }
intUserID, err := strconv.Atoi(string(user.ForgeRemoteID)) intUserID, err := strconv.Atoi(string(user.ForgeRemoteID))
@ -335,7 +335,7 @@ func (g *GitLab) Repos(ctx context.Context, user *model.User) ([]*model.Repo, er
func (g *GitLab) PullRequests(ctx context.Context, u *model.User, r *model.Repo, p *model.ListOptions) ([]*model.PullRequest, error) { func (g *GitLab) PullRequests(ctx context.Context, u *model.User, r *model.Repo, p *model.ListOptions) ([]*model.PullRequest, error) {
token := common.UserToken(ctx, r, u) token := common.UserToken(ctx, r, u)
client, err := newClient(g.url, token, g.SkipVerify) client, err := newClient(g.url, token, g.skipVerify)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -366,7 +366,7 @@ func (g *GitLab) PullRequests(ctx context.Context, u *model.User, r *model.Repo,
// File fetches a file from the forge repository and returns in string format. // File fetches a file from the forge repository and returns in string format.
func (g *GitLab) File(ctx context.Context, user *model.User, repo *model.Repo, pipeline *model.Pipeline, fileName string) ([]byte, error) { func (g *GitLab) File(ctx context.Context, user *model.User, repo *model.Repo, pipeline *model.Pipeline, fileName string) ([]byte, error) {
client, err := newClient(g.url, user.AccessToken, g.SkipVerify) client, err := newClient(g.url, user.AccessToken, g.skipVerify)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -383,7 +383,7 @@ func (g *GitLab) File(ctx context.Context, user *model.User, repo *model.Repo, p
// Dir fetches a folder from the forge repository. // Dir fetches a folder from the forge repository.
func (g *GitLab) Dir(ctx context.Context, user *model.User, repo *model.Repo, pipeline *model.Pipeline, path string) ([]*forge_types.FileMeta, error) { func (g *GitLab) Dir(ctx context.Context, user *model.User, repo *model.Repo, pipeline *model.Pipeline, path string) ([]*forge_types.FileMeta, error) {
client, err := newClient(g.url, user.AccessToken, g.SkipVerify) client, err := newClient(g.url, user.AccessToken, g.skipVerify)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -435,7 +435,7 @@ func (g *GitLab) Dir(ctx context.Context, user *model.User, repo *model.Repo, pi
// Status sends the commit status back to gitlab. // Status sends the commit status back to gitlab.
func (g *GitLab) Status(ctx context.Context, user *model.User, repo *model.Repo, pipeline *model.Pipeline, workflow *model.Workflow) error { func (g *GitLab) Status(ctx context.Context, user *model.User, repo *model.Repo, pipeline *model.Pipeline, workflow *model.Workflow) error {
client, err := newClient(g.url, user.AccessToken, g.SkipVerify) client, err := newClient(g.url, user.AccessToken, g.skipVerify)
if err != nil { if err != nil {
return err return err
} }
@ -493,7 +493,7 @@ func (g *GitLab) getTokenAndWebURL(link string) (token, webURL string, err error
// Activate activates a repository by adding a Post-commit hook and // Activate activates a repository by adding a Post-commit hook and
// a Public Deploy key, if applicable. // a Public Deploy key, if applicable.
func (g *GitLab) Activate(ctx context.Context, user *model.User, repo *model.Repo, link string) error { func (g *GitLab) Activate(ctx context.Context, user *model.User, repo *model.Repo, link string) error {
client, err := newClient(g.url, user.AccessToken, g.SkipVerify) client, err := newClient(g.url, user.AccessToken, g.skipVerify)
if err != nil { if err != nil {
return err return err
} }
@ -519,7 +519,7 @@ func (g *GitLab) Activate(ctx context.Context, user *model.User, repo *model.Rep
TagPushEvents: gitlab.Ptr(true), TagPushEvents: gitlab.Ptr(true),
MergeRequestsEvents: gitlab.Ptr(true), MergeRequestsEvents: gitlab.Ptr(true),
DeploymentEvents: gitlab.Ptr(true), DeploymentEvents: gitlab.Ptr(true),
EnableSSLVerification: gitlab.Ptr(!g.SkipVerify), EnableSSLVerification: gitlab.Ptr(!g.skipVerify),
}, gitlab.WithContext(ctx)) }, gitlab.WithContext(ctx))
return err return err
@ -528,7 +528,7 @@ func (g *GitLab) Activate(ctx context.Context, user *model.User, repo *model.Rep
// Deactivate removes a repository by removing all the post-commit hooks // Deactivate removes a repository by removing all the post-commit hooks
// which are equal to link and removing the SSH deploy key. // which are equal to link and removing the SSH deploy key.
func (g *GitLab) Deactivate(ctx context.Context, user *model.User, repo *model.Repo, link string) error { func (g *GitLab) Deactivate(ctx context.Context, user *model.User, repo *model.Repo, link string) error {
client, err := newClient(g.url, user.AccessToken, g.SkipVerify) client, err := newClient(g.url, user.AccessToken, g.skipVerify)
if err != nil { if err != nil {
return err return err
} }
@ -577,7 +577,7 @@ func (g *GitLab) Deactivate(ctx context.Context, user *model.User, repo *model.R
// Branches returns the names of all branches for the named repository. // Branches returns the names of all branches for the named repository.
func (g *GitLab) Branches(ctx context.Context, user *model.User, repo *model.Repo, p *model.ListOptions) ([]string, error) { func (g *GitLab) Branches(ctx context.Context, user *model.User, repo *model.Repo, p *model.ListOptions) ([]string, error) {
token := common.UserToken(ctx, repo, user) token := common.UserToken(ctx, repo, user)
client, err := newClient(g.url, token, g.SkipVerify) client, err := newClient(g.url, token, g.skipVerify)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -604,7 +604,7 @@ func (g *GitLab) Branches(ctx context.Context, user *model.User, repo *model.Rep
// BranchHead returns the sha of the head (latest commit) of the specified branch. // BranchHead returns the sha of the head (latest commit) of the specified branch.
func (g *GitLab) BranchHead(ctx context.Context, u *model.User, r *model.Repo, branch string) (*model.Commit, error) { func (g *GitLab) BranchHead(ctx context.Context, u *model.User, r *model.Repo, branch string) (*model.Commit, error) {
token := common.UserToken(ctx, r, u) token := common.UserToken(ctx, r, u)
client, err := newClient(g.url, token, g.SkipVerify) client, err := newClient(g.url, token, g.skipVerify)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -677,7 +677,7 @@ func (g *GitLab) Hook(ctx context.Context, req *http.Request) (*model.Repo, *mod
// OrgMembership returns if user is member of organization and if user // OrgMembership returns if user is member of organization and if user
// is admin/owner in this organization. // is admin/owner in this organization.
func (g *GitLab) OrgMembership(ctx context.Context, u *model.User, owner string) (*model.OrgPerm, error) { func (g *GitLab) OrgMembership(ctx context.Context, u *model.User, owner string) (*model.OrgPerm, error) {
client, err := newClient(g.url, u.AccessToken, g.SkipVerify) client, err := newClient(g.url, u.AccessToken, g.skipVerify)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -731,7 +731,7 @@ func (g *GitLab) OrgMembership(ctx context.Context, u *model.User, owner string)
} }
func (g *GitLab) Org(ctx context.Context, u *model.User, owner string) (*model.Org, error) { func (g *GitLab) Org(ctx context.Context, u *model.User, owner string) (*model.Org, error) {
client, err := newClient(g.url, u.AccessToken, g.SkipVerify) client, err := newClient(g.url, u.AccessToken, g.skipVerify)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -797,7 +797,7 @@ func (g *GitLab) loadChangedFilesFromMergeRequest(ctx context.Context, tmpRepo *
return nil, err return nil, err
} }
client, err := newClient(g.url, user.AccessToken, g.SkipVerify) client, err := newClient(g.url, user.AccessToken, g.skipVerify)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -36,13 +36,13 @@ func load(config string) *GitLab {
gitlab := GitLab{} gitlab := GitLab{}
gitlab.url = _url.String() gitlab.url = _url.String()
gitlab.ClientID = params.Get("client_id") gitlab.oAuthClientID = params.Get("client_id")
gitlab.ClientSecret = params.Get("client_secret") gitlab.oAuthClientSecret = params.Get("client_secret")
gitlab.SkipVerify, _ = strconv.ParseBool(params.Get("skip_verify")) gitlab.skipVerify, _ = strconv.ParseBool(params.Get("skip_verify"))
gitlab.HideArchives, _ = strconv.ParseBool(params.Get("hide_archives")) gitlab.hideArchives, _ = strconv.ParseBool(params.Get("hide_archives"))
// this is a temp workaround // this is a temp workaround
gitlab.Search, _ = strconv.ParseBool(params.Get("search")) gitlab.search, _ = strconv.ParseBool(params.Get("search"))
return &gitlab return &gitlab
} }
@ -70,14 +70,14 @@ func Test_GitLab(t *testing.T) {
ctx := t.Context() ctx := t.Context()
// Test projects method // Test projects method
t.Run("Should return only non-archived projects is hidden", func(t *testing.T) { t.Run("Should return only non-archived projects is hidden", func(t *testing.T) {
client.HideArchives = true client.hideArchives = true
_projects, err := client.Repos(ctx, &user) _projects, err := client.Repos(ctx, &user)
assert.NoError(t, err) assert.NoError(t, err)
assert.Len(t, _projects, 1) assert.Len(t, _projects, 1)
}) })
t.Run("Should return all the projects", func(t *testing.T) { t.Run("Should return all the projects", func(t *testing.T) {
client.HideArchives = false client.hideArchives = false
_projects, err := client.Repos(ctx, &user) _projects, err := client.Repos(ctx, &user)
assert.NoError(t, err) assert.NoError(t, err)

View File

@ -41,12 +41,13 @@ func Forge(forge *model.Forge) (forge.Forge, error) {
func setupBitbucket(forge *model.Forge) (forge.Forge, error) { func setupBitbucket(forge *model.Forge) (forge.Forge, error) {
opts := &bitbucket.Opts{ opts := &bitbucket.Opts{
Client: forge.Client, OAuthClientID: forge.OAuthClientID,
Secret: forge.ClientSecret, OAuthClientSecret: forge.OAuthClientSecret,
} }
log.Debug(). log.Debug().
Bool("client-set", opts.Client != ""). Bool("oauth-client-id-set", opts.OAuthClientID != "").
Bool("secret-set", opts.Secret != ""). Bool("oauth-client-secret-set", opts.OAuthClientSecret != "").
Str("type", string(forge.Type)). Str("type", string(forge.Type)).
Msg("setting up forge") Msg("setting up forge")
return bitbucket.New(opts) return bitbucket.New(opts)
@ -59,11 +60,11 @@ func setupGitea(forge *model.Forge) (forge.Forge, error) {
} }
opts := gitea.Opts{ opts := gitea.Opts{
URL: strings.TrimRight(serverURL.String(), "/"), URL: strings.TrimRight(serverURL.String(), "/"),
Client: forge.Client, OAuthClientID: forge.OAuthClientID,
Secret: forge.ClientSecret, OAuthClientSecret: forge.OAuthClientSecret,
SkipVerify: forge.SkipVerify, SkipVerify: forge.SkipVerify,
OAuthHost: forge.OAuthHost, OAuthHost: forge.OAuthHost,
} }
if len(opts.URL) == 0 { if len(opts.URL) == 0 {
return nil, fmt.Errorf("WOODPECKER_GITEA_URL must be set") return nil, fmt.Errorf("WOODPECKER_GITEA_URL must be set")
@ -72,8 +73,8 @@ func setupGitea(forge *model.Forge) (forge.Forge, error) {
Str("url", opts.URL). Str("url", opts.URL).
Str("oauth-host", opts.OAuthHost). Str("oauth-host", opts.OAuthHost).
Bool("skip-verify", opts.SkipVerify). Bool("skip-verify", opts.SkipVerify).
Bool("client-set", opts.Client != ""). Bool("oauth-client-id-set", opts.OAuthClientID != "").
Bool("secret-set", opts.Secret != ""). Bool("oauth-secret-id-set", opts.OAuthClientSecret != "").
Str("type", string(forge.Type)). Str("type", string(forge.Type)).
Msg("setting up forge") Msg("setting up forge")
return gitea.New(opts) return gitea.New(opts)
@ -86,11 +87,11 @@ func setupForgejo(forge *model.Forge) (forge.Forge, error) {
} }
opts := forgejo.Opts{ opts := forgejo.Opts{
URL: strings.TrimRight(server.String(), "/"), URL: strings.TrimRight(server.String(), "/"),
Client: forge.Client, OAuthClientID: forge.OAuthClientID,
Secret: forge.ClientSecret, OAuthClientSecret: forge.OAuthClientSecret,
SkipVerify: forge.SkipVerify, SkipVerify: forge.SkipVerify,
OAuth2URL: forge.OAuthHost, OAuth2URL: forge.OAuthHost,
} }
if len(opts.URL) == 0 { if len(opts.URL) == 0 {
return nil, fmt.Errorf("WOODPECKER_FORGEJO_URL must be set") return nil, fmt.Errorf("WOODPECKER_FORGEJO_URL must be set")
@ -99,8 +100,8 @@ func setupForgejo(forge *model.Forge) (forge.Forge, error) {
Str("url", opts.URL). Str("url", opts.URL).
Str("oauth2-url", opts.OAuth2URL). Str("oauth2-url", opts.OAuth2URL).
Bool("skip-verify", opts.SkipVerify). Bool("skip-verify", opts.SkipVerify).
Bool("client-set", opts.Client != ""). Bool("oauth-client-id-set", opts.OAuthClientID != "").
Bool("secret-set", opts.Secret != ""). Bool("oauth-client-secret-set", opts.OAuthClientSecret != "").
Str("type", string(forge.Type)). Str("type", string(forge.Type)).
Msg("setting up forge") Msg("setting up forge")
return forgejo.New(opts) return forgejo.New(opts)
@ -108,18 +109,18 @@ func setupForgejo(forge *model.Forge) (forge.Forge, error) {
func setupGitLab(forge *model.Forge) (forge.Forge, error) { func setupGitLab(forge *model.Forge) (forge.Forge, error) {
opts := gitlab.Opts{ opts := gitlab.Opts{
URL: forge.URL, URL: forge.URL,
ClientID: forge.Client, OAuthClientID: forge.OAuthClientID,
ClientSecret: forge.ClientSecret, OAuthClientSecret: forge.OAuthClientSecret,
SkipVerify: forge.SkipVerify, SkipVerify: forge.SkipVerify,
OAuthHost: forge.OAuthHost, OAuthHost: forge.OAuthHost,
} }
log.Debug(). log.Debug().
Str("url", opts.URL). Str("url", opts.URL).
Str("oauth-host", opts.OAuthHost). Str("oauth-host", opts.OAuthHost).
Bool("skip-verify", opts.SkipVerify). Bool("skip-verify", opts.SkipVerify).
Bool("client-id-set", opts.ClientID != ""). Bool("oauth-client-id-set", opts.OAuthClientID != "").
Bool("client-secret-set", opts.ClientSecret != ""). Bool("oauth-client-secret-set", opts.OAuthClientSecret != "").
Str("type", string(forge.Type)). Str("type", string(forge.Type)).
Msg("setting up forge") Msg("setting up forge")
return gitlab.New(opts) return gitlab.New(opts)
@ -137,13 +138,13 @@ func setupGitHub(forge *model.Forge) (forge.Forge, error) {
} }
opts := github.Opts{ opts := github.Opts{
URL: forge.URL, URL: forge.URL,
Client: forge.Client, OAuthClientID: forge.OAuthClientID,
Secret: forge.ClientSecret, OAuthClientSecret: forge.OAuthClientSecret,
SkipVerify: forge.SkipVerify, SkipVerify: forge.SkipVerify,
MergeRef: mergeRef, MergeRef: mergeRef,
OnlyPublic: publicOnly, OnlyPublic: publicOnly,
OAuthHost: forge.OAuthHost, OAuthHost: forge.OAuthHost,
} }
log.Debug(). log.Debug().
Str("url", opts.URL). Str("url", opts.URL).
@ -151,8 +152,8 @@ func setupGitHub(forge *model.Forge) (forge.Forge, error) {
Bool("merge-ref", opts.MergeRef). Bool("merge-ref", opts.MergeRef).
Bool("only-public", opts.OnlyPublic). Bool("only-public", opts.OnlyPublic).
Bool("skip-verify", opts.SkipVerify). Bool("skip-verify", opts.SkipVerify).
Bool("client-set", opts.Client != ""). Bool("oauth-client-id-set", opts.OAuthClientID != "").
Bool("secret-set", opts.Secret != ""). Bool("oauth-client-secret-set", opts.OAuthClientSecret != "").
Str("type", string(forge.Type)). Str("type", string(forge.Type)).
Msg("setting up forge") Msg("setting up forge")
return github.New(opts) return github.New(opts)
@ -169,18 +170,18 @@ func setupBitbucketDatacenter(forge *model.Forge) (forge.Forge, error) {
} }
opts := bitbucketdatacenter.Opts{ opts := bitbucketdatacenter.Opts{
URL: forge.URL, URL: forge.URL,
ClientID: forge.Client, OAuthClientID: forge.OAuthClientID,
ClientSecret: forge.ClientSecret, OAuthClientSecret: forge.OAuthClientSecret,
Username: gitUsername, Username: gitUsername,
Password: gitPassword, Password: gitPassword,
OAuthHost: forge.OAuthHost, OAuthHost: forge.OAuthHost,
} }
log.Debug(). log.Debug().
Str("url", opts.URL). Str("url", opts.URL).
Str("oauth-host", opts.OAuthHost). Str("oauth-host", opts.OAuthHost).
Bool("client-id-set", opts.ClientID != ""). Bool("oauth-client-id-set", opts.OAuthClientID != "").
Bool("client-secret-set", opts.ClientSecret != ""). Bool("oauth-client-secret-set", opts.OAuthClientSecret != "").
Str("type", string(forge.Type)). Str("type", string(forge.Type)).
Msg("setting up forge") Msg("setting up forge")
return bitbucketdatacenter.New(opts) return bitbucketdatacenter.New(opts)

View File

@ -30,8 +30,8 @@ type Forge struct {
ID int64 `json:"id" xorm:"pk autoincr 'id'"` ID int64 `json:"id" xorm:"pk autoincr 'id'"`
Type ForgeType `json:"type" xorm:"VARCHAR(250)"` Type ForgeType `json:"type" xorm:"VARCHAR(250)"`
URL string `json:"url" xorm:"VARCHAR(500) 'url'"` URL string `json:"url" xorm:"VARCHAR(500) 'url'"`
Client string `json:"client,omitempty" xorm:"VARCHAR(250)"` OAuthClientID string `json:"client,omitempty" xorm:"VARCHAR(250)"`
ClientSecret string `json:"-" xorm:"VARCHAR(250)"` // do not expose client secret OAuthClientSecret string `json:"-" xorm:"VARCHAR(250)"` // do not expose client secret
SkipVerify bool `json:"skip_verify,omitempty" xorm:"bool"` SkipVerify bool `json:"skip_verify,omitempty" xorm:"bool"`
OAuthHost string `json:"oauth_host,omitempty" xorm:"VARCHAR(250) 'oauth_host'"` // public url for oauth if different from url OAuthHost string `json:"oauth_host,omitempty" xorm:"VARCHAR(250) 'oauth_host'"` // public url for oauth if different from url
AdditionalOptions map[string]any `json:"additional_options,omitempty" xorm:"json"` AdditionalOptions map[string]any `json:"additional_options,omitempty" xorm:"json"`

View File

@ -115,8 +115,8 @@ func setupForgeService(c *cli.Command, _store store.Store) error {
_forge.AdditionalOptions = make(map[string]any) _forge.AdditionalOptions = make(map[string]any)
} }
_forge.Client = strings.TrimSpace(c.String("forge-oauth-client")) _forge.OAuthClientID = strings.TrimSpace(c.String("forge-oauth-client"))
_forge.ClientSecret = strings.TrimSpace(c.String("forge-oauth-secret")) _forge.OAuthClientSecret = strings.TrimSpace(c.String("forge-oauth-secret"))
_forge.URL = c.String("forge-url") _forge.URL = c.String("forge-url")
_forge.SkipVerify = c.Bool("forge-skip-verify") _forge.SkipVerify = c.Bool("forge-skip-verify")
_forge.OAuthHost = c.String("forge-oauth-host") _forge.OAuthHost = c.String("forge-oauth-host")

View File

@ -27,11 +27,11 @@ func TestForgeCRUD(t *testing.T) {
defer closer() defer closer()
forge1 := &model.Forge{ forge1 := &model.Forge{
Type: "github", Type: "github",
URL: "https://github.com", URL: "https://github.com",
Client: "client", OAuthClientID: "client",
ClientSecret: "secret", OAuthClientSecret: "secret",
SkipVerify: false, SkipVerify: false,
AdditionalOptions: map[string]any{ AdditionalOptions: map[string]any{
"foo": "bar", "foo": "bar",
}, },