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

Commit e89145e

Browse files
committed
Allow request changes with only file comments.
Also fix unit test for `no body/>0 file comments` case - it wasn't correct before as it was assigning a body.
1 parent 223e904 commit e89145e

File tree

2 files changed

+32
-20
lines changed

2 files changed

+32
-20
lines changed

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,18 @@ public PullRequestReviewAuthoringViewModel(
5757
.ToProperty(this, x => x.CanApproveRequestChanges);
5858

5959
Files = files;
60+
61+
var hasBodyOrComments = this.WhenAnyValue(
62+
x => x.Body,
63+
x => x.FileComments.Count,
64+
(body, comments) => !string.IsNullOrWhiteSpace(body) || comments > 0);
65+
6066
Approve = ReactiveCommand.CreateAsyncTask(_ => DoSubmit(Octokit.PullRequestReviewEvent.Approve));
6167
Comment = ReactiveCommand.CreateAsyncTask(
62-
this.WhenAnyValue(
63-
x => x.Body,
64-
x => x.FileComments.Count,
65-
(body, comments) => !string.IsNullOrWhiteSpace(body) || comments > 0),
68+
hasBodyOrComments,
6669
_ => DoSubmit(Octokit.PullRequestReviewEvent.Comment));
6770
RequestChanges = ReactiveCommand.CreateAsyncTask(
68-
this.WhenAnyValue(x => x.Body, body => !string.IsNullOrWhiteSpace(body)),
71+
hasBodyOrComments,
6972
_ => DoSubmit(Octokit.PullRequestReviewEvent.RequestChanges));
7073
Cancel = ReactiveCommand.CreateAsyncTask(DoCancel);
7174
}

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

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -257,17 +257,15 @@ public async Task Comment_Is_Enabled_When_Has_Body()
257257
[Test]
258258
public async Task Comment_Is_Enabled_When_Has_File_Comments()
259259
{
260-
var comment = CreateReviewComment(12);
261260
var review = CreateReview(12, "grokys", body: "", state: PullRequestReviewState.Pending);
262-
var model = CreatePullRequest(
263-
authorLogin: "shana",
264-
reviews: new[] { review },
265-
reviewComments: new[] { comment });
266-
var session = CreateSession();
261+
var model = CreatePullRequest("shana", review);
262+
var session = CreateSession(
263+
"grokys",
264+
CreateSessionFile(
265+
CreateInlineCommentThread(CreateReviewComment(12))));
267266

268267
var target = CreateTarget(model, session);
269268
await Initialize(target);
270-
target.Body = "Review body";
271269

272270
Assert.IsTrue(target.Comment.CanExecute(null));
273271
}
@@ -292,19 +290,14 @@ public async Task Comment_Calls_Session_PostReview_And_Closes()
292290
}
293291

294292
[Test]
295-
public async Task RequestChanges_Is_Disabled_When_Has_Empty_Body()
293+
public async Task RequestChanges_Is_Disabled_When_Has_Empty_Body_And_No_File_RequestChangess()
296294
{
297-
var comment = CreateReviewComment(12);
298295
var review = CreateReview(12, "grokys", body: "", state: PullRequestReviewState.Pending);
299-
var model = CreatePullRequest(
300-
authorLogin: "shana",
301-
reviews: new[] { review },
302-
reviewComments: new[] { comment });
296+
var model = CreatePullRequest("shana", review);
303297
var session = CreateSession();
304298

305299
var target = CreateTarget(model, session);
306300
await Initialize(target);
307-
target.Body = "";
308301

309302
Assert.IsFalse(target.RequestChanges.CanExecute(null));
310303
}
@@ -318,7 +311,23 @@ public async Task RequestChanges_Is_Enabled_When_Has_Body()
318311

319312
var target = CreateTarget(model, session);
320313
await Initialize(target);
321-
target.Body = "Request Changes";
314+
target.Body = "Review body";
315+
316+
Assert.IsTrue(target.RequestChanges.CanExecute(null));
317+
}
318+
319+
[Test]
320+
public async Task RequestChanges_Is_Enabled_When_Has_File_Comments()
321+
{
322+
var review = CreateReview(12, "grokys", body: "", state: PullRequestReviewState.Pending);
323+
var model = CreatePullRequest("shana", review);
324+
var session = CreateSession(
325+
"grokys",
326+
CreateSessionFile(
327+
CreateInlineCommentThread(CreateReviewComment(12))));
328+
329+
var target = CreateTarget(model, session);
330+
await Initialize(target);
322331

323332
Assert.IsTrue(target.RequestChanges.CanExecute(null));
324333
}

0 commit comments

Comments
 (0)