[autoroll] Add another Gerrit config

Bug: fuchsia:39547
Change-Id: I65d28d090828164489307e10628d39175fc2dc4e
Reviewed-on: https://skia-review.googlesource.com/c/buildbot/+/255265
Commit-Queue: Eric Boren <borenet@google.com>
Reviewed-by: Ravi Mistry <rmistry@google.com>
diff --git a/autoroll/go/codereview/config.go b/autoroll/go/codereview/config.go
index f805b06..6cfac2c 100644
--- a/autoroll/go/codereview/config.go
+++ b/autoroll/go/codereview/config.go
@@ -27,6 +27,10 @@
 	// GERRIT_CONFIG_CHROMIUM_NO_CQ is a Gerrit server configuration used by
 	// Chromium for projects with no Commit Queue.
 	GERRIT_CONFIG_CHROMIUM_NO_CQ = "chromium-no-cq"
+
+	// GERRIT_CONFIG_LIBASSISTANT is a Gerrit server configuration used by
+	// libassistant.
+	GERRIT_CONFIG_LIBASSISTANT = "libassistant"
 )
 
 var (
@@ -36,6 +40,7 @@
 		GERRIT_CONFIG_ANGLE:          gerrit.CONFIG_ANGLE,
 		GERRIT_CONFIG_CHROMIUM:       gerrit.CONFIG_CHROMIUM,
 		GERRIT_CONFIG_CHROMIUM_NO_CQ: gerrit.CONFIG_CHROMIUM_NO_CQ,
+		GERRIT_CONFIG_LIBASSISTANT:   gerrit.CONFIG_LIBASSISTANT,
 	}
 )
 
diff --git a/go/gerrit/config.go b/go/gerrit/config.go
index 7c19073..e38f9e2 100644
--- a/go/gerrit/config.go
+++ b/go/gerrit/config.go
@@ -28,6 +28,7 @@
 		CqFailureLabels: map[string]int{
 			PRESUBMIT_VERIFIED_LABEL: PRESUBMIT_VERIFIED_LABEL_REJECTED,
 		},
