git-codereview: add GIT_CODEREVIEW_TRYBOT env var to control CI system

The mail command has a -trybot flag, useful to start TryBots on the CL
being mailed. The new LUCI trybots are almost ready, and we'll soon be
asking contributors to consider them the new default. Prepare for that
by adding a temporary GIT_CODEREVIEW_TRYBOT environment variable which
will make it possible to override the CI system invoked by the -trybot
flag.

This CL keeps the default as the old CI system (farmer.golang.org),
and the next CL switches it to the new one (ci.chromium.org/p/golang).

The environment variable will eventually be removed once it has no use.

Change-Id: Ia20bb0cad1fee387b2d94a8438e8a3be3ec87e6b
Reviewed-on: https://go-review.googlesource.com/c/review/+/523095
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Run-TryBot: Dmitri Shuralyov <dmitshur@golang.org>
Auto-Submit: Dmitri Shuralyov <dmitshur@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Heschi Kreinick <heschi@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
diff --git a/git-codereview/doc.go b/git-codereview/doc.go
index 4be0c0d..0754479 100644
--- a/git-codereview/doc.go
+++ b/git-codereview/doc.go
@@ -256,6 +256,9 @@
 
 The -trybot flag sets a Run-TryBot+1 vote on any uploaded changes.
 The Go project uses this vote to start running integration tests on the CL.
+During the transition between two CI systems, the environment variable
+GIT_CODEREVIEW_TRYBOT can be set to one of "luci", "farmer", or "both"
+to explicitly override where the -trybot flag starts integration tests.
 
 The -autosubmit flag sets a Auto-Submit+1 vote on any uploaded changes.
 
diff --git a/git-codereview/mail.go b/git-codereview/mail.go
index 5d385f9..4bcd85c 100644
--- a/git-codereview/mail.go
+++ b/git-codereview/mail.go
@@ -6,6 +6,7 @@
 
 import (
 	"fmt"
+	"os"
 	"regexp"
 	"sort"
 	"strings"
@@ -47,6 +48,19 @@
 		exit(2)
 	}
 
+	var trybotVotes []string
+	switch os.Getenv("GIT_CODEREVIEW_TRYBOT") {
+	case "luci":
+		trybotVotes = []string{"Commit-Queue+1"}
+	case "", "farmer":
+		trybotVotes = []string{"Run-TryBot"}
+	case "both":
+		trybotVotes = []string{"Commit-Queue+1", "Run-TryBot"}
+	default:
+		fmt.Fprintf(stderr(), "GIT_CODEREVIEW_TRYBOT must be unset, blank, or one of 'luci', 'farmer', or 'both'\n")
+		exit(2)
+	}
+
 	b := CurrentBranch()
 
 	var c *Commit
@@ -142,8 +156,10 @@
 		start = ","
 	}
 	if *trybot {
-		refSpec += start + "l=Run-TryBot"
-		start = ","
+		for _, v := range trybotVotes {
+			refSpec += start + "l=" + v
+			start = ","
+		}
 	}
 	if *wip {
 		refSpec += start + "wip"