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

maintner, gerritapi: handle draft status

The latest Gerrit API documents only NEW, MERGED, and ABANDONED statuses
at https://gerrit-review.googlesource.com/Documentation/rest-api-changes.html#change-info.
Update changeState in the gerritapi package accordingly.

On the other hand, the maintner API documents that GerritCL.Status will
be will be "new", "merged", "abandoned", or "draft". Out of the options
available in change.Status, change.OpenState is the best available pick
for "draft", so use it. One example of such a CL in the maintner corpus
with "draft" status is CL 38720 in x/build, so there's no choice but to
handle that status somehow. It can be refined, if needed, in the future.

Also upgrade to go@1.23.0 and go-gerrit@v1.0.0 while here.
dmitshur committed 2 days ago commit 6140fdcb140798fe4fda313c57be133bf235e796
Collapse all
gerritapi/gerritapi.go
@@ -127,20 +127,21 @@ func (s service) Get(ctx context.Context, repo string, id uint64) (change.Change
		Commits:      len(chg.Revisions),
		ChangedFiles: 0, // TODO.
	}, nil
}

// changeState converts a Gerrit change status
// as defined at https://gerrit-review.googlesource.com/Documentation/rest-api-changes.html#change-info
// to [change.State].
func changeState(status string) change.State {
	switch status {
	case "NEW":
		return change.OpenState
	case "ABANDONED":
		return change.ClosedState
	case "MERGED":
		return change.MergedState
	case "DRAFT":
		panic("not sure how to deal with DRAFT status")
	default:
		panic("unreachable")
	}
}

go.mod
@@ -1,5 +1,5 @@
module dmitri.shuralyov.com/service/change

go 1.19
go 1.23.0

require github.com/andygrunwald/go-gerrit v0.0.0-20231116202240-40e4f30dae8f
require github.com/andygrunwald/go-gerrit v1.0.0
go.sum
@@ -1,2 +1,2 @@
github.com/andygrunwald/go-gerrit v0.0.0-20231116202240-40e4f30dae8f h1:BvVRbHp1pHrA+TSGUNBqfu+Pc0CICaD807Dq2zEOta8=
github.com/andygrunwald/go-gerrit v0.0.0-20231116202240-40e4f30dae8f/go.mod h1:SeP12EkHZxEVjuJ2HZET304NBtHGG2X6w2Gzd0QXAZw=
github.com/andygrunwald/go-gerrit v1.0.0 h1:TrRGbso70QjJcXPC4kkLiKQrAfCBoBV+cBs7NrJxeno=
github.com/andygrunwald/go-gerrit v1.0.0/go.mod h1:SeP12EkHZxEVjuJ2HZET304NBtHGG2X6w2Gzd0QXAZw=
maintner/maintner.go
@@ -291,20 +291,19 @@ func (s service) GetDiff(_ context.Context, repo string, id uint64, opt *change.

func (service) EditComment(_ context.Context, repo string, id uint64, cr change.CommentRequest) (change.Comment, error) {
	return change.Comment{}, fmt.Errorf("EditComment: not implemented")
}

// changeState converts a [golang.org/x/build/maintner.GerritCL.Status] to [change.State].
func changeState(status string) change.State {
	switch status {
	case "new":
	case "new", "draft":
		return change.OpenState
	case "abandoned":
		return change.ClosedState
	case "merged":
		return change.MergedState
	case "draft":
		panic("not sure how to deal with draft status")
	default:
		panic(fmt.Errorf("unrecognized status %q", status))
	}
}