dmitri.shuralyov.com/service/change/githubapi

switch order of PR review and PR review comment cases

Their previous arrangement made it so that the PR review case
completely shadowed the PR review comment case, since
strings.HasPrefix(cr.ID, "r") is always true whenever
strings.HasPrefix(cr.ID, "rc") is true.
dmitshur committed 5 years ago commit 217368fe45775f398496f79e329f005b9ebba453
Showing partial commit. Full Commit
Collapse all
githubapi/githubapi.go
@@ -675,57 +675,57 @@ 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"):]
		case strings.HasPrefix(cr.ID, "rc"):
			commentID := "024:PullRequestReviewComment" + cr.ID[len("rc"):]
			var q struct {
				Node struct {
					PullRequestReview struct {
					PullRequestReviewComment struct {
						ID        githubv4.ID
						Reactions struct {
							ViewerHasReacted bool
						} `graphql:"reactions(content:$reactionContent)"`
					} `graphql:"...on PullRequestReview"`
				} `graphql:"node(id:$reviewID)"`
					} `graphql:"...on PullRequestReviewComment"`
				} `graphql:"node(id:$commentID)"`
				Viewer githubV4User
			}
			variables := map[string]interface{}{
				"reviewID":        githubv4.ID(base64.StdEncoding.EncodeToString([]byte(reviewID))), // HACK, TODO: Confirm StdEncoding vs URLEncoding.
				"commentID":       githubv4.ID(base64.StdEncoding.EncodeToString([]byte(commentID))), // 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
			subjectID = q.Node.PullRequestReviewComment.ID
			viewerHasReacted = q.Node.PullRequestReviewComment.Reactions.ViewerHasReacted
			viewer = ghUser(&q.Viewer)
		case strings.HasPrefix(cr.ID, "rc"):
			commentID := "024:PullRequestReviewComment" + cr.ID[len("rc"):]
		case strings.HasPrefix(cr.ID, "r"):
			reviewID := "017:PullRequestReview" + cr.ID[len("r"):]
			var q struct {
				Node struct {
					PullRequestReviewComment struct {
					PullRequestReview struct {
						ID        githubv4.ID
						Reactions struct {
							ViewerHasReacted bool
						} `graphql:"reactions(content:$reactionContent)"`
					} `graphql:"...on PullRequestReviewComment"`
				} `graphql:"node(id:$commentID)"`
					} `graphql:"...on PullRequestReview"`
				} `graphql:"node(id:$reviewID)"`
				Viewer githubV4User
			}
			variables := map[string]interface{}{
				"commentID":       githubv4.ID(base64.StdEncoding.EncodeToString([]byte(commentID))), // HACK, TODO: Confirm StdEncoding vs URLEncoding.
				"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.PullRequestReviewComment.ID
			viewerHasReacted = q.Node.PullRequestReviewComment.Reactions.ViewerHasReacted
			subjectID = q.Node.PullRequestReview.ID
			viewerHasReacted = q.Node.PullRequestReview.Reactions.ViewerHasReacted
			viewer = ghUser(&q.Viewer)
		default:
			return change.Comment{}, fmt.Errorf("EditComment: unrecognized kind of comment ID: %q", cr.ID)
		}