maintner: support multi-line commit message subjects

In git, the text up to the first blank line in a commit message
is treated as the commit subject.

Most subjects are short and fit in one line (hopefully under
50 characters). In some cases, they end up being split into
multiple lines.

Report the entire subject rather than just the first line,
and join multiple lines with spaces.

Reference: https://git-scm.com/docs/git-commit#_discussion.

Fixes golang/go#30101

Change-Id: I1ea8212202fce0033e5ac8075352d5d7e0ae823c
Reviewed-on: https://go-review.googlesource.com/c/161222
Reviewed-by: Andrew Bonventre <andybons@golang.org>
diff --git a/maintner/gerrit.go b/maintner/gerrit.go
index b007932..e28e4a8 100644
--- a/maintner/gerrit.go
+++ b/maintner/gerrit.go
@@ -487,10 +487,11 @@
 	return commit.Author
 }
 
-// Subject returns the first line of the latest commit message.
+// Subject returns the subject of the latest commit message.
+// The subject is separated from the body by a blank line.
 func (cl *GerritCL) Subject() string {
-	if i := strings.Index(cl.Commit.Msg, "\n"); i >= 0 {
-		return cl.Commit.Msg[:i]
+	if i := strings.Index(cl.Commit.Msg, "\n\n"); i >= 0 {
+		return strings.Replace(cl.Commit.Msg[:i], "\n", " ", -1)
 	}
 	return cl.Commit.Msg
 }
diff --git a/maintner/gerrit_test.go b/maintner/gerrit_test.go
index 691ae25..91822c5 100644
--- a/maintner/gerrit_test.go
+++ b/maintner/gerrit_test.go
@@ -229,6 +229,7 @@
 	testcases := []struct{ msg, subject string }{
 		{"maintner: slurp up all the things", "maintner: slurp up all the things"},
 		{"cmd/go: build stuff\n\nand do other stuff, too.", "cmd/go: build stuff"},
+		{"cmd/go: build lots\nof stuff\n\nand do other stuff, too.", "cmd/go: build lots of stuff"}, // Subject is separated from body by a blank line.
 	}
 	for _, tc := range testcases {
 		cl := &GerritCL{Commit: &GitCommit{Msg: tc.msg}}