maintner: skip incomplete CLs in ForeachOpenCL

CL 107296 has created a GerritCL.complete method and started
using it to enforce non-nil Meta and Commit fields in GerritCL
that are returned to the client.

It was used in ForeachCLUnsorted to skip incomplete CLs when
iterating over the gp.cls map, but due to an oversight, it
was not added to ForeachOpenCL. As a result, it was possible
for incomplete CLs to be iterated over via ForeachOpenCL.
This change fixes that by adding the missing complete check.

Update TestGerritMetaNonNil test to check ForeachOpenCL too.

Add missing period at the end of a sentence in ForeachCLUnsorted
documentation.

Fixes golang/go#27536.

Change-Id: I453d0f2b2b2793ed1b8a55bae1c2254906d74792
Reviewed-on: https://go-review.googlesource.com/135677
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
diff --git a/maintner/gerrit.go b/maintner/gerrit.go
index 4b926a5..51aa42b 100644
--- a/maintner/gerrit.go
+++ b/maintner/gerrit.go
@@ -179,7 +179,7 @@
 func (gp *GerritProject) ForeachOpenCL(fn func(*GerritCL) error) error {
 	var s []*GerritCL
 	for _, cl := range gp.cls {
-		if cl.Status != "new" || cl.Private {
+		if !cl.complete() || cl.Status != "new" || cl.Private {
 			continue
 		}
 		s = append(s, cl)
@@ -193,7 +193,7 @@
 	return nil
 }
 
-// ForeachCLUnsorted calls fn for each CL in the repo, in any order
+// ForeachCLUnsorted calls fn for each CL in the repo, in any order.
 //
 // If fn returns an error, iteration ends and ForeachCLUnsorted returns with
 // that error.
diff --git a/maintner/godata/godata_test.go b/maintner/godata/godata_test.go
index b294c5c..2152338 100644
--- a/maintner/godata/godata_test.go
+++ b/maintner/godata/godata_test.go
@@ -108,19 +108,34 @@
 		var maxCL int32
 		gp.ForeachCLUnsorted(func(cl *maintner.GerritCL) error {
 			if cl.Meta == nil {
-				t.Errorf("%s: enumerated CL %d has nil Meta", gp.ServerSlashProject(), cl.Number)
+				t.Errorf("%s: ForeachCLUnsorted-enumerated CL %d has nil Meta", gp.ServerSlashProject(), cl.Number)
 			}
 			if len(cl.Metas) == 0 {
-				t.Errorf("%s: enumerated CL %d has empty Metas", gp.ServerSlashProject(), cl.Number)
+				t.Errorf("%s: ForeachCLUnsorted-enumerated CL %d has empty Metas", gp.ServerSlashProject(), cl.Number)
 			}
 			if cl.Commit == nil {
-				t.Errorf("%s: enumerated CL %d has nil Commit", gp.ServerSlashProject(), cl.Number)
+				t.Errorf("%s: ForeachCLUnsorted-enumerated CL %d has nil Commit", gp.ServerSlashProject(), cl.Number)
 			}
 			if cl.Number > maxCL {
 				maxCL = cl.Number
 			}
 			return nil
 		})
+		gp.ForeachOpenCL(func(cl *maintner.GerritCL) error {
+			if cl.Meta == nil {
+				t.Errorf("%s: ForeachOpenCL-enumerated CL %d has nil Meta", gp.ServerSlashProject(), cl.Number)
+			}
+			if len(cl.Metas) == 0 {
+				t.Errorf("%s: ForeachOpenCL-enumerated CL %d has empty Metas", gp.ServerSlashProject(), cl.Number)
+			}
+			if cl.Commit == nil {
+				t.Errorf("%s: ForeachOpenCL-enumerated CL %d has nil Commit", gp.ServerSlashProject(), cl.Number)
+			}
+			if cl.Number > maxCL {
+				t.Fatalf("%s: ForeachOpenCL-enumerated CL %d higher than max CL %d from ForeachCLUnsorted", gp.ServerSlashProject(), cl.Number, maxCL)
+			}
+			return nil
+		})
 
 		// And test that CL won't yield an incomplete one either:
 		for n := int32(0); n <= maxCL; n++ {