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

Commit 337771d

Browse files
authored
Merge branch 'master' into refactor/repository-model-part3
2 parents 2ef556b + 85f0093 commit 337771d

File tree

9 files changed

+55
-44
lines changed

9 files changed

+55
-44
lines changed

Directory.Build.Props

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<Project>
22
<PropertyGroup>
33
<Product>GitHub Extension for Visual Studio</Product>
4-
<Version>2.5.9.0</Version>
4+
<Version>2.6.0.0</Version>
55
<Copyright>Copyright © GitHub, Inc. 2014-2018</Copyright>
66
<LangVersion>7.3</LangVersion>
77
</PropertyGroup>
8-
</Project>
8+
</Project>

appveyor.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
os: Visual Studio 2017
2-
version: '2.5.9.{build}'
2+
version: '2.6.0.{build}'
33
skip_tags: true
44
install:
55
- ps: |

src/GitHub.App/ViewModels/PullRequestReviewCommentThreadViewModel.cs

Lines changed: 46 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ public bool IsNewThread
7878
public async Task InitializeAsync(
7979
IPullRequestSession session,
8080
IPullRequestSessionFile file,
81-
PullRequestReviewModel review,
8281
IInlineCommentThreadModel thread,
8382
bool addPlaceholder)
8483
{
@@ -97,7 +96,7 @@ public async Task InitializeAsync(
9796
await vm.InitializeAsync(
9897
session,
9998
this,
100-
review,
99+
comment.Review,
101100
comment.Comment,
102101
CommentEditState.None).ConfigureAwait(false);
103102
Comments.Add(vm);
@@ -110,7 +109,7 @@ await vm.InitializeAsync(
110109
await vm.InitializeAsPlaceholderAsync(
111110
session,
112111
this,
113-
review.State == PullRequestReviewState.Pending,
112+
session.HasPendingReview,
114113
false).ConfigureAwait(true);
115114

116115
var (key, secondaryKey) = GetDraftKeys(vm);
@@ -162,35 +161,43 @@ public override async Task PostComment(ICommentViewModel comment)
162161
{
163162
Guard.ArgumentNotNull(comment, nameof(comment));
164163

165-
if (IsNewThread)
164+
await DeleteDraft(comment).ConfigureAwait(false);
165+
166+
try
166167
{
167-
var diffPosition = File.Diff
168-
.SelectMany(x => x.Lines)
169-
.FirstOrDefault(x =>
168+
if (IsNewThread)
169+
{
170+
var diffPosition = File.Diff
171+
.SelectMany(x => x.Lines)
172+
.FirstOrDefault(x =>
173+
{
174+
var line = Side == DiffSide.Left ? x.OldLineNumber : x.NewLineNumber;
175+
return line == LineNumber + 1;
176+
});
177+
178+
if (diffPosition == null)
170179
{
171-
var line = Side == DiffSide.Left ? x.OldLineNumber : x.NewLineNumber;
172-
return line == LineNumber + 1;
173-
});
174-
175-
if (diffPosition == null)
180+
throw new InvalidOperationException("Unable to locate line in diff.");
181+
}
182+
183+
await Session.PostReviewComment(
184+
comment.Body,
185+
File.CommitSha,
186+
File.RelativePath.Replace("\\", "/"),
187+
File.Diff,
188+
diffPosition.DiffLineNumber).ConfigureAwait(false);
189+
}
190+
else
176191
{
177-
throw new InvalidOperationException("Unable to locate line in diff.");
192+
var replyId = Comments[0].Id;
193+
await Session.PostReviewComment(comment.Body, replyId).ConfigureAwait(false);
178194
}
179-
180-
await Session.PostReviewComment(
181-
comment.Body,
182-
File.CommitSha,
183-
File.RelativePath.Replace("\\", "/"),
184-
File.Diff,
185-
diffPosition.DiffLineNumber).ConfigureAwait(false);
186195
}
187-
else
196+
catch
188197
{
189-
var replyId = Comments[0].Id;
190-
await Session.PostReviewComment(comment.Body, replyId).ConfigureAwait(false);
198+
UpdateDraft(comment).Forget();
199+
throw;
191200
}
192-
193-
await DeleteDraft(comment).ConfigureAwait(false);
194201
}
195202

196203
public override async Task EditComment(ICommentViewModel comment)
@@ -220,12 +227,13 @@ public static (string key, string secondaryKey) GetDraftKeys(
220227

221228
protected override CommentDraft BuildDraft(ICommentViewModel comment)
222229
{
223-
return new PullRequestReviewCommentDraft
224-
{
225-
Body = comment.Body,
226-
Side = Side,
227-
UpdatedAt = DateTimeOffset.UtcNow,
228-
};
230+
return !string.IsNullOrEmpty(comment.Body) ?
231+
new PullRequestReviewCommentDraft
232+
{
233+
Body = comment.Body,
234+
Side = Side,
235+
UpdatedAt = DateTimeOffset.UtcNow,
236+
} : null;
229237
}
230238

231239
protected override (string key, string secondaryKey) GetDraftKeys(ICommentViewModel comment)
@@ -236,5 +244,12 @@ protected override (string key, string secondaryKey) GetDraftKeys(ICommentViewMo
236244
File.RelativePath,
237245
LineNumber);
238246
}
247+
248+
async Task UpdateDraft(ICommentViewModel comment)
249+
{
250+
var draft = BuildDraft(comment);
251+
var (key, secondaryKey) = GetDraftKeys(comment);
252+
await DraftStore.UpdateDraft(key, secondaryKey, draft).ConfigureAwait(true);
253+
}
239254
}
240255
}

