Skip to content

Commit 6b55d0e

Browse files
committed
fix: commit status for unauthorized user in Bitbucket Data Center
For unauthorized users waiting for /ok-to-test approval, build status was incorrectly showing as "running" instead of "pending". This was caused by the CreateStatus function setting statusOpts.Conclusion to "UNKNOWN" when statusOpts.Status was "queued", instead of preserving the "pending" conclusion. The fix ensures that when status is "queued" and conclusion is "pending", the pending state is preserved, resulting in the correct "pending" build status in Bitbucket Data Center while waiting for repository admin approval via /ok-to-test comment. fixes: openshift-pipelines#2148 JIRA: https://issues.redhat.com/browse/SRVKP-8269 Signed-off-by: Zaki Shaikh <[email protected]>
1 parent 542f1a0 commit 6b55d0e

File tree

2 files changed

+45
-23
lines changed

2 files changed

+45
-23
lines changed

pkg/provider/bitbucketdatacenter/bitbucketdatacenter.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,12 @@ func (v *Provider) CreateStatus(ctx context.Context, event *info.Event, statusOp
101101
statusOpts.Conclusion = "FAILED"
102102
statusOpts.Title = "❌ Failed"
103103
case "pending":
104-
statusOpts.Conclusion = "INPROGRESS"
105-
statusOpts.Title = "⚡ CI has started"
104+
if statusOpts.Status == "queued" {
105+
statusOpts.Conclusion = "UNKNOWN"
106+
} else {
107+
statusOpts.Conclusion = "INPROGRESS"
108+
statusOpts.Title = "⚡ CI has started"
109+
}
106110
case "success":
107111
statusOpts.Conclusion = "SUCCESSFUL"
108112
statusOpts.Title = "Commit has been validated"
@@ -119,18 +123,18 @@ func (v *Provider) CreateStatus(ctx context.Context, event *info.Event, statusOp
119123

120124
key := statusOpts.PipelineRunName
121125
if key == "" {
122-
key = statusOpts.Conclusion
126+
key = statusOpts.Title
123127
}
124128

125129
if v.pacInfo.ApplicationName != "" {
126-
key = fmt.Sprintf("%s/%s", v.pacInfo.ApplicationName, key)
130+
key = fmt.Sprintf("%s / %s", v.pacInfo.ApplicationName, key)
127131
}
128132

129133
OrgAndRepo := fmt.Sprintf("%s/%s", event.Organization, event.Repository)
130134
opts := &scm.StatusInput{
131135
State: convertState(statusOpts.Conclusion),
132136
Label: key,
133-
Desc: statusOpts.Title,
137+
Desc: statusOpts.Text,
134138
Link: detailsURL,
135139
}
136140
_, _, err := v.Client().Repositories.CreateStatus(ctx, OrgAndRepo, event.SHA, opts)
@@ -167,6 +171,8 @@ func convertState(from string) scm.State {
167171
return scm.StatePending
168172
case "SUCCESSFUL":
169173
return scm.StateSuccess
174+
case "UNKNOWN":
175+
return scm.StateUnknown
170176
default:
171177
return scm.StateUnknown
172178
}

pkg/provider/bitbucketdatacenter/bitbucketdatacenter_test.go

Lines changed: 34 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,6 @@ func TestCreateStatus(t *testing.T) {
111111
tests := []struct {
112112
name string
113113
status provider.StatusOpts
114-
expectedDescSubstr string
115114
expectedCommentSubstr string
116115
pacOpts info.PacOpts
117116
nilClient bool
@@ -126,69 +125,86 @@ func TestCreateStatus(t *testing.T) {
126125
name: "good/skipped",
127126
status: provider.StatusOpts{
128127
Conclusion: "skipped",
128+
Text: "Skipping",
129129
},
130-
expectedDescSubstr: "Skipping",
131-
pacOpts: pacopts,
130+
131+
pacOpts: pacopts,
132132
},
133133
{
134134
name: "good/neutral",
135135
status: provider.StatusOpts{
136136
Conclusion: "neutral",
137+
Text: "stopped",
137138
},
138-
expectedDescSubstr: "stopped",
139-
pacOpts: pacopts,
139+
140+
pacOpts: pacopts,
140141
},
141142
{
142143
name: "good/completed with comment",
143144
status: provider.StatusOpts{
144145
Conclusion: "success",
145146
Status: "completed",
146-
Text: "Happy as a bunny",
147+
Text: "validated",
147148
},
148-
expectedDescSubstr: "validated",
149+
149150
expectedCommentSubstr: "Happy as a bunny",
150151
pacOpts: pacopts,
151152
},
152153
{
153154
name: "good/failed",
154155
status: provider.StatusOpts{
155156
Conclusion: "failure",
157+
Text: "Failed",
156158
},
157-
expectedDescSubstr: "Failed",
158-
pacOpts: pacopts,
159+
160+
pacOpts: pacopts,
159161
},
160162
{
161163
name: "good/details url",
162164
status: provider.StatusOpts{
163165
Conclusion: "failure",
164166
DetailsURL: "http://fail.com",
167+
Text: "Failed",
165168
},
166-
expectedDescSubstr: "Failed",
167-
pacOpts: pacopts,
169+
170+
pacOpts: pacopts,
168171
},
169172
{
170173
name: "good/pending",
171174
status: provider.StatusOpts{
172175
Conclusion: "pending",
176+
Text: "started",
173177
},
174-
expectedDescSubstr: "started",
175-
pacOpts: pacopts,
178+
179+
pacOpts: pacopts,
176180
},
177181
{
178182
name: "good/success",
179183
status: provider.StatusOpts{
180184
Conclusion: "success",
185+
Text: "validated",
181186
},
182-
expectedDescSubstr: "validated",
183-
pacOpts: pacopts,
187+
188+
pacOpts: pacopts,
184189
},
185190
{
186191
name: "good/completed",
187192
status: provider.StatusOpts{
188193
Conclusion: "completed",
194+
Text: "Completed",
189195
},
190-
expectedDescSubstr: "Completed",
191-
pacOpts: pacopts,
196+
197+
pacOpts: pacopts,
198+
},
199+
{
200+
name: "good/pending",
201+
status: provider.StatusOpts{
202+
Conclusion: "pending",
203+
Status: "queued",
204+
Text: "Pending approval, waiting for an /ok-to-test",
205+
},
206+
207+
pacOpts: pacopts,
192208
},
193209
}
194210
for _, tt := range tests {
@@ -210,7 +226,7 @@ func TestCreateStatus(t *testing.T) {
210226
run: &params.Run{},
211227
pacInfo: &tt.pacOpts,
212228
}
213-
bbtest.MuxCreateAndTestCommitStatus(t, mux, event, tt.expectedDescSubstr, tt.status)
229+
bbtest.MuxCreateAndTestCommitStatus(t, mux, event, tt.status.Text, tt.status)
214230
bbtest.MuxCreateComment(t, mux, event, tt.expectedCommentSubstr, pullRequestNumber)
215231
err := v.CreateStatus(ctx, event, tt.status)
216232
if tt.wantErrSubstr != "" {

0 commit comments

Comments
 (0)