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

Commit f20e874

Browse files
Attempting to create a pull request status circle
1 parent 5722b18 commit f20e874

File tree

8 files changed

+375
-5
lines changed

8 files changed

+375
-5
lines changed

src/GitHub.App/SampleData/PullRequestListItemViewModelDesigner.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,8 @@ public class PullRequestListItemViewModelDesigner : ViewModelBase, IPullRequestL
1818
public string Title { get; set; }
1919
public DateTimeOffset UpdatedAt { get; set; }
2020
public PullRequestChecksState Checks { 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: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,9 +217,10 @@ public async Task<Page<PullRequestListItemModel>> ReadPullRequests(
217217
item.Reviews = null;
218218

219219
var checkRuns = item.LastCommit?.CheckSuites?.SelectMany(model => model.CheckRuns).ToArray();
220+
var statuses = item.LastCommit?.Statuses;
220221

221222
var hasCheckRuns = checkRuns?.Any() ?? false;
222-
var hasStatuses = item.LastCommit?.Statuses?.Any() ?? false;
223+
var hasStatuses = statuses?.Any() ?? false;
223224

224225
if (!hasCheckRuns && !hasStatuses)
225226
{
@@ -277,6 +278,39 @@ public async Task<Page<PullRequestListItemModel>> ReadPullRequests(
277278
}
278279
}
279280

281+
var pendingCount = 0;
282+
var successCount = 0;
283+
var errorCount = 0;
284+
285+
if (checkRuns != null)
286+
{
287+
pendingCount += checkRuns.Count(model => model.Status != CheckStatusState.Completed);
288+
289+
successCount += checkRuns.Count(model => model.Status == CheckStatusState.Completed &&
290+
model.Conclusion.HasValue &&
291+
(model.Conclusion == CheckConclusionState.Success ||
292+
model.Conclusion == CheckConclusionState.Neutral));
293+
errorCount += checkRuns.Count(model => model.Status == CheckStatusState.Completed &&
294+
model.Conclusion.HasValue &&
295+
!(model.Conclusion == CheckConclusionState.Success ||
296+
model.Conclusion == CheckConclusionState.Neutral));
297+
}
298+
299+
if (statuses != null)
300+
{
301+
pendingCount += statuses.Count(model =>
302+
model.State == StatusState.Pending || model.State == StatusState.Expected);
303+
304+
successCount += statuses.Count(model => model.State == StatusState.Success);
305+
306+
errorCount += statuses.Count(model =>
307+
model.State == StatusState.Error || model.State == StatusState.Failure);
308+
}
309+
310+
item.ChecksPendingCount = pendingCount;
311+
item.ChecksSuccessCount = successCount;
312+
item.ChecksErrorCount = errorCount;
313+
280314
item.LastCommit = null;
281315
}
282316

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ public PullRequestListItemViewModel(PullRequestListItemModel model)
2020
Id = model.Id;
2121
Author = new ActorViewModel(model.Author);
2222
Checks = model.Checks;
23+
ChecksErrorCount = model.ChecksErrorCount;
24+
ChecksPendingCount = model.ChecksPendingCount;
25+
ChecksSuccessCount = model.ChecksSuccessCount;
2326
CommentCount = model.CommentCount;
2427
Number = model.Number;
2528
Title = model.Title;
@@ -35,6 +38,15 @@ public PullRequestListItemViewModel(PullRequestListItemModel model)
3538
/// <inheritdoc/>
3639
public PullRequestChecksState Checks { get; }
3740

41+
/// <inheritdoc/>
42+
public int ChecksSuccessCount { get; }
43+
44+
/// <inheritdoc/>
45+
public int ChecksPendingCount { get; }
46+
47+
/// <inheritdoc/>
48+
public int ChecksErrorCount { get; }
49+
3850
/// <inheritdoc/>
3951
public int CommentCount { get; }
4052

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,20 @@ public interface IPullRequestListItemViewModel : IIssueListItemViewModelBase
3333
/// Gets the pull request checks and statuses summary
3434
/// </summary>
3535
PullRequestChecksState Checks { 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/PullRequestListItemModel.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,21 @@ public class PullRequestListItemModel
4242
/// </summary>
4343
public PullRequestChecksState Checks { get; set; }
4444

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; }
59+
4560
/// <summary>
4661
/// Gets or sets the date/time at which the pull request was last updated.
4762
/// </summary>
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<UserControl x:Class="GitHub.VisualStudio.UI.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.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+
Width="{Binding ActualWidth, RelativeSource={RelativeSource AncestorType=Grid}}"
12+
Height="{Binding ActualWidth, RelativeSource={RelativeSource AncestorType=Grid}}"
13+
StrokeThickness="0" Fill="Yellow"
14+
Points="0,0 250,0 250,250 0,250">
15+
<Polygon.Clip>
16+
<CombinedGeometry GeometryCombineMode="Exclude">
17+
<CombinedGeometry.Geometry1>
18+
<EllipseGeometry Center="125 125" RadiusX="125" RadiusY="125" />
19+
</CombinedGeometry.Geometry1>
20+
<CombinedGeometry.Geometry2>
21+
<EllipseGeometry Center="125 125" RadiusX="100" RadiusY="100" />
22+
</CombinedGeometry.Geometry2>
23+
</CombinedGeometry>
24+
</Polygon.Clip>
25+
</Polygon>
26+
<Polygon Grid.Row="0" Grid.Column="0" Name="SuccessPolygon"
27+
Width="{Binding ActualWidth, RelativeSource={RelativeSource AncestorType=Grid}}"
28+
Height="{Binding ActualWidth, RelativeSource={RelativeSource AncestorType=Grid}}"
29+
StrokeThickness="0" Fill="Green"
30+
Points="125,125 125,0 250,0 250,250 0,250 0,216.50635094611">
31+
<Polygon.Clip>
32+
<CombinedGeometry GeometryCombineMode="Exclude">
33+
<CombinedGeometry.Geometry1>
34+
<EllipseGeometry Center="125 125" RadiusX="125" RadiusY="125" />
35+
</CombinedGeometry.Geometry1>
36+
<CombinedGeometry.Geometry2>
37+
<EllipseGeometry Center="125 125" RadiusX="100" RadiusY="100" />
38+
</CombinedGeometry.Geometry2>
39+
</CombinedGeometry>
40+
</Polygon.Clip>
41+
</Polygon>
42+
<Polygon Grid.Row="0" Grid.Column="0" Name="ErrorPolygon"
43+
Width="{Binding ActualWidth, RelativeSource={RelativeSource AncestorType=Grid}}"
44+
Height="{Binding ActualWidth, RelativeSource={RelativeSource AncestorType=Grid}}"
45+
StrokeThickness="0" Fill="Red"
46+
Points="125,125 125,0 250,0 250,197.168783648703">
47+
<Polygon.Clip>
48+
<CombinedGeometry GeometryCombineMode="Exclude">
49+
<CombinedGeometry.Geometry1>
50+
<EllipseGeometry Center="125 125" RadiusX="125" RadiusY="125" />
51+
</CombinedGeometry.Geometry1>
52+
<CombinedGeometry.Geometry2>
53+
<EllipseGeometry Center="125 125" RadiusX="100" RadiusY="100" />
54+
</CombinedGeometry.Geometry2>
55+
</CombinedGeometry>
56+
</Polygon.Clip>
57+
</Polygon>
58+
</Grid>
59+
</UserControl>

0 commit comments

Comments
 (0)