src/GitHub.Exports.Reactive/ViewModels/IPullRequestReviewCommentThreadViewModel.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,13 @@ public interface IPullRequestReviewCommentThreadViewModel : ICommentThreadViewMo
4646
/// </summary>
4747
/// <param name="session">The pull request session.</param>
4848
/// <param name="file">The file that the comment is on.</param>
49-
/// <param name="review">The associated review.</param>
5049
/// <param name="thread">The thread.</param>
5150
/// <param name="addPlaceholder">
5251
/// Whether to add a placeholder comment at the end of the thread.
5352
/// </param>
5453
Task InitializeAsync(
5554
IPullRequestSession session,
5655
IPullRequestSessionFile file,
57-
PullRequestReviewModel review,
5856
IInlineCommentThreadModel thread,
5957
bool addPlaceholder);
6058

src/GitHub.InlineReviews/Services/PullRequestSessionService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -845,7 +845,7 @@ static void BuildPullRequestThreads(PullRequestDetailModel model)
845845
}
846846

847847
// Get the comments that are replies and place them into the relevant list.
848-
foreach (CommentAdapter comment in model.Reviews.SelectMany(x => x.Comments))
848+
foreach (CommentAdapter comment in model.Reviews.SelectMany(x => x.Comments).OrderBy(x => x.CreatedAt))
849849
{
850850
if (comment.ReplyTo != null)
851851
{

src/GitHub.InlineReviews/ViewModels/InlineCommentPeekViewModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ async Task UpdateThread()
181181

182182
if (thread?.Comments.Count > 0)
183183
{
184-
await vm.InitializeAsync(session, file, thread.Comments[0].Review, thread, true);
184+
await vm.InitializeAsync(session, file, thread, true);
185185
}
186186
else
187187
{

src/GitHub.VisualStudio/source.extension.vsixmanifest

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<PackageManifest Version="2.0.0" xmlns="http://schemas.microsoft.com/developer/vsx-schema/2011" xmlns:d="http://schemas.microsoft.com/developer/vsx-schema-design/2011">
33
<Metadata>
4-
<Identity Id="c3d3dc68-c977-411f-b3e8-03b0dccf7dfc" Version="2.5.9.0" Language="en-US" Publisher="GitHub, Inc" />
4+
<Identity Id="c3d3dc68-c977-411f-b3e8-03b0dccf7dfc" Version="2.6.0.0" Language="en-US" Publisher="GitHub, Inc" />
55
<DisplayName>GitHub Extension for Visual Studio</DisplayName>
66
<Description xml:space="preserve">A Visual Studio Extension that brings the GitHub Flow into Visual Studio.</Description>
77
<PackageId>GitHub.VisualStudio</PackageId>
@@ -44,4 +44,4 @@
4444
<Prerequisites>
4545
<Prerequisite Id="Microsoft.VisualStudio.Component.CoreEditor" Version="[15.0.25824.0,)" DisplayName="Visual Studio core editor" />
4646
</Prerequisites>
47-
</PackageManifest>
47+
</PackageManifest>

src/common/SolutionInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@
1818
namespace System
1919
{
2020
internal static class AssemblyVersionInformation {
21-
internal const string Version = "2.5.9.0";
21+
internal const string Version = "2.6.0.0";
2222
}
2323
}

test/GitHub.App.UnitTests/ViewModels/PullRequestReviewCommentThreadViewModelTests.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,15 +111,13 @@ async Task<PullRequestReviewCommentThreadViewModel> CreateTarget(
111111
IViewViewModelFactory factory = null,
112112
IPullRequestSession session = null,
113113
IPullRequestSessionFile file = null,
114-
PullRequestReviewModel review = null,
115114
IEnumerable<InlineCommentModel> comments = null,
116115
bool newThread = false)
117116
{
118117
draftStore = draftStore ?? Substitute.For<IMessageDraftStore>();
119118
factory = factory ?? CreateFactory();
120119
session = session ?? CreateSession();
121120
file = file ?? CreateFile();
122-
review = review ?? new PullRequestReviewModel();
123121
comments = comments ?? CreateComments();
124122

125123
var result = new PullRequestReviewCommentThreadViewModel(draftStore, factory);
@@ -134,7 +132,7 @@ async Task<PullRequestReviewCommentThreadViewModel> CreateTarget(
134132
thread.Comments.Returns(comments.ToList());
135133
thread.LineNumber.Returns(10);
136134

137-
await result.InitializeAsync(session, file, review, thread, true);
135+
await result.InitializeAsync(session, file, thread, true);
138136
}
139137

140138
return result;

0 commit comments

Comments
 (0)