diff --git a/server/events/vcs/github_client.go b/server/events/vcs/github_client.go
index fc1b8c43d9..43e0deb1f7 100644
--- a/server/events/vcs/github_client.go
+++ b/server/events/vcs/github_client.go
@@ -141,10 +141,10 @@ func (g *GithubClient) CreateComment(repo models.Repo, pullNum int, comment stri
"\n
\n\n**Warning**: Output length greater than max comment size. Continued in next comment."
if command != "" {
- sepStart = "Continued from previous comment.\nShow Output
\n\n" +
+ sepStart = fmt.Sprintf("Continued %s output from previous comment.\nShow Output
\n\n", command) +
"```diff\n"
} else {
- sepStart = fmt.Sprintf("Continued %s output from previous comment.\nShow Output
\n\n", command) +
+ sepStart = "Continued from previous comment.\nShow Output
\n\n" +
"```diff\n"
}
diff --git a/server/events/vcs/github_client_test.go b/server/events/vcs/github_client_test.go
index abff8fb215..06a18f47f5 100644
--- a/server/events/vcs/github_client_test.go
+++ b/server/events/vcs/github_client_test.go
@@ -784,3 +784,67 @@ func disableSSLVerification() func() {
http.DefaultTransport.(*http.Transport).TLSClientConfig = orig
}
}
+
+func TestGithubClient_SplitComments(t *testing.T) {
+ type githubComment struct {
+ Body string `json:"body"`
+ }
+ githubComments := make([]githubComment, 0, 1)
+
+ testServer := httptest.NewTLSServer(
+ http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+
+ switch r.Method + " " + r.RequestURI {
+ case "POST /api/v3/repos/runatlantis/atlantis/issues/1/comments":
+ defer r.Body.Close() // nolint: errcheck
+ body, err := ioutil.ReadAll(r.Body)
+ if err != nil {
+ t.Errorf("read body error: %v", err)
+ http.Error(w, "server error", http.StatusInternalServerError)
+ return
+ }
+ requestBody := githubComment{}
+ err = json.Unmarshal(body, &requestBody)
+ if err != nil {
+ t.Errorf("parse body error: %v", err)
+ http.Error(w, "server error", http.StatusInternalServerError)
+ return
+ }
+ githubComments = append(githubComments, requestBody)
+ return
+ default:
+ t.Errorf("got unexpected request at %q", r.RequestURI)
+ http.Error(w, "not found", http.StatusNotFound)
+ return
+ }
+ }))
+
+ testServerURL, err := url.Parse(testServer.URL)
+ Ok(t, err)
+ client, err := vcs.NewGithubClient(testServerURL.Host, &vcs.GithubUserCredentials{"user", "pass"}, nil)
+ Ok(t, err)
+ defer disableSSLVerification()()
+ pull := models.PullRequest{Num: 1}
+ repo := models.Repo{
+ FullName: "runatlantis/atlantis",
+ Owner: "runatlantis",
+ Name: "atlantis",
+ CloneURL: "",
+ SanitizedCloneURL: "",
+ VCSHost: models.VCSHost{
+ Type: models.Github,
+ Hostname: "github.com",
+ },
+ }
+ // create an extra long string
+ comment := strings.Repeat("a", 65537)
+ err = client.CreateComment(repo, pull.Num, comment, models.PlanCommand.String())
+ Ok(t, err)
+
+ // copied from github_client.HidePrevPlanComments to ensure proper string matching
+ body := strings.Split(githubComments[1].Body, "\n")
+ firstLine := strings.ToLower(body[0])
+
+ Equals(t, 2, len(githubComments))
+ Assert(t, strings.Contains(firstLine, models.PlanCommand.String()), fmt.Sprintf("comment should contain the command name but was %q", firstLine))
+}