Fix spelling: gitlab (#1411)

This is most of the GitLab changes that I dropped from #1405. 

As before, I'm happy to adjust things...

<details><summary>Problematic Changes</summary>

Fwiw, this is the part that causes the tests to break (I don't
understand why, but I'm leaving this change out):

```patch
commit 703cbe3ed398bf32535120ead733b80aa145c8db
Author: Josh Soref <2119212+jsoref@users.noreply.github.com>
Date:   Tue Nov 8 17:09:06 2022 -0500

    event?! -- this seems broken

diff --git a/server/forge/gitlab/testdata/hooks.go b/server/forge/gitlab/testdata/hooks.go
index 7d39306..e394afc 100644
--- a/server/forge/gitlab/testdata/hooks.go
+++ b/server/forge/gitlab/testdata/hooks.go
@@ -27,7 +27,7 @@ var (
 	ServiceHookHeaders = http.Header{
 		"Content-Type":   []string{"application/json"},
 		"User-Agent":     []string{"GitLab/14.3.0"},
-		"X-Gitlab-Event": []string{"Service Hook"},
+		"X-GitLab-Event": []string{"Service Hook"},
 	}
 )
 
diff --git a/shared/token/token.go b/shared/token/token.go
index 3f15537..191e5ee 100644
--- a/shared/token/token.go
+++ b/shared/token/token.go
@@ -64,7 +64,7 @@ func ParseRequest(r *http.Request, fn SecretFunc) (*Token, error) {
 		return parse(bearer, fn)
 	}
 
-	token = r.Header.Get("X-Gitlab-Token")
+	token = r.Header.Get("X-GitLab-Token")
 	if len(token) != 0 {
 		return parse(token, fn)
 	}

```
</details>

Signed-off-by: Josh Soref <2119212+jsoref@users.noreply.github.com>
Co-authored-by: qwerty287 <80460567+qwerty287@users.noreply.github.com>
This commit is contained in:
Josh Soref 2022-11-09 11:16:17 -05:00 committed by GitHub
parent 023d03dd61
commit 12cbe15de0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 35 additions and 35 deletions

View file

@ -192,7 +192,7 @@ func setupForge(c *cli.Context) (forge.Forge, error) {
case c.Bool("github"):
return setupGitHub(c)
case c.Bool("gitlab"):
return setupGitlab(c)
return setupGitLab(c)
case c.Bool("bitbucket"):
return setupBitbucket(c)
case c.Bool("stash"):
@ -265,8 +265,8 @@ func setupStash(c *cli.Context) (forge.Forge, error) {
return bitbucketserver.New(opts)
}
// helper function to setup the Gitlab forge from the CLI arguments.
func setupGitlab(c *cli.Context) (forge.Forge, error) {
// helper function to setup the GitLab forge from the CLI arguments.
func setupGitLab(c *cli.Context) (forge.Forge, error) {
return gitlab.New(gitlab.Opts{
URL: c.String("gitlab-server"),
ClientID: c.String("gitlab-client"),

View file

@ -31,7 +31,7 @@ const (
mergeRefs = "refs/merge-requests/%d/head" // merge request merged with base
)
func (g *Gitlab) convertGitlabRepo(_repo *gitlab.Project) (*model.Repo, error) {
func (g *GitLab) convertGitLabRepo(_repo *gitlab.Project) (*model.Repo, error) {
parts := strings.Split(_repo.PathWithNamespace, "/")
// TODO(648) save repo id (support nested repos)
owner := strings.Join(parts[:len(parts)-1], "/")

View file

@ -53,7 +53,7 @@ type Opts struct {
}
// Gitlab implements "Forge" interface
type Gitlab struct {
type GitLab struct {
URL string
ClientID string
ClientSecret string
@ -65,7 +65,7 @@ type Gitlab struct {
// New returns a Forge implementation that integrates with Gitlab, an open
// source Git service. See https://gitlab.com
func New(opts Opts) (forge.Forge, error) {
return &Gitlab{
return &GitLab{
URL: opts.URL,
ClientID: opts.ClientID,
ClientSecret: opts.ClientSecret,
@ -74,11 +74,11 @@ func New(opts Opts) (forge.Forge, error) {
}
// Name returns the string name of this driver
func (g *Gitlab) Name() string {
func (g *GitLab) Name() string {
return "gitlab"
}
func (g *Gitlab) oauth2Config(ctx context.Context) (*oauth2.Config, context.Context) {
func (g *GitLab) oauth2Config(ctx context.Context) (*oauth2.Config, context.Context) {
return &oauth2.Config{
ClientID: g.ClientID,
ClientSecret: g.ClientSecret,
@ -98,7 +98,7 @@ func (g *Gitlab) oauth2Config(ctx context.Context) (*oauth2.Config, context.Cont
// Login authenticates the session and returns the
// forge user details.
func (g *Gitlab) Login(ctx context.Context, res http.ResponseWriter, req *http.Request) (*model.User, error) {
func (g *GitLab) Login(ctx context.Context, res http.ResponseWriter, req *http.Request) (*model.User, error) {
config, oauth2Ctx := g.oauth2Config(ctx)
// get the OAuth errors
@ -148,7 +148,7 @@ func (g *Gitlab) Login(ctx context.Context, res http.ResponseWriter, req *http.R
// Refresh refreshes the Gitlab oauth2 access token. If the token is
// refreshed the user is updated and a true value is returned.
func (g *Gitlab) Refresh(ctx context.Context, user *model.User) (bool, error) {
func (g *GitLab) Refresh(ctx context.Context, user *model.User) (bool, error) {
config, oauth2Ctx := g.oauth2Config(ctx)
config.RedirectURL = ""
@ -170,7 +170,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
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)
if err != nil {
return "", err
@ -184,7 +184,7 @@ func (g *Gitlab) Auth(ctx context.Context, token, _ string) (string, error) {
}
// 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.Token, g.SkipVerify)
if err != nil {
return nil, err
@ -219,7 +219,7 @@ func (g *Gitlab) Teams(ctx context.Context, user *model.User) ([]*model.Team, er
}
// getProject fetches the named repository from the forge.
func (g *Gitlab) getProject(ctx context.Context, client *gitlab.Client, owner, name string) (*gitlab.Project, error) {
func (g *GitLab) getProject(ctx context.Context, client *gitlab.Client, owner, name string) (*gitlab.Project, error) {
repo, _, err := client.Projects.GetProject(fmt.Sprintf("%s/%s", owner, name), nil, gitlab.WithContext(ctx))
if err != nil {
return nil, err
@ -229,7 +229,7 @@ func (g *Gitlab) getProject(ctx context.Context, client *gitlab.Client, owner, n
}
// Repo fetches the repository from the forge.
func (g *Gitlab) Repo(ctx context.Context, user *model.User, id model.ForgeID, owner, name string) (*model.Repo, error) {
func (g *GitLab) Repo(ctx context.Context, user *model.User, id model.ForgeID, owner, name string) (*model.Repo, error) {
client, err := newClient(g.URL, user.Token, g.SkipVerify)
if err != nil {
return nil, err
@ -244,7 +244,7 @@ func (g *Gitlab) Repo(ctx context.Context, user *model.User, id model.ForgeID, o
if err != nil {
return nil, err
}
return g.convertGitlabRepo(_repo)
return g.convertGitLabRepo(_repo)
}
_repo, err := g.getProject(ctx, client, owner, name)
@ -252,11 +252,11 @@ func (g *Gitlab) Repo(ctx context.Context, user *model.User, id model.ForgeID, o
return nil, err
}
return g.convertGitlabRepo(_repo)
return g.convertGitLabRepo(_repo)
}
// 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.Token, g.SkipVerify)
if err != nil {
return nil, err
@ -279,7 +279,7 @@ func (g *Gitlab) Repos(ctx context.Context, user *model.User) ([]*model.Repo, er
}
for i := range batch {
repo, err := g.convertGitlabRepo(batch[i])
repo, err := g.convertGitLabRepo(batch[i])
if err != nil {
return nil, err
}
@ -302,7 +302,7 @@ func (g *Gitlab) Repos(ctx context.Context, user *model.User) ([]*model.Repo, er
}
// Perm fetches the named repository from the forge.
func (g *Gitlab) Perm(ctx context.Context, user *model.User, r *model.Repo) (*model.Perm, error) {
func (g *GitLab) Perm(ctx context.Context, user *model.User, r *model.Repo) (*model.Perm, error) {
client, err := newClient(g.URL, user.Token, g.SkipVerify)
if err != nil {
return nil, err
@ -326,7 +326,7 @@ func (g *Gitlab) Perm(ctx context.Context, user *model.User, r *model.Repo) (*mo
}
// 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.Token, g.SkipVerify)
if err != nil {
return nil, err
@ -340,7 +340,7 @@ func (g *Gitlab) File(ctx context.Context, user *model.User, repo *model.Repo, p
}
// 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.Token, g.SkipVerify)
if err != nil {
return nil, err
@ -388,7 +388,7 @@ func (g *Gitlab) Dir(ctx context.Context, user *model.User, repo *model.Repo, pi
}
// Status sends the commit status back to gitlab.
func (g *Gitlab) Status(ctx context.Context, user *model.User, repo *model.Repo, pipeline *model.Pipeline, step *model.Step) error {
func (g *GitLab) Status(ctx context.Context, user *model.User, repo *model.Repo, pipeline *model.Pipeline, step *model.Step) error {
client, err := newClient(g.URL, user.Token, g.SkipVerify)
if err != nil {
return err
@ -412,7 +412,7 @@ func (g *Gitlab) Status(ctx context.Context, user *model.User, repo *model.Repo,
// Netrc returns a netrc file capable of authenticating Gitlab requests and
// cloning Gitlab repositories. The netrc will use the global machine account
// when configured.
func (g *Gitlab) Netrc(u *model.User, r *model.Repo) (*model.Netrc, error) {
func (g *GitLab) Netrc(u *model.User, r *model.Repo) (*model.Netrc, error) {
login := ""
token := ""
@ -433,7 +433,7 @@ func (g *Gitlab) Netrc(u *model.User, r *model.Repo) (*model.Netrc, error) {
}, nil
}
func (g *Gitlab) getTokenAndWebURL(link string) (token, webURL string, err error) {
func (g *GitLab) getTokenAndWebURL(link string) (token, webURL string, err error) {
uri, err := url.Parse(link)
if err != nil {
return "", "", err
@ -445,7 +445,7 @@ func (g *Gitlab) getTokenAndWebURL(link string) (token, webURL string, err error
// Activate activates a repository by adding a Post-commit hook and
// 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.Token, g.SkipVerify)
if err != nil {
return err
@ -480,7 +480,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
// 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.Token, g.SkipVerify)
if err != nil {
return err
@ -533,7 +533,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.
func (g *Gitlab) Branches(ctx context.Context, user *model.User, repo *model.Repo) ([]string, error) {
func (g *GitLab) Branches(ctx context.Context, user *model.User, repo *model.Repo) ([]string, error) {
token := ""
if user != nil {
token = user.Token
@ -561,7 +561,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
func (g *Gitlab) BranchHead(ctx context.Context, u *model.User, r *model.Repo, branch string) (string, error) {
func (g *GitLab) BranchHead(ctx context.Context, u *model.User, r *model.Repo, branch string) (string, error) {
token := ""
if u != nil {
token = u.Token
@ -586,7 +586,7 @@ func (g *Gitlab) BranchHead(ctx context.Context, u *model.User, r *model.Repo, b
// Hook parses the post-commit hook from the Request body
// and returns the required data in a standard format.
func (g *Gitlab) Hook(ctx context.Context, req *http.Request) (*model.Repo, *model.Pipeline, error) {
func (g *GitLab) Hook(ctx context.Context, req *http.Request) (*model.Repo, *model.Pipeline, error) {
defer req.Body.Close()
payload, err := io.ReadAll(req.Body)
if err != nil {
@ -621,7 +621,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
// 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.Token, g.SkipVerify)
if err != nil {
return nil, err
@ -675,7 +675,7 @@ func (g *Gitlab) OrgMembership(ctx context.Context, u *model.User, owner string)
return &model.OrgPerm{}, nil
}
func (g *Gitlab) loadChangedFilesFromMergeRequest(ctx context.Context, tmpRepo *model.Repo, pipeline *model.Pipeline, mergeIID int) (*model.Pipeline, error) {
func (g *GitLab) loadChangedFilesFromMergeRequest(ctx context.Context, tmpRepo *model.Repo, pipeline *model.Pipeline, mergeIID int) (*model.Pipeline, error) {
_store, ok := store.TryFromContext(ctx)
if !ok {
log.Error().Msg("could not get store from context")

View file

@ -30,7 +30,7 @@ import (
"github.com/woodpecker-ci/woodpecker/server/model"
)
func load(t *testing.T, config string) *Gitlab {
func load(t *testing.T, config string) *GitLab {
_url, err := url.Parse(config)
if err != nil {
t.FailNow()
@ -38,7 +38,7 @@ func load(t *testing.T, config string) *Gitlab {
params := _url.Query()
_url.RawQuery = ""
gitlab := Gitlab{}
gitlab := GitLab{}
gitlab.URL = _url.String()
gitlab.ClientID = params.Get("client_id")
gitlab.ClientSecret = params.Get("client_secret")
@ -51,7 +51,7 @@ func load(t *testing.T, config string) *Gitlab {
return &gitlab
}
func Test_Gitlab(t *testing.T) {
func Test_GitLab(t *testing.T) {
// setup a dummy gitlab server
server := testdata.NewServer(t)
defer server.Close()
@ -72,7 +72,7 @@ func Test_Gitlab(t *testing.T) {
ctx := context.Background()
g := goblin.Goblin(t)
g.Describe("Gitlab Plugin", func() {
g.Describe("GitLab Plugin", func() {
// Test projects method
g.Describe("AllProjects", func() {
g.It("Should return only non-archived projects is hidden", func() {