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

Commit f713152

Browse files
Tying in a lot of the delete comment functionality
1 parent 5bd3bb9 commit f713152

File tree

10 files changed

+74
-8
lines changed

10 files changed

+74
-8
lines changed

src/GitHub.App/Api/ApiClient.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,14 @@ public IObservable<PullRequestReviewComment> CreatePullRequestReviewComment(
110110
return gitHubClient.PullRequest.ReviewComment.CreateReply(owner, name, number, comment);
111111
}
112112

113+
public IObservable<Unit> DeletePullRequestReviewComment(
114+
string owner,
115+
string name,
116+
int number)
117+
{
118+
return gitHubClient.PullRequest.ReviewComment.Delete(owner, name, number);
119+
}
120+
113121
public IObservable<Gist> CreateGist(NewGist newGist)
114122
{
115123
return gitHubClient.Gist.Create(newGist);

src/GitHub.Exports.Reactive/Api/IApiClient.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,5 +94,10 @@ IObservable<PullRequestReviewComment> CreatePullRequestReviewComment(
9494
IObservable<Repository> GetRepositories();
9595
IObservable<Repository> GetRepository(string owner, string repo);
9696
IObservable<RepositoryContent> GetFileContents(string owner, string name, string reference, string path);
97+
98+
IObservable<Unit> DeletePullRequestReviewComment(
99+
string owner,
100+
string name,
101+
int number);
97102
}
98103
}

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ Task<IPullRequestReviewCommentModel> PostReviewComment(
134134
/// Posts the currently pending review.
135135
/// </summary>
136136
/// <param name="body">The review body.</param>
137-
/// <param name="state">The review event.</param>
137+
/// <param name="e">The review event.</param>
138138
/// <returns>The review model.</returns>
139139
Task<IPullRequestReviewModel> PostReview(string body, PullRequestReviewEvent e);
140140

@@ -145,5 +145,12 @@ Task<IPullRequestReviewCommentModel> PostReviewComment(
145145
/// <param name="pullRequest">The new pull request model.</param>
146146
/// <returns>A task which completes when the session has completed updating.</returns>
147147
Task Update(IPullRequestModel pullRequest);
148+
149+
/// <summary>
150+
/// Deletes a pull request comment.
151+
/// </summary>
152+
/// <param name="number">The number of the pull request comment to delete</param>
153+
/// <returns>A task which completes when the session has completed updating.</returns>
154+
Task DeleteComment(int number);
148155
}
149156
}

src/GitHub.Exports/Models/UsageModel.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ public class MeasuresModel
6464
public int NumberOfPRDetailsOpenFileInSolution { get; set; }
6565
public int NumberOfPRReviewDiffViewInlineCommentOpen { get; set; }
6666
public int NumberOfPRReviewDiffViewInlineCommentPost { get; set; }
67+
public int NumberOfPRReviewDiffViewInlineCommentDelete { get; set; }
6768
public int NumberOfPRReviewDiffViewInlineCommentStartReview { get; set; }
6869
public int NumberOfPRReviewPosts { get; set; }
6970
public int NumberOfShowCurrentPullRequest { get; set; }