+		CqLabelsUnsetOnCompletion: true,
 		DryRunActiveLabels: map[string]int{
 			AUTOSUBMIT_LABEL:      AUTOSUBMIT_LABEL_NONE,
 			PRESUBMIT_READY_LABEL: PRESUBMIT_READY_LABEL_ENABLE,
@@ -58,8 +59,9 @@
 		CqActiveLabels: map[string]int{
 			COMMITQUEUE_LABEL: COMMITQUEUE_LABEL_SUBMIT,
 		},
-		CqSuccessLabels: map[string]int{},
-		CqFailureLabels: map[string]int{},
+		CqSuccessLabels:           map[string]int{},
+		CqFailureLabels:           map[string]int{},
+		CqLabelsUnsetOnCompletion: true,
 		DryRunActiveLabels: map[string]int{
 			COMMITQUEUE_LABEL: COMMITQUEUE_LABEL_DRY_RUN,
 		},
@@ -85,8 +87,9 @@
 		CqActiveLabels: map[string]int{
 			COMMITQUEUE_LABEL: COMMITQUEUE_LABEL_SUBMIT,
 		},
-		CqSuccessLabels: map[string]int{},
-		CqFailureLabels: map[string]int{},
+		CqSuccessLabels:           map[string]int{},
+		CqFailureLabels:           map[string]int{},
+		CqLabelsUnsetOnCompletion: true,
 		DryRunActiveLabels: map[string]int{
 			COMMITQUEUE_LABEL: COMMITQUEUE_LABEL_DRY_RUN,
 		},
@@ -105,12 +108,49 @@
 		NoCqLabels: map[string]int{
 			COMMITQUEUE_LABEL: COMMITQUEUE_LABEL_NONE,
 		},
-		CqActiveLabels:          map[string]int{},
-		CqSuccessLabels:         map[string]int{},
-		CqFailureLabels:         map[string]int{},
-		DryRunActiveLabels:      map[string]int{},
-		DryRunSuccessLabels:     map[string]int{},
-		DryRunFailureLabels:     map[string]int{},
+		CqActiveLabels:            map[string]int{},
+		CqSuccessLabels:           map[string]int{},
+		CqFailureLabels:           map[string]int{},
+		CqLabelsUnsetOnCompletion: true,
+		DryRunActiveLabels:        map[string]int{},
+		DryRunSuccessLabels:       map[string]int{},
+		DryRunFailureLabels:       map[string]int{},
+		DryRunUsesTryjobResults:   false,
+	}
+
+	CONFIG_LIBASSISTANT = &Config{
+		SelfApproveLabels: map[string]int{
+			CODEREVIEW_LABEL: CODEREVIEW_LABEL_SELF_APPROVE,
+		},
+		HasCq: true,
+		SetCqLabels: map[string]int{
+			COMMITQUEUE_LABEL: COMMITQUEUE_LABEL_SUBMIT,
+		},
+		SetDryRunLabels: map[string]int{
+			COMMITQUEUE_LABEL: COMMITQUEUE_LABEL_DRY_RUN,
+		},
+		NoCqLabels: map[string]int{
+			COMMITQUEUE_LABEL: COMMITQUEUE_LABEL_NONE,
+		},
+		CqActiveLabels: map[string]int{
+			COMMITQUEUE_LABEL: COMMITQUEUE_LABEL_SUBMIT,
+		},
+		CqSuccessLabels: map[string]int{
+			VERIFIED_LABEL: VERIFIED_LABEL_ACCEPTED,
+		},
+		CqFailureLabels: map[string]int{
+			VERIFIED_LABEL: VERIFIED_LABEL_REJECTED,
+		},
+		CqLabelsUnsetOnCompletion: false,
+		DryRunActiveLabels: map[string]int{
+			COMMITQUEUE_LABEL: COMMITQUEUE_LABEL_DRY_RUN,
+		},
+		DryRunSuccessLabels: map[string]int{
+			VERIFIED_LABEL: VERIFIED_LABEL_ACCEPTED,
+		},
+		DryRunFailureLabels: map[string]int{
+			VERIFIED_LABEL: VERIFIED_LABEL_REJECTED,
+		},
 		DryRunUsesTryjobResults: false,
 	}
 )
@@ -139,6 +179,9 @@
 	// If the issue is abandoned or all of these labels are set, the Commit
 	// Queue is considered to have failed.
 	CqFailureLabels map[string]int
+	// CqLabelsUnsetOnCompletion is true if the commit queue unsets the
+	// labels when it finishes.
+	CqLabelsUnsetOnCompletion bool
 
 	// If the issue is open and all of these labels are set, the dry run is
 	// considered active.
@@ -195,8 +238,8 @@
 	if ci.IsClosed() {
 		return false
 	}
-	if len(c.CqActiveLabels) > 0 && all(ci, c.CqActiveLabels) {
-		return true
+	if len(c.CqActiveLabels) > 0 && !all(ci, c.CqActiveLabels) {
+		return false
 	}
 	// CqSuccess is only true if the change is merged, so if CqSuccessLabels
 	// are set but the change is not yet merged, we have to consider the CQ
@@ -206,7 +249,15 @@
 	if len(c.CqSuccessLabels) > 0 && all(ci, c.CqSuccessLabels) {
 		return true
 	}
-	return false
+	if c.CqLabelsUnsetOnCompletion {
+		return true
+	}
+	if len(c.CqSuccessLabels) > 0 && all(ci, c.CqSuccessLabels) {
+		return false
+	} else if len(c.CqFailureLabels) > 0 && all(ci, c.CqFailureLabels) {
+		return false
+	}
+	return true
 }
 
 // CqSuccess returns true if the commit queue has finished successfully. This
@@ -226,10 +277,18 @@
 	if ci.IsClosed() {
 		return false
 	}
