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

Commit eeeca7c

Browse files
Adding functionality to delete a pull request comment
1 parent 49ad951 commit eeeca7c

File tree

10 files changed

+82
-32
lines changed

10 files changed

+82
-32
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: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,16 @@ 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; }
1424

1525
/// <summary>
1626
/// Gets the author of the comment.

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/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>

src/GitHub.InlineReviews/ViewModels/InlineCommentThreadViewModel.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ async Task DoDeleteComment(object parameter)
8080
{
8181
Guard.ArgumentNotNull(parameter, nameof(parameter));
8282

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

src/GitHub.InlineReviews/ViewModels/PullRequestReviewCommentViewModel.cs

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,24 +30,28 @@ public class PullRequestReviewCommentViewModel : CommentViewModel, IPullRequestR
3030
/// <param name="session">The pull request session.</param>
3131
/// <param name="thread">The thread that the comment is a part of.</param>
3232
/// <param name="currentUser">The current user.</param>
33+
/// <param name="pullRequestId">The pull request id of the comment.</param>
3334
/// <param name="commentId">The GraphQL ID of the comment.</param>
35+
/// <param name="databaseId">The database id of the comment.</param>
3436
/// <param name="body">The comment body.</param>
3537
/// <param name="state">The comment edit state.</param>
3638
/// <param name="author">The author of the comment.</param>
3739
/// <param name="updatedAt">The modified date of the comment.</param>
3840
/// <param name="isPending">Whether this is a pending comment.</param>
39-
public PullRequestReviewCommentViewModel(
40-
IPullRequestSession session,
41+
/// <param name="webUrl"></param>
42+
public PullRequestReviewCommentViewModel(IPullRequestSession session,
4143
ICommentThreadViewModel thread,
4244
IActorViewModel currentUser,
45+
int pullRequestId,
4346
string commentId,
47+
int databaseId,
4448
string body,
4549
CommentEditState state,
4650
IActorViewModel author,
4751
DateTimeOffset updatedAt,
4852
bool isPending,
4953
Uri webUrl)
50-
: base(thread, currentUser, commentId, body, state, author, updatedAt, webUrl)
54+
: base(thread, currentUser, pullRequestId, commentId, databaseId, body, state, author, updatedAt, webUrl)
5155
{
5256
Guard.ArgumentNotNull(session, nameof(session));
5357

@@ -87,14 +91,16 @@ public PullRequestReviewCommentViewModel(
8791
PullRequestReviewModel review,
8892
PullRequestReviewCommentModel model)
8993
: this(
90-
session,
91-
thread,
92-
currentUser,
93-
model.Id,
94-
model.Body,
95-
CommentEditState.None,
96-
new ActorViewModel(model.Author),
97-
model.CreatedAt,
94+
session,
95+
thread,
96+
currentUser,
97+
model.PullRequestId,
98+
model.Id,
99+
model.DatabaseId,
100+
model.Body,
101+
CommentEditState.None,
102+
new ActorViewModel(model.Author),
103+
model.CreatedAt,
98104
review.State == PullRequestReviewState.Pending,
99105
model.Url != null ? new Uri(model.Url) : null)
100106
{
@@ -116,7 +122,9 @@ public static CommentViewModel CreatePlaceholder(
116122
session,
117123
thread,
118124
currentUser,
125+
0,
119126
null,
127+
0,
120128
string.Empty,
121129
CommentEditState.Placeholder,
122130
currentUser,

0 commit comments

Comments
 (0)