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

gerritapi: handle labels in new patchset messages

It's possible for messages with the "autogenerated:gerrit:newPatchSet"
tag to also set labels, which wasn't previously supported. E.g.:

	Uploaded patch set 4: Run-TryBot+1.

	(1 comment)

Or:

	Uploaded patch set 5: Run-TryBot+1.

Update the code to handle these.
dmitshur committed 5 years ago commit 205e36f8ceaeebb11a7a4f8cd2568713a819e83a
Collapse all
gerritapi/gerritapi.go
@@ -416,15 +416,27 @@ func parsePSMessage(m string, revisionNumber int) (body string, _ error) {
	if i == -1 {
		return "", fmt.Errorf("unexpected format")
	}
	m = m[i:]

	switch {
	// ".".
	if len(m) < 1 || m[0] != '.' {
	case len(m) >= 1 && m[0] == '.':
		m = m[1:]
	// ":".
	case len(m) >= 1 && m[0] == ':':
		m = m[1:]

		// " Run-TryBot+1."
		i := strings.IndexByte(m, '.')
		if i == -1 {
			return "", fmt.Errorf("unexpected format")
		}
		m = m[i+1:]
	default:
		return "", fmt.Errorf("unexpected format")
	}
	m = m[1:]

	if m == "" {
		// No body.
		return "", nil
	}
gerritapi/gerritapi_test.go
@@ -65,10 +65,20 @@ func TestParsePSMessage(t *testing.T) {
		{
			inMessage:        "Patch Set 3: Commit message was updated.",
			inRevisionNumber: 3,
			wantBody:         "",
		},
		{
			inMessage:        "Uploaded patch set 4: Run-TryBot+1.\n\n(1 comment)",
			inRevisionNumber: 4,
			wantBody:         "(1 comment)",
		},
		{
			inMessage:        "Uploaded patch set 5: Run-TryBot+1.",
			inRevisionNumber: 5,
			wantBody:         "",
		},
		{
			inMessage:        "something unexpected",
			inRevisionNumber: 3,
			wantError:        true,
		},