Skip to content

Commit

Permalink
Ensure rendered markdown is shown on edit on description page, fixes #…
Browse files Browse the repository at this point in the history
  • Loading branch information
Rachel Macfarlane authored Dec 9, 2019
1 parent fc4091c commit f30791b
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 35 deletions.
10 changes: 10 additions & 0 deletions src/github/graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,16 @@ export interface DeleteReactionResponse {
};
}

export interface UpdatePullRequestResponse {
updatePullRequest: {
pullRequest: {
body: string;
bodyHTML: string;
title: string;
};
};
}

export interface Ref {
name: string;
repository: {
Expand Down
49 changes: 16 additions & 33 deletions src/github/pullRequestManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import Logger from '../common/logger';
import { EXTENSION_ID } from '../constants';
import { fromPRUri } from '../common/uri';
import { convertRESTPullRequestToRawPullRequest, convertPullRequestsGetCommentsResponseItemToComment, convertIssuesCreateCommentResponseToComment, parseGraphQLTimelineEvents, getRelatedUsersFromTimelineEvents, parseGraphQLComment, getReactionGroup, convertRESTUserToAccount, convertRESTReviewEvent, parseGraphQLReviewEvent, loginComparator } from './utils';
import { PendingReviewIdResponse, TimelineEventsResponse, PullRequestCommentsResponse, AddCommentResponse, SubmitReviewResponse, DeleteReviewResponse, EditCommentResponse, DeleteReactionResponse, AddReactionResponse, MarkPullRequestReadyForReviewResponse, PullRequestState } from './graphql';
import { PendingReviewIdResponse, TimelineEventsResponse, PullRequestCommentsResponse, AddCommentResponse, SubmitReviewResponse, DeleteReviewResponse, EditCommentResponse, DeleteReactionResponse, AddReactionResponse, MarkPullRequestReadyForReviewResponse, PullRequestState, UpdatePullRequestResponse } from './graphql';
import { ITelemetry } from '../common/telemetry';
import { ApiImpl } from '../api/api1';

Expand Down Expand Up @@ -1278,35 +1278,13 @@ export class PullRequestManager implements vscode.Disposable {
}

async editReviewComment(pullRequest: PullRequestModel, comment: IComment, text: string): Promise<IComment> {
try {
if (comment.isDraft) {
return this.editPendingReviewComment(pullRequest, comment.graphNodeId, text);
}

const githubRepository = pullRequest.githubRepository;
const { octokit, remote } = await githubRepository.ensure();

const ret = await octokit.pulls.updateComment({
owner: remote.owner,
repo: remote.repositoryName,
body: text,
comment_id: comment.id
});

return this.addCommentPermissions(convertPullRequestsGetCommentsResponseItemToComment(ret.data, githubRepository), remote);
} catch (e) {
throw new Error(formatError(e));
}
}

private async editPendingReviewComment(pullRequest: PullRequestModel, commentNodeId: string, text: string): Promise<IComment> {
const { mutate, schema } = await pullRequest.githubRepository.ensure();

const { data } = await mutate<EditCommentResponse>({
mutation: schema.EditComment,
variables: {
input: {
pullRequestReviewCommentId: commentNodeId,
pullRequestReviewCommentId: comment.graphNodeId,
body: text
}
}
Expand Down Expand Up @@ -1374,17 +1352,22 @@ export class PullRequestManager implements vscode.Disposable {
return [ret.data, pullRequest.githubRepository];
}

async editPullRequest(pullRequest: PullRequestModel, toEdit: IPullRequestEditData): Promise<Octokit.PullsUpdateResponse> {
async editPullRequest(pullRequest: PullRequestModel, toEdit: IPullRequestEditData): Promise<{ body: string, bodyHTML: string, title: string }> {
try {
const { octokit, remote } = await pullRequest.githubRepository.ensure();
const { data } = await octokit.pulls.update({
owner: remote.owner,
repo: remote.repositoryName,
pull_number: pullRequest.prNumber,
body: toEdit.body,
title: toEdit.title
const { mutate, schema } = await pullRequest.githubRepository.ensure();

const { data } = await mutate<UpdatePullRequestResponse>({
mutation: schema.UpdatePullRequest,
variables: {
input: {
pullRequestId: pullRequest.graphNodeId,
body: toEdit.body,
title: toEdit.title
}
}
});
return data;

return data!.updatePullRequest.pullRequest;
} catch (e) {
throw new Error(formatError(e));
}
Expand Down
4 changes: 2 additions & 2 deletions src/github/pullRequestOverview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,7 @@ export class PullRequestOverviewPanel {

private editDescription(message: IRequestMessage<{ text: string }>) {
this._pullRequestManager.editPullRequest(this._pullRequest, { body: message.args.text }).then(result => {
this._replyMessage(message, { body: result.body, bodyHTML: result.body });
this._replyMessage(message, { body: result.body, bodyHTML: result.bodyHTML });
}).catch(e => {
this._throwError(message, e);
vscode.window.showErrorMessage(`Editing description failed: ${formatError(e)}`);
Expand All @@ -563,7 +563,7 @@ export class PullRequestOverviewPanel {
editCommentPromise.then(result => {
this._replyMessage(message, {
body: result.body,
bodyHTML: result.body
bodyHTML: result.bodyHTML
});
}).catch(e => {
this._throwError(message, e);
Expand Down
11 changes: 11 additions & 0 deletions src/github/queries.gql
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ fragment ReviewComment on PullRequestReviewComment {
}
path originalPosition
body
bodyHTML
diffHunk
position
state
Expand Down Expand Up @@ -372,6 +373,16 @@ mutation DeleteReaction($input: RemoveReactionInput!){
}
}

mutation UpdatePullRequest($input: UpdatePullRequestInput!) {
updatePullRequest(input: $input) {
pullRequest {
body
bodyHTML
title
}
}
}

query GetMentionableUsers($owner: String!, $name: String!, $first: Int!, $after: String) {
repository(owner: $owner, name: $name) {
mentionableUsers(first: $first, after: $after) {
Expand Down
1 change: 1 addition & 0 deletions src/github/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ export function parseGraphQLComment(comment: GraphQL.ReviewComment): IComment {
id: comment.databaseId,
url: comment.url,
body: comment.body,
bodyHTML: comment.bodyHTML,
path: comment.path,
canEdit: comment.viewerCanDelete,
canDelete: comment.viewerCanDelete,
Expand Down

0 comments on commit f30791b

Please sign in to comment.