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

Commit 7a69a15

Browse files
Merge pull request #2145 from github/pull-request-status-circle
Adding a Pull Request status circle User Control
2 parents a598422 + 7981d0e commit 7a69a15

File tree

9 files changed

+519
-59
lines changed

9 files changed

+519
-59
lines changed

src/GitHub.App/SampleData/PullRequestListItemViewModelDesigner.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ public class PullRequestListItemViewModelDesigner : ViewModelBase, IPullRequestL
1717
public int Number { get; set; }
1818
public string Title { get; set; }
1919
public DateTimeOffset UpdatedAt { get; set; }
20-
public PullRequestChecksState Checks { get; set; }
20+
public PullRequestChecksSummaryState ChecksSummary { get; set; }
21+
public int ChecksPendingCount { get; set; }
22+
public int ChecksSuccessCount { get; set; }
23+
public int ChecksErrorCount { get; set; }
2124
}
2225
}

src/GitHub.App/Services/PullRequestService.cs

Lines changed: 49 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -223,64 +223,65 @@ public async Task<Page<PullRequestListItemModel>> ReadPullRequests(
223223
item.Reviews = null;
224224

225225
var checkRuns = item.LastCommit?.CheckSuites?.SelectMany(model => model.CheckRuns).ToArray();
226+
var statuses = item.LastCommit?.Statuses;
226227

227-
var hasCheckRuns = checkRuns?.Any() ?? false;
228-
var hasStatuses = item.LastCommit?.Statuses?.Any() ?? false;
228+
var totalCount = 0;
229+
var pendingCount = 0;
230+
var successCount = 0;
231+
var errorCount = 0;
229232

230-
if (!hasCheckRuns && !hasStatuses)
233+
if (checkRuns != null)
231234
{
232-
item.Checks = PullRequestChecksState.None;
235+
totalCount += checkRuns.Length;
236+
237+
pendingCount += checkRuns.Count(model => model.Status != CheckStatusState.Completed);
238+
239+
successCount += checkRuns.Count(model => model.Status == CheckStatusState.Completed &&
240+
model.Conclusion.HasValue &&
241+
(model.Conclusion == CheckConclusionState.Success ||
242+
model.Conclusion == CheckConclusionState.Neutral));
243+
errorCount += checkRuns.Count(model => model.Status == CheckStatusState.Completed &&
244+
model.Conclusion.HasValue &&
245+
!(model.Conclusion == CheckConclusionState.Success ||
246+
model.Conclusion == CheckConclusionState.Neutral));
233247
}
234-
else
235-
{
236-
var checksHasFailure = false;
237-
var checksHasCompleteSuccess = true;
238248

239-
if (hasCheckRuns)
240-
{
241-
checksHasFailure = checkRuns
242-
.Any(model => model.Conclusion.HasValue
243-
&& (model.Conclusion.Value == CheckConclusionState.Failure
244-
|| model.Conclusion.Value == CheckConclusionState.ActionRequired));
249+
if (statuses != null)
250+
{
251+
totalCount += statuses.Count;
245252

246-
if (!checksHasFailure)
247-
{
248-
checksHasCompleteSuccess = checkRuns
249-
.All(model => model.Conclusion.HasValue
250-
&& (model.Conclusion.Value == CheckConclusionState.Success
251-
|| model.Conclusion.Value == CheckConclusionState.Neutral));
252-
}
253-
}
253+
pendingCount += statuses.Count(model =>
254+
model.State == StatusState.Pending || model.State == StatusState.Expected);
254255

255-
var statusHasFailure = false;
256-
var statusHasCompleteSuccess = true;
256+
successCount += statuses.Count(model => model.State == StatusState.Success);
257257

258-
if (!checksHasFailure && hasStatuses)
259-
{
260-
statusHasFailure = item.LastCommit
261-
.Statuses
262-
.Any(status => status.State == StatusState.Failure
263-
|| status.State == StatusState.Error);
258+
errorCount += statuses.Count(model =>
259+
model.State == StatusState.Error || model.State == StatusState.Failure);
260+
}
264261

265-
if (!statusHasFailure)
266-
{
267-
statusHasCompleteSuccess =
268-
item.LastCommit.Statuses.All(status => status.State == StatusState.Success);
269-
}
270-
}
262+
item.ChecksPendingCount = pendingCount;
263+
item.ChecksSuccessCount = successCount;
264+
item.ChecksErrorCount = errorCount;
271265

272-
if (checksHasFailure || statusHasFailure)
273-
{
274-
item.Checks = PullRequestChecksState.Failure;
275-
}
276-
else if (statusHasCompleteSuccess && checksHasCompleteSuccess)
277-
{
278-
item.Checks = PullRequestChecksState.Success;
279-
}
280-
else
281-
{
282-
item.Checks = PullRequestChecksState.Pending;
283-
}
266+
if (totalCount == 0)
267+
{
268+
item.ChecksSummary = PullRequestChecksSummaryState.None;
269+
}
270+
else if (totalCount == pendingCount)
271+
{
272+
item.ChecksSummary = PullRequestChecksSummaryState.Pending;
273+
}
274+
else if (totalCount == successCount)
275+
{
276+
item.ChecksSummary = PullRequestChecksSummaryState.Success;
277+
}
278+
else if (totalCount == errorCount)
279+
{
280+
item.ChecksSummary = PullRequestChecksSummaryState.Failure;
281+
}
282+
else
283+
{
284+
item.ChecksSummary = PullRequestChecksSummaryState.Mixed;
284285
}
285286

286287
item.LastCommit = null;

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

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ public PullRequestListItemViewModel(PullRequestListItemModel model)
1919
{
2020
Id = model.Id;
2121
Author = new ActorViewModel(model.Author);
22-
Checks = model.Checks;
22+
ChecksSummary = model.ChecksSummary;
23+
ChecksErrorCount = model.ChecksErrorCount;
24+
ChecksPendingCount = model.ChecksPendingCount;
25+
ChecksSuccessCount = model.ChecksSuccessCount;
2326
CommentCount = model.CommentCount;
2427
Number = model.Number;
2528
Title = model.Title;
@@ -33,7 +36,16 @@ public PullRequestListItemViewModel(PullRequestListItemModel model)
3336
public IActorViewModel Author { get; }
3437

3538
/// <inheritdoc/>
36-
public PullRequestChecksState Checks { get; }
39+
public PullRequestChecksSummaryState ChecksSummary { get; }
40+
41+
/// <inheritdoc/>
42+
public int ChecksSuccessCount { get; }
43+
44+
/// <inheritdoc/>
45+
public int ChecksPendingCount { get; }
46+
47+
/// <inheritdoc/>
48+
public int ChecksErrorCount { get; }
3749

3850
/// <inheritdoc/>
3951
public int CommentCount { get; }

src/GitHub.Exports.Reactive/ViewModels/GitHubPane/IPullRequestListItemViewModel.cs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,21 @@ public interface IPullRequestListItemViewModel : IIssueListItemViewModelBase
3232
/// <summary>
3333
/// Gets the pull request checks and statuses summary
3434
/// </summary>
35-
PullRequestChecksState Checks { get; }
35+
PullRequestChecksSummaryState ChecksSummary { get; }
36+
37+
/// <summary>
38+
/// Gets the number of pending checks and statuses
39+
/// </summary>
40+
int ChecksPendingCount { get; }
41+
42+
/// <summary>
43+
/// Gets the number of successful checks and statuses
44+
/// </summary>
45+
int ChecksSuccessCount { get; }
46+
47+
/// <summary>
48+
/// Gets the number of erroneous checks and statuses
49+
/// </summary>
50+
int ChecksErrorCount { get; }
3651
}
3752
}

src/GitHub.Exports/Models/IPullRequestModel.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@ public enum PullRequestStateEnum
1313
Merged,
1414
}
1515