-	if len(c.DryRunActiveLabels) > 0 && all(ci, c.DryRunActiveLabels) {
+	if len(c.DryRunActiveLabels) > 0 && !all(ci, c.DryRunActiveLabels) {
+		return false
+	}
+	if c.CqLabelsUnsetOnCompletion {
 		return true
 	}
-	return false
+	if len(c.DryRunSuccessLabels) > 0 && all(ci, c.DryRunSuccessLabels) {
+		return false
+	} else if len(c.DryRunFailureLabels) > 0 && all(ci, c.DryRunFailureLabels) {
+		return false
+	}
+	return true
 }
 
 // DryRunSuccess returns true if the dry run succeeded. The allTrybotsSucceeded
@@ -245,11 +304,13 @@
 		// it has passed all of them by default.
 		return true
 	}
-	if len(c.CqActiveLabels) > 0 && all(ci, c.CqActiveLabels) {
-		return false
-	}
-	if len(c.DryRunActiveLabels) > 0 && all(ci, c.DryRunActiveLabels) {
-		return false
+	if c.CqLabelsUnsetOnCompletion {
+		if len(c.CqActiveLabels) > 0 && all(ci, c.CqActiveLabels) {
+			return false
+		}
+		if len(c.DryRunActiveLabels) > 0 && all(ci, c.DryRunActiveLabels) {
+			return false
+		}
 	}
 	if len(c.DryRunSuccessLabels) > 0 && all(ci, c.DryRunSuccessLabels) {
 		return true
diff --git a/go/gerrit/config_test.go b/go/gerrit/config_test.go
index e68cb69..bd90268 100644
--- a/go/gerrit/config_test.go
+++ b/go/gerrit/config_test.go
@@ -52,7 +52,9 @@
 	if len(cfg.CqSuccessLabels) > 0 {
 		SetLabels(ci, cfg.CqSuccessLabels)
 	}
-	UnsetLabels(ci, cfg.CqActiveLabels)
+	if cfg.CqLabelsUnsetOnCompletion {
+		UnsetLabels(ci, cfg.CqActiveLabels)
+	}
 	ci.Status = CHANGE_STATUS_MERGED
 	if cfg.HasCq {
 		require.False(t, cfg.CqRunning(ci))
@@ -117,7 +119,9 @@
 	if len(cfg.DryRunSuccessLabels) > 0 {
 		SetLabels(ci, cfg.DryRunSuccessLabels)
 	}
-	UnsetLabels(ci, cfg.DryRunActiveLabels)
+	if cfg.CqLabelsUnsetOnCompletion {
+		UnsetLabels(ci, cfg.DryRunActiveLabels)
+	}
 	// Unfortunately, with no labels to differentiate, we can't verify that
 	// CqRunning is false here.
 	//require.False(t, cfg.CqRunning(ci))
@@ -163,3 +167,7 @@
 func TestConfigChromiumNoCQ(t *testing.T) {
 	testConfig(t, CONFIG_CHROMIUM_NO_CQ)
 }
+
+func TestConfigLibassistant(t *testing.T) {
+	testConfig(t, CONFIG_LIBASSISTANT)
+}
diff --git a/go/gerrit/gerrit.go b/go/gerrit/gerrit.go
index c04f7a3..4d3c39e 100644
--- a/go/gerrit/gerrit.go
+++ b/go/gerrit/gerrit.go
@@ -73,6 +73,12 @@
 	PRESUBMIT_VERIFIED_LABEL_RUNNING  = 0
 	PRESUBMIT_VERIFIED_LABEL_ACCEPTED = 1
 
+	// Some Gerrit hosts use the "Verified" label instead of "Presubmit-Verified".
+	VERIFIED_LABEL          = "Verified"
+	VERIFIED_LABEL_REJECTED = -1
+	VERIFIED_LABEL_RUNNING  = 0
+	VERIFIED_LABEL_ACCEPTED = 1
+
 	URL_TMPL_CHANGE = "/changes/%d/detail?o=ALL_REVISIONS"
 
 	// Kinds of patchsets.