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

Commit c2d2cee

Browse files
Revert "Removing functionality to read CheckSuites"
This reverts commit b086078.
1 parent bade798 commit c2d2cee

26 files changed

+343
-37
lines changed

lib/Octokit.GraphQL.0.1.1-beta.nupkg

182 KB
Binary file not shown.

src/GitHub.Api/GitHub.Api.csproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,11 @@
5050
<Reference Include="Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
5151
<HintPath>..\..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
5252
</Reference>
53-
<Reference Include="Octokit.GraphQL, Version=0.1.0.0, Culture=neutral, PublicKeyToken=0be8860aee462442, processorArchitecture=MSIL">
54-
<HintPath>..\..\packages\Octokit.GraphQL.0.1.0-beta\lib\netstandard1.1\Octokit.GraphQL.dll</HintPath>
53+
<Reference Include="Octokit.GraphQL, Version=0.1.1.0, Culture=neutral, PublicKeyToken=0be8860aee462442, processorArchitecture=MSIL">
54+
<HintPath>..\..\packages\Octokit.GraphQL.0.1.1-beta\lib\netstandard1.1\Octokit.GraphQL.dll</HintPath>
5555
</Reference>
56-
<Reference Include="Octokit.GraphQL.Core, Version=0.1.0.0, Culture=neutral, PublicKeyToken=0be8860aee462442, processorArchitecture=MSIL">
57-
<HintPath>..\..\packages\Octokit.GraphQL.0.1.0-beta\lib\netstandard1.1\Octokit.GraphQL.Core.dll</HintPath>
56+
<Reference Include="Octokit.GraphQL.Core, Version=0.1.1.0, Culture=neutral, PublicKeyToken=0be8860aee462442, processorArchitecture=MSIL">
57+
<HintPath>..\..\packages\Octokit.GraphQL.0.1.1-beta\lib\netstandard1.1\Octokit.GraphQL.Core.dll</HintPath>
5858
</Reference>
5959
<Reference Include="Serilog, Version=2.0.0.0, Culture=neutral, PublicKeyToken=24c2f752a8e58a10, processorArchitecture=MSIL">
6060
<HintPath>..\..\packages\Serilog.2.5.0\lib\net46\Serilog.dll</HintPath>

src/GitHub.Api/packages.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<packages>
33
<package id="Newtonsoft.Json" version="9.0.1" targetFramework="net461" />
4-
<package id="Octokit.GraphQL" version="0.1.0-beta" targetFramework="net461" />
4+
<package id="Octokit.GraphQL" version="0.1.1-beta" targetFramework="net461" />
55
<package id="Serilog" version="2.5.0" targetFramework="net461" />
66
</packages>

