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

Commit 3abe757

Browse files
authored
Merge pull request #1789 from github/fixes/delete-comment
Fixing functionality to delete a pull request comment
2 parents 2773ed4 + 4718774 commit 3abe757

13 files changed

+101
-39
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,10 @@ Task PostReviewComment(
138138
/// <summary>
139139
/// Deletes a pull request comment.
140140
/// </summary>
141-
/// <param name="number">The number of the pull request comment to delete</param>
141+
/// <param name="pullRequestId">The number of the pull request id of the comment</param>
142+
/// <param name="commentDatabaseId">The number of the pull request comment to delete</param>
142143
/// <returns>A task which completes when the session has completed updating.</returns>
143-
Task DeleteComment(int number);
144+
Task DeleteComment(int pullRequestId, int commentDatabaseId);
144145

145146
/// <summary>
146147
/// Edit a PR review comment reply.

src/GitHub.Exports/Models/CommentModel.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,19 @@ public class CommentModel
1111
/// Gets the ID of the comment.
1212
/// </summary>
1313
public string Id { get; set; }
14+
15+
/// <summary>
16+
/// Gets the DatabaseId of the comment.
17+
/// </summary>
18+
public int DatabaseId { get; set; }
19+
20+
/// <summary>
21+
/// Gets the PullRequestId of the comment.
22+
/// </summary>
23+
public int PullRequestId { get; set; }
24+
// The GraphQL Api does not allow for deleting of pull request comments.
25+
// REST Api must be used, and PullRequestId is needed to reload the pull request.
26+
// This field should be removed with better GraphQL support.
1427

1528
/// <summary>
1629
/// Gets the author of the comment.

src/GitHub.InlineReviews/GitHub.InlineReviews.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,10 @@
191191
<Project>{9aea02db-02b5-409c-b0ca-115d05331a6b}</Project>
192192
<Name>GitHub.Exports</Name>
193193
</ProjectReference>
194+
<ProjectReference Include="..\GitHub.Extensions.Reactive\GitHub.Extensions.Reactive.csproj">
195+
<Project>{6559E128-8B40-49A5-85A8-05565ED0C7E3}</Project>
196+
<Name>GitHub.Extensions.Reactive</Name>
197+
</ProjectReference>
194198
<ProjectReference Include="..\GitHub.Extensions\GitHub.Extensions.csproj">
195199
<Project>{6AFE2E2D-6DB0-4430-A2EA-F5F5388D2F78}</Project>
196200
<Name>GitHub.Extensions</Name>

src/GitHub.InlineReviews/SampleData/CommentViewModelDesigner.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ public CommentViewModelDesigner()
1616
}
1717

1818
public string Id { get; set; }
19+
public int PullRequestId { get; set; }
20+
public int DatabaseId { get; set; }
1921
public string Body { get; set; }
2022
public string ErrorMessage { get; set; }
2123
public CommentEditState EditState { get; set; }

src/GitHub.InlineReviews/Services/IPullRequestSessionService.cs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -322,21 +322,20 @@ Task<PullRequestDetailModel> PostStandaloneReviewCommentReply(
322322
/// Delete a PR review comment.
323323
/// </summary>
324324
/// <param name="localRepository">The local repository.</param>
325-
/// <param name="remoteRepositoryOwner">The owner of the repository fork to delete from.</param>
326-
/// <param name="user">The user deleting the comment.</param>
327-
/// <param name="number">The pull request comment number.</param>
325+
/// <param name="remoteRepositoryOwner">The owner of the repository.</param>
326+
/// <param name="pullRequestId">The pull request id of the comment</param>
327+
/// <param name="commentDatabaseId">The pull request comment number.</param>
328328
/// <returns>The updated state of the pull request.</returns>
329-
Task<PullRequestDetailModel> DeleteComment(
330-
ILocalRepositoryModel localRepository,
329+
Task<PullRequestDetailModel> DeleteComment(ILocalRepositoryModel localRepository,
331330
string remoteRepositoryOwner,
332-
int number);
331+
int pullRequestId,
332+
int commentDatabaseId);
333333

334334
/// <summary>
335335
/// Edit a PR review comment.
336336
/// </summary>
337337
/// <param name="localRepository">The local repository.</param>
338-
/// <param name="remoteRepositoryOwner">The owner of the repository fork to delete from.</param>
339-
/// <param name="user">The user deleting the comment.</param>
338+
/// <param name="remoteRepositoryOwner">The owner of the repository.</param>
340339
/// <param name="commentNodeId">The pull request comment node id.</param>
341340
/// <param name="body">The replacement comment body.</param>
342341
/// <returns>The updated state of the pull request.</returns>

src/GitHub.InlineReviews/Services/InlineCommentPeekService.cs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -107,12 +107,7 @@ public ITrackingPoint Show(ITextView textView, AddInlineCommentTag tag)
107107

108108
var session = peekBroker.TriggerPeekSession(options);
109109
var item = session.PeekableItems.OfType<InlineCommentPeekableItem>().FirstOrDefault();
110-
111-
if (item != null)
112-
{
113-
var placeholder = item.ViewModel.Thread.Comments.Last();
114-
placeholder.CancelEdit.Take(1).Subscribe(_ => session.Dismiss());
115-
}
110+
item?.ViewModel.Close.Take(1).Subscribe(_ => session.Dismiss());
116111

117112
return trackingPoint;
118113
}
@@ -134,7 +129,9 @@ public ITrackingPoint Show(ITextView textView, ShowInlineCommentTag tag)
134129

135130
ExpandCollapsedRegions(textView, line.Extent);
136131

