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

gerritapi: Fetch messages in Get; simplify project helper.

We need to fetch messages in Get method, so that counting them works.
Previously, len(chg.Messages) was always zero, and so was Replies as
a result.

Make project helper implementation simpler by making its error handling
path indented, and the normal execution path not indented.
dmitshur committed 6 months ago commit 7b7788c77483cdab4134f879966f36cfad8e48c6
gerritapi/gerritapi.go
@@ -89,11 +89,11 @@ func (s service) Count(_ context.Context, repo string, opt change.ListOptions) (
 	return 0, nil
 }
 
 func (s service) Get(ctx context.Context, _ string, id uint64) (change.Change, error) {
 	chg, _, err := s.cl.Changes.GetChange(fmt.Sprint(id), &gerrit.ChangeOptions{
-		AdditionalFields: []string{"DETAILED_ACCOUNTS", "ALL_REVISIONS"},
+		AdditionalFields: []string{"DETAILED_ACCOUNTS", "MESSAGES", "ALL_REVISIONS"},
 	})
 	if err != nil {
 		return change.Change{}, err
 	}
 	if chg.Status == "DRAFT" {
@@ -385,10 +385,11 @@ func (s service) gerritUser(user gerrit.AccountInfo) users.User {
 		AvatarURL: avatarURL,
 	}
 }
 
 func project(repo string) string {
-	if i := strings.IndexByte(repo, '/'); i != -1 {
-		return repo[i+1:]
+	i := strings.IndexByte(repo, '/')
+	if i == -1 {
+		return ""
 	}
-	return ""
+	return repo[i+1:]
 }