Add lint check to suggest 'Bug: issue NNNN'

Change-Id: Ief0eb484d89752f3e9fa111754fd93759b20a448
diff --git a/lint/lint.go b/lint/lint.go
index 0d48050..01a760b 100644
--- a/lint/lint.go
+++ b/lint/lint.go
@@ -22,6 +22,7 @@
 	"errors"
 	"fmt"
 	"log"
+	"regexp"
 	"strings"
 
 	"gwt.googlesource.com/buildglue.git/checkstyle"
@@ -143,6 +144,9 @@
 	return nil
 }
 
+var fixesIssueRegexp = regexp.MustCompile("(?i)^fixes issue [0-9]{3,}[.]?$")
+var issueRegexp = regexp.MustCompile("(?i)issue [0-9]{3,}")
+
 func (l *linter) checkMessage(commitmsg []string) {
 	warn := func(line int, message string) {
 		// Gerrit includes some extra header lines before the commit message.
@@ -150,12 +154,30 @@
 		l.comment("/COMMIT_MSG", line+6, "warning", message)
 	}
 
+	lengthWarning := false
+	bugWarning := false
+
 	if len(commitmsg) >= 3 && len(commitmsg[1]) > 0 {
 		warn(2, "Subject line and body should be separated by a blank line.")
 	}
 	for i, line := range commitmsg {
-		if i != 1 && len(line) > 72 {
+		if !lengthWarning && i != 1 && len(line) > 72 {
 			warn(i+1, "Commit message lines should be 72 characters or fewer.")
+			lengthWarning = true
+		}
+		if !bugWarning && ((i == 0 && issueRegexp.MatchString(line)) || fixesIssueRegexp.MatchString(line)) {
+			warn(i+1, "Please use 'Bug: issue NNNN' and place it just above the Change-Id line.")
+			bugWarning = true
+		}
+	}
+
+	for i := len(commitmsg) - 1; i >= 0 && len(commitmsg[i]) > 0; i-- {
+		if commitmsg[i][0] == ' ' {
+			continue
+		}
+		field := strings.TrimSpace(strings.Split(commitmsg[i], ":")[0])
+		if field != strings.Title(field) {
+			warn(i+1, "Footer fields should be in Title-Case.")
 			break
 		}
 	}
diff --git a/lint/lint_test.go b/lint/lint_test.go
index d3ad33a..515a39a 100644
--- a/lint/lint_test.go
+++ b/lint/lint_test.go
@@ -71,6 +71,48 @@
 				},
 			},
 		},
+		{
+			message: []string{
+				"Subject line",
+				"",
+				"Fixes issue 3171",
+				"",
+				"Change-Id: blah2",
+			},
+			warnings: []gerrit.Comment{
+				gerrit.Comment{
+					Line:    9,
+					Message: "[warning] Please use 'Bug: issue NNNN' and place it just above the Change-Id line.",
+				},
+			},
+		},
+		{
+			message: []string{
+				"ISSUE 712 - change some stuff",
+				"",
+				"Change-Id: blah2",
+			},
+			warnings: []gerrit.Comment{
+				gerrit.Comment{
+					Line:    7,
+					Message: "[warning] Please use 'Bug: issue NNNN' and place it just above the Change-Id line.",
+				},
+			},
+		},
+		{
+			message: []string{
+				"Subject line",
+				"",
+				"bug: issue 88",
+				"Change-Id: blah2",
+			},
+			warnings: []gerrit.Comment{
+				gerrit.Comment{
+					Line:    9,
+					Message: "[warning] Footer fields should be in Title-Case.",
+				},
+			},
+		},
 	}
 
 	for _, test := range tests {