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

maintner: Skip private and empty status CLs consistently.

A CL is considered to not exist if it's private or if it has an empty
status (possible due to an upstream bug).

Updates https://golang.org/issue/22060.
dmitshur committed 6 years ago commit eaa9889a9d9daf03ec8c07c8341eb48bfb976497
Collapse all
maintner/maintner.go
@@ -3,11 +3,10 @@
package maintner

import (
	"context"
	"fmt"
	"log"
	"os"
	"sort"
	"strings"
	"unicode"

@@ -35,12 +34,11 @@ func (s service) List(_ context.Context, repo string, opt change.ListOptions) ([
	if project == nil {
		return nil, os.ErrNotExist
	}
	var is []change.Change
	err := project.ForeachCLUnsorted(func(cl *maintner.GerritCL) error {
		if cl.Status == "" {
			log.Printf("empty status for CL %d\n", cl.Number)
		if cl.Private || cl.Status == "" {
			return nil
		}
		state := state(cl.Status)
		switch {
		case opt.Filter == change.FilterOpen && state != change.OpenState:
@@ -75,11 +73,11 @@ func (s service) Count(_ context.Context, repo string, opt change.ListOptions) (
	if project == nil {
		return 0, os.ErrNotExist
	}
	var count uint64
	err := project.ForeachCLUnsorted(func(cl *maintner.GerritCL) error {
		if cl.Status == "" {
		if cl.Private || cl.Status == "" {
			return nil
		}
		state := state(cl.Status)
		switch {
		case opt.Filter == change.FilterOpen && state != change.OpenState:
@@ -99,11 +97,11 @@ func (s service) Get(_ context.Context, repo string, id uint64) (change.Change,
	project := s.c.Gerrit().Project(serverProject(repo))
	if project == nil {
		return change.Change{}, os.ErrNotExist
	}
	cl := project.CL(int32(id))
	if cl == nil || cl.Private {
	if cl == nil || cl.Private || cl.Status == "" {
		return change.Change{}, os.ErrNotExist
	}
	return change.Change{
		ID:           uint64(cl.Number),
		State:        state(cl.Status),
@@ -122,11 +120,11 @@ func (s service) ListTimeline(_ context.Context, repo string, id uint64, opt *ch
	project := s.c.Gerrit().Project(serverProject(repo))
	if project == nil {
		return nil, os.ErrNotExist
	}
	cl := project.CL(int32(id))
	if cl == nil || cl.Private {
	if cl == nil || cl.Private || cl.Status == "" {
		return nil, os.ErrNotExist
	}
	var timeline []interface{}
	for _, m := range cl.Messages {
		label, body, ok := parseMessage(m.Message)
@@ -210,11 +208,11 @@ func (s service) ListCommits(_ context.Context, repo string, id uint64) ([]chang
	project := s.c.Gerrit().Project(serverProject(repo))
	if project == nil {
		return nil, os.ErrNotExist
	}
	cl := project.CL(int32(id))
	if cl == nil || cl.Private {
	if cl == nil || cl.Private || cl.Status == "" {
		return nil, os.ErrNotExist
	}
	commits := make([]change.Commit, int(cl.Version))
	for n := int32(1); n <= cl.Version; n++ {
		c := cl.CommitAtVersion(n)
@@ -234,11 +232,11 @@ func (s service) GetDiff(_ context.Context, repo string, id uint64, opt *change.
	project := s.c.Gerrit().Project(serverProject(repo))
	if project == nil {
		return nil, os.ErrNotExist
	}
	cl := project.CL(int32(id))
	if cl == nil || cl.Private {
	if cl == nil || cl.Private || cl.Status == "" {
		return nil, os.ErrNotExist
	}
	var c *maintner.GitCommit
	switch opt {
	case nil: