cmd/gerritbot: update gerritChangeRE for new Gerrit output format

Gerrit has changed the format it uses for the Change URL in its output.
It used to be something like:

	remote: SUCCESS
	remote:
	remote: New Changes:
	remote:   https://go-review.googlesource.com/#/c/dl/+/134117 remove blank line from codereview.cfg

Now it is:

	remote: SUCCESS
	remote:
	remote: New Changes:
	remote:   https://go-review.googlesource.com/c/dl/+/134117 remove blank line from codereview.cfg

(The '#' path element in the Change URL is removed.)

Update the regexp to match, and add a test for it.

This fix will likely cause the previously unposted "This PR has been
imported to Gerrit for code review" comments to get posted during
next pull request activity, since they haven't already been.

Fixes golang/go#27561.
Updates golang/go#27504.

Change-Id: I37a75ddb8d879017ebd887c651ca74a6ad6b892d
Reviewed-on: https://go-review.googlesource.com/134175
Reviewed-by: Andrew Bonventre <andybons@golang.org>
diff --git a/cmd/gerritbot/gerritbot.go b/cmd/gerritbot/gerritbot.go
index 9352584..0b9ff18 100644
--- a/cmd/gerritbot/gerritbot.go
+++ b/cmd/gerritbot/gerritbot.go
@@ -530,7 +530,7 @@
 const gerritHostBase = "https://go.googlesource.com/"
 
 // gerritChangeRE matches the URL to the Change within the git output when pushing to Gerrit.
-var gerritChangeRE = regexp.MustCompile(`https:\/\/go-review\.googlesource\.com\/#\/c\/\w+\/\+\/\d+`)
+var gerritChangeRE = regexp.MustCompile(`https:\/\/go-review\.googlesource\.com\/c\/\w+\/\+\/\d+`)
 
 // importGerritChangeFromPR mirrors the latest state of pr to cl. If cl is nil,
 // then a new Gerrit Change is created.
diff --git a/cmd/gerritbot/gerritbot_test.go b/cmd/gerritbot/gerritbot_test.go
index 7ad44f9..0f81a48 100644
--- a/cmd/gerritbot/gerritbot_test.go
+++ b/cmd/gerritbot/gerritbot_test.go
@@ -115,3 +115,19 @@
 		})
 	}
 }
+
+// Test that gerritChangeRE matches the URL to the Change within
+// the git output from Gerrit after successfully creating a new CL.
+// Whenever Gerrit changes the Change URL format in its output,
+// we need to update gerritChangeRE and this test accordingly.
+//
+// See https://golang.org/issue/27561.
+func TestFindChangeURL(t *testing.T) {
+	// Sample git output from Gerrit, extracted from production logs on 2018/09/07.
+	const out = "remote: \rremote: Processing changes: new: 1 (\\)\rremote: Processing changes: new: 1 (|)\rremote: Processing changes: refs: 1, new: 1 (|)\rremote: Processing changes: refs: 1, new: 1 (|)        \rremote: Processing changes: refs: 1, new: 1, done            \nremote: \nremote: SUCCESS        \nremote: \nremote: New Changes:        \nremote:   https://go-review.googlesource.com/c/dl/+/134117 remove blank line from codereview.cfg        \nTo https://go.googlesource.com/dl\n * [new branch]      HEAD -> refs/for/master"
+	got := gerritChangeRE.FindString(out)
+	want := "https://go-review.googlesource.com/c/dl/+/134117"
+	if got != want {
+		t.Errorf("could not find change URL in command output: %q\n\ngot %q, want %q", out, got, want)
+	}
+}