@@ -5,11 +5,14 @@ package test
55import (
66 "context"
77 "fmt"
8+ "strings"
89 "testing"
910 "time"
1011
1112 "github.com/ktrysmt/go-bitbucket"
13+ "github.com/mitchellh/mapstructure"
1214 "github.com/openshift-pipelines/pipelines-as-code/pkg/params/triggertype"
15+ "github.com/openshift-pipelines/pipelines-as-code/pkg/provider/bitbucketcloud/types"
1316 tbb "github.com/openshift-pipelines/pipelines-as-code/test/pkg/bitbucketcloud"
1417 "github.com/openshift-pipelines/pipelines-as-code/test/pkg/options"
1518 "github.com/openshift-pipelines/pipelines-as-code/test/pkg/payload"
@@ -107,6 +110,65 @@ func TestBitbucketCloudPullRequestCancelInProgressMerged(t *testing.T) {
107110 assert .Equal (t , prs .Items [0 ].GetStatusCondition ().GetCondition (apis .ConditionSucceeded ).GetReason (), "Cancelled" , "should have been cancelled" )
108111}
109112
113+ func TestBitbucketCloudPRBuildStatusReported (t * testing.T ) {
114+ targetNS := names .SimpleNameGenerator .RestrictLengthWithRandomSuffix ("pac-e2e-ns" )
115+ ctx := context .Background ()
116+
117+ runcnx , opts , bprovider , err := tbb .Setup (ctx )
118+ if err != nil {
119+ t .Skip (err .Error ())
120+ return
121+ }
122+ bcrepo := tbb .CreateCRD (ctx , t , bprovider , runcnx , opts , targetNS )
123+ targetRefName := names .SimpleNameGenerator .RestrictLengthWithRandomSuffix ("pac-e2e-test" )
124+ title := "TestPullRequest - " + targetRefName
125+
126+ entries , err := payload .GetEntries (
127+ map [string ]string {".tekton/pipelinerun.yaml" : "testdata/pipelinerun.yaml" },
128+ targetNS , options .MainBranch , triggertype .PullRequest .String (), map [string ]string {})
129+ assert .NilError (t , err )
130+
131+ pr , repobranch := tbb .MakePR (t , bprovider , runcnx , bcrepo , opts , title , targetRefName , entries )
132+ defer tbb .TearDown (ctx , t , runcnx , bprovider , opts , pr .ID , targetRefName , targetNS , false )
133+
134+ hash , ok := repobranch .Target ["hash" ].(string )
135+ assert .Assert (t , ok )
136+
137+ sopt := twait.SuccessOpt {
138+ TargetNS : targetNS ,
139+ OnEvent : triggertype .PullRequest .String (),
140+ NumberofPRMatch : 1 ,
141+ SHA : hash ,
142+ Title : title ,
143+ MinNumberStatus : 1 ,
144+ }
145+ twait .Succeeded (ctx , t , runcnx , opts , sopt )
146+
147+ resp , err := bprovider .Client ().Repositories .Commits .GetCommitStatuses (& bitbucket.CommitsOptions {
148+ Owner : opts .Organization ,
149+ RepoSlug : opts .Repo ,
150+ Revision : hash ,
151+ })
152+ assert .NilError (t , err )
153+
154+ statusesMap , ok := resp .(map [string ]any )
155+ assert .Equal (t , ok , true , "cannot convert Bitbucket commit statuses response to map[string]any" )
156+
157+ statues := []* types.Status {}
158+
159+ err = mapstructure .Decode (statusesMap ["values" ], & statues )
160+ assert .NilError (t , err , fmt .Sprintf ("cannot decode Bitbucket commit statuses from response payload: %v" , err ))
161+
162+ foundStatus := false
163+ for _ , status := range statues {
164+ if strings .Contains (status .Key , "pipelinerun-" ) {
165+ foundStatus = true
166+ break
167+ }
168+ }
169+ assert .Equal (t , foundStatus , true , "should have found the status for the pipeline run" )
170+ }
171+
110172// Local Variables:
111173// compile-command: "go test -tags=e2e -v -run TestBitbucketCloudPullRequest$ ."
112174// End:
0 commit comments