137-
peekBroker.TriggerPeekSession(options);
132+
var session = peekBroker.TriggerPeekSession(options);
133+
var item = session.PeekableItems.OfType<InlineCommentPeekableItem>().FirstOrDefault();
134+
item?.ViewModel.Close.Take(1).Subscribe(_ => session.Dismiss());
138135

139136
return trackingPoint;
140137
}

src/GitHub.InlineReviews/Services/PullRequestSession.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,13 +159,15 @@ public async Task PostReviewComment(
159159
}
160160

161161
/// <inheritdoc/>
162-
public async Task DeleteComment(
163-
int number)
162+
public async Task DeleteComment(int pullRequestId, int commentDatabaseId)
164163
{
165-
await service.DeleteComment(
164+
var model = await service.DeleteComment(
166165
LocalRepository,
167166
RepositoryOwner,
168-
number);
167+
pullRequestId,
168+
commentDatabaseId);
169+
170+
await Update(model);
169171
}
170172

171173
/// <inheritdoc/>

src/GitHub.InlineReviews/Services/PullRequestSessionService.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,8 @@ public virtual async Task<PullRequestDetailModel> ReadPullRequestDetail(HostAddr
307307
Comments = review.Comments(null, null, null, null).AllPages().Select(comment => new CommentAdapter
308308
{
309309
Id = comment.Id.Value,
310+
PullRequestId = comment.PullRequest.Number,
311+
DatabaseId = comment.DatabaseId.Value,
310312
Author = new ActorModel
311313
{
312314
Login = comment.Author.Login,
@@ -650,18 +652,19 @@ public async Task<PullRequestDetailModel> PostStandaloneReviewCommentReply(
650652
public async Task<PullRequestDetailModel> DeleteComment(
651653
ILocalRepositoryModel localRepository,
652654
string remoteRepositoryOwner,
653-
int number)
655+
int pullRequestId,
656+
int commentDatabaseId)
654657
{
655658
var address = HostAddress.Create(localRepository.CloneUrl.Host);
656659
var apiClient = await apiClientFactory.Create(address);
657660

658661
await apiClient.DeletePullRequestReviewComment(
659662
remoteRepositoryOwner,
660663
localRepository.Name,
661-
number);
664+
commentDatabaseId);
662665

663666
await usageTracker.IncrementCounter(x => x.NumberOfPRReviewDiffViewInlineCommentDelete);
664-
return await ReadPullRequestDetail(address, remoteRepositoryOwner, localRepository.Name, number);
667+
return await ReadPullRequestDetail(address, remoteRepositoryOwner, localRepository.Name, pullRequestId);
665668
}
666669

667670
/// <inheritdoc/>

src/GitHub.InlineReviews/ViewModels/CommentViewModel.cs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,20 @@ public class CommentViewModel : ReactiveObject, ICommentViewModel
3232
/// </summary>
3333
/// <param name="thread">The thread that the comment is a part of.</param>
3434
/// <param name="currentUser">The current user.</param>
35+
/// <param name="pullRequestId">The pull request id of the comment.</param>
3536
/// <param name="commentId">The GraphQL ID of the comment.</param>
37+
/// <param name="databaseId">The database id of the comment.</param>
3638
/// <param name="body">The comment body.</param>
3739
/// <param name="state">The comment edit state.</param>
3840
/// <param name="author">The author of the comment.</param>
3941
/// <param name="updatedAt">The modified date of the comment.</param>
42+
/// <param name="webUrl"></param>
4043
protected CommentViewModel(
4144
ICommentThreadViewModel thread,
4245
IActorViewModel currentUser,
46+
int pullRequestId,
4347
string commentId,
48+
int databaseId,
4449
string body,
4550
CommentEditState state,
4651
IActorViewModel author,
@@ -54,6 +59,8 @@ protected CommentViewModel(
5459
Thread = thread;
5560
CurrentUser = currentUser;
5661
Id = commentId;
62+
DatabaseId = databaseId;
63+
PullRequestId = pullRequestId;
5764
Body = body;
5865
EditState = state;
5966
Author = author;
@@ -104,8 +111,10 @@ protected CommentViewModel(
104111
CommentModel model)
105112
: this(
106113
thread,
107-
new ActorViewModel(currentUser),
114+
new ActorViewModel(currentUser),
115+
model.PullRequestId,
108116
model.Id,
117+
model.DatabaseId,
109118
model.Body,
110119
CommentEditState.None,
111120
new ActorViewModel(model.Author),
@@ -126,7 +135,7 @@ async Task DoDelete(object unused)
126135
ErrorMessage = null;
127136
IsSubmitting = true;
128137

129-
await Thread.DeleteComment.ExecuteAsyncTask(Id);
138+
await Thread.DeleteComment.ExecuteAsyncTask(new Tuple<int, int>(PullRequestId, DatabaseId));
130139
}
131140
catch (Exception e)
132141
{
@@ -192,6 +201,12 @@ async Task DoCommitEdit(object unused)
192201
/// <inheritdoc/>
193202
public string Id { get; private set; }
194203

204+
/// <inheritdoc/>
205+
public int DatabaseId { get; private set; }
206+
207+
/// <inheritdoc/>
208+
public int PullRequestId { get; private set; }
209+
195210
/// <inheritdoc/>
196211
public string Body
197212
{

src/GitHub.InlineReviews/ViewModels/ICommentViewModel.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,16 @@ public interface ICommentViewModel : IViewModel
2323
/// </summary>
2424
string Id { get; }
2525

26+
/// <summary>
27+
/// Gets the Database ID of the comment.
28+
/// </summary>
29+
int DatabaseId { get; }
30+
31+
/// <summary>
32+
/// The pull request id of the comment
33+
/// </summary>
34+
int PullRequestId { get; }
35+
2636
/// <summary>
2737
/// Gets or sets the body of the comment.
2838
/// </summary>

0 commit comments

Comments
 (0)