dmitri.shuralyov.com/service/change/githubapi

Add basic support for PullRequestReviewStatePending.

Previously, it panicked. Now that I have a better how to deal with it,
add a comment describing the state. For now, skip such reviews. In the
future, can display them with a pending/draft style.
dmitshur committed 6 years ago commit 47ea38f763134b0c754ab12274b8cbd3b05f426f
Showing partial commit. Full Commit
Collapse all
githubapi/githubapi.go
@@ -440,10 +440,14 @@ func (s service) ListTimeline(ctx context.Context, rs string, id uint64, opt *ch
			Reactions: s.reactions(comment.ReactionGroups),
			Editable:  comment.ViewerCanUpdate,
		})
	}
	for _, review := range q.Repository.PullRequest.Reviews.Nodes {
		state, ok := ghPRReviewState(review.State)
		if !ok {
			continue
		}
		var edited *change.Edited
		if review.LastEditedAt != nil {
			edited = &change.Edited{
				By: ghActor(review.Editor),
				At: review.LastEditedAt.Time,
@@ -468,11 +472,11 @@ func (s service) ListTimeline(ctx context.Context, rs string, id uint64, opt *ch
		timeline = append(timeline, change.Review{
			ID:        fmt.Sprintf("r%d", review.DatabaseID),
			User:      ghActor(review.Author),
			CreatedAt: review.PublishedAt.Time,
			Edited:    edited,
			State:     ghPRReviewState(review.State),
			State:     state,
			Body:      review.Body,
			Editable:  review.ViewerCanUpdate,
			Comments:  cs,
		})
	}
@@ -838,26 +842,29 @@ func ghPRState(state githubql.PullRequestState) change.State {
	default:
		panic("unreachable")
	}
}

// ghPRReviewState converts a GitHub PullRequestReviewState to change.ReviewState.
func ghPRReviewState(state githubql.PullRequestReviewState) change.ReviewState {
// ghPRReviewState converts a GitHub PullRequestReviewState to change.ReviewState, if it's supported.
func ghPRReviewState(state githubql.PullRequestReviewState) (_ change.ReviewState, ok bool) {
	switch state {
	case githubql.PullRequestReviewStateApproved:
		return change.Approved
		return change.Approved, true
	case githubql.PullRequestReviewStateCommented:
		return change.Commented
		return change.Commented, true
	case githubql.PullRequestReviewStateChangesRequested:
		return change.ChangesRequested
		return change.ChangesRequested, true
	case githubql.PullRequestReviewStateDismissed:
		// PullRequestReviewStateDismissed are reviews that have been retroactively dismissed.
		// Display them as a regular comment review for now (we can't know the original state).
		// THINK: Consider displaying these more distinctly.
		return change.Commented
		return change.Commented, true
	case githubql.PullRequestReviewStatePending:
		panic("PullRequestReviewStatePending not implemented") // TODO.
		// PullRequestReviewStatePending are reviews that are pending (haven't been posted yet).
		// TODO: Consider displaying pending review comments. Figure this out
		//       when adding ability to leave reviews.
		return 0, false
	default:
		panic("unreachable")
	}
}