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

Commit aefe19b

Browse files
Functionality to display the cirlce for non uniform states
1 parent 2526f55 commit aefe19b

File tree

8 files changed

+83
-66
lines changed

8 files changed

+83
-66
lines changed

src/GitHub.App/SampleData/PullRequestListItemViewModelDesigner.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ 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; }
2121
public int ChecksPendingCount { get; set; }
2222
public int ChecksSuccessCount { get; set; }
2323
public int ChecksErrorCount { get; set; }

src/GitHub.App/Services/PullRequestService.cs

Lines changed: 26 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -219,71 +219,15 @@ public async Task<Page<PullRequestListItemModel>> ReadPullRequests(
219219
var checkRuns = item.LastCommit?.CheckSuites?.SelectMany(model => model.CheckRuns).ToArray();
220220
var statuses = item.LastCommit?.Statuses;
221221

222-
var hasCheckRuns = checkRuns?.Any() ?? false;
223-
var hasStatuses = statuses?.Any() ?? false;
224-
225-
if (!hasCheckRuns && !hasStatuses)
226-
{
227-
item.Checks = PullRequestChecksState.None;
228-
}
229-
else
230-
{
231-
var checksHasFailure = false;
232-
var checksHasCompleteSuccess = true;
233-
234-
if (hasCheckRuns)
235-
{
236-
checksHasFailure = checkRuns
237-
.Any(model => model.Conclusion.HasValue
238-
&& (model.Conclusion.Value == CheckConclusionState.Failure
239-
|| model.Conclusion.Value == CheckConclusionState.ActionRequired));
240-
241-
if (!checksHasFailure)
242-
{
243-
checksHasCompleteSuccess = checkRuns
244-
.All(model => model.Conclusion.HasValue
245-
&& (model.Conclusion.Value == CheckConclusionState.Success
246-
|| model.Conclusion.Value == CheckConclusionState.Neutral));
247-
}
248-
}
249-
250-
var statusHasFailure = false;
251-
var statusHasCompleteSuccess = true;
252-
253-
if (!checksHasFailure && hasStatuses)
254-
{
255-
statusHasFailure = item.LastCommit
256-
.Statuses
257-
.Any(status => status.State == StatusState.Failure
258-
|| status.State == StatusState.Error);
259-
260-
if (!statusHasFailure)
261-
{
262-
statusHasCompleteSuccess =
263-
item.LastCommit.Statuses.All(status => status.State == StatusState.Success);
264-
}
265-
}
266-
267-
if (checksHasFailure || statusHasFailure)
268-
{
269-
item.Checks = PullRequestChecksState.Failure;
270-
}
271-
else if (statusHasCompleteSuccess && checksHasCompleteSuccess)
272-
{
273-
item.Checks = PullRequestChecksState.Success;
274-
}
275-
else
276-
{
277-
item.Checks = PullRequestChecksState.Pending;
278-
}
279-
}
280-
222+
var totalCount = 0;
281223
var pendingCount = 0;
282224
var successCount = 0;
283225
var errorCount = 0;
284226

285227
if (checkRuns != null)
286228
{
229+
totalCount += checkRuns.Length;
230+
287231
pendingCount += checkRuns.Count(model => model.Status != CheckStatusState.Completed);
288232

289233
successCount += checkRuns.Count(model => model.Status == CheckStatusState.Completed &&
@@ -298,6 +242,8 @@ public async Task<Page<PullRequestListItemModel>> ReadPullRequests(
298242

299243
if (statuses != null)
300244
{
245+
totalCount += statuses.Count;
246+
301247
pendingCount += statuses.Count(model =>
302248
model.State == StatusState.Pending || model.State == StatusState.Expected);
303249

@@ -311,6 +257,27 @@ public async Task<Page<PullRequestListItemModel>> ReadPullRequests(
311257
item.ChecksSuccessCount = successCount;
312258
item.ChecksErrorCount = errorCount;
313259

260+
if (totalCount == 0)
261+
{
262+
item.ChecksSummary = PullRequestChecksSummaryState.None;
263+
}
264+
else if (totalCount == pendingCount)
265+
{
266+
item.ChecksSummary = PullRequestChecksSummaryState.Pending;
267+
}
268+
else if (totalCount == successCount)
269+
{
270+
item.ChecksSummary = PullRequestChecksSummaryState.Success;
271+
}
272+
else if (totalCount == errorCount)
273+
{
274+
item.ChecksSummary = PullRequestChecksSummaryState.Failure;
275+
}
276+
else
277+
{
278+
item.ChecksSummary = PullRequestChecksSummaryState.Mixed;
279+
}
280+
314281
item.LastCommit = null;
315282
}
316283

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public PullRequestListItemViewModel(PullRequestListItemModel model)
1919
{
2020
Id = model.Id;
2121
Author = new ActorViewModel(model.Author);
22-
Checks = model.Checks;
22+
ChecksSummary = model.ChecksSummary;
2323
ChecksErrorCount = model.ChecksErrorCount;
2424
ChecksPendingCount = model.ChecksPendingCount;
2525
ChecksSuccessCount = model.ChecksSuccessCount;
@@ -36,7 +36,7 @@ public PullRequestListItemViewModel(PullRequestListItemModel model)
3636
public IActorViewModel Author { get; }
3737

3838
/// <inheritdoc/>
39-
public PullRequestChecksState Checks { get; }
39+
public PullRequestChecksSummaryState ChecksSummary { get; }
4040

4141
/// <inheritdoc/>
4242
public int ChecksSuccessCount { get; }

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ 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; }
3636

3737
/// <summary>
3838
/// Gets the number of pending checks and statuses

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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ 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; }
4444

4545
/// <summary>
4646
/// Gets the number of pending checks and statuses

src/GitHub.VisualStudio.UI/UI/Controls/PullRequestStatusCircle.xaml.cs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,18 @@ public partial class PullRequestStatusCircle : UserControl
4141
"InnerRadius", typeof(double), typeof(PullRequestStatusCircle),
4242
new PropertyMetadata((double)200, (d, args) => ((PullRequestStatusCircle)d).InnerRadius = (double)args.NewValue));
4343

44+
public static readonly DependencyProperty PendingColorProperty = DependencyProperty.Register(
45+
"PendingColor", typeof(Brush), typeof(PullRequestStatusCircle),
46+
new PropertyMetadata(Brushes.Yellow, (d, args) => ((PullRequestStatusCircle)d).PendingColor = (Brush)args.NewValue));
47+
48+
public static readonly DependencyProperty ErrorColorProperty = DependencyProperty.Register(
49+
"ErrorColor", typeof(Brush), typeof(PullRequestStatusCircle),
50+
new PropertyMetadata(Brushes.Red, (d, args) => ((PullRequestStatusCircle)d).ErrorColor = (Brush)args.NewValue));
51+
52+
public static readonly DependencyProperty SuccessColorProperty = DependencyProperty.Register(
53+
"SuccessColor", typeof(Brush), typeof(PullRequestStatusCircle),
54+
new PropertyMetadata(Brushes.Green, (d, args) => ((PullRequestStatusCircle)d).SuccessColor = (Brush)args.NewValue));
55+
4456
public IEnumerable<Point> GeneratePoints(float percentage)
4557
{
4658
double ToRadians(float val)
@@ -242,6 +254,36 @@ public double InnerRadius
242254
}
243255
}
244256

257+
public Brush PendingColor
258+
{
259+
get => (Brush)GetValue(PendingColorProperty);
260+
set
261+
{
262+
SetValue(PendingColorProperty, value);
263+
PendingPolygon.Fill = value;
264+
}
265+
}
266+
267+
public Brush ErrorColor
268+
{
269+
get => (Brush)GetValue(ErrorColorProperty);
270+
set
271+
{
272+
SetValue(ErrorColorProperty, value);
273+
ErrorPolygon.Fill = value;
274+
}
275+
}
276+
277+
public Brush SuccessColor
278+
{
279+
get => (Brush)GetValue(SuccessColorProperty);
280+
set
281+
{
282+
SetValue(SuccessColorProperty, value);
283+
SuccessPolygon.Fill = value;
284+
}
285+
}
286+
245287
protected override void OnRenderSizeChanged(SizeChangedInfo sizeInfo)
246288
{
247289
base.OnRenderSizeChanged(sizeInfo);

src/GitHub.VisualStudio.UI/Views/GitHubPane/PullRequestListItemView.xaml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
CommentCount="4"
1515
IsCurrent="True"
1616
UpdatedAt="2018-01-29"
17-
Checks="Success">
17+
ChecksSummary="Success">
1818
<ghfvs:PullRequestListItemViewModelDesigner.Author>
1919
<ghfvs:ActorViewModelDesigner Login="shana"/>
2020
</ghfvs:PullRequestListItemViewModelDesigner.Author>
@@ -99,12 +99,19 @@
9999
<TextBlock Opacity="0.5" HorizontalAlignment="Right" VerticalAlignment="Center" Margin="0 0 4 0" Visibility="{Binding CommentCount, Converter={ghfvs:CountToVisibilityConverter}}"> <ghfvs:OcticonImage Icon="comment" Width="12" Height="12" Margin="0 0 0 -2"/>
100100
<Run Text="{Binding CommentCount, Mode=OneWay}" BaselineAlignment="Bottom"/>
101101
</TextBlock>
102+
<ghfvs:OcticonImage Icon="check" Foreground="#2cbe4e" Visibility="{Binding ChecksSummary, Converter={ghfvs:EqualsToVisibilityConverter Success}}"/>
103+
<ghfvs:OcticonImage Icon="x" Foreground="#cb2431" Visibility="{Binding ChecksSummary, Converter={ghfvs:EqualsToVisibilityConverter Failure}}"/>
104+
<ghfvs:OcticonImage Icon="primitive_dot" Foreground="#f1c647" Visibility="{Binding ChecksSummary, Converter={ghfvs:EqualsToVisibilityConverter Pending}}"/>
102105
<controls:PullRequestStatusCircle
103106
Height="18" Width="18"
104107
Radius="8" InnerRadius="3"
108+
Visibility="{Binding ChecksSummary, Converter={ghfvs:EqualsToVisibilityConverter Mixed}}"
105109
PendingCount="{Binding ChecksPendingCount}"
110+
PendingColor="#f1c647"
106111
ErrorCount="{Binding ChecksErrorCount}"
112+
ErrorColor="#cb2431"
107113
SuccessCount="{Binding ChecksSuccessCount}"
114+
SuccessColor="#2cbe4e"
108115
/>
109116
</StackPanel>
110117
</Grid>

0 commit comments

Comments
 (0)