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

Commit 2603075

Browse files
Using CheckRuns to compute pull request status
1 parent b8345d9 commit 2603075

File tree

5 files changed

+31
-67
lines changed

5 files changed

+31
-67
lines changed

src/GitHub.App/Services/PullRequestService.cs

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,12 @@ public async Task<Page<PullRequestListItemModel>> ReadPullRequests(
103103
CheckSuites = commit.Commit.CheckSuites(null, null, null, null, null).AllPages(10)
104104
.Select(suite => new CheckSuiteSummaryModel
105105
{
106-
Conclusion = (CheckConclusionState?)suite.Conclusion,
107-
Status = (CheckStatusState)suite.Status,
106+
CheckRuns = suite.CheckRuns(null, null, null, null, null).AllPages(10)
107+
.Select(run => new CheckRunSummaryModel
108+
{
109+
Conclusion = (CheckConclusionState?)run.Conclusion,
110+
Status = (CheckStatusState)run.Status
111+
}).ToList()
108112
}).ToList(),
109113
Statuses = commit.Commit.Status
110114
.Select(context =>
@@ -144,15 +148,17 @@ public async Task<Page<PullRequestListItemModel>> ReadPullRequests(
144148

145149
var result = await graphql.Run(readPullRequests, vars);
146150

147-
foreach (ListItemAdapter item in result.Items)
151+
foreach (var item in result.Items.Cast<ListItemAdapter>())
148152
{
149153
item.CommentCount += item.Reviews.Sum(x => x.Count);
150154
item.Reviews = null;
151155

152-
var hasCheckSuites = item.LastCommit?.CheckSuites.Any() ?? false;
156+
var checkRuns = item.LastCommit?.CheckSuites.SelectMany(model => model.CheckRuns).ToArray();
157+
158+
var hasCheckRuns = checkRuns?.Any() ?? false;
153159
var hasStatuses = item.LastCommit?.Statuses.Any() ?? false;
154160

155-
if (!hasCheckSuites && !hasStatuses)
161+
if (!hasCheckRuns && !hasStatuses)
156162
{
157163
item.Checks = PullRequestChecksState.None;
158164
}
@@ -161,19 +167,19 @@ public async Task<Page<PullRequestListItemModel>> ReadPullRequests(
161167
var checksHasFailure = false;
162168
var checksHasCompleteSuccess = true;
163169

164-
if (hasCheckSuites)
170+
if (hasCheckRuns)
165171
{
166-
checksHasFailure = item.LastCommit
167-
.CheckSuites.Any(model => model.Conclusion.HasValue
168-
&& (model.Conclusion.Value == CheckConclusionState.Failure
169-
|| model.Conclusion.Value == CheckConclusionState.ActionRequired));
172+
checksHasFailure = checkRuns
173+
.Any(model => model.Conclusion.HasValue
174+
&& (model.Conclusion.Value == CheckConclusionState.Failure
175+
|| model.Conclusion.Value == CheckConclusionState.ActionRequired));
170176

171177
if (!checksHasFailure)
172178
{
173-
checksHasCompleteSuccess = item.LastCommit
174-
.CheckSuites.All(model => model.Conclusion.HasValue
175-
&& (model.Conclusion.Value == CheckConclusionState.Success
176-
|| model.Conclusion.Value == CheckConclusionState.Neutral));
179+
checksHasCompleteSuccess = checkRuns
180+
.All(model => model.Conclusion.HasValue
181+
&& (model.Conclusion.Value == CheckConclusionState.Success
182+
|| model.Conclusion.Value == CheckConclusionState.Neutral));
177183
}
178184
}
179185

@@ -942,11 +948,6 @@ class ReviewAdapter
942948
public int Count => CommentCount + (!string.IsNullOrWhiteSpace(Body) ? 1 : 0);
943949
}
944950

945-
class StatusSummaryModel
946-
{
947-
public StatusState State { get; set; }
948-
}
949-
950951
class LastCommitSummaryModel
951952
{
952953
public List<CheckSuiteSummaryModel> CheckSuites { get; set; }
@@ -956,9 +957,18 @@ class LastCommitSummaryModel
956957

957958
class CheckSuiteSummaryModel
958959
{
959-
public CheckConclusionState? Conclusion { get; set; }
960+
public List<CheckRunSummaryModel> CheckRuns { get; set; }
961+
}
960962

963+
class CheckRunSummaryModel
964+
{
965+
public CheckConclusionState? Conclusion { get; set; }
961966
public CheckStatusState Status { get; set; }
962967
}
968+
969+
class StatusSummaryModel
970+
{
971+
public StatusState State { get; set; }
972+
}
963973
}
964974
}

src/GitHub.Exports/Models/CheckRunModel.cs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,11 @@ public class CheckRunModel
1616
/// </summary>
1717
public CheckStatusState Status { get; set; }
1818

19-
/// <summary>
20-
/// Identifies the date and time when the check run was started.
21-
/// </summary>
22-
public DateTimeOffset? StartedAt { get; set; }
23-
2419
/// <summary>
2520
/// Identifies the date and time when the check run was completed.
2621
/// </summary>
2722
public DateTimeOffset? CompletedAt { get; set; }
2823

29-
/// <summary>The check run's annotations.</summary>
30-
public List<CheckRunAnnotationModel> Annotations { get; set; }
31-
3224
/// <summary>The name of the check for this check run.</summary>
3325
public string Name { get; set; }
3426

src/GitHub.Exports/Models/CheckSuiteModel.cs

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,6 @@ namespace GitHub.Models
88
/// </summary>
99
public class CheckSuiteModel
1010
{
11-
/// <summary>
12-
/// The conclusion of this check suite.
13-
/// </summary>
14-
public CheckConclusionState? Conclusion { get; set; }
15-
16-
/// <summary>
17-
/// The status of this check suite.
18-
/// </summary>
19-
public CheckStatusState Status { get; set; }
20-
21-
/// <summary>
22-
/// Identifies the date and time when the object was created.
23-
/// </summary>
24-
public DateTimeOffset CreatedAt { get; set; }
25-
26-
/// <summary>
27-
/// Identifies the date and time when the object was last updated.
28-
/// </summary>
29-
public DateTimeOffset UpdatedAt { get; set; }
30-
3111
/// <summary>
3212
/// The check runs associated with a check suite.
3313
/// </summary>

src/GitHub.Exports/Models/StatusModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
namespace GitHub.Models
22
{
33
/// <summary>
4-
/// Holds details about a pull request Status
4+
/// Model for a single pull request Status.
55
/// </summary>
66
public class StatusModel
77
{

src/GitHub.InlineReviews/Services/PullRequestSessionService.cs

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -757,10 +757,6 @@ async Task<LastCommitAdapter> GetPullRequestLastCommitAdapter(HostAddress addres
757757
CheckSuites = commit.Commit.CheckSuites(null, null, null, null, null).AllPages(10)
758758
.Select(suite => new CheckSuiteModel
759759
{
760-
Conclusion = (CheckConclusionState?) suite.Conclusion,
761-
Status = (CheckStatusState) suite.Status,
762-
CreatedAt = suite.CreatedAt,
763-
UpdatedAt = suite.UpdatedAt,
764760
CheckRuns = suite.CheckRuns(null, null, null, null, null).AllPages(10)
765761
.Select(run => new CheckRunModel
766762
{
@@ -769,20 +765,6 @@ async Task<LastCommitAdapter> GetPullRequestLastCommitAdapter(HostAddress addres
769765
Name = run.Name,
770766
DetailsUrl = run.Permalink,
771767
Summary = run.Summary,
772-
StartedAt = run.StartedAt,
773-
CompletedAt = run.CompletedAt,
774-
Annotations = run.Annotations(null, null, null, null).AllPages()
775-
.Select(annotation => new CheckRunAnnotationModel
776-
{
777-
BlobUrl = annotation.BlobUrl,
778-
StartLine = annotation.Location.Start.Line,
779-
EndLine = annotation.Location.End.Line,
780-
Filename = annotation.Path,
781-
Message = annotation.Message,
782-
Title = annotation.Title,
783-
AnnotationLevel = (CheckAnnotationLevel?) annotation.AnnotationLevel,
784-
RawDetails = annotation.RawDetails
785-
}).ToList()
786768
}).ToList()
787769
}).ToList(),
788770
Statuses = commit.Commit.Status

0 commit comments

Comments
 (0)