src/GitHub.App/GitHub.App.csproj

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -144,11 +144,11 @@
144144
<Reference Include="Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
145145
<HintPath>..\..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
146146
</Reference>
147-
<Reference Include="Octokit.GraphQL, Version=0.1.0.0, Culture=neutral, PublicKeyToken=0be8860aee462442, processorArchitecture=MSIL">
148-
<HintPath>..\..\packages\Octokit.GraphQL.0.1.0-beta\lib\netstandard1.1\Octokit.GraphQL.dll</HintPath>
147+
<Reference Include="Octokit.GraphQL, Version=0.1.1.0, Culture=neutral, PublicKeyToken=0be8860aee462442, processorArchitecture=MSIL">
148+
<HintPath>..\..\packages\Octokit.GraphQL.0.1.1-beta\lib\netstandard1.1\Octokit.GraphQL.dll</HintPath>
149149
</Reference>
150-
<Reference Include="Octokit.GraphQL.Core, Version=0.1.0.0, Culture=neutral, PublicKeyToken=0be8860aee462442, processorArchitecture=MSIL">
151-
<HintPath>..\..\packages\Octokit.GraphQL.0.1.0-beta\lib\netstandard1.1\Octokit.GraphQL.Core.dll</HintPath>
150+
<Reference Include="Octokit.GraphQL.Core, Version=0.1.1.0, Culture=neutral, PublicKeyToken=0be8860aee462442, processorArchitecture=MSIL">
151+
<HintPath>..\..\packages\Octokit.GraphQL.0.1.1-beta\lib\netstandard1.1\Octokit.GraphQL.Core.dll</HintPath>
152152
</Reference>
153153
<Reference Include="PresentationCore" />
154154
<Reference Include="PresentationFramework" />
@@ -230,6 +230,7 @@
230230
<Compile Include="Services\EnterpriseCapabilitiesService.cs" />
231231
<Compile Include="Services\GitHubContextService.cs" />
232232
<Compile Include="Services\GlobalConnection.cs" />
233+
<Compile Include="Services\ChecksService.cs" />
233234
<Compile Include="Services\RepositoryForkService.cs" />
234235
<Compile Include="Services\RepositoryService.cs" />
235236
<Compile Include="ViewModels\ActorViewModel.cs" />
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.ComponentModel.Composition;
4+
using System.Diagnostics;
5+
using System.Globalization;
6+
using System.IO;
7+
using System.Linq;
8+
using System.Reactive;
9+
using System.Reactive.Linq;
10+
using System.Reactive.Threading.Tasks;
11+
using System.Text;
12+
using System.Text.RegularExpressions;
13+
using System.Threading.Tasks;
14+
using GitHub.Api;
15+
using GitHub.Extensions;
16+
using GitHub.Logging;
17+
using GitHub.Models;
18+
using GitHub.Primitives;
19+
using LibGit2Sharp;
20+
using Octokit.GraphQL;
21+
using Octokit.GraphQL.Core;
22+
using Octokit.GraphQL.Model;
23+
using Rothko;
24+
using static System.FormattableString;
25+
using static Octokit.GraphQL.Variable;
26+
27+
namespace GitHub.Services
28+
{
29+
[Export(typeof(IChecksService))]
30+
[PartCreationPolicy(CreationPolicy.Shared)]
31+
public class ChecksService : IChecksService
32+
{
33+
readonly IGitClient gitClient;
34+
readonly IGitService gitService;
35+
readonly IVSGitExt gitExt;
36+
readonly IGraphQLClientFactory graphqlFactory;
37+
readonly IOperatingSystem os;
38+
readonly IUsageTracker usageTracker;
39+
40+
[ImportingConstructor]
41+
public ChecksService(
42+
IGitClient gitClient,
43+
IGitService gitService,
44+
IVSGitExt gitExt,
45+
IGraphQLClientFactory graphqlFactory,
46+
IOperatingSystem os,
47+
IUsageTracker usageTracker)
48+
{
49+
this.gitClient = gitClient;
50+
this.gitService = gitService;
51+
this.gitExt = gitExt;
52+
this.graphqlFactory = graphqlFactory;
53+
this.os = os;
54+
this.usageTracker = usageTracker;
55+
}
56+
57+
static ICompiledQuery<IEnumerable<List<CheckSuiteModel>>> readCheckSuites;
58+
59+
public async Task<List<CheckSuiteModel>> ReadCheckSuites(
60+
HostAddress address,
61+
string owner,
62+
string name,
63+
int pullRequestNumber)
64+
{
65+
if (readCheckSuites == null)
66+
{
67+
readCheckSuites = new Query()
68+
.Repository(Var(nameof(owner)), Var(nameof(name)))
69+
.PullRequest(Var(nameof(pullRequestNumber)))
70+
.Commits(last: 1).Nodes.Select(
71+
commit => commit.Commit.CheckSuites(null,null, null,null, null).AllPages()
72+
.Select(suite => new CheckSuiteModel
73+
{
74+
Conclusion = (CheckSuiteConclusionStateEnum?) suite.Conclusion,
75+
Status = (CheckSuiteStatusStateEnum) suite.Status,
76+
CreatedAt = suite.CreatedAt,
77+
UpdatedAt = suite.UpdatedAt,
78+
CheckRuns = suite.CheckRuns(null, null, null, null, null).AllPages()
79+
.Select(run => new CheckRunModel
80+
{
81+
Conclusion = (CheckSuiteConclusionStateEnum?) run.Conclusion,
82+
Status = (CheckSuiteStatusStateEnum) run.Status,
83+
StartedAt = run.StartedAt,
84+
CompletedAt = run.CompletedAt,
85+
Annotations = run.Annotations(null, null, null, null).AllPages()
86+
.Select(annotation => new CheckRunAnnotationModel
87+
{
88+
BlobUrl = annotation.BlobUrl,
89+
StartLine = annotation.StartLine,
90+
EndLine = annotation.EndLine,
91+
Filename = annotation.Filename,
92+
Message = annotation.Message,
93+
Title = annotation.Title,
94+
WarningLevel = (CheckAnnotationLevelEnum?) annotation.WarningLevel,
95+
RawDetails = annotation.RawDetails
96+
}).ToList()
97+
}).ToList()
98+
}).ToList()
99+
).Compile();
100+
}
101+
102+
var graphql = await graphqlFactory.CreateConnection(address);
103+
var vars = new Dictionary<string, object>
104+
{
105+
{ nameof(owner), owner },
106+
{ nameof(name), name },
107+
{ nameof(pullRequestNumber), pullRequestNumber },
108+
};
109+
110+
var result = await graphql.Run(readCheckSuites, vars);
111+
return result.FirstOrDefault();
112+
}
113+
}
114+
}

src/GitHub.App/Services/PullRequestService.cs

