Skip to content

Commit

Permalink
fix(vcs): notif bitbucket cloud (#6183)
Browse files Browse the repository at this point in the history
Signed-off-by: Yvonnick Esnault <[email protected]>
  • Loading branch information
yesnault authored May 25, 2022
1 parent 3d47f79 commit a070b16
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 2 deletions.
7 changes: 7 additions & 0 deletions engine/api/repositoriesmanager/repositories_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ import (
"github.com/ovh/cds/sdk/telemetry"
)

func (c *vcsClient) IsBitbucketCloud() bool {
if c.vcsProject != nil {
return c.vcsProject.Type == "bitbucketcloud"
}
return false
}

func (c *vcsClient) IsGerrit(ctx context.Context, db gorp.SqlExecutor) (bool, error) {
if c.vcsProject != nil {
return c.vcsProject.Type == "gerrit", nil
Expand Down
6 changes: 6 additions & 0 deletions engine/api/workflow/workflow_run_event.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,12 @@ loopNotif:
NodeName: nodeRun.WorkflowNodeName,
})

if e.vcsClient.IsBitbucketCloud() {
if len(expected) > 36 { // 40 maxlength on bitbucket cloud
expected = expected[:36]
}
}

var statusFound *sdk.VCSCommitStatus
for i, status := range statuses {
if status.Decription == expected {
Expand Down
7 changes: 5 additions & 2 deletions engine/vcs/bitbucketcloud/client_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func (client *bitbucketcloudClient) SetStatus(ctx context.Context, event sdk.Eve
var err error
switch event.EventType {
case fmt.Sprintf("%T", sdk.EventRunWorkflowNode{}):
data, err = processEventWorkflowNodeRun(event, client.uiURL, disableStatusDetails)
data, err = client.processEventWorkflowNodeRun(event, client.uiURL, disableStatusDetails)
default:
log.Error(ctx, "bitbucketcloud.SetStatus> Unknown event %v", event)
return nil
Expand Down Expand Up @@ -135,7 +135,7 @@ func processBbitbucketState(s Status) string {
}
}

func processEventWorkflowNodeRun(event sdk.Event, cdsUIURL string, disableStatusDetails bool) (statusData, error) {
func (client *bitbucketcloudClient) processEventWorkflowNodeRun(event sdk.Event, cdsUIURL string, disableStatusDetails bool) (statusData, error) {
data := statusData{}
var eventNR sdk.EventRunWorkflowNode
if err := sdk.JSONUnmarshal(event.Payload, &eventNR); err != nil {
Expand Down Expand Up @@ -180,6 +180,9 @@ func processEventWorkflowNodeRun(event sdk.Event, cdsUIURL string, disableStatus
}

data.context = sdk.VCSCommitStatusDescription(event.ProjectKey, event.WorkflowName, eventNR)
if len(data.context) > 36 { // 40 maxlength on bitbucket cloud
data.context = data.context[:36]
}
data.desc = eventNR.NodeName + ": " + eventNR.Status
return data, nil
}
1 change: 1 addition & 0 deletions sdk/vcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,7 @@ type VCSAuthorizedClientService interface {
VCSAuthorizedClientCommon
PullRequests(ctx context.Context, repo string, mods ...VCSRequestModifier) ([]VCSPullRequest, error)
IsGerrit(ctx context.Context, db gorp.SqlExecutor) (bool, error)
IsBitbucketCloud() bool
}

type VCSRequestModifier func(r *http.Request)
Expand Down

0 comments on commit a070b16

Please sign in to comment.