From 6707e440fee9ab33dce1c42724a8c3cc9bf7eafc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thor=20Anker=20Kvisg=C3=A5rd=20Lange?= Date: Mon, 25 Sep 2023 11:32:41 +0200 Subject: [PATCH] fix: Adjusted according to interface changes --- .../forge/bitbucketserver/bitbucketserver.go | 33 ++++++++++++------- .../bitbucketserver/bitbucketserver_test.go | 2 +- 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/server/forge/bitbucketserver/bitbucketserver.go b/server/forge/bitbucketserver/bitbucketserver.go index c6c219ed8e..97853f972e 100644 --- a/server/forge/bitbucketserver/bitbucketserver.go +++ b/server/forge/bitbucketserver/bitbucketserver.go @@ -59,7 +59,7 @@ type Opts struct { } type client struct { - URL string + url string URLApi string Username string Password string @@ -71,7 +71,7 @@ type client struct { // the on-premise edition of Bitbucket Cloud, formerly known as Stash. func New(opts Opts) (forge.Forge, error) { config := &client{ - URL: opts.URL, + url: opts.URL, URLApi: fmt.Sprintf("%s/rest", opts.URL), Username: opts.Username, Password: opts.Password, @@ -117,6 +117,11 @@ func (c *client) Name() string { return "stash" } +// URL returns the root url of a configured forge +func (c *client) URL() string { + return c.url +} + func (c *client) Login(ctx context.Context, res http.ResponseWriter, req *http.Request) (*model.User, error) { requestToken, u, err := c.Consumer.GetRequestTokenAndUrl("oob") if err != nil { @@ -133,7 +138,7 @@ func (c *client) Login(ctx context.Context, res http.ResponseWriter, req *http.R return nil, err } - client := internal.NewClientWithToken(ctx, c.URL, c.Consumer, accessToken.Token) + client := internal.NewClientWithToken(ctx, c.url, c.Consumer, accessToken.Token) userID, err := client.FindCurrentUser() if err != nil { return nil, err @@ -150,7 +155,7 @@ func (c *client) Login(ctx context.Context, res http.ResponseWriter, req *http.R return nil, fmt.Errorf("unable to query for user: %w", err) } - return convertUser(user, accessToken.Token, c.URL), nil + return convertUser(user, accessToken.Token, c.url), nil } // Auth is not supported by the Stash driver. @@ -255,15 +260,15 @@ func (c *client) Dir(ctx context.Context, u *model.User, r *model.Repo, p *model return all, nil } -func (c *client) Status(ctx context.Context, u *model.User, repo *model.Repo, pipeline *model.Pipeline, step *model.Step) error { +func (c *client) Status(ctx context.Context, u *model.User, repo *model.Repo, pipeline *model.Pipeline, workflow *model.Workflow) error { bc, err := c.newClient(u) if err != nil { return fmt.Errorf("unable to create bitbucket client: %w", err) } status := &bb.BuildStatus{ State: convertStatus(pipeline.Status), - URL: common.GetPipelineStatusLink(repo, pipeline, step), - Key: common.GetPipelineStatusContext(repo, pipeline, step), + URL: common.GetPipelineStatusLink(repo, pipeline, workflow), + Key: common.GetPipelineStatusContext(repo, pipeline, workflow), Description: common.GetPipelineStatusDescription(pipeline.Status), } _, err = bc.Projects.CreateBuildStatus(ctx, repo.Owner, repo.Name, pipeline.Commit, status) @@ -284,7 +289,7 @@ func (c *client) Netrc(_ *model.User, r *model.Repo) (*model.Netrc, error) { } // Branches returns the names of all branches for the named repository. -func (c *client) Branches(ctx context.Context, u *model.User, r *model.Repo) ([]string, error) { +func (c *client) Branches(ctx context.Context, u *model.User, r *model.Repo, _ *model.ListOptions) ([]string, error) { bc, err := c.newClient(u) if err != nil { return nil, fmt.Errorf("unable to create bitbucket client: %w", err) @@ -329,7 +334,7 @@ func (c *client) BranchHead(ctx context.Context, u *model.User, r *model.Repo, b return "", fmt.Errorf("no matching branches found") } -func (c *client) PullRequests(ctx context.Context, u *model.User, r *model.Repo, p *model.PaginationData) ([]*model.PullRequest, error) { +func (c *client) PullRequests(ctx context.Context, u *model.User, r *model.Repo, p *model.ListOptions) ([]*model.PullRequest, error) { bc, err := c.newClient(u) if err != nil { return nil, fmt.Errorf("unable to create bitbucket client: %w", err) @@ -424,10 +429,10 @@ func (c *client) Hook(ctx context.Context, r *http.Request) (*model.Repo, *model switch e := ev.(type) { case *bb.RepositoryPushEvent: repo = convertRepo(&e.Repository, nil, "") - pipe = convertRepositoryPushEvent(e, c.URL) + pipe = convertRepositoryPushEvent(e, c.url) case *bb.PullRequestEvent: repo = convertRepo(&e.PullRequest.Source.Repository, nil, "") - pipe = convertPullRequestEvent(e, c.URL) + pipe = convertPullRequestEvent(e, c.url) default: return nil, nil, nil } @@ -513,6 +518,12 @@ func (c *client) OrgMembership(_ context.Context, _ *model.User, _ string) (*mod return nil, nil } +// Org fetches the organization from the forge by name. If the name is a user an org with type user is returned. +func (c *client) Org(ctx context.Context, u *model.User, owner string) (*model.Org, error) { + // TODO: Not implemented currently + return nil, nil +} + type httpLogger struct { Transport http.RoundTripper } diff --git a/server/forge/bitbucketserver/bitbucketserver_test.go b/server/forge/bitbucketserver/bitbucketserver_test.go index fc8b042acd..fbfbc9080f 100644 --- a/server/forge/bitbucketserver/bitbucketserver_test.go +++ b/server/forge/bitbucketserver/bitbucketserver_test.go @@ -58,7 +58,7 @@ func Test_stash(t *testing.T) { }) g.Assert(err).IsNil() g.Assert(forge).IsNotNil() - g.Assert(forge.(*client).URL).Equal("http://localhost:8080") + g.Assert(forge.(*client).url).Equal("http://localhost:8080") g.Assert(forge.(*client).Username).Equal("0ZXh0IjoiI") g.Assert(forge.(*client).Password).Equal("I1NiIsInR5") g.Assert(forge.(*client).SkipVerify).Equal(true)