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

Commit 785bc44

Browse files
authored
Merge branch 'master' into fixes/1832-explicit-github-and-enterprise-gists
2 parents dd2609d + a119e89 commit 785bc44

37 files changed

+765
-60
lines changed

src/GitHub.App/GitHub.App.csproj

Lines changed: 3 additions & 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" />
@@ -257,6 +258,7 @@
257258
<Compile Include="ViewModels\GitHubPane\LoggedOutViewModel.cs" />
258259
<Compile Include="ViewModels\GitHubPane\NavigationViewModel.cs" />
259260
<Compile Include="ViewModels\GitHubPane\GitHubPaneViewModel.cs" />
261+
<Compile Include="SampleData\PullRequestCheckViewModelDesigner.cs" />
260262
<Compile Include="ViewModels\GitHubPane\PullRequestFilesViewModel.cs" />
261263
<Compile Include="ViewModels\GitHubPane\PullRequestListItemViewModel.cs" />
262264
<Compile Include="ViewModels\GitHubPane\PullRequestListViewModel.cs" />
@@ -267,6 +269,7 @@
267269
<Compile Include="ViewModels\GitHubPane\NotAGitRepositoryViewModel.cs" />
268270
<Compile Include="ViewModels\GitHubPane\PullRequestReviewAuthoringViewModel.cs" />
269271
<Compile Include="ViewModels\GitHubPane\PullRequestReviewCommentViewModel.cs" />
272+
<Compile Include="ViewModels\GitHubPane\PullRequestCheckViewModel.cs" />
270273
<Compile Include="ViewModels\GitHubPane\PullRequestReviewSummaryViewModel.cs" />
271274
<Compile Include="ViewModels\GitHubPane\PullRequestReviewViewModel.cs" />
272275
<Compile Include="ViewModels\GitHubPane\PullRequestUserReviewsViewModel.cs" />

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>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using System;
2+
using System.Windows.Media.Imaging;
3+
using GitHub.ViewModels;
4+
using GitHub.ViewModels.GitHubPane;
5+
using ReactiveUI;
6+
7+
namespace GitHub.SampleData
8+
{
9+
public sealed class PullRequestCheckViewModelDesigner : ViewModelBase, IPullRequestCheckViewModel
10+
{
11+
public string Title { get; set; } = "continuous-integration/appveyor/pr";
12+
13+
public string Description { get; set; } = "AppVeyor build failed";
14+
15+
public PullRequestCheckStatus Status { get; set; } = PullRequestCheckStatus.Failure;
16+
17+
public Uri DetailsUrl { get; set; } = new Uri("http://github.com");
18+
19+
public string AvatarUrl { get; set; } = "https://avatars1.githubusercontent.com/u/417571?s=88&v=4";
20+
21+
public BitmapImage Avatar { get; set; } = null;
22+
23+
public ReactiveCommand<object> OpenDetailsUrl { get; set; } = null;
24+
}
25+
}

src/GitHub.App/SampleData/PullRequestDetailViewModelDesigner.cs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Diagnostics.CodeAnalysis;
4-
using System.Reactive;
5-
using System.Text;
6-
using System.Threading.Tasks;
71
using GitHub.Models;
82
using GitHub.Services;
93
using GitHub.ViewModels;
104
using GitHub.ViewModels.GitHubPane;
115
using ReactiveUI;
6+
using System;
7+
using System.Collections.Generic;
8+
using System.Diagnostics.CodeAnalysis;
9+
using System.Reactive;
10+
using System.Threading.Tasks;
11+
using GitHub.SampleData;
1212

1313
namespace GitHub.SampleData
1414
{
@@ -95,6 +95,8 @@ public PullRequestDetailViewModelDesigner()
9595
};
9696

9797
Files = new PullRequestFilesViewModelDesigner();
98+
99+
Checks = new PullRequestCheckViewModelDesigner[0];
98100
}
99101

100102
public PullRequestDetailModel Model { get; }
@@ -123,6 +125,8 @@ public PullRequestDetailViewModelDesigner()
123125
public ReactiveCommand<object> OpenOnGitHub { get; }
124126
public ReactiveCommand<object> ShowReview { get; }
125127

