diff --git a/engine/api/repositoriesmanager/repositories_manager.go b/engine/api/repositoriesmanager/repositories_manager.go index 18003b7f32..a6906f00ee 100644 --- a/engine/api/repositoriesmanager/repositories_manager.go +++ b/engine/api/repositoriesmanager/repositories_manager.go @@ -442,7 +442,7 @@ func (c *vcsClient) Branch(ctx context.Context, fullname string, filters sdk.VCS branch := sdk.VCSBranch{} path := fmt.Sprintf("/vcs/%s/repos/%s/branches/?branch=%s&default=%v", c.name, fullname, url.QueryEscape(filters.BranchName), filters.Default) if _, err := c.doJSONRequest(ctx, "GET", path, nil, &branch); err != nil { - return nil, sdk.NewErrorFrom(err, "unable to find branch %s/%v on repository %s from %s", filters.BranchName, filters.Default, fullname, c.name) + return nil, sdk.NewErrorFrom(err, "unable to find branch %q (default: %t) on repository %s from %s", filters.BranchName, filters.Default, fullname, c.name) } return &branch, nil } diff --git a/engine/api/workflow/workflow_run_event.go b/engine/api/workflow/workflow_run_event.go index 1715dd5cab..b7f729c204 100644 --- a/engine/api/workflow/workflow_run_event.go +++ b/engine/api/workflow/workflow_run_event.go @@ -64,28 +64,27 @@ func (e *VCSEventMessenger) SendVCSEvent(ctx context.Context, db *gorp.DbMap, st return nil } - var notif *sdk.WorkflowNotification + var notifs []sdk.WorkflowNotification // browse notification to find vcs one -loopNotif: for _, n := range wr.Workflow.Notifications { if n.Type != sdk.VCSUserNotification { continue } // If list of node is nill, send notification to all of them if len(n.NodeIDs) == 0 { - notif = &n - break + notifs = append(notifs, n) + continue } // browser source node id for _, src := range n.NodeIDs { if src == node.ID { - notif = &n - break loopNotif + notifs = append(notifs, n) + break } } } - if notif == nil { + if len(notifs) == 0 { return nil } @@ -134,8 +133,10 @@ loopNotif: } if statusFound == nil || statusFound.State == "" { - if err := e.sendVCSEventStatus(ctx, tx, store, proj.Key, wr, &nodeRun, notif, vcsServerName); err != nil { - return sdk.WrapError(err, "can't sendVCSEventStatus vcs %v/%v", proj.Key, vcsServerName) + for i := range notifs { + if err := e.sendVCSEventStatus(ctx, tx, store, proj.Key, wr, &nodeRun, notifs[i], vcsServerName); err != nil { + return sdk.WrapError(err, "can't sendVCSEventStatus vcs %v/%v", proj.Key, vcsServerName) + } } } else { skipStatus := false @@ -159,8 +160,10 @@ loopNotif: } if !skipStatus { - if err := e.sendVCSEventStatus(ctx, tx, store, proj.Key, wr, &nodeRun, notif, vcsServerName); err != nil { - return sdk.WrapError(err, "can't sendVCSEventStatus vcs %v/%v", proj.Key, vcsServerName) + for i := range notifs { + if err := e.sendVCSEventStatus(ctx, tx, store, proj.Key, wr, &nodeRun, notifs[i], vcsServerName); err != nil { + return sdk.WrapError(err, "can't sendVCSEventStatus vcs %v/%v", proj.Key, vcsServerName) + } } } } @@ -168,8 +171,10 @@ loopNotif: if !sdk.StatusIsTerminated(nodeRun.Status) { return nil } - if err := e.sendVCSPullRequestComment(ctx, tx, wr, &nodeRun, notif, vcsServerName); err != nil { - return sdk.WrapError(err, "can't sendVCSPullRequestComment vcs %v/%v", proj.Key, vcsServerName) + for i := range notifs { + if err := e.sendVCSPullRequestComment(ctx, tx, wr, &nodeRun, notifs[i], vcsServerName); err != nil { + return sdk.WrapError(err, "can't sendVCSPullRequestComment vcs %v/%v", proj.Key, vcsServerName) + } } if err := tx.Commit(); err != nil { @@ -180,8 +185,8 @@ loopNotif: } // sendVCSEventStatus send status -func (e *VCSEventMessenger) sendVCSEventStatus(ctx context.Context, db gorp.SqlExecutor, store cache.Store, projectKey string, wr sdk.WorkflowRun, nodeRun *sdk.WorkflowNodeRun, notif *sdk.WorkflowNotification, vcsServerName string) error { - if notif == nil || notif.Settings.Template == nil || (notif.Settings.Template.DisableStatus != nil && *notif.Settings.Template.DisableStatus) { +func (e *VCSEventMessenger) sendVCSEventStatus(ctx context.Context, db gorp.SqlExecutor, store cache.Store, projectKey string, wr sdk.WorkflowRun, nodeRun *sdk.WorkflowNodeRun, notif sdk.WorkflowNotification, vcsServerName string) error { + if notif.Settings.Template == nil || (notif.Settings.Template.DisableStatus != nil && *notif.Settings.Template.DisableStatus) { return nil } @@ -305,8 +310,8 @@ func (e *VCSEventMessenger) sendVCSEventStatus(ctx context.Context, db gorp.SqlE return nil } -func (e *VCSEventMessenger) sendVCSPullRequestComment(ctx context.Context, db gorp.SqlExecutor, wr sdk.WorkflowRun, nodeRun *sdk.WorkflowNodeRun, notif *sdk.WorkflowNotification, vcsServerName string) error { - if notif == nil || notif.Settings.Template == nil || (notif.Settings.Template.DisableComment != nil && *notif.Settings.Template.DisableComment) { +func (e *VCSEventMessenger) sendVCSPullRequestComment(ctx context.Context, db gorp.SqlExecutor, wr sdk.WorkflowRun, nodeRun *sdk.WorkflowNodeRun, notif sdk.WorkflowNotification, vcsServerName string) error { + if notif.Settings.Template == nil || (notif.Settings.Template.DisableComment != nil && *notif.Settings.Template.DisableComment) { return nil } diff --git a/engine/vcs/gitlab/client_pull_request.go b/engine/vcs/gitlab/client_pull_request.go index ea7b5266e3..83d36fea01 100644 --- a/engine/vcs/gitlab/client_pull_request.go +++ b/engine/vcs/gitlab/client_pull_request.go @@ -2,8 +2,10 @@ package gitlab import ( "context" + "fmt" "strconv" + "github.com/rockbears/log" "github.com/xanzy/go-gitlab" "github.com/ovh/cds/sdk" @@ -41,13 +43,27 @@ func (c *gitlabClient) PullRequests(ctx context.Context, repo string, opts sdk.V } res := make([]sdk.VCSPullRequest, 0, len(mrs)) for i := range mrs { - res = append(res, toSDKPullRequest(repo, *mrs[i])) + mr, err := c.PullRequest(ctx, repo, fmt.Sprintf("%d", mrs[i].IID)) + if err != nil { + return nil, sdk.WithStack(err) + } + res = append(res, mr) } return res, nil } // PullRequestComment push a new comment on a pull request -func (c *gitlabClient) PullRequestComment(context.Context, string, sdk.VCSPullRequestCommentRequest) error { +func (c *gitlabClient) PullRequestComment(ctx context.Context, repo string, prReq sdk.VCSPullRequestCommentRequest) error { + if c.disableStatus { + log.Warn(ctx, "gitlab.PullRequestComment> ⚠ Gitlab statuses are disabled") + return nil + } + _, _, err := c.client.Notes.CreateMergeRequestNote(repo, prReq.ID, &gitlab.CreateMergeRequestNoteOptions{ + Body: gitlab.String(prReq.Message), + }) + if err != nil { + return sdk.WithStack(err) + } return nil } @@ -93,5 +109,4 @@ func toSDKPullRequest(repo string, mr gitlab.MergeRequest) sdk.VCSPullRequest { pr.Updated = *mr.UpdatedAt } return pr - } diff --git a/ui/proxy.conf.json b/ui/proxy.conf.json index 6ccf648934..7502ee1a01 100644 --- a/ui/proxy.conf.json +++ b/ui/proxy.conf.json @@ -15,6 +15,14 @@ "^/cdscdn": "" } }, + "/cdshooks": { + "target": "http://localhost:8083", + "secure": false, + "ws": true, + "pathRewrite": { + "^/cdshooks": "" + } + }, "/mon/version": { "target": "http://localhost:8080", "secure": false,