From 36e5b9514b6a4a4fc6d24f5838b08d8141735c7a Mon Sep 17 00:00:00 2001 From: Joan Flotats <96056718+j04n-f@users.noreply.github.com> Date: Tue, 10 Dec 2024 14:21:37 +0100 Subject: [PATCH] Add Bitbucket fixes to Release/2.8 (#4547) Co-authored-by: Joan Flotats --- server/forge/bitbucket/bitbucket.go | 4 ++-- server/forge/bitbucket/convert.go | 4 ++-- server/forge/bitbucket/convert_test.go | 7 ++++--- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/server/forge/bitbucket/bitbucket.go b/server/forge/bitbucket/bitbucket.go index 4712a613d..f41ddd024 100644 --- a/server/forge/bitbucket/bitbucket.go +++ b/server/forge/bitbucket/bitbucket.go @@ -290,11 +290,11 @@ func (c *config) Dir(ctx context.Context, u *model.User, r *model.Repo, p *model } // Status creates a pipeline status for the Bitbucket commit. -func (c *config) Status(ctx context.Context, user *model.User, repo *model.Repo, pipeline *model.Pipeline, _ *model.Workflow) error { +func (c *config) Status(ctx context.Context, user *model.User, repo *model.Repo, pipeline *model.Pipeline, workflow *model.Workflow) error { status := internal.PipelineStatus{ State: convertStatus(pipeline.Status), Desc: common.GetPipelineStatusDescription(pipeline.Status), - Key: "Woodpecker", + Key: common.GetPipelineStatusContext(repo, pipeline, workflow), URL: common.GetPipelineStatusURL(repo, pipeline, nil), } return c.newClient(ctx, user).CreateStatus(repo.Owner, repo.Name, pipeline.Commit, &status) diff --git a/server/forge/bitbucket/convert.go b/server/forge/bitbucket/convert.go index 431c24086..e4e385650 100644 --- a/server/forge/bitbucket/convert.go +++ b/server/forge/bitbucket/convert.go @@ -171,14 +171,14 @@ func convertPullHook(from *internal.PullRequestHook) *model.Pipeline { pipeline := &model.Pipeline{ Event: event, Commit: from.PullRequest.Source.Commit.Hash, - Ref: fmt.Sprintf("refs/heads/%s", from.PullRequest.Source.Branch.Name), + Ref: fmt.Sprintf("refs/pull-requests/%d/from", from.PullRequest.ID), Refspec: fmt.Sprintf("%s:%s", from.PullRequest.Source.Branch.Name, from.PullRequest.Dest.Branch.Name, ), ForgeURL: from.PullRequest.Links.HTML.Href, Branch: from.PullRequest.Source.Branch.Name, - Message: from.PullRequest.Desc, + Message: from.PullRequest.Title, Avatar: from.Actor.Links.Avatar.Href, Author: from.Actor.Login, Sender: from.Actor.Login, diff --git a/server/forge/bitbucket/convert_test.go b/server/forge/bitbucket/convert_test.go index ee47a2770..70dac2bae 100644 --- a/server/forge/bitbucket/convert_test.go +++ b/server/forge/bitbucket/convert_test.go @@ -131,8 +131,9 @@ func Test_helper(t *testing.T) { hook.PullRequest.Source.Repo.FullName = "baz/bar" hook.PullRequest.Source.Commit.Hash = "c8411d7" hook.PullRequest.Links.HTML.Href = "https://bitbucket.org/foo/bar/pulls/5" - hook.PullRequest.Desc = "updated README" + hook.PullRequest.Title = "updated README" hook.PullRequest.Updated = time.Now() + hook.PullRequest.ID = 1 pipeline := convertPullHook(hook) g.Assert(pipeline.Event).Equal(model.EventPull) @@ -141,9 +142,9 @@ func Test_helper(t *testing.T) { g.Assert(pipeline.Commit).Equal(hook.PullRequest.Source.Commit.Hash) g.Assert(pipeline.Branch).Equal(hook.PullRequest.Source.Branch.Name) g.Assert(pipeline.ForgeURL).Equal(hook.PullRequest.Links.HTML.Href) - g.Assert(pipeline.Ref).Equal("refs/heads/change") + g.Assert(pipeline.Ref).Equal("refs/pull-requests/1/from") g.Assert(pipeline.Refspec).Equal("change:main") - g.Assert(pipeline.Message).Equal(hook.PullRequest.Desc) + g.Assert(pipeline.Message).Equal(hook.PullRequest.Title) g.Assert(pipeline.Timestamp).Equal(hook.PullRequest.Updated.Unix()) })