128+
public IReadOnlyList<IPullRequestCheckViewModel> Checks { get; }
129+
126130
public Task InitializeAsync(ILocalRepositoryModel localRepository, IConnection connection, string owner, string repo, int number) => Task.CompletedTask;
127131

128132
public string GetLocalFilePath(IPullRequestFileNode file)

src/GitHub.App/SampleData/PullRequestListItemViewModelDesigner.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Diagnostics.CodeAnalysis;
4+
using GitHub.Models;
45
using GitHub.ViewModels;
56
using GitHub.ViewModels.GitHubPane;
67

@@ -16,5 +17,6 @@ public class PullRequestListItemViewModelDesigner : ViewModelBase, IPullRequestL
1617
public int Number { get; set; }
1718
public string Title { get; set; }
1819
public DateTimeOffset UpdatedAt { get; set; }
20+
public PullRequestChecksState Checks { get; set; }
1921
}
2022
}

src/GitHub.App/Services/PullRequestService.cs

Lines changed: 72 additions & 1 deletion
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;
@@ -22,6 +23,7 @@
2223
using Rothko;
2324
using static System.FormattableString;
2425
using static Octokit.GraphQL.Variable;
26+
using StatusState = GitHub.Models.StatusState;
2527

2628
namespace GitHub.Services
2729
{
@@ -93,6 +95,17 @@ public async Task<Page<PullRequestListItemModel>> ReadPullRequests(
9395
Items = page.Nodes.Select(pr => new ListItemAdapter
9496
{
9597
Id = pr.Id.Value,
98+
LastCommit = pr.Commits(null, null, 1, null).Nodes.Select(commit =>
99+
new LastCommitSummaryModel
100+
{
101+
Statuses = commit.Commit.Status
102+
.Select(context =>
103+
context.Contexts.Select(statusContext => new StatusSummaryModel
104+
{
105+
State = (StatusState)statusContext.State,
106+
}).ToList()
107+
).SingleOrDefault()
108+
}).ToList().FirstOrDefault(),
96109
Author = new ActorModel
97110
{
98111
Login = pr.Author.Login,
@@ -123,10 +136,46 @@ public async Task<Page<PullRequestListItemModel>> ReadPullRequests(
123136

124137
var result = await graphql.Run(readPullRequests, vars);
125138

126-
foreach (ListItemAdapter item in result.Items)
139+
foreach (var item in result.Items.Cast<ListItemAdapter>())
127140
{
128141
item.CommentCount += item.Reviews.Sum(x => x.Count);
129142
item.Reviews = null;
143+
144+
var hasStatuses = item.LastCommit.Statuses != null
145+
&& item.LastCommit.Statuses.Any();
146+
147+
if (!hasStatuses)
148+
{
149+
item.Checks = PullRequestChecksState.None;
150+
}
151+
else
152+
{
153+
var statusHasFailure = item.LastCommit
154+
.Statuses
155+
.Any(status => status.State == StatusState.Failure);
156+
157+
var statusHasCompleteSuccess = true;
158+
if (!statusHasFailure)
159+
{
160+
statusHasCompleteSuccess =
161+
item.LastCommit.Statuses.All(status => status.State == StatusState.Success);
162+
}
163+
164+
if (statusHasFailure)
165+
{
166+
item.Checks = PullRequestChecksState.Failure;
167+
}
168+
else if (statusHasCompleteSuccess)
169+
{
170+
item.Checks = PullRequestChecksState.Success;
171+
}
172+
else
173+
{
174+
item.Checks = PullRequestChecksState.Pending;
175+
}
176+
}
177+
178+
item.LastCommit = null;
130179
}
131180

132181
return result;
@@ -666,6 +715,16 @@ public IObservable<Unit> RemoveUnusedRemotes(ILocalRepositoryModel repository)
666715
});
667716
}
668717

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+
669728
async Task<string> CreateRemote(IRepository repo, UriString cloneUri)
670729
{
671730
foreach (var remote in repo.Network.Remotes)
@@ -840,6 +899,8 @@ static Tuple<string, int> ParseGHfVSConfigKeyValue(string value)
840899
class ListItemAdapter : PullRequestListItemModel
841900
{
842901
public IList<ReviewAdapter> Reviews { get; set; }
902+
903+
public LastCommitSummaryModel LastCommit { get; set; }
843904
}
844905

845906
class ReviewAdapter
@@ -848,5 +909,15 @@ class ReviewAdapter
848909
public int CommentCount { get; set; }
849910
public int Count => CommentCount + (!string.IsNullOrWhiteSpace(Body) ? 1 : 0);
850911
}
912+
913+
class StatusSummaryModel
914+
{
915+
public StatusState State { get; set; }
916+
}
917+
918+
class LastCommitSummaryModel
919+
{
920+
public List<StatusSummaryModel> Statuses { get; set; }
921+
}
851922
}
852923
}
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.ComponentModel.Composition;
4+
using System.Linq;
5+
using System.Reactive;
6+
using System.Reactive.Linq;
7+
using System.Windows.Media.Imaging;
8+
using GitHub.Extensions;
9+
using GitHub.Factories;
10+
using GitHub.Models;
11+
using GitHub.Services;
12+
using ReactiveUI;
13+
14+
namespace GitHub.ViewModels.GitHubPane
15+
{
16+
[Export(typeof(IPullRequestCheckViewModel))]
17+
[PartCreationPolicy(CreationPolicy.NonShared)]
18+
public class PullRequestCheckViewModel: ViewModelBase, IPullRequestCheckViewModel
19+
{
20+
private readonly IUsageTracker usageTracker;
21+
const string DefaultAvatar = "pack://application:,,,/GitHub.App;component/Images/default_user_avatar.png";
22+
23+
public static IEnumerable<IPullRequestCheckViewModel> Build(IViewViewModelFactory viewViewModelFactory, PullRequestDetailModel pullRequest)
24+
{
25+
return pullRequest.Statuses?.Select(model =>
26+
{
27+
PullRequestCheckStatus checkStatus;
28+
switch (model.State)
29+
{
30+
case StatusState.Expected:
31+
case StatusState.Error:
32+
case StatusState.Failure:
33+
checkStatus = PullRequestCheckStatus.Failure;
34+
break;
35+
case StatusState.Pending:
36+
checkStatus = PullRequestCheckStatus.Pending;
37+
break;
38+
case StatusState.Success:
39+
checkStatus = PullRequestCheckStatus.Success;
40+
break;
41+
default:
42+
throw new InvalidOperationException("Unkown PullRequestCheckStatusEnum");
43+
}
44+
45+
var pullRequestCheckViewModel = (PullRequestCheckViewModel) viewViewModelFactory.CreateViewModel<IPullRequestCheckViewModel>();
46+
pullRequestCheckViewModel.Title = model.Context;
47+
pullRequestCheckViewModel.Description = model.Description;
48+
pullRequestCheckViewModel.Status = checkStatus;
49+
pullRequestCheckViewModel.DetailsUrl = new Uri(model.TargetUrl);
50+
pullRequestCheckViewModel.AvatarUrl = model.AvatarUrl ?? DefaultAvatar;
51+
pullRequestCheckViewModel.Avatar = model.AvatarUrl != null
52+
? new BitmapImage(new Uri(model.AvatarUrl))
53+
: AvatarProvider.CreateBitmapImage(DefaultAvatar);
54+
55+
return pullRequestCheckViewModel;
56+
57+
}) ?? new PullRequestCheckViewModel[0];
58+
}
59+
60+
[ImportingConstructor]
61+
public PullRequestCheckViewModel(IUsageTracker usageTracker)
62+
{
63+
this.usageTracker = usageTracker;
64+
OpenDetailsUrl = ReactiveCommand.Create().OnExecuteCompleted(DoOpenDetailsUrl);
65+
}
66+
67+
private void DoOpenDetailsUrl(object obj)
68+
{
69+
usageTracker.IncrementCounter(x => x.NumberOfPRCheckStatusesOpenInGitHub).Forget();
70+
}
71+
72+
public string Title { get; private set; }
73+
74+
public string Description { get; private set; }
75+
76+
public PullRequestCheckStatus Status{ get; private set; }
77+
78+
public Uri DetailsUrl { get; private set; }
79+
80+
public string AvatarUrl { get; private set; }
81+
82+
public BitmapImage Avatar { get; private set; }
83+
84+
public ReactiveCommand<object> OpenDetailsUrl { get; }
85+
}
86+
}

0 commit comments

Comments
 (0)