Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.

Commit 6a4667d

Browse files
Using graphql to edit comments
1 parent 46bab4e commit 6a4667d

File tree

6 files changed

+36
-30
lines changed

6 files changed

+36
-30
lines changed

src/GitHub.Exports.Reactive/Services/IPullRequestSession.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,9 +156,9 @@ Task<IPullRequestReviewCommentModel> PostReviewComment(
156156
/// <summary>
157157
/// Edit a PR review comment reply.
158158
/// </summary>
159-
/// <param name="number">The number of the pull request comment</param>
159+
/// <param name="commentNodeId">The node id of the pull request comment</param>
160160
/// <param name="body">The replacement comment body.</param>
161161
/// <returns>A comment model.</returns>
162-
Task<IPullRequestReviewCommentModel> EditComment(int number, string body);
162+
Task<IPullRequestReviewCommentModel> EditComment(string commentNodeId, string body);
163163
}
164164
}

src/GitHub.InlineReviews/Services/IPullRequestSessionService.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -320,13 +320,13 @@ Task DeleteComment(
320320
/// <param name="localRepository">The local repository.</param>
321321
/// <param name="remoteRepositoryOwner">The owner of the repository fork to delete from.</param>
322322
/// <param name="user">The user deleting the comment.</param>
323-
/// <param name="number">The pull request comment number.</param>
323+
/// <param name="commentNodeId">The pull request comment node id.</param>
324324
/// <param name="body">The replacement comment body.</param>
325325
/// <returns>A model representing the edited comment.</returns>
326326
Task<PullRequestReviewCommentModel> EditComment(ILocalRepositoryModel localRepository,
327327
string remoteRepositoryOwner,
328328
IAccount user,
329-
int number,
329+
string commentNodeId,
330330
string body);
331331
}
332332
}

src/GitHub.InlineReviews/Services/PullRequestSession.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,14 +178,13 @@ await service.DeleteComment(
178178
}
179179

180180
/// <inheritdoc/>
181-
public async Task<IPullRequestReviewCommentModel> EditComment(
182-
int number, string body)
181+
public async Task<IPullRequestReviewCommentModel> EditComment(string commentNodeId, string body)
183182
{
184183
var model = await service.EditComment(
185184
LocalRepository,
186185
RepositoryOwner,
187186
User,
188-
number,
187+
commentNodeId,
189188
body);
190189

191190
await ReplaceComment(model);

src/GitHub.InlineReviews/Services/PullRequestSessionService.cs

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
using Microsoft.VisualStudio.Text;
1919
using Microsoft.VisualStudio.Text.Projection;
2020
using Octokit.GraphQL;
21+
using Octokit.GraphQL.Core;
2122
using Octokit.GraphQL.Model;
2223
using ReactiveUI;
2324
using Serilog;
@@ -622,33 +623,39 @@ await apiClient.DeletePullRequestReviewComment(
622623
public async Task<PullRequestReviewCommentModel> EditComment(ILocalRepositoryModel localRepository,
623624
string remoteRepositoryOwner,
624625
IAccount user,
625-
int number,
626+
string commentNodeId,
626627
string body)
627628
{
628629
var address = HostAddress.Create(localRepository.CloneUrl.Host);
629-
var apiClient = await apiClientFactory.Create(address);
630-
631-
var result = await apiClient.EditPullRequestReviewComment(
632-
remoteRepositoryOwner,
633-
localRepository.Name,
634-
number,
635-
body);
636-
637-
await usageTracker.IncrementCounter(x => x.NumberOfPRReviewDiffViewInlineCommentEdit);
630+
var graphql = await graphqlFactory.CreateConnection(address);
638631

639-
return new PullRequestReviewCommentModel
632+
var updatePullRequestReviewCommentInput = new UpdatePullRequestReviewCommentInput
640633
{
641-
Body = result.Body,
642-
CommitId = result.CommitId,
643-
DiffHunk = result.DiffHunk,
644-
Id = result.Id,
645-
OriginalCommitId = result.OriginalCommitId,
646-
OriginalPosition = result.OriginalPosition,
647-
Path = result.Path,
648-
Position = result.Position,
649-
CreatedAt = result.CreatedAt,
650-
User = user,
634+
Body = body,
635+
PullRequestReviewCommentId = commentNodeId
651636
};
637+
638+
var editComment = new Mutation().UpdatePullRequestReviewComment(updatePullRequestReviewCommentInput)
639+
.Select(x => new PullRequestReviewCommentModel
640+
{
641+
Id = x.PullRequestReviewComment.DatabaseId.Value,
642+
NodeId = x.PullRequestReviewComment.Id,
643+
Body = x.PullRequestReviewComment.Body,
644+
CommitId = x.PullRequestReviewComment.Commit.Oid,
645+
Path = x.PullRequestReviewComment.Path,
646+
Position = x.PullRequestReviewComment.Position,
647+
CreatedAt = x.PullRequestReviewComment.CreatedAt.Value,
648+
DiffHunk = x.PullRequestReviewComment.DiffHunk,
649+
OriginalPosition = x.PullRequestReviewComment.OriginalPosition,
650+
OriginalCommitId = x.PullRequestReviewComment.OriginalCommit.Oid,
651+
PullRequestReviewId = x.PullRequestReviewComment.PullRequestReview.DatabaseId.Value,
652+
User = user,
653+
IsPending = false,
654+
});
655+
656+
var result = await graphql.Run(editComment);
657+
await usageTracker.IncrementCounter(x => x.NumberOfPRReviewDiffViewInlineCommentPost);
658+
return result;
652659
}
653660

654661
int GetUpdatedLineNumber(IInlineCommentThreadModel thread, IEnumerable<DiffChunk> diff)

src/GitHub.InlineReviews/ViewModels/CommentViewModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ async Task DoCommitEdit(object unused)
168168
}
169169
else
170170
{
171-
model = await Thread.EditComment.ExecuteAsyncTask(new Tuple<int, string>(Id, Body));
171+
model = await Thread.EditComment.ExecuteAsyncTask(new Tuple<string, string>(NodeId, Body));
172172
}
173173

174174
Id = model.Id;

src/GitHub.InlineReviews/ViewModels/InlineCommentThreadViewModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ async Task<ICommentModel> DoEditComment(object parameter)
8181
{
8282
Guard.ArgumentNotNull(parameter, nameof(parameter));
8383

84-
var item = (Tuple<int, string>)parameter;
84+
var item = (Tuple<string, string>)parameter;
8585
return await Session.EditComment(item.Item1, item.Item2);
8686
}
8787

0 commit comments

Comments
 (0)