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

Commit c0dc9cb

Browse files
authored
Merge pull request #1491 from github/feature/pr-reviews-master
Master PR for Pull Request Reviews
2 parents a345b94 + c2b105e commit c0dc9cb

File tree

166 files changed

+7802
-2046
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

166 files changed

+7802
-2046
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,3 +98,4 @@ Visit the [Contributor Guidelines](CONTRIBUTING.md) for details on how to contri
9898
Copyright 2015 - 2017 GitHub, Inc.
9999

100100
Licensed under the [MIT License](LICENSE.md)
101+

appveyor.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
version: '2.4.4.{build}'
1+
version: '2.4.99.{build}'
22
skip_tags: true
33
install:
44
- ps: |

lib/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
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.2.0, Culture=neutral, PublicKeyToken=0be8860aee462442, processorArchitecture=MSIL">
54+
<HintPath>..\..\packages\Octokit.GraphQL.0.0.2-alpha\lib\netstandard1.1\Octokit.GraphQL.dll</HintPath>
55+
<Private>True</Private>
56+
</Reference>
57+
<Reference Include="Octokit.GraphQL.Core, Version=0.0.2.0, Culture=neutral, PublicKeyToken=0be8860aee462442, processorArchitecture=MSIL">
58+
<HintPath>..\..\packages\Octokit.GraphQL.0.0.2-alpha\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, address.GraphQLUri, 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.2-alpha" targetFramework="net461" />
35
<package id="Serilog" version="2.5.0" targetFramework="net461" />
46
</packages>

src/GitHub.App/Api/ApiClient.cs

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,27 @@ public IObservable<Repository> CreateRepository(NewRepository repository, string
4848
return (isUser ? client.Create(repository) : client.Create(login, repository));
4949
}
5050

51+
public IObservable<PullRequestReview> PostPullRequestReview(
52+
string owner,
53+
string name,
54+
int number,
55+
string commitId,
56+
string body,
57+
PullRequestReviewEvent e)
58+
{
59+
Guard.ArgumentNotEmptyString(owner, nameof(owner));
60+
Guard.ArgumentNotEmptyString(name, nameof(name));
61+
62+
var review = new PullRequestReviewCreate
63+
{
64+
Body = body,
65+
CommitId = commitId,
66+
Event = e,
67+
};
68+
69+
return gitHubClient.PullRequest.Review.Create(owner, name, number, review);
70+
}
71+
5172
public IObservable<PullRequestReviewComment> CreatePullRequestReviewComment(
5273
string owner,
5374
string name,
@@ -88,6 +109,11 @@ public IObservable<User> GetUser()
88109
return gitHubClient.User.Current();
89110
}
90111

112+
public IObservable<User> GetUser(string login)
113+
{
114+
return gitHubClient.User.Get(login);
115+
}
116+
91117
public IObservable<Organization> GetOrganizations()
92118
{
93119
// Organization.GetAllForCurrent doesn't return all of the information we need (we
@@ -123,30 +149,10 @@ public IObservable<LicenseMetadata> GetLicenses()
123149

124150
public HostAddress HostAddress { get; }
125151

126-
static string GetSha256Hash(string input)
127-
{
128-
Guard.ArgumentNotEmptyString(input, nameof(input));
129-
130-
try
131-
{
132-
using (var sha256 = SHA256.Create())
133-
{
134-
var bytes = Encoding.UTF8.GetBytes(input);
135-
var hash = sha256.ComputeHash(bytes);
136-
137-
return string.Join("", hash.Select(b => b.ToString("x2", CultureInfo.InvariantCulture)));
138-
}
139-
}
140-
catch (Exception e)
141-
{
142-
log.Error(e, "IMPOSSIBLE! Generating Sha256 hash caused an exception");
143-
return null;
144-
}
145-
}
146-
147152
static string GetFingerprint()
148153
{
149-
return GetSha256Hash(ProductName + ":" + GetMachineIdentifier());
154+
var fingerprint = ProductName + ":" + GetMachineIdentifier();
155+
return fingerprint.GetSha256Hash();
150156
}
151157

152158
static string GetMachineNameSafe()
@@ -269,11 +275,7 @@ public IObservable<Branch> GetBranches(string owner, string repo)
269275
Guard.ArgumentNotEmptyString(owner, nameof(owner));
270276
Guard.ArgumentNotEmptyString(repo, nameof(repo));
271277

272-
#pragma warning disable 618
273-
// GetAllBranches is obsolete, but don't want to introduce the change to fix the
274-
// warning in the PR, so disabling for now.
275-
return gitHubClient.Repository.GetAllBranches(owner, repo);
276-
#pragma warning restore
278+
return gitHubClient.Repository.Branch.GetAll(owner, repo);
277279
}
278280

279281
public IObservable<Repository> GetRepository(string owner, string repo)

0 commit comments

Comments
 (0)