From 7e6c443f271040d982f7fbcc6370ba3c5f2a4ce5 Mon Sep 17 00:00:00 2001 From: zakisk <49492007+zakisk@users.noreply.github.com> Date: Fri, 8 Nov 2024 22:00:30 +0530 Subject: [PATCH] Fix Variables Resolution in PipelineRun on Bitbucket Server (#1817) --- pkg/provider/bitbucketserver/detect_test.go | 12 ++++++------ pkg/provider/bitbucketserver/parse_payload.go | 1 + .../bitbucketserver/parse_payload_test.go | 8 ++++---- pkg/provider/bitbucketserver/test/test.go | 6 +++--- pkg/provider/bitbucketserver/types/types.go | 16 ++++++++++++---- 5 files changed, 26 insertions(+), 17 deletions(-) diff --git a/pkg/provider/bitbucketserver/detect_test.go b/pkg/provider/bitbucketserver/detect_test.go index e4afa8ded..efc2d2b5f 100644 --- a/pkg/provider/bitbucketserver/detect_test.go +++ b/pkg/provider/bitbucketserver/detect_test.go @@ -37,7 +37,7 @@ func TestProvider_Detect(t *testing.T) { { name: "push event", event: types.PushRequestEvent{ - Actor: types.EventActor{ + Actor: bbv1.UserWithLinks{ ID: 111, }, Repository: bbv1.Repository{}, @@ -69,7 +69,7 @@ func TestProvider_Detect(t *testing.T) { { name: "retest comment", event: types.PullRequestEvent{ - Comment: bbv1.Comment{Text: "/retest"}, + Comment: bbv1.ActivityComment{Text: "/retest"}, }, eventType: "pr:comment:added", isBS: true, @@ -78,7 +78,7 @@ func TestProvider_Detect(t *testing.T) { { name: "random comment", event: types.PullRequestEvent{ - Comment: bbv1.Comment{Text: "random string, ignore me :)"}, + Comment: bbv1.ActivityComment{Text: "random string, ignore me :)"}, }, eventType: "pr:comment:added", isBS: true, @@ -87,7 +87,7 @@ func TestProvider_Detect(t *testing.T) { { name: "ok-to-test comment", event: types.PullRequestEvent{ - Comment: bbv1.Comment{Text: "/ok-to-test"}, + Comment: bbv1.ActivityComment{Text: "/ok-to-test"}, }, eventType: "pr:comment:added", isBS: true, @@ -96,7 +96,7 @@ func TestProvider_Detect(t *testing.T) { { name: "cancel comment", event: types.PullRequestEvent{ - Comment: bbv1.Comment{Text: "/cancel"}, + Comment: bbv1.ActivityComment{Text: "/cancel"}, }, eventType: "pr:comment:added", isBS: true, @@ -105,7 +105,7 @@ func TestProvider_Detect(t *testing.T) { { name: "cancel a pipelinerun comment", event: types.PullRequestEvent{ - Comment: bbv1.Comment{Text: "/cancel dummy"}, + Comment: bbv1.ActivityComment{Text: "/cancel dummy"}, }, eventType: "pr:comment:added", isBS: true, diff --git a/pkg/provider/bitbucketserver/parse_payload.go b/pkg/provider/bitbucketserver/parse_payload.go index f431f4a9a..f75fc482f 100644 --- a/pkg/provider/bitbucketserver/parse_payload.go +++ b/pkg/provider/bitbucketserver/parse_payload.go @@ -129,6 +129,7 @@ func (v *Provider) ParsePayload(_ context.Context, _ *params.Run, request *http. processedEvent.CancelPipelineRuns = true processedEvent.TargetCancelPipelineRun = provider.GetPipelineRunFromCancelComment(e.Comment.Text) } + processedEvent.TriggerComment = e.Comment.Text } if err := checkValidPayload(e); err != nil { diff --git a/pkg/provider/bitbucketserver/parse_payload_test.go b/pkg/provider/bitbucketserver/parse_payload_test.go index 97dcf646f..7d1ee577f 100644 --- a/pkg/provider/bitbucketserver/parse_payload_test.go +++ b/pkg/provider/bitbucketserver/parse_payload_test.go @@ -390,7 +390,7 @@ func TestCheckValidPayload(t *testing.T) { }, ID: 1, }, - Actor: types.EventActor{}, + Actor: bbv1.UserWithLinks{}, }, wantErrString: "bitbucket toRef repository clone links are empty", }, @@ -438,7 +438,7 @@ func TestCheckValidPayload(t *testing.T) { }, ID: 1, }, - Actor: types.EventActor{}, + Actor: bbv1.UserWithLinks{}, }, wantErrString: "bitbucket fromRef repository clone links are empty", }, @@ -487,7 +487,7 @@ func TestCheckValidPayload(t *testing.T) { }, ID: 1, }, - Actor: types.EventActor{}, + Actor: bbv1.UserWithLinks{}, }, wantErrString: "bitbucket actor ID is zero", }, @@ -536,7 +536,7 @@ func TestCheckValidPayload(t *testing.T) { }, ID: 1, }, - Actor: types.EventActor{ + Actor: bbv1.UserWithLinks{ ID: 1, }, }, diff --git a/pkg/provider/bitbucketserver/test/test.go b/pkg/provider/bitbucketserver/test/test.go index 08a4f0157..414a70707 100644 --- a/pkg/provider/bitbucketserver/test/test.go +++ b/pkg/provider/bitbucketserver/test/test.go @@ -269,7 +269,7 @@ func MakePREvent(event *info.Event, comment string) *types.PullRequestEvent { iii, _ := strconv.Atoi(event.AccountID) pr := &types.PullRequestEvent{ - Actor: types.EventActor{ID: iii, Name: event.Sender}, + Actor: bbv1.UserWithLinks{ID: iii, Name: event.Sender}, PullRequest: bbv1.PullRequest{ ID: 1, ToRef: bbv1.PullRequestRef{ @@ -318,7 +318,7 @@ func MakePREvent(event *info.Event, comment string) *types.PullRequestEvent { }, } if comment != "" { - pr.Comment = bbv1.Comment{ + pr.Comment = bbv1.ActivityComment{ Text: comment, } } @@ -329,7 +329,7 @@ func MakePushEvent(event *info.Event) *types.PushRequestEvent { iii, _ := strconv.Atoi(event.AccountID) return &types.PushRequestEvent{ - Actor: types.EventActor{ID: iii, Name: event.Sender}, + Actor: bbv1.UserWithLinks{ID: iii, Name: event.Sender}, Repository: bbv1.Repository{ Project: &bbv1.Project{ Key: event.Organization, diff --git a/pkg/provider/bitbucketserver/types/types.go b/pkg/provider/bitbucketserver/types/types.go index b202ef1cd..ca1b20596 100644 --- a/pkg/provider/bitbucketserver/types/types.go +++ b/pkg/provider/bitbucketserver/types/types.go @@ -10,9 +10,16 @@ type EventActor struct { } type PullRequestEvent struct { - Actor EventActor - PullRequest bbv1.PullRequest `json:"pullRequest"` - Comment bbv1.Comment `json:"comment"` + Actor bbv1.UserWithLinks `json:"actor"` + PullRequest bbv1.PullRequest `json:"pullRequest"` + EventKey string `json:"eventKey"` + + // Comment should be used when event is `pr:comment:added` or `pr:comment:edited`. + Comment bbv1.ActivityComment `json:"comment"` + + // CommentParentID and PreviousComment should be used when event is `pr:comment:edited`. + CommentParentID string `json:"commentParentId"` + PreviousComment string `json:"previousComment"` } type PushRequestEventChange struct { @@ -21,7 +28,8 @@ type PushRequestEventChange struct { } type PushRequestEvent struct { - Actor EventActor `json:"actor"` + Actor bbv1.UserWithLinks `json:"actor"` Repository bbv1.Repository `json:"repository"` Changes []PushRequestEventChange `json:"changes"` + Commits []bbv1.Commit `json:"commits"` }