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

Commit 4a9ef96

Browse files
Merge pull request #1838 from github/fixes/pull-request-review-cancel
Adding functionality to confirm before cancelling a review
2 parents 0e69faa + 570595d commit 4a9ef96

File tree

7 files changed

+66
-7
lines changed

7 files changed

+66
-7
lines changed

src/GitHub.App/GitHub.App.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@
197197
<HintPath>..\..\packages\System.ValueTuple.4.5.0\lib\net461\System.ValueTuple.dll</HintPath>
198198
</Reference>
199199
<Reference Include="System.Web" />
200+
<Reference Include="System.Windows.Forms" />
200201
<Reference Include="System.Xaml" />
201202
<Reference Include="System.Xml.Linq" />
202203
<Reference Include="System.Data.DataSetExtensions" />

src/GitHub.App/Resources.Designer.cs

Lines changed: 21 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/GitHub.App/Resources.resx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,4 +321,10 @@ https://git-scm.com/download/win</value>
321321
<data name="SwitchOriginTitle" xml:space="preserve">
322322
<value>Switch Origin</value>
323323
</data>
324+
<data name="CancelPendingReviewConfirmation" xml:space="preserve">
325+
<value>Are you sure you want to cancel this review? You will lose all your pending comments.</value>
326+
</data>
327+
<data name="CancelPendingReviewConfirmationCaption" xml:space="preserve">
328+
<value>Cancel Review</value>
329+
</data>
324330
</root>

src/GitHub.App/Services/PullRequestService.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
using System.Text;
1212
using System.Text.RegularExpressions;
1313
using System.Threading.Tasks;
14+
using System.Windows.Forms;
1415
using GitHub.Api;
1516
using GitHub.Extensions;
1617
using GitHub.Logging;
@@ -714,6 +715,16 @@ public IObservable<Unit> RemoveUnusedRemotes(ILocalRepositoryModel repository)
714715
});
715716
}
716717

718+
/// <inheritdoc />
719+
public bool ConfirmCancelPendingReview()
720+
{
721+
return MessageBox.Show(
722+
GitHub.App.Resources.CancelPendingReviewConfirmation,
723+
GitHub.App.Resources.CancelPendingReviewConfirmationCaption,
724+
MessageBoxButtons.YesNo,
725+
MessageBoxIcon.Question) == DialogResult.Yes;
726+
}
727+
717728
async Task<string> CreateRemote(IRepository repo, UriString cloneUri)
718729
{
719730
foreach (var remote in repo.Network.Remotes)

src/GitHub.App/ViewModels/GitHubPane/PullRequestReviewAuthoringViewModel.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public class PullRequestReviewAuthoringViewModel : PanePageViewModelBase, IPullR
2424

2525
readonly IPullRequestEditorService editorService;
2626
readonly IPullRequestSessionManager sessionManager;
27+
readonly IPullRequestService pullRequestService;
2728
IPullRequestSession session;
2829
IDisposable sessionSubscription;
2930
PullRequestReviewModel model;
@@ -35,6 +36,7 @@ public class PullRequestReviewAuthoringViewModel : PanePageViewModelBase, IPullR
3536

3637
[ImportingConstructor]
3738
public PullRequestReviewAuthoringViewModel(
39+
IPullRequestService pullRequestService,
3840
IPullRequestEditorService editorService,
3941
IPullRequestSessionManager sessionManager,
4042
IPullRequestFilesViewModel files)
@@ -43,6 +45,7 @@ public PullRequestReviewAuthoringViewModel(
4345
Guard.ArgumentNotNull(sessionManager, nameof(sessionManager));
4446
Guard.ArgumentNotNull(files, nameof(files));
4547

48+
this.pullRequestService = pullRequestService;
4649
this.editorService = editorService;
4750
this.sessionManager = sessionManager;
4851

@@ -271,10 +274,17 @@ async Task DoCancel(object arg)
271274
{
272275
if (Model?.Id != null)
273276
{
274-
await session.CancelReview();
277+
if (pullRequestService.ConfirmCancelPendingReview())
278+
{
279+
await session.CancelReview();
280+
Close();
281+
}
282+
}
283+
else
284+
{
285+
Close();
275286
}
276287

277-
Close();
278288
}
279289
catch (Exception ex)
280290
{

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,5 +224,11 @@ IObservable<IReadOnlyList<CommitMessage>> GetMessagesForUniqueCommits(
224224
string baseBranch,
225225
string compareBranch,
226226
int maxCommits);
227+
228+
/// <summary>
229+
/// Displays a confirmation diaglog to ask if the user wants to cancel a pending review.
230+
/// </summary>
231+
/// <returns></returns>
232+
bool ConfirmCancelPendingReview();
227233
}
228234
}

test/GitHub.App.UnitTests/ViewModels/GitHubPane/PullRequestReviewAuthoringViewModelTests.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,10 @@ public async Task Cancel_Calls_Session_CancelReview_And_Closes_When_Has_Pending_
368368
var session = CreateSession(model: model);
369369
var closed = false;
370370

371-
var target = CreateTarget(model, session);
371+
var pullRequestService = Substitute.For<IPullRequestService>();
372+
pullRequestService.ConfirmCancelPendingReview().Returns(true);
373+
374+
var target = CreateTarget(model, session, pullRequestService);
372375
await InitializeAsync(target);
373376

374377
target.CloseRequested.Subscribe(_ => closed = true);
@@ -397,15 +400,18 @@ public async Task Cancel_Just_Closes_When_Has_No_Pending_Review_Async()
397400

398401
static PullRequestReviewAuthoringViewModel CreateTarget(
399402
PullRequestDetailModel model,
400-
IPullRequestSession session = null)
403+
IPullRequestSession session = null,
404+
IPullRequestService pullRequestService = null)
401405
{
402406
session = session ?? CreateSession(model: model);
403407

404408
return CreateTarget(
409+
pullRequestService: pullRequestService,
405410
sessionManager: CreateSessionManager(session));
406411
}
407412

408413
static PullRequestReviewAuthoringViewModel CreateTarget(
414+
IPullRequestService pullRequestService = null,
409415
IPullRequestEditorService editorService = null,
410416
IPullRequestSessionManager sessionManager = null,
411417
IPullRequestFilesViewModel files = null)
@@ -415,6 +421,7 @@ static PullRequestReviewAuthoringViewModel CreateTarget(
415421
files = files ?? Substitute.For<IPullRequestFilesViewModel>();
416422

417423
return new PullRequestReviewAuthoringViewModel(
424+
pullRequestService,
418425
editorService,
419426
sessionManager,
420427
files);

0 commit comments

Comments
 (0)