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

Commit 8622f21

Browse files
Experimenting with ways to get the data via GraphQL
1 parent bfd6bfb commit 8622f21

File tree

17 files changed

+311
-22
lines changed

17 files changed

+311
-22
lines changed

src/GitHub.App/GitHub.App.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@
229229
<Compile Include="SampleData\UserFilterViewModelDesigner.cs" />
230230
<Compile Include="Services\EnterpriseCapabilitiesService.cs" />
231231
<Compile Include="Services\GlobalConnection.cs" />
232+
<Compile Include="Services\ChecksService.cs" />
232233
<Compile Include="Services\RepositoryForkService.cs" />
233234
<Compile Include="Services\RepositoryService.cs" />
234235
<Compile Include="ViewModels\ActorViewModel.cs" />

src/GitHub.App/Models/PullRequestModel.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
using GitHub.Primitives;
44
using GitHub.VisualStudio.Helpers;
55
using System.Diagnostics;
6-
using System.Collections.Generic;
76
using GitHub.Extensions;
87

98
namespace GitHub.Models
@@ -183,4 +182,4 @@ internal string DebuggerDisplay
183182
}
184183
}
185184
}
186-
}
185+
}
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 = (CheckConclusionStateEnum?) suite.Conclusion,
75+
Status = (CheckStatusStateEnum) 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 = (CheckConclusionStateEnum?) run.Conclusion,
82+
Status = (CheckStatusStateEnum) 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: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -93,22 +93,28 @@ public async Task<Page<PullRequestListItemModel>> ReadPullRequests(
9393
Items = page.Nodes.Select(pr => new ListItemAdapter
9494
{
9595
Id = pr.Id.Value,
96-
CheckSuites = pr.Commits(null, null, 1, null).Nodes.Select(commit =>
97-
commit.Commit.CheckSuites(null, null, null, null, null).AllPages()
98-
.Select(suite => new
99-
{
100-
suite.Conclusion,
101-
suite.Status,
102-
}).ToList()
103-
).ToList().FirstOrDefault(),
104-
Statuses = pr.Commits(null, null, 1, null).Nodes.Select(commit =>
105-
commit.Commit.Status.Contexts
106-
.Select(context => new
107-
{
108-
context.Context,
109-
context.State,
110-
}).ToList()
111-
).ToList().FirstOrDefault(),
96+
LastCommit = pr.Commits(null, null, 1, null).Nodes.Select(commit =>
97+
new
98+
{
99+
Checks = commit.Commit.CheckSuites(null, null, null, null, null).AllPages()
100+
.Select(suite => new
101+
{
102+
suite.Conclusion,
103+
suite.Status,
104+
}).ToList(),
105+
106+
/*
107+
TODO: Resolve https://github.com/octokit/octokit.graphql.net/pull/122
108+
Contexts can be null
109+
110+
Statuses = commit.Commit.Status.Contexts
111+
.Select(context => new
112+
{
113+
context.Context,
114+
context.State,
115+
}).ToList()
116+
*/
117+
}).ToList().FirstOrDefault(),
112118
Author = new ActorModel
113119
{
114120
Login = pr.Author.Login,
@@ -857,8 +863,7 @@ class ListItemAdapter : PullRequestListItemModel
857863
{
858864
public IList<ReviewAdapter> Reviews { get; set; }
859865

860-
public object CheckSuites { get; set; }
861-
public object Statuses { get; set; }
866+
public object LastCommit { get; set; }
862867
}
863868

864869
class ReviewAdapter

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;
@@ -73,7 +74,8 @@ public PullRequestDetailViewModel(
7374
IUsageTracker usageTracker,
7475
ITeamExplorerContext teamExplorerContext,
7576
IPullRequestFilesViewModel files,
76-
ISyncSubmodulesCommand syncSubmodulesCommand)
77+
ISyncSubmodulesCommand syncSubmodulesCommand,
78+
IChecksService checksService)
7779
{
7880
Guard.ArgumentNotNull(pullRequestsService, nameof(pullRequestsService));
7981
Guard.ArgumentNotNull(sessionManager, nameof(sessionManager));
@@ -88,6 +90,7 @@ public PullRequestDetailViewModel(
8890
this.usageTracker = usageTracker;
8991
this.teamExplorerContext = teamExplorerContext;
9092
this.syncSubmodulesCommand = syncSubmodulesCommand;
93+
this.checksService = checksService;
9194
Files = files;
9295

9396
Checkout = ReactiveCommand.CreateAsyncObservable(

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
@@ -168,6 +168,12 @@
168168
<Compile Include="Extensions\ConnectionManagerExtensions.cs" />
169169
<Compile Include="GitHubLogicException.cs" />
170170
<Compile Include="Models\ActorModel.cs" />
171+
<Compile Include="Models\AnnotationModel.cs" />
172+
<Compile Include="Models\CheckAnnotationLevelEnum.cs" />
173+
<Compile Include="Models\CheckConclusionStateEnum.cs" />
174+
<Compile Include="Models\CheckRunModel.cs" />
175+
<Compile Include="Models\CheckStatusStateEnum.cs" />
176+
<Compile Include="Models\CheckSuiteModel.cs" />
171177
<Compile Include="Models\CommitMessage.cs" />
172178
<Compile Include="Models\DiffChangeType.cs" />
173179
<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+
}

0 commit comments

Comments
 (0)