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

githubapi: Start fetching PR review bodies as comments.
dmitshur committed 7 years ago commit cd5d0dc9febf2e0ed81acedd64c3a20c25e0ee48
Collapse all
githubapi/githubapi.go
@@ -322,10 +322,25 @@ func (s service) ListComments(ctx context.Context, rs string, id uint64, opt *ch
						PageInfo struct {
							EndCursor   githubql.String
							HasNextPage githubql.Boolean
						}
					} `graphql:"comments(first:1,after:$commentsCursor)"` // TODO: Increase page size too 100 after done testing.
					Reviews struct {
						Nodes []struct {
							DatabaseID      uint64
							Author          githubqlActor
							PublishedAt     githubql.DateTime
							LastEditedAt    *githubql.DateTime
							Editor          *githubqlActor
							Body            string
							ViewerCanUpdate bool
						}
						PageInfo struct {
							EndCursor   githubql.String
							HasNextPage githubql.Boolean
						}
					} `graphql:"reviews(first:100)"` // TODO: Figure out how to make pagination across 2 resource types work...
				} `graphql:"pullRequest(number:$prNumber)"`
			} `graphql:"repository(owner:$repositoryOwner,name:$repositoryName)"`
		}
		variables := map[string]interface{}{
			"repositoryOwner": githubql.String(repo.Owner),
@@ -363,10 +378,30 @@ func (s service) ListComments(ctx context.Context, rs string, id uint64, opt *ch
			if !q.Repository.PullRequest.Comments.PageInfo.HasNextPage {
				break
			}
			variables["commentsCursor"] = githubql.NewString(q.Repository.PullRequest.Comments.PageInfo.EndCursor)
		}
		for _, review := range q.Repository.PullRequest.Reviews.Nodes {
			if review.Body == "" {
				continue
			}
			var edited *issues.Edited
			if review.LastEditedAt != nil {
				edited = &issues.Edited{
					By: ghActor(*review.Editor),
					At: review.LastEditedAt.Time,
				}
			}
			comments = append(comments, issues.Comment{
				ID:        review.DatabaseID,
				User:      ghActor(review.Author),
				CreatedAt: review.PublishedAt.Time,
				Edited:    edited,
				Body:      review.Body,
				Editable:  review.ViewerCanUpdate,
			})
		}
	}

	return comments, nil
}