16-
public enum PullRequestChecksState
16+
public enum PullRequestChecksSummaryState
1717
{
1818
None,
19+
Mixed,
1920
Pending,
2021
Success,
2122
Failure

src/GitHub.Exports/Models/PullRequestListItemModel.cs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,22 @@ public class PullRequestListItemModel
4040
/// <summary>
4141
/// Gets the pull request checks and statuses summary
4242
/// </summary>
43-
public PullRequestChecksState Checks { get; set; }
43+
public PullRequestChecksSummaryState ChecksSummary { get; set; }
44+
45+
/// <summary>
46+
/// Gets the number of pending checks and statuses
47+
/// </summary>
48+
public int ChecksPendingCount { get; set; }
49+
50+
/// <summary>
51+
/// Gets the number of successful checks and statuses
52+
/// </summary>
53+
public int ChecksSuccessCount { get; set; }
54+
55+
/// <summary>
56+
/// Gets the number of erroneous checks and statuses
57+
/// </summary>
58+
public int ChecksErrorCount { get; set; }
4459

4560
/// <summary>
4661
/// Gets or sets the date/time at which the pull request was last updated.
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<UserControl x:Class="GitHub.VisualStudio.UI.Controls.PullRequestStatusCircle"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
5+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
6+
xmlns:local="clr-namespace:GitHub.VisualStudio.UI.Controls"
7+
mc:Ignorable="d"
8+
d:DesignHeight="250" d:DesignWidth="250">
9+
<Grid>
10+
<Polygon Grid.Row="0" Grid.Column="0" Name="PendingPolygon"
11+
StrokeThickness="0" Fill="Yellow"
12+
Points="0,0 250,0 250,250 0,250">
13+
<Polygon.Clip>
14+
<CombinedGeometry GeometryCombineMode="Exclude">
15+
<CombinedGeometry.Geometry1>
16+
<EllipseGeometry Center="125 125" RadiusX="125" RadiusY="125" />
17+
</CombinedGeometry.Geometry1>
18+
<CombinedGeometry.Geometry2>
19+
<EllipseGeometry Center="125 125" RadiusX="100" RadiusY="100" />
20+
</CombinedGeometry.Geometry2>
21+
</CombinedGeometry>
22+
</Polygon.Clip>
23+
</Polygon>
24+
<Polygon Grid.Row="0" Grid.Column="0" Name="SuccessPolygon"
25+
StrokeThickness="0" Fill="Green"
26+
Points="125,125 125,0 250,0 250,250 0,250 0,216.50635094611">
27+
<Polygon.Clip>
28+
<CombinedGeometry GeometryCombineMode="Exclude">
29+
<CombinedGeometry.Geometry1>
30+
<EllipseGeometry Center="125 125" RadiusX="125" RadiusY="125" />
31+
</CombinedGeometry.Geometry1>
32+
<CombinedGeometry.Geometry2>
33+
<EllipseGeometry Center="125 125" RadiusX="100" RadiusY="100" />
34+
</CombinedGeometry.Geometry2>
35+
</CombinedGeometry>
36+
</Polygon.Clip>
37+
</Polygon>
38+
<Polygon Grid.Row="0" Grid.Column="0" Name="ErrorPolygon"
39+
StrokeThickness="0" Fill="Red"
40+
Points="125,125 125,0 250,0 250,197.168783648703">
41+
<Polygon.Clip>
42+
<CombinedGeometry GeometryCombineMode="Exclude">
43+
<CombinedGeometry.Geometry1>
44+
<EllipseGeometry Center="125 125" RadiusX="125" RadiusY="125" />
45+
</CombinedGeometry.Geometry1>
46+
<CombinedGeometry.Geometry2>
47+
<EllipseGeometry Center="125 125" RadiusX="100" RadiusY="100" />
48+
</CombinedGeometry.Geometry2>
49+
</CombinedGeometry>
50+
</Polygon.Clip>
51+
</Polygon>
52+
</Grid>
53+
</UserControl>

0 commit comments

Comments
 (0)