dmitri.shuralyov.com/service/change/...

gerritapi: handle newPatchSet body without blank line

This is yet another possible newPatchSet message format.

See example at https://go-review.googlesource.com/c/tools/+/151057/5#message-def598911f85f6435674a5ebeccc9981cfc59195.
dmitshur committed 7 months ago commit 39f3e6215b805980ae58696573473fe62d9bae2f
gerritapi/gerritapi.go
@@ -456,15 +456,20 @@ func parsePSMessage(m string, revisionNumber int) (body string, _ error) {
 	if m == "" {
 		// No body.
 		return "", nil
 	}
 
+	switch {
 	// "\n\n".
-	if !strings.HasPrefix(m, "\n\n") {
+	case strings.HasPrefix(m, "\n\n"):
+		m = m[len("\n\n"):]
+	// "\n".
+	case strings.HasPrefix(m, "\n"):
+		m = m[len("\n"):]
+	default:
 		return "", fmt.Errorf("unexpected format")
 	}
-	m = m[len("\n\n"):]
 
 	// The remainer is the body.
 	return m, nil
 }
 
gerritapi/gerritapi_test.go
@@ -75,10 +75,15 @@ func TestParsePSMessage(t *testing.T) {
 		{
 			inMessage:        "Uploaded patch set 5: Run-TryBot+1.",
 			inRevisionNumber: 5,
 			wantBody:         "",
 		},
+		{
+			inMessage:        "Uploaded patch set 6.\nThis Gerrit CL corresponds to GitHub PR golang/tools#123.\n\nAuthor: Foo Bar \u003cfoo@bar.com\u003e",
+			inRevisionNumber: 6,
+			wantBody:         "This Gerrit CL corresponds to GitHub PR golang/tools#123.\n\nAuthor: Foo Bar \u003cfoo@bar.com\u003e",
+		},
 		{
 			inMessage:        "something unexpected",
 			inRevisionNumber: 3,
 			wantError:        true,
 		},