Skip to content

Commit

Permalink
Fix Variables Resolution in PipelineRun on Bitbucket Server (#1817)
Browse files Browse the repository at this point in the history
  • Loading branch information
zakisk authored Nov 8, 2024
1 parent 684efda commit 7e6c443
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 17 deletions.
12 changes: 6 additions & 6 deletions pkg/provider/bitbucketserver/detect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{},
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down
1 change: 1 addition & 0 deletions pkg/provider/bitbucketserver/parse_payload.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
8 changes: 4 additions & 4 deletions pkg/provider/bitbucketserver/parse_payload_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
Expand Down Expand Up @@ -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",
},
Expand Down Expand Up @@ -487,7 +487,7 @@ func TestCheckValidPayload(t *testing.T) {
},
ID: 1,
},
Actor: types.EventActor{},
Actor: bbv1.UserWithLinks{},
},
wantErrString: "bitbucket actor ID is zero",
},
Expand Down Expand Up @@ -536,7 +536,7 @@ func TestCheckValidPayload(t *testing.T) {
},
ID: 1,
},
Actor: types.EventActor{
Actor: bbv1.UserWithLinks{
ID: 1,
},
},
Expand Down
6 changes: 3 additions & 3 deletions pkg/provider/bitbucketserver/test/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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,
}
}
Expand All @@ -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,
Expand Down
16 changes: 12 additions & 4 deletions pkg/provider/bitbucketserver/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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"`
}

0 comments on commit 7e6c443

Please sign in to comment.