Skip to content

Commit 7e6c443

Browse files
authored
Fix Variables Resolution in PipelineRun on Bitbucket Server (#1817)
1 parent 684efda commit 7e6c443

File tree

5 files changed

+26
-17
lines changed

5 files changed

+26
-17
lines changed

pkg/provider/bitbucketserver/detect_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func TestProvider_Detect(t *testing.T) {
3737
{
3838
name: "push event",
3939
event: types.PushRequestEvent{
40-
Actor: types.EventActor{
40+
Actor: bbv1.UserWithLinks{
4141
ID: 111,
4242
},
4343
Repository: bbv1.Repository{},
@@ -69,7 +69,7 @@ func TestProvider_Detect(t *testing.T) {
6969
{
7070
name: "retest comment",
7171
event: types.PullRequestEvent{
72-
Comment: bbv1.Comment{Text: "/retest"},
72+
Comment: bbv1.ActivityComment{Text: "/retest"},
7373
},
7474
eventType: "pr:comment:added",
7575
isBS: true,
@@ -78,7 +78,7 @@ func TestProvider_Detect(t *testing.T) {
7878
{
7979
name: "random comment",
8080
event: types.PullRequestEvent{
81-
Comment: bbv1.Comment{Text: "random string, ignore me :)"},
81+
Comment: bbv1.ActivityComment{Text: "random string, ignore me :)"},
8282
},
8383
eventType: "pr:comment:added",
8484
isBS: true,
@@ -87,7 +87,7 @@ func TestProvider_Detect(t *testing.T) {
8787
{
8888
name: "ok-to-test comment",
8989
event: types.PullRequestEvent{
90-
Comment: bbv1.Comment{Text: "/ok-to-test"},
90+
Comment: bbv1.ActivityComment{Text: "/ok-to-test"},
9191
},
9292
eventType: "pr:comment:added",
9393
isBS: true,
@@ -96,7 +96,7 @@ func TestProvider_Detect(t *testing.T) {
9696
{
9797
name: "cancel comment",
9898
event: types.PullRequestEvent{
99-
Comment: bbv1.Comment{Text: "/cancel"},
99+
Comment: bbv1.ActivityComment{Text: "/cancel"},
100100
},
101101
eventType: "pr:comment:added",
102102
isBS: true,
@@ -105,7 +105,7 @@ func TestProvider_Detect(t *testing.T) {
105105
{
106106
name: "cancel a pipelinerun comment",
107107
event: types.PullRequestEvent{
108-
Comment: bbv1.Comment{Text: "/cancel dummy"},
108+
Comment: bbv1.ActivityComment{Text: "/cancel dummy"},
109109
},
110110
eventType: "pr:comment:added",
111111
isBS: true,

pkg/provider/bitbucketserver/parse_payload.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ func (v *Provider) ParsePayload(_ context.Context, _ *params.Run, request *http.
129129
processedEvent.CancelPipelineRuns = true
130130
processedEvent.TargetCancelPipelineRun = provider.GetPipelineRunFromCancelComment(e.Comment.Text)
131131
}
132+
processedEvent.TriggerComment = e.Comment.Text
132133
}
133134

134135
if err := checkValidPayload(e); err != nil {

pkg/provider/bitbucketserver/parse_payload_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ func TestCheckValidPayload(t *testing.T) {
390390
},
391391
ID: 1,
392392
},
393-
Actor: types.EventActor{},
393+
Actor: bbv1.UserWithLinks{},
394394
},
395395
wantErrString: "bitbucket toRef repository clone links are empty",
396396
},
@@ -438,7 +438,7 @@ func TestCheckValidPayload(t *testing.T) {
438438
},
439439
ID: 1,
440440
},
441-
Actor: types.EventActor{},
441+
Actor: bbv1.UserWithLinks{},
442442
},
443443
wantErrString: "bitbucket fromRef repository clone links are empty",
444444
},
@@ -487,7 +487,7 @@ func TestCheckValidPayload(t *testing.T) {
487487
},
488488
ID: 1,
489489
},
490-
Actor: types.EventActor{},
490+
Actor: bbv1.UserWithLinks{},
491491
},
492492
wantErrString: "bitbucket actor ID is zero",
493493
},
@@ -536,7 +536,7 @@ func TestCheckValidPayload(t *testing.T) {
536536
},
537537
ID: 1,
538538
},
539-
Actor: types.EventActor{
539+
Actor: bbv1.UserWithLinks{
540540
ID: 1,
541541
},
542542
},

pkg/provider/bitbucketserver/test/test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ func MakePREvent(event *info.Event, comment string) *types.PullRequestEvent {
269269
iii, _ := strconv.Atoi(event.AccountID)
270270

271271
pr := &types.PullRequestEvent{
272-
Actor: types.EventActor{ID: iii, Name: event.Sender},
272+
Actor: bbv1.UserWithLinks{ID: iii, Name: event.Sender},
273273
PullRequest: bbv1.PullRequest{
274274
ID: 1,
275275
ToRef: bbv1.PullRequestRef{
@@ -318,7 +318,7 @@ func MakePREvent(event *info.Event, comment string) *types.PullRequestEvent {
318318
},
319319
}
320320
if comment != "" {
321-
pr.Comment = bbv1.Comment{
321+
pr.Comment = bbv1.ActivityComment{
322322
Text: comment,
323323
}
324324
}
@@ -329,7 +329,7 @@ func MakePushEvent(event *info.Event) *types.PushRequestEvent {
329329
iii, _ := strconv.Atoi(event.AccountID)
330330

331331
return &types.PushRequestEvent{
332-
Actor: types.EventActor{ID: iii, Name: event.Sender},
332+
Actor: bbv1.UserWithLinks{ID: iii, Name: event.Sender},
333333
Repository: bbv1.Repository{
334334
Project: &bbv1.Project{
335335
Key: event.Organization,

pkg/provider/bitbucketserver/types/types.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,16 @@ type EventActor struct {
1010
}
1111

1212
type PullRequestEvent struct {
13-
Actor EventActor
14-
PullRequest bbv1.PullRequest `json:"pullRequest"`
15-
Comment bbv1.Comment `json:"comment"`
13+
Actor bbv1.UserWithLinks `json:"actor"`
14+
PullRequest bbv1.PullRequest `json:"pullRequest"`
15+
EventKey string `json:"eventKey"`
16+
17+
// Comment should be used when event is `pr:comment:added` or `pr:comment:edited`.
18+
Comment bbv1.ActivityComment `json:"comment"`
19+
20+
// CommentParentID and PreviousComment should be used when event is `pr:comment:edited`.
21+
CommentParentID string `json:"commentParentId"`
22+
PreviousComment string `json:"previousComment"`
1623
}
1724

1825
type PushRequestEventChange struct {
@@ -21,7 +28,8 @@ type PushRequestEventChange struct {
2128
}
2229

2330
type PushRequestEvent struct {
24-
Actor EventActor `json:"actor"`
31+
Actor bbv1.UserWithLinks `json:"actor"`
2532
Repository bbv1.Repository `json:"repository"`
2633
Changes []PushRequestEventChange `json:"changes"`
34+
Commits []bbv1.Commit `json:"commits"`
2735
}

0 commit comments

Comments
 (0)