src/GitHub.InlineReviews/Services/IPullRequestSessionService.cs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,8 @@ Task<bool> IsUnmodifiedAndPushed(
9090
/// Extracts a file at a specified commit from the repository.
9191
/// </summary>
9292
/// <param name="repository">The repository.</param>
93-
/// <param name="commitSha">The SHA of the commit.</param>
93+
/// <param name="pullRequestNumber">The pull request number</param>
94+
/// <param name="sha">The SHA of the commit.</param>
9495
/// <param name="relativePath">The path to the file, relative to the repository.</param>
9596
/// <returns>
9697
/// The contents of the file, or null if the file was not found at the specified commit.
@@ -146,7 +147,7 @@ Task<byte[]> ExtractFileFromGit(
146147
/// <summary>
147148
/// Gets the GraphQL ID for a pull request.
148149
/// </summary>
149-
/// <param name="repository">The local repository.</param>
150+
/// <param name="localRepository">The local repository.</param>
150151
/// <param name="repositoryOwner">The owner of the remote fork.</param>
151152
/// <param name="number">The pull request number.</param>
152153
/// <returns></returns>
@@ -184,6 +185,7 @@ Task<IPullRequestReviewModel> CreatePendingReview(
184185
/// <summary>
185186
/// Cancels a pending review on the server.
186187
/// </summary>
188+
/// <param name="localRepository">The local repository.</param>
187189
/// <param name="reviewId">The GraphQL ID of the review.</param>
188190
Task CancelPendingReview(
189191
ILocalRepositoryModel localRepository,
@@ -297,5 +299,19 @@ Task<IPullRequestReviewCommentModel> PostStandaloneReviewCommentReply(
297299
int number,
298300
string body,
299301
int inReplyTo);
302+
303+
/// <summary>
304+
/// Delete a PR review comment.
305+
/// </summary>
306+
/// <param name="localRepository">The local repository.</param>
307+
/// <param name="remoteRepositoryOwner">The owner of the repository fork to delete from.</param>
308+
/// <param name="user">The user deleting the comment.</param>
309+
/// <param name="number">The pull request comment number.</param>
310+
/// <returns></returns>
311+
Task DeleteComment(
312+
ILocalRepositoryModel localRepository,
313+
string remoteRepositoryOwner,
314+
IAccount user,
315+
int number);
300316
}
301317
}

src/GitHub.InlineReviews/Services/PullRequestSession.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,17 @@ public async Task<IPullRequestReviewCommentModel> PostReviewComment(
164164
return model;
165165
}
166166

167+
/// <inheritdoc/>
168+
public async Task DeleteComment(
169+
int number)
170+
{
171+
await service.DeleteComment(
172+
LocalRepository,
173+
RepositoryOwner,
174+
User,
175+
number);
176+
}
177+
167178
/// <inheritdoc/>
168179
public async Task<IPullRequestReviewCommentModel> PostReviewComment(
169180
string body,

src/GitHub.InlineReviews/Services/PullRequestSessionService.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -600,6 +600,23 @@ public async Task<IPullRequestReviewCommentModel> PostStandaloneReviewCommentRep
600600
};
601601
}
602602

603+
public async Task DeleteComment(
604+
ILocalRepositoryModel localRepository,
605+
string remoteRepositoryOwner,
606+
IAccount user,
607+
int number)
608+
{
609+
var address = HostAddress.Create(localRepository.CloneUrl.Host);
610+
var apiClient = await apiClientFactory.Create(address);
611+
612+
await apiClient.DeletePullRequestReviewComment(
613+
remoteRepositoryOwner,
614+
localRepository.Name,
615+
number);
616+
617+
await usageTracker.IncrementCounter(x => x.NumberOfPRReviewDiffViewInlineCommentDelete);
618+
}
619+
603620
int GetUpdatedLineNumber(IInlineCommentThreadModel thread, IEnumerable<DiffChunk> diff)
604621
{
605622
var line = DiffUtilities.Match(diff, thread.DiffMatch);

src/GitHub.InlineReviews/ViewModels/CommentThreadViewModel.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public abstract class CommentThreadViewModel : ReactiveObject, ICommentThreadVie
1313
{
1414
ReactiveCommand<ICommentModel> postComment;
1515
private ReactiveCommand<ICommentModel> editComment;
16-
private ReactiveCommand<ICommentModel> deleteComment;
16+
private ReactiveCommand<object> deleteComment;
1717

1818
/// <summary>
1919
/// Intializes a new instance of the <see cref="CommentThreadViewModel"/> class.
@@ -57,7 +57,7 @@ public ReactiveCommand<ICommentModel> EditComment
5757
}
5858
}
5959

60-
public ReactiveCommand<ICommentModel> DeleteComment
60+
public ReactiveCommand<object> DeleteComment
6161
{
6262
get { return deleteComment; }
6363
set

src/GitHub.InlineReviews/ViewModels/ICommentThreadViewModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,6 @@ public interface ICommentThreadViewModel
4040
/// <summary>
4141
/// Called by a comment in the thread to send a delete of the comment to the API.
4242
/// </summary>
43-
ReactiveCommand<ICommentModel> DeleteComment { get; }
43+
ReactiveCommand<object> DeleteComment { get; }
4444
}
4545
}

src/GitHub.InlineReviews/ViewModels/InlineCommentThreadViewModel.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,12 @@ Task<ICommentModel> DoEditComment(object parameter)
8888
throw new NotImplementedException();
8989
}
9090

91-
Task<ICommentModel> DoDeleteComment(object parameter)
91+
async Task<object> DoDeleteComment(object parameter)
9292
{
9393
Guard.ArgumentNotNull(parameter, nameof(parameter));
9494

95-
throw new NotImplementedException();
95+
var number = (int)parameter;
96+
await Session.DeleteComment(number);
9697
}
9798
}
9899
}

0 commit comments

Comments
 (0)