dmitri.shuralyov.com/service/change/githubapi

add support for viewing/editing reactions on PR reviews

Previously, GitHub itself did not support leaving reactions on Pull
Request reviews. It was only possible to leave reactions on normal
comments and inline review comments. They've added that feature now,
so this change implements it accordingly in this package.

Reference: https://developer.github.com/v4/changelog/2019-01-11-schema-changes/.
dmitshur committed 5 years ago commit 184eb3bb42b2f88fc2b2be1149cb873317bb25e6
Showing partial commit. Full Commit
Collapse all
githubapi/githubapi.go
@@ -373,10 +373,11 @@ func (s service) ListTimeline(ctx context.Context, rs string, id uint64, opt *ch
						PublishedAt     githubv4.DateTime
						LastEditedAt    *githubv4.DateTime
						Editor          *githubV4Actor
						State           githubv4.PullRequestReviewState
						Body            string
						ReactionGroups  reactionGroups
						ViewerCanUpdate bool
						Comments        struct {
							Nodes []struct {
								DatabaseID       uint64
								Path             string
@@ -479,10 +480,11 @@ func (s service) ListTimeline(ctx context.Context, rs string, id uint64, opt *ch
					User:      ghActor(review.Author),
					CreatedAt: review.PublishedAt.Time,
					Edited:    edited,
					State:     state,
					Body:      review.Body,
					Reactions: ghReactions(review.ReactionGroups, ghUser(&q.Viewer)),
					Editable:  review.ViewerCanUpdate,
					Comments:  cs,
				})
			}
		}
@@ -673,10 +675,34 @@ func (s service) EditComment(ctx context.Context, rs string, id uint64, cr chang
				return change.Comment{}, err
			}
			subjectID = q.Node.IssueComment.ID
			viewerHasReacted = q.Node.IssueComment.Reactions.ViewerHasReacted
			viewer = ghUser(&q.Viewer)
		case strings.HasPrefix(cr.ID, "r"):
			reviewID := "017:PullRequestReview" + cr.ID[len("r"):]
			var q struct {
				Node struct {
					PullRequestReview struct {
						ID        githubv4.ID
						Reactions struct {
							ViewerHasReacted bool
						} `graphql:"reactions(content:$reactionContent)"`
					} `graphql:"...on PullRequestReview"`
				} `graphql:"node(id:$reviewID)"`
				Viewer githubV4User
			}
			variables := map[string]interface{}{
				"reviewID":        githubv4.ID(base64.StdEncoding.EncodeToString([]byte(reviewID))), // HACK, TODO: Confirm StdEncoding vs URLEncoding.
				"reactionContent": reactionContent,
			}
			err = s.clV4.Query(ctx, &q, variables)
			if err != nil {
				return change.Comment{}, err
			}
			subjectID = q.Node.PullRequestReview.ID
			viewerHasReacted = q.Node.PullRequestReview.Reactions.ViewerHasReacted
			viewer = ghUser(&q.Viewer)
		case strings.HasPrefix(cr.ID, "rc"):
			commentID := "024:PullRequestReviewComment" + cr.ID[len("rc"):]
			var q struct {
				Node struct {
					PullRequestReviewComment struct {