dmitri.shuralyov.com/service/change/...

maintner: Skip CLs with empty status.

Update docs to be more accurate.
dmitshur committed 2 years ago commit 954df004222583acf66615c6292e98ccc3badf87
maintner/maintner.go
@@ -1,22 +1,24 @@
-// Package maintner implements issues.Service using a x/build/maintner corpus.
+// Package maintner implements a read-only issues.Service using
+// a x/build/maintner corpus that serves Gerrit changes.
 package maintner
 
 import (
 	"context"
 	"fmt"
+	"log"
 	"os"
 	"sort"
 	"strings"
 
 	"github.com/shurcooL/issues"
 	"github.com/shurcooL/users"
 	"golang.org/x/build/maintner"
 )
 
-// NewService creates a Gerrit-backed issues.Service using given Gerrit client.
-// corpus must be non-nil.
+// NewService creates an issues.Service backed with the given corpus.
+// However, it serves Gerrit changes, not GitHub issues.
 func NewService(corpus *maintner.Corpus) issues.Service {
 	return service{
 		c: corpus,
 	}
 }
@@ -30,10 +32,14 @@ func (s service) List(ctx context.Context, rs issues.RepoSpec, opt issues.IssueL
 
 	var is []issues.Issue
 
 	project := s.c.Gerrit().Project(serverProject(rs))
 	err := project.ForeachCLUnsorted(func(cl *maintner.GerritCL) error {
+		if cl.Status == "" {
+			log.Printf("empty status for CL %d\n", cl.Number)
+			return nil
+		}
 		state := state(cl.Status)
 		switch {
 		case opt.State == issues.StateFilter(issues.OpenState) && state != issues.OpenState:
 			return nil
 		case opt.State == issues.StateFilter(issues.ClosedState) && state != issues.ClosedState:
@@ -69,10 +75,13 @@ func (s service) List(ctx context.Context, rs issues.RepoSpec, opt issues.IssueL
 func (s service) Count(_ context.Context, rs issues.RepoSpec, opt issues.IssueListOptions) (uint64, error) {
 	var count uint64
 
 	project := s.c.Gerrit().Project(serverProject(rs))
 	err := project.ForeachCLUnsorted(func(cl *maintner.GerritCL) error {
+		if cl.Status == "" {
+			return nil
+		}
 		state := state(cl.Status)
 		switch {
 		case opt.State == issues.StateFilter(issues.OpenState) && state != issues.OpenState:
 			return nil
 		case opt.State == issues.StateFilter(issues.ClosedState) && state != issues.ClosedState:
@@ -102,11 +111,11 @@ func state(status string) issues.State {
 	case "abandoned", "merged":
 		return issues.ClosedState
 	case "draft":
 		panic("not sure how to deal with draft status")
 	default:
-		panic("unreachable")
+		panic(fmt.Errorf("unrecognized status %q", status))
 	}
 }
 
 func (s service) ListComments(ctx context.Context, _ issues.RepoSpec, id uint64, opt *issues.ListOptions) ([]issues.Comment, error) {
 	// TODO.