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

gerritapi: handle another newPatchSet message format

Some messages with the "autogenerated:gerrit:newPatchSet" tag have a
different format than previously expected:

	Patch Set 3: Commit message was updated.

I'm not aware that such messages could have inline comments, so handle
them by looking for a "Patch Set " prefix, and stop there. No need to do
more for now.
dmitshur committed 6 years ago commit 6cc1393835614a463bad5fa3ee0e75c1685cfb8e
Collapse all
gerritapi/gerritapi.go
@@ -401,10 +401,14 @@ func parseMessage(m string) (labels string, body string, ok bool) {
// parsePSMessage parses an autogenerated:gerrit:newPatchSet
// message and returns its body, if any.
func parsePSMessage(m string, revisionNumber int) (body string, _ error) {
	// "Uploaded patch set ".
	if !strings.HasPrefix(m, "Uploaded patch set ") {
		if strings.HasPrefix(m, "Patch Set ") {
			// No body. Maybe just the commit message changed.
			return "", nil
		}
		return "", fmt.Errorf("unexpected format")
	}
	m = m[len("Uploaded patch set "):]

	// Revision number, e.g., "123".
gerritapi/gerritapi_test.go
@@ -60,10 +60,15 @@ func TestParsePSMessage(t *testing.T) {
		{
			inMessage:        "Uploaded patch set 2.\n\n(3 comments)",
			inRevisionNumber: 2,
			wantBody:         "(3 comments)",
		},
		{
			inMessage:        "Patch Set 3: Commit message was updated.",
			inRevisionNumber: 3,
			wantBody:         "",
		},
		{
			inMessage:        "something unexpected",
			inRevisionNumber: 3,
			wantError:        true,
		},