Lines changed: 54 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,12 @@ public async Task<Page<PullRequestListItemModel>> ReadPullRequests(
9696
LastCommit = pr.Commits(null, null, 1, null).Nodes.Select(commit =>
9797
new LastCommitSummaryModel
9898
{
99+
// CheckSuites = commit.Commit.CheckSuites(null, null, null, null, null).AllPages(10)
100+
// .Select(suite => new CheckSuiteSummaryModel
101+
// {
102+
// Conclusion = (CheckConclusionStateEnum?)suite.Conclusion,
103+
// Status = (CheckStatusStateEnum)suite.Status,
104+
// }).ToList(),
99105
Statuses = commit.Commit.Status
100106
.Select(context =>
101107
context.Contexts.Select(statusContext => new StatusSummaryModel
@@ -134,36 +140,65 @@ public async Task<Page<PullRequestListItemModel>> ReadPullRequests(
134140

135141
var result = await graphql.Run(readPullRequests, vars);
136142

137-
foreach (var item in result.Items.Cast<ListItemAdapter>())
143+
foreach (ListItemAdapter item in result.Items)
138144
{
139145
item.CommentCount += item.Reviews.Sum(x => x.Count);
140146
item.Reviews = null;
141147

148+
var hasCheckSuites = item.LastCommit.CheckSuites != null
149+
&& item.LastCommit.CheckSuites.Any();
150+
142151
var hasStatuses = item.LastCommit.Statuses != null
143152
&& item.LastCommit.Statuses.Any();
144153

145-
if (!hasStatuses)
154+
if (!hasCheckSuites && !hasStatuses)
146155
{
147156
item.Checks = PullRequestChecksEnum.None;
148157
}
149158
else
150159
{
151-
var statusHasFailure = item.LastCommit
152-
.Statuses
153-
.Any(status => status.State == StatusStateEnum.Failure);
160+
var checksHasFailure = false;
161+
var checksHasCompleteSuccess = true;
162+
163+
if (hasCheckSuites)
164+
{
165+
checksHasFailure = item.LastCommit
166+
.CheckSuites.Any(model => model.Conclusion.HasValue
167+
&& (model.Conclusion.Value == CheckSuiteConclusionStateEnum.Failure
168+
|| model.Conclusion.Value ==
169+
CheckSuiteConclusionStateEnum.ActionRequired));
170+
171+
if (!checksHasFailure)
172+
{
173+
checksHasCompleteSuccess = item.LastCommit
174+
.CheckSuites.All(model => model.Conclusion.HasValue
175+
&& (model.Conclusion.Value == CheckSuiteConclusionStateEnum.Success
176+
|| model.Conclusion.Value ==
177+
CheckSuiteConclusionStateEnum.Neutral));
178+
}
179+
}
154180

181+
var statusHasFailure = false;
155182
var statusHasCompleteSuccess = true;
156-
if (!statusHasFailure)
183+
184+
if (!checksHasFailure && hasStatuses)
157185
{
158-
statusHasCompleteSuccess =
159-
item.LastCommit.Statuses.All(status => status.State == StatusStateEnum.Success);
186+
statusHasFailure = item.LastCommit
187+
.Statuses
188+
.Any(status => status.State == StatusStateEnum.Failure);
189+
190+
if (!statusHasFailure)
191+
{
192+
statusHasCompleteSuccess =
193+
item.LastCommit.Statuses.All(status => status.State == StatusStateEnum.Success);
194+
}
160195
}
161196

162-
if (statusHasFailure)
197+
if (checksHasFailure || statusHasFailure)
163198
{
164199
item.Checks = PullRequestChecksEnum.Failure;
165200
}
166-
else if (statusHasCompleteSuccess)
201+
else if (statusHasCompleteSuccess && checksHasCompleteSuccess)
167202
{
168203
item.Checks = PullRequestChecksEnum.Success;
169204
}
@@ -900,8 +935,17 @@ class ReviewAdapter
900935

901936
class LastCommitSummaryModel
902937
{
938+
public List<CheckSuiteSummaryModel> CheckSuites { get; set; }
939+
903940
public List<StatusSummaryModel> Statuses { get; set; }
904941
}
942+
943+
class CheckSuiteSummaryModel
944+
{
945+
public CheckSuiteConclusionStateEnum? Conclusion { get; set; }
946+
947+
public CheckSuiteStatusStateEnum Status { get; set; }
948+
}
905949
}
906950

907951
public class StatusSummaryModel

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ public sealed class PullRequestDetailViewModel : PanePageViewModelBase, IPullReq
3838
readonly IUsageTracker usageTracker;
3939
readonly ITeamExplorerContext teamExplorerContext;
4040
readonly ISyncSubmodulesCommand syncSubmodulesCommand;
41+
private IChecksService checksService;
4142
IModelService modelService;
4243
PullRequestDetailModel model;
4344
IActorViewModel author;
@@ -74,7 +75,8 @@ public PullRequestDetailViewModel(
7475
IUsageTracker usageTracker,
7576
ITeamExplorerContext teamExplorerContext,
7677
IPullRequestFilesViewModel files,
77-
ISyncSubmodulesCommand syncSubmodulesCommand)
78+
ISyncSubmodulesCommand syncSubmodulesCommand,
79+
IChecksService checksService)
7880
{
7981
Guard.ArgumentNotNull(pullRequestsService, nameof(pullRequestsService));
8082
Guard.ArgumentNotNull(sessionManager, nameof(sessionManager));
@@ -89,6 +91,7 @@ public PullRequestDetailViewModel(
8991
this.usageTracker = usageTracker;
9092
this.teamExplorerContext = teamExplorerContext;
9193
this.syncSubmodulesCommand = syncSubmodulesCommand;
94+
this.checksService = checksService;
9295
Files = files;
9396

9497
Checkout = ReactiveCommand.CreateAsyncObservable(

src/GitHub.App/packages.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
<package id="Microsoft.VisualStudio.TextManager.Interop.8.0" version="8.0.50728" targetFramework="net461" />
2222
<package id="Microsoft.VisualStudio.Utilities" version="14.3.25407" targetFramework="net461" />
2323
<package id="Newtonsoft.Json" version="9.0.1" targetFramework="net461" />
24-
<package id="Octokit.GraphQL" version="0.1.0-beta" targetFramework="net461" />
24+
<package id="Octokit.GraphQL" version="0.1.1-beta" targetFramework="net461" />
2525
<package id="Rothko" version="0.0.3-ghfvs" targetFramework="net461" />
2626
<package id="Rx-Core" version="2.2.5-custom" targetFramework="net45" />
2727
<package id="Rx-Interfaces" version="2.2.5-custom" targetFramework="net45" />

src/GitHub.Exports.Reactive/GitHub.Exports.Reactive.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@
175175
<Compile Include="Models\IInlineCommentThreadModel.cs" />
176176
<Compile Include="Models\IPullRequestSessionFile.cs" />
177177
<Compile Include="Models\PullRequestTextBufferInfo.cs" />
178+
<Compile Include="Services\IChecksService.cs" />
178179
<Compile Include="Services\IModelService.cs" />
179180
<Compile Include="Services\IGistPublishService.cs" />
180181
<Compile Include="Services\IPullRequestEditorService.cs" />
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using System.Collections.Generic;
2+
using System.Threading.Tasks;
3+
using GitHub.Primitives;
4+
5+
namespace GitHub.Services
6+
{
7+
public interface IChecksService
8+
{
9+
Task<List<GitHub.Models.CheckSuiteModel>> ReadCheckSuites(
10+
HostAddress address,
11+
string owner,
12+
string name,
13+
int pullRequestNumber);
14+
}
15+
}

src/GitHub.Exports/GitHub.Exports.csproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,12 @@
170170
<Compile Include="Extensions\ConnectionManagerExtensions.cs" />
171171
<Compile Include="GitHubLogicException.cs" />
172172
<Compile Include="Models\ActorModel.cs" />
173+
<Compile Include="Models\AnnotationModel.cs" />
174+
<Compile Include="Models\CheckAnnotationLevelEnum.cs" />
175+
<Compile Include="Models\CheckConclusionStateEnum.cs" />
176+
<Compile Include="Models\CheckRunModel.cs" />
177+
<Compile Include="Models\CheckStatusStateEnum.cs" />
178+
<Compile Include="Models\CheckSuiteModel.cs" />
173179
<Compile Include="Models\CommitMessage.cs" />
174180
<Compile Include="Models\DiffChangeType.cs" />
175181
<Compile Include="Models\DiffChunk.cs" />
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
namespace GitHub.Models
2+
{
3+
public class CheckRunAnnotationModel
4+
{
5+
public string BlobUrl { get; set; }
6+
7+
public int StartLine { get; set; }
8+
9+
public int EndLine { get; set; }
10+
11+
public string Filename { get; set; }
12+
13+
public string Message { get; set; }
14+
15+
public string Title { get; set; }
16+
17+
public CheckAnnotationLevelEnum? WarningLevel { get; set; }
18+
19+
public string RawDetails { get; set; }
20+
}
21+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace GitHub.Models
2+
{
3+
public enum CheckAnnotationLevelEnum
4+
{
5+
Failure,
6+
Notice,
7+
Warning,
8+
}
9+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
namespace GitHub.Models
2+
{
3+
public enum CheckSuiteConclusionStateEnum
4+
{
5+
ActionRequired,
6+
TimedOut,
7+
Cancelled,
8+
Failure,
9+
Success,
10+
Neutral,
11+
}
12+
}

0 commit comments

Comments
 (0)