diff --git a/server/events/vcs/gitlab_client.go b/server/events/vcs/gitlab_client.go
index d3f32373c1..07e26df88d 100644
--- a/server/events/vcs/gitlab_client.go
+++ b/server/events/vcs/gitlab_client.go
@@ -34,6 +34,10 @@ import (
gitlab "github.com/xanzy/go-gitlab"
)
+// gitlabMaxCommentLength is the maximum number of chars allowed by Gitlab in a
+// single comment.
+const gitlabMaxCommentLength = 1000000
+
type GitlabClient struct {
Client *gitlab.Client
// Version is set to the server version.
@@ -146,8 +150,17 @@ func (g *GitlabClient) GetModifiedFiles(repo models.Repo, pull models.PullReques
// CreateComment creates a comment on the merge request.
func (g *GitlabClient) CreateComment(repo models.Repo, pullNum int, comment string, command string) error {
- _, _, err := g.Client.Notes.CreateMergeRequestNote(repo.FullName, pullNum, &gitlab.CreateMergeRequestNoteOptions{Body: gitlab.String(comment)})
- return err
+ sepEnd := "\n```\n" +
+ "\n
\n\n**Warning**: Output length greater than max comment size. Continued in next comment."
+ sepStart := "Continued from previous comment.\nShow Output
\n\n" +
+ "```diff\n"
+ comments := common.SplitComment(comment, gitlabMaxCommentLength, sepEnd, sepStart)
+ for _, c := range comments {
+ if _, _, err := g.Client.Notes.CreateMergeRequestNote(repo.FullName, pullNum, &gitlab.CreateMergeRequestNoteOptions{Body: gitlab.String(c)}); err != nil {
+ return err
+ }
+ }
+ return nil
}
func (g *GitlabClient) HidePrevCommandComments(repo models.Repo, pullNum int, command string) error {