Skip to content

Commit

Permalink
Split Gitlab Server comments if over max length (#1755)
Browse files Browse the repository at this point in the history
  • Loading branch information
krrrr38 authored and msarvar committed Sep 27, 2021
1 parent 9588dc3 commit 3649f6b
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions server/events/vcs/gitlab_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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</details>" +
"\n<br>\n\n**Warning**: Output length greater than max comment size. Continued in next comment."
sepStart := "Continued from previous comment.\n<details><summary>Show Output</summary>\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 {
Expand Down

0 comments on commit 3649f6b

Please sign in to comment.