Skip to content

Commit d1a3a5d

Browse files
committed
fix(bitbucket-cloud): assign unique statue name in Bitbucket Cloud
Update Bitbucket Cloud provider to use GetCheckName helper for commit status key. This enables unique status reporting per PipelineRun by using the format "ApplicationName / PipelineRunName" instead of just the application name. Changes: - Replace hardcoded ApplicationName with GetCheckName in CreateStatus - Update tests to include OriginalPipelineRunName in StatusOpts - Add assertion in MuxCreateCommitstatus to verify correct key format Fixes: #2237 JIRA: https://issues.redhat.com/browse/SRVKP-9636 Signed-off-by: Zaki Shaikh <[email protected]>
1 parent 9572f3b commit d1a3a5d

File tree

3 files changed

+43
-15
lines changed

3 files changed

+43
-15
lines changed

pkg/provider/bitbucketcloud/bitbucket.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ func (v *Provider) CreateStatus(_ context.Context, event *info.Event, statusopts
109109
}
110110

111111
cso := &bitbucket.CommitStatusOptions{
112-
Key: v.pacInfo.ApplicationName,
112+
Key: provider.GetCheckName(statusopts, v.pacInfo),
113113
Url: detailsURL,
114114
State: statusopts.Conclusion,
115115
Description: statusopts.Title,

pkg/provider/bitbucketcloud/bitbucket_test.go

Lines changed: 38 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -273,93 +273,118 @@ func TestGetCommitInfo(t *testing.T) {
273273
}
274274

275275
func TestCreateStatus(t *testing.T) {
276+
originalPipelineRunName := "hello-af9ch"
276277
tests := []struct {
277278
name string
278279
wantErr bool
279280
status provider.StatusOpts
281+
applicationName string
280282
expectedDescSubstr string
281283
expectedCommentSubstr string
282284
}{
283285
{
284286
name: "skipped",
285287
status: provider.StatusOpts{
286-
Conclusion: "skipped",
288+
Conclusion: "skipped",
289+
OriginalPipelineRunName: originalPipelineRunName,
287290
},
288291
expectedDescSubstr: "Skipping",
289292
},
290293
{
291294
name: "neutral",
292295
status: provider.StatusOpts{
293-
Conclusion: "neutral",
296+
Conclusion: "neutral",
297+
OriginalPipelineRunName: originalPipelineRunName,
294298
},
295299
expectedDescSubstr: "stopped",
296300
},
297301
{
298302
name: "completed with comment",
299303
status: provider.StatusOpts{
300-
Conclusion: "success",
301-
Status: "completed",
302-
Text: "Happy as a bunny",
304+
Conclusion: "success",
305+
Status: "completed",
306+
OriginalPipelineRunName: originalPipelineRunName,
307+
Text: "Happy as a bunny",
303308
},
304309
expectedDescSubstr: "validated",
305310
expectedCommentSubstr: "Happy as a bunny",
306311
},
307312
{
308313
name: "failed",
309314
status: provider.StatusOpts{
310-
Conclusion: "failure",
315+
Conclusion: "failure",
316+
OriginalPipelineRunName: originalPipelineRunName,
311317
},
312318
expectedDescSubstr: "Failed",
313319
},
314320
{
315321
name: "details url",
316322
status: provider.StatusOpts{
317-
Conclusion: "failure",
318-
DetailsURL: "http://fail.com",
323+
Conclusion: "failure",
324+
DetailsURL: "http://fail.com",
325+
OriginalPipelineRunName: originalPipelineRunName,
319326
},
320327
expectedDescSubstr: "Failed",
321328
},
322329
{
323330
name: "pending",
324331
status: provider.StatusOpts{
325-
Conclusion: "pending",
332+
Conclusion: "pending",
333+
OriginalPipelineRunName: originalPipelineRunName,
326334
},
327335
expectedDescSubstr: "started",
328336
},
329337
{
330338
name: "success",
331339
status: provider.StatusOpts{
332-
Conclusion: "success",
340+
Conclusion: "success",
341+
OriginalPipelineRunName: originalPipelineRunName,
333342
},
334343
expectedDescSubstr: "validated",
335344
},
336345
{
337346
name: "completed",
338347
status: provider.StatusOpts{
339-
Conclusion: "completed",
348+
Conclusion: "completed",
349+
OriginalPipelineRunName: originalPipelineRunName,
340350
},
341351
expectedDescSubstr: "Completed",
342352
},
353+
{
354+
name: "application name",
355+
status: provider.StatusOpts{
356+
Conclusion: "completed",
357+
OriginalPipelineRunName: originalPipelineRunName,
358+
},
359+
applicationName: "HELLO APP",
360+
expectedDescSubstr: "Completed",
361+
},
343362
}
344363
for _, tt := range tests {
345364
t.Run(tt.name, func(t *testing.T) {
346365
ctx, _ := rtesting.SetupFakeContext(t)
347366
bbclient, mux, tearDown := bbcloudtest.SetupBBCloudClient(t)
348367
defer tearDown()
368+
369+
appName := tt.applicationName
370+
if appName == "" {
371+
appName = settings.PACApplicationNameDefaultValue
372+
}
373+
349374
v := &Provider{
350375
bbClient: bbclient,
351376
run: params.New(),
352377
pacInfo: &info.PacOpts{
353378
Settings: settings.Settings{
354-
ApplicationName: settings.PACApplicationNameDefaultValue,
379+
ApplicationName: appName,
355380
},
356381
},
357382
}
358383
event := bbcloudtest.MakeEvent(nil)
359384
event.EventType = "pull_request"
360385
event.Provider.Token = "token"
361386

362-
bbcloudtest.MuxCreateCommitstatus(t, mux, event, tt.expectedDescSubstr, tt.status)
387+
bbcloudtest.MuxCreateCommitstatus(t, mux, event, tt.expectedDescSubstr, appName, tt.status)
363388
bbcloudtest.MuxCreateComment(t, mux, event, tt.expectedCommentSubstr)
364389

365390
err := v.CreateStatus(ctx, event, tt.status)

pkg/provider/bitbucketcloud/test/bbcloudtest.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313

1414
"github.com/ktrysmt/go-bitbucket"
1515
"github.com/openshift-pipelines/pipelines-as-code/pkg/params/info"
16+
"github.com/openshift-pipelines/pipelines-as-code/pkg/params/settings"
1617
"github.com/openshift-pipelines/pipelines-as-code/pkg/provider"
1718
"github.com/openshift-pipelines/pipelines-as-code/pkg/provider/bitbucketcloud/types"
1819
"gotest.tools/v3/assert"
@@ -144,7 +145,7 @@ func MuxRepoInfo(t *testing.T, mux *http.ServeMux, event *info.Event, repo *bitb
144145
})
145146
}
146147

147-
func MuxCreateCommitstatus(t *testing.T, mux *http.ServeMux, event *info.Event, expectedDescSubstr string, expStatus provider.StatusOpts) {
148+
func MuxCreateCommitstatus(t *testing.T, mux *http.ServeMux, event *info.Event, expectedDescSubstr, applicationName string, expStatus provider.StatusOpts) {
148149
t.Helper()
149150

150151
path := fmt.Sprintf("/repositories/%s/%s/commit/%s/statuses/build", event.Organization, event.Repository, event.SHA)
@@ -153,6 +154,8 @@ func MuxCreateCommitstatus(t *testing.T, mux *http.ServeMux, event *info.Event,
153154
bit, _ := io.ReadAll(r.Body)
154155
err := json.Unmarshal(bit, cso)
155156
assert.NilError(t, err)
157+
pacOpts := &info.PacOpts{Settings: settings.Settings{ApplicationName: applicationName}}
158+
assert.Equal(t, provider.GetCheckName(expStatus, pacOpts), cso.Key)
156159

157160
if expStatus.DetailsURL != "" {
158161
assert.Equal(t, expStatus.DetailsURL, cso.Url)

0 commit comments

Comments
 (0)