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

Commit 774fa48

Browse files
authored
Merge pull request #1501 from github/feature/graphql-modelservice-pr-reviews
Use GraphQL in ModelService to read PR reviews/comments.
2 parents 31cdd81 + 05dd045 commit 774fa48

35 files changed

+628
-61
lines changed

lib/Octokit.GraphQL.0.0.1.nupkg

161 KB
Binary file not shown.

src/GitHub.Api/GitHub.Api.csproj

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,18 @@
4646
</PropertyGroup>
4747
<Import Project="$(SolutionDir)\src\common\signing.props" />
4848
<ItemGroup>
49+
<Reference Include="Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
50+
<HintPath>..\..\packages\Newtonsoft.Json.10.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
51+
<Private>True</Private>
52+
</Reference>
53+
<Reference Include="Octokit.GraphQL, Version=0.0.1.0, Culture=neutral, PublicKeyToken=0be8860aee462442, processorArchitecture=MSIL">
54+
<HintPath>..\..\packages\Octokit.GraphQL.0.0.1\lib\netstandard1.1\Octokit.GraphQL.dll</HintPath>
55+
<Private>True</Private>
56+
</Reference>
57+
<Reference Include="Octokit.GraphQL.Core, Version=0.0.1.0, Culture=neutral, PublicKeyToken=0be8860aee462442, processorArchitecture=MSIL">
58+
<HintPath>..\..\packages\Octokit.GraphQL.0.0.1\lib\netstandard1.1\Octokit.GraphQL.Core.dll</HintPath>
59+
<Private>True</Private>
60+
</Reference>
4961
<Reference Include="Serilog, Version=2.0.0.0, Culture=neutral, PublicKeyToken=24c2f752a8e58a10, processorArchitecture=MSIL">
5062
<HintPath>..\..\packages\Serilog.2.5.0\lib\net46\Serilog.dll</HintPath>
5163
<Private>True</Private>
@@ -66,6 +78,9 @@
6678
<Link>ApiClientConfiguration_User.cs</Link>
6779
</Compile>
6880
<Compile Include="ApiClientConfiguration_User.cs" Condition="$(Buildtype) != 'Internal'" />
81+
<Compile Include="GraphQLKeychainCredentialStore.cs" />
82+
<Compile Include="IGraphQLClientFactory.cs" />
83+
<Compile Include="GraphQLClientFactory.cs" />
6984
<Compile Include="IKeychain.cs" />
7085
<Compile Include="ILoginManager.cs" />
7186
<Compile Include="IOAuthCallbackListener.cs" />
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
using System;
2+
using System.ComponentModel.Composition;
3+
using System.Threading.Tasks;
4+
using GitHub.Models;
5+
using GitHub.Primitives;
6+
using Octokit.GraphQL;
7+
8+
namespace GitHub.Api
9+
{
10+
/// <summary>
11+
/// Creates GraphQL <see cref="Octokit.GraphQL.IConnection"/>s for querying the
12+
/// GitHub GraphQL API.
13+
/// </summary>
14+
[Export(typeof(IGraphQLClientFactory))]
15+
[PartCreationPolicy(CreationPolicy.Shared)]
16+
public class GraphQLClientFactory : IGraphQLClientFactory
17+
{
18+
readonly IKeychain keychain;
19+
readonly IProgram program;
20+
21+
/// <summary>
22+
/// Initializes a new instance of the <see cref="GraphQLClientFactory"/> class.
23+
/// </summary>
24+
/// <param name="keychain">The <see cref="IKeychain"/> to use.</param>
25+
/// <param name="program">The program details.</param>
26+
[ImportingConstructor]
27+
public GraphQLClientFactory(IKeychain keychain, IProgram program)
28+
{
29+
this.keychain = keychain;
30+
this.program = program;
31+
}
32+
33+
/// <inheirtdoc/>
34+
public Task<Octokit.GraphQL.IConnection> CreateConnection(HostAddress address)
35+
{
36+
var credentials = new GraphQLKeychainCredentialStore(keychain, address);
37+
var header = new ProductHeaderValue(program.ProductHeader.Name, program.ProductHeader.Version);
38+
return Task.FromResult<Octokit.GraphQL.IConnection>(new Connection(header, credentials));
39+
}
40+
}
41+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
using System;
2+
using System.Threading.Tasks;
3+
using GitHub.Extensions;
4+
using GitHub.Primitives;
5+
using Octokit.GraphQL;
6+
7+
namespace GitHub.Api
8+
{
9+
/// <summary>
10+
/// An Octokit.GraphQL credential store that reads from an <see cref="IKeychain"/>.
11+
/// </summary>
12+
public class GraphQLKeychainCredentialStore : ICredentialStore
13+
{
14+
readonly IKeychain keychain;
15+
readonly HostAddress address;
16+
17+
public GraphQLKeychainCredentialStore(IKeychain keychain, HostAddress address)
18+
{
19+
Guard.ArgumentNotNull(keychain, nameof(keychain));
20+
Guard.ArgumentNotNull(address, nameof(keychain));
21+
22+
this.keychain = keychain;
23+
this.address = address;
24+
}
25+
26+
public async Task<string> GetCredentials()
27+
{
28+
var userPass = await keychain.Load(address).ConfigureAwait(false);
29+
return userPass?.Item2;
30+
}
31+
}
32+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using System.Threading.Tasks;
2+
using GitHub.Primitives;
3+
4+
namespace GitHub.Api
5+
{
6+
/// <summary>
7+
/// Creates GraphQL <see cref="Octokit.GraphQL.IConnection"/>s for querying the
8+
/// GitHub GraphQL API.
9+
/// </summary>
10+
public interface IGraphQLClientFactory
11+
{
12+
/// <summary>
13+
/// Creates a new <see cref="Octokit.GraphQL.IConnection"/>.
14+
/// </summary>
15+
/// <param name="address">The address of the server.</param>
16+
/// <returns>A task returning the created connection.</returns>
17+
Task<Octokit.GraphQL.IConnection> CreateConnection(HostAddress address);
18+
}
19+
}

src/GitHub.Api/packages.config

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<packages>
3+
<package id="Newtonsoft.Json" version="10.0.3" targetFramework="net461" />
4+
<package id="Octokit.GraphQL" version="0.0.1" targetFramework="net461" />
35
<package id="Serilog" version="2.5.0" targetFramework="net461" />
46
</packages>

src/GitHub.App/Factories/ModelServiceFactory.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.ComponentModel.Composition;
44
using System.Threading;
55
using System.Threading.Tasks;
6+
using GitHub.Api;
67
using GitHub.Caches;
78
using GitHub.Models;
89
using GitHub.Services;
@@ -15,6 +16,7 @@ namespace GitHub.Factories
1516
public sealed class ModelServiceFactory : IModelServiceFactory, IDisposable
1617
{
1718
readonly IApiClientFactory apiClientFactory;
19+
readonly IGraphQLClientFactory graphQLClientFactory;
1820
readonly IHostCacheFactory hostCacheFactory;
1921
readonly IAvatarProvider avatarProvider;
2022
readonly Dictionary<IConnection, ModelService> cache = new Dictionary<IConnection, ModelService>();
@@ -23,10 +25,12 @@ public sealed class ModelServiceFactory : IModelServiceFactory, IDisposable
2325
[ImportingConstructor]
2426
public ModelServiceFactory(
2527
IApiClientFactory apiClientFactory,
28+
IGraphQLClientFactory graphQLClientFactory,
2629
IHostCacheFactory hostCacheFactory,
2730
IAvatarProvider avatarProvider)
2831
{
2932
this.apiClientFactory = apiClientFactory;
33+
this.graphQLClientFactory = graphQLClientFactory;
3034
this.hostCacheFactory = hostCacheFactory;
3135
this.avatarProvider = avatarProvider;
3236
}
@@ -43,6 +47,7 @@ public async Task<IModelService> CreateAsync(IConnection connection)
4347
{
4448
result = new ModelService(
4549
await apiClientFactory.Create(connection.HostAddress),
50+
await graphQLClientFactory.CreateConnection(connection.HostAddress),
4651
await hostCacheFactory.Create(connection.HostAddress),
4752
avatarProvider);
4853
result.InsertUser(AccountCacheItem.Create(connection.User));

src/GitHub.App/GitHub.App.csproj

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -132,15 +132,22 @@
132132
<SpecificVersion>False</SpecificVersion>
133133
<HintPath>..\..\packages\Microsoft.VisualStudio.Threading.14.1.131\lib\net45\Microsoft.VisualStudio.Threading.dll</HintPath>
134134
</Reference>
135+
<Reference Include="Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
136+
<HintPath>..\..\packages\Newtonsoft.Json.10.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
137+
<Private>True</Private>
138+
</Reference>
139+
<Reference Include="Octokit.GraphQL, Version=0.0.1.0, Culture=neutral, PublicKeyToken=0be8860aee462442, processorArchitecture=MSIL">
140+
<HintPath>..\..\packages\Octokit.GraphQL.0.0.1\lib\netstandard1.1\Octokit.GraphQL.dll</HintPath>
141+
<Private>True</Private>
142+
</Reference>
143+
<Reference Include="Octokit.GraphQL.Core, Version=0.0.1.0, Culture=neutral, PublicKeyToken=0be8860aee462442, processorArchitecture=MSIL">
144+
<HintPath>..\..\packages\Octokit.GraphQL.0.0.1\lib\netstandard1.1\Octokit.GraphQL.Core.dll</HintPath>
145+
<Private>True</Private>
146+
</Reference>
135147
<Reference Include="Microsoft.VisualStudio.Utilities, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
136148
<HintPath>..\..\packages\Microsoft.VisualStudio.Utilities.14.3.25407\lib\net45\Microsoft.VisualStudio.Utilities.dll</HintPath>
137149
<Private>True</Private>
138150
</Reference>
139-
<Reference Include="Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
140-
<SpecificVersion>False</SpecificVersion>
141-
<HintPath>..\..\packages\Newtonsoft.Json.6.0.8\lib\net45\Newtonsoft.Json.dll</HintPath>
142-
<Private>False</Private>
143-
</Reference>
144151
<Reference Include="PresentationCore" />
145152
<Reference Include="PresentationFramework" />
146153
<Reference Include="rothko, Version=0.0.3.0, Culture=neutral, PublicKeyToken=9f664c41f503810a, processorArchitecture=MSIL">
@@ -199,6 +206,7 @@
199206
<Compile Include="Models\IssueCommentModel.cs" />
200207
<Compile Include="Models\PullRequestReviewCommentModel.cs" />
201208
<Compile Include="Models\PullRequestDetailArgument.cs" />
209+
<Compile Include="Models\PullRequestReviewModel.cs" />
202210
<Compile Include="SampleData\PullRequestFilesViewModelDesigner.cs" />
203211
<Compile Include="Services\EnterpriseCapabilitiesService.cs" />
204212
<Compile Include="Services\GlobalConnection.cs" />

src/GitHub.App/Models/Account.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public Account(
2323
bool isEnterprise,
2424
int ownedPrivateRepositoryCount,
2525
long privateRepositoryInPlanCount,
26+
string avatarUrl,
2627
IObservable<BitmapSource> bitmapSource)
2728
{
2829
Guard.ArgumentNotEmptyString(login, nameof(login));
@@ -34,6 +35,7 @@ public Account(
3435
PrivateReposInPlan = privateRepositoryInPlanCount;
3536
IsOnFreePlan = privateRepositoryInPlanCount == 0;
3637
HasMaximumPrivateRepositories = OwnedPrivateRepos >= PrivateReposInPlan;
38+
AvatarUrl = avatarUrl;
3739
this.bitmapSource = bitmapSource;
3840

3941
bitmapSourceSubscription = bitmapSource
@@ -54,6 +56,7 @@ public Account(Octokit.Account account)
5456
OwnedPrivateRepos = account.OwnedPrivateRepos;
5557
IsOnFreePlan = PrivateReposInPlan == 0;
5658
HasMaximumPrivateRepositories = OwnedPrivateRepos >= PrivateReposInPlan;
59+
AvatarUrl = account.AvatarUrl;
5760
}
5861

5962
public Account(Octokit.Account account, IObservable<BitmapSource> bitmapSource)
@@ -77,6 +80,8 @@ public Account(Octokit.Account account, IObservable<BitmapSource> bitmapSource)
7780

7881
public long PrivateReposInPlan { get; private set; }
7982

83+
public string AvatarUrl { get; private set; }
84+
8085
public BitmapSource Avatar
8186
{
8287
get { return avatar; }
@@ -115,7 +120,7 @@ public override bool Equals(object obj)
115120

116121
public override int GetHashCode()
117122
{
118-
return (Login?.GetHashCode() ?? 0) ^ IsUser .GetHashCode() ^ IsEnterprise.GetHashCode();
123+
return (Login?.GetHashCode() ?? 0) ^ IsUser.GetHashCode() ^ IsEnterprise.GetHashCode();
119124
}
120125

121126
bool IEquatable<IAccount>.Equals(IAccount other)

src/GitHub.App/Models/IssueCommentModel.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ namespace GitHub.Models
44
{
55
public class IssueCommentModel : ICommentModel
66
{
7-
public string Body { get; set; }
87
public int Id { get; set; }
8+
public string NodeId { get; set; }
9+
public string Body { get; set; }
910
public DateTimeOffset CreatedAt { get; set; }
1011
public IAccount User { get; set; }
1112
}

0 commit comments

Comments
 (0)