maintner: add Gerrit statuses, ForeachOpenCL function
When we add a meta commit to the corpus, find the CL's status (buried
in the meta commit message or one of its parent commits) and store it
on the CL object.
Add ForeachOpenCL to allow callers to take an action for each open
Gerrit CL. This requires exporting the existing Gerrit and Git
structs.
Change-Id: Ic72721e437c0281244c2d6fb2eb5435f06a7acb5
Reviewed-on: https://go-review.googlesource.com/38724
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
diff --git a/maintner/gerrit_test.go b/maintner/gerrit_test.go
new file mode 100644
index 0000000..271da13
--- /dev/null
+++ b/maintner/gerrit_test.go
@@ -0,0 +1,53 @@
+// Copyright 2017 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package maintner
+
+import "testing"
+
+var statusTests = []struct {
+ msg string
+ want string
+}{
+ {` Create change
+
+ Uploaded patch set 1.
+
+ Patch-set: 1 (draft)
+ Change-id: I38a08cacc17bcd9587475495111fe98f10d6875c
+ Subject: test: test
+ Branch: refs/heads/master
+ Status: draft
+ Topic:
+ Commit: fee468c613a70d89f60fb5d683b0f796aabecaac`, "draft"},
+ {` Update patch set 1
+
+ Change has been successfully cherry-picked as 117ac82c422a11e4dd5f4c14b50bafc1df840481 by Brad Fitzpatrick
+
+ Patch-set: 1
+ Status: merged
+ Submission-id: 16401-1446004855021-a20b3823`, "merged"},
+ {` Create patch set 8
+
+ Uploaded patch set 8: Patch Set 7 was rebased.
+
+ Patch-set: 8
+ Subject: devapp: initial support for App Engine Flex
+ Commit: 17839a9f284b473986f235ad2757a2b445d05068
+ Tag: autogenerated:gerrit:newPatchSet
+ Groups: 17839a9f284b473986f235ad2757a2b445d05068`, "new"},
+}
+
+func TestGetGerritStatus(t *testing.T) {
+ c := NewCorpus(&dummyMutationLogger{}, "")
+ c.AddGerrit("go.googlesource.com/build")
+ gp := c.gerrit.projects["go.googlesource.com/build"]
+ for _, tt := range statusTests {
+ gc := &GitCommit{Msg: tt.msg}
+ got := gp.getGerritStatus(gc, nil)
+ if got != tt.want {
+ t.Errorf("getGerritStatus msg:\n%s\ngot %s, want %s", tt.msg, got, tt.want)
+ }
+ }
+}