From 87c01d4d8ecb6839b5ae725f5523f28b07dd50b5 Mon Sep 17 00:00:00 2001 From: Adrian Godong Date: Wed, 27 Dec 2017 22:32:53 -0800 Subject: [PATCH 01/84] Added authentication using bearer token. --- Octokit/Authentication/AuthenticationType.cs | 6 ++++- Octokit/Authentication/Authenticator.cs | 3 ++- .../BearerTokenAuthenticator.cs | 23 +++++++++++++++++++ Octokit/Http/Credentials.cs | 16 ++++++++----- 4 files changed, 40 insertions(+), 8 deletions(-) create mode 100644 Octokit/Authentication/BearerTokenAuthenticator.cs diff --git a/Octokit/Authentication/AuthenticationType.cs b/Octokit/Authentication/AuthenticationType.cs index 96c2b4b0d8..4047c8141f 100644 --- a/Octokit/Authentication/AuthenticationType.cs +++ b/Octokit/Authentication/AuthenticationType.cs @@ -16,6 +16,10 @@ public enum AuthenticationType /// /// Delegated access to a third party /// - Oauth + Oauth, + /// + /// Credential for GitHub App using signed JWT + /// + Bearer } } diff --git a/Octokit/Authentication/Authenticator.cs b/Octokit/Authentication/Authenticator.cs index a9a0e856d8..fa07e7b551 100644 --- a/Octokit/Authentication/Authenticator.cs +++ b/Octokit/Authentication/Authenticator.cs @@ -10,7 +10,8 @@ class Authenticator { { AuthenticationType.Anonymous, new AnonymousAuthenticator() }, { AuthenticationType.Basic, new BasicAuthenticator() }, - { AuthenticationType.Oauth, new TokenAuthenticator() } + { AuthenticationType.Oauth, new TokenAuthenticator() }, + { AuthenticationType.Bearer, new BearerTokenAuthenticator() } }; public Authenticator(ICredentialStore credentialStore) diff --git a/Octokit/Authentication/BearerTokenAuthenticator.cs b/Octokit/Authentication/BearerTokenAuthenticator.cs new file mode 100644 index 0000000000..c8fe0953f6 --- /dev/null +++ b/Octokit/Authentication/BearerTokenAuthenticator.cs @@ -0,0 +1,23 @@ +using System; +using System.Globalization; + +namespace Octokit.Internal +{ + class BearerTokenAuthenticator: IAuthenticationHandler + { + public void Authenticate(IRequest request, Credentials credentials) + { + Ensure.ArgumentNotNull(request, "request"); + Ensure.ArgumentNotNull(credentials, "credentials"); + Ensure.ArgumentNotNull(credentials.Password, "credentials.Password"); + + if (credentials.Login != null) + { + throw new InvalidOperationException("The Login is not null for a token authentication request. You " + + "probably did something wrong."); + } + + request.Headers["Authorization"] = string.Format(CultureInfo.InvariantCulture, "Bearer {0}", credentials.Password); + } + } +} diff --git a/Octokit/Http/Credentials.cs b/Octokit/Http/Credentials.cs index f62efa6316..e4cd21b508 100644 --- a/Octokit/Http/Credentials.cs +++ b/Octokit/Http/Credentials.cs @@ -13,13 +13,8 @@ private Credentials() AuthenticationType = AuthenticationType.Anonymous; } - public Credentials(string token) + public Credentials(string token) : this(token, AuthenticationType.Oauth) { - Ensure.ArgumentNotNullOrEmptyString(token, "token"); - - Login = null; - Password = token; - AuthenticationType = AuthenticationType.Oauth; } public Credentials(string login, string password) @@ -32,6 +27,15 @@ public Credentials(string login, string password) AuthenticationType = AuthenticationType.Basic; } + public Credentials(string token, AuthenticationType authenticationType) + { + Ensure.ArgumentNotNullOrEmptyString(token, "token"); + + Login = null; + Password = token; + AuthenticationType = authenticationType; + } + public string Login { get; From 002b7bd72fc5c4661ae7c3dfa80a96c3f29fe2e2 Mon Sep 17 00:00:00 2001 From: Adrian Godong Date: Wed, 27 Dec 2017 23:07:43 -0800 Subject: [PATCH 02/84] Added Installation and AccessToken clients. --- Octokit/Clients/AccessTokensClient.cs | 18 ++++++++++++++++++ Octokit/Clients/IAccessTokensClient.cs | 9 +++++++++ Octokit/Clients/IInstallationsClient.cs | 7 +++++++ Octokit/Clients/InstallationsClient.cs | 12 ++++++++++++ Octokit/GitHubClient.cs | 4 ++++ Octokit/Helpers/ApiUrls.cs | 5 +++++ Octokit/IGitHubClient.cs | 2 ++ Octokit/Models/Response/AccessToken.cs | 10 ++++++++++ 8 files changed, 67 insertions(+) create mode 100644 Octokit/Clients/AccessTokensClient.cs create mode 100644 Octokit/Clients/IAccessTokensClient.cs create mode 100644 Octokit/Clients/IInstallationsClient.cs create mode 100644 Octokit/Clients/InstallationsClient.cs create mode 100644 Octokit/Models/Response/AccessToken.cs diff --git a/Octokit/Clients/AccessTokensClient.cs b/Octokit/Clients/AccessTokensClient.cs new file mode 100644 index 0000000000..098674e9ea --- /dev/null +++ b/Octokit/Clients/AccessTokensClient.cs @@ -0,0 +1,18 @@ +using System.Threading.Tasks; + +namespace Octokit +{ + class AccessTokensClient : ApiClient, IAccessTokensClient + { + private const string AcceptHeader = "application/vnd.github.machine-man-preview+json"; + + public AccessTokensClient(IApiConnection apiConnection) : base(apiConnection) + { + } + + public Task Create(int installationId) + { + return ApiConnection.Post(ApiUrls.AccessTokens(installationId), null, AcceptHeader); + } + } +} diff --git a/Octokit/Clients/IAccessTokensClient.cs b/Octokit/Clients/IAccessTokensClient.cs new file mode 100644 index 0000000000..46f18cb7aa --- /dev/null +++ b/Octokit/Clients/IAccessTokensClient.cs @@ -0,0 +1,9 @@ +using System.Threading.Tasks; + +namespace Octokit +{ + public interface IAccessTokensClient + { + Task Create(int installationId); + } +} diff --git a/Octokit/Clients/IInstallationsClient.cs b/Octokit/Clients/IInstallationsClient.cs new file mode 100644 index 0000000000..66253f8d1b --- /dev/null +++ b/Octokit/Clients/IInstallationsClient.cs @@ -0,0 +1,7 @@ +namespace Octokit +{ + public interface IInstallationsClient + { + IAccessTokensClient AccessTokens { get; } + } +} diff --git a/Octokit/Clients/InstallationsClient.cs b/Octokit/Clients/InstallationsClient.cs new file mode 100644 index 0000000000..d25da7664f --- /dev/null +++ b/Octokit/Clients/InstallationsClient.cs @@ -0,0 +1,12 @@ +namespace Octokit +{ + class InstallationsClient : ApiClient, IInstallationsClient + { + public InstallationsClient(IApiConnection apiConnection) : base(apiConnection) + { + AccessTokens = new AccessTokensClient(apiConnection); + } + + public IAccessTokensClient AccessTokens { get; private set; } + } +} diff --git a/Octokit/GitHubClient.cs b/Octokit/GitHubClient.cs index a630e91254..3623a7da97 100644 --- a/Octokit/GitHubClient.cs +++ b/Octokit/GitHubClient.cs @@ -87,6 +87,7 @@ public GitHubClient(IConnection connection) Enterprise = new EnterpriseClient(apiConnection); Gist = new GistsClient(apiConnection); Git = new GitDatabaseClient(apiConnection); + Installations = new InstallationsClient(apiConnection); Issue = new IssuesClient(apiConnection); Migration = new MigrationClient(apiConnection); Miscellaneous = new MiscellaneousClient(connection); @@ -171,6 +172,9 @@ public Uri BaseAddress /// public IActivitiesClient Activity { get; private set; } + public IInstallationsClient Installations { get; private set; } + + /// /// Access GitHub's Issue API. /// diff --git a/Octokit/Helpers/ApiUrls.cs b/Octokit/Helpers/ApiUrls.cs index 24120b3165..c7602e99c8 100644 --- a/Octokit/Helpers/ApiUrls.cs +++ b/Octokit/Helpers/ApiUrls.cs @@ -293,6 +293,11 @@ public static Uri NotificationSubscription(int id) return "notifications/threads/{0}/subscription".FormatUri(id); } + public static Uri AccessTokens(int installationId) + { + return "installations/{0}/access_tokens".FormatUri(installationId); + } + /// /// Returns the that returns all of the issues across all the authenticated user’s visible /// repositories including owned repositories, member repositories, and organization repositories: diff --git a/Octokit/IGitHubClient.cs b/Octokit/IGitHubClient.cs index 1a66aa446b..5d2b7f594e 100644 --- a/Octokit/IGitHubClient.cs +++ b/Octokit/IGitHubClient.cs @@ -38,6 +38,8 @@ public interface IGitHubClient : IApiInfoProvider /// IActivitiesClient Activity { get; } + IInstallationsClient Installations { get; } + /// /// Access GitHub's Issue API. /// diff --git a/Octokit/Models/Response/AccessToken.cs b/Octokit/Models/Response/AccessToken.cs new file mode 100644 index 0000000000..04d8c41605 --- /dev/null +++ b/Octokit/Models/Response/AccessToken.cs @@ -0,0 +1,10 @@ +using System; + +namespace Octokit +{ + public class AccessToken + { + public string Token { get; set; } + public DateTime ExpiresAt { get; set; } + } +} From 33d659edfe7a133d11f7ae65b7f4687c4a2567e0 Mon Sep 17 00:00:00 2001 From: Adrian Godong Date: Wed, 27 Dec 2017 23:43:39 -0800 Subject: [PATCH 03/84] Added new clients to Reactive project --- .../Clients/IObservableAccessTokensClient.cs | 9 +++++++ .../Clients/IObservableInstallationsClient.cs | 7 ++++++ .../Clients/ObservableAccessTokensClient.cs | 24 +++++++++++++++++++ .../Clients/ObservableInstallationsClient.cs | 19 +++++++++++++++ Octokit.Reactive/IObservableGitHubClient.cs | 1 + Octokit.Reactive/ObservableGitHubClient.cs | 2 ++ Octokit/Models/Response/AccessToken.cs | 23 ++++++++++++++++-- 7 files changed, 83 insertions(+), 2 deletions(-) create mode 100644 Octokit.Reactive/Clients/IObservableAccessTokensClient.cs create mode 100644 Octokit.Reactive/Clients/IObservableInstallationsClient.cs create mode 100644 Octokit.Reactive/Clients/ObservableAccessTokensClient.cs create mode 100644 Octokit.Reactive/Clients/ObservableInstallationsClient.cs diff --git a/Octokit.Reactive/Clients/IObservableAccessTokensClient.cs b/Octokit.Reactive/Clients/IObservableAccessTokensClient.cs new file mode 100644 index 0000000000..629e37378f --- /dev/null +++ b/Octokit.Reactive/Clients/IObservableAccessTokensClient.cs @@ -0,0 +1,9 @@ +using System; + +namespace Octokit.Reactive +{ + public interface IObservableAccessTokensClient + { + IObservable Create(int installationId); + } +} diff --git a/Octokit.Reactive/Clients/IObservableInstallationsClient.cs b/Octokit.Reactive/Clients/IObservableInstallationsClient.cs new file mode 100644 index 0000000000..7bffda2775 --- /dev/null +++ b/Octokit.Reactive/Clients/IObservableInstallationsClient.cs @@ -0,0 +1,7 @@ +namespace Octokit.Reactive +{ + public interface IObservableInstallationsClient + { + IObservableAccessTokensClient AccessTokens { get; } + } +} diff --git a/Octokit.Reactive/Clients/ObservableAccessTokensClient.cs b/Octokit.Reactive/Clients/ObservableAccessTokensClient.cs new file mode 100644 index 0000000000..56f38ac7e9 --- /dev/null +++ b/Octokit.Reactive/Clients/ObservableAccessTokensClient.cs @@ -0,0 +1,24 @@ +using System; +using System.Reactive.Threading.Tasks; + +namespace Octokit.Reactive +{ + class ObservableAccessTokensClient : IObservableAccessTokensClient + { + readonly IAccessTokensClient _client; + readonly IConnection _connection; + + public ObservableAccessTokensClient(IGitHubClient client) + { + Ensure.ArgumentNotNull(client, "client"); + + _client = client.Installations.AccessTokens; + _connection = client.Connection; + } + + public IObservable Create(int installationId) + { + return _client.Create(installationId).ToObservable(); + } + } +} diff --git a/Octokit.Reactive/Clients/ObservableInstallationsClient.cs b/Octokit.Reactive/Clients/ObservableInstallationsClient.cs new file mode 100644 index 0000000000..c03d9fe6fa --- /dev/null +++ b/Octokit.Reactive/Clients/ObservableInstallationsClient.cs @@ -0,0 +1,19 @@ +namespace Octokit.Reactive +{ + class ObservableInstallationsClient : IObservableInstallationsClient + { + readonly IInstallationsClient _client; + readonly IConnection _connection; + + public ObservableInstallationsClient(IGitHubClient client) + { + Ensure.ArgumentNotNull(client, "client"); + + _client = client.Installations; + _connection = client.Connection; + AccessTokens = new ObservableAccessTokensClient(client); + } + + public IObservableAccessTokensClient AccessTokens { get; } + } +} diff --git a/Octokit.Reactive/IObservableGitHubClient.cs b/Octokit.Reactive/IObservableGitHubClient.cs index 9f1875224a..f6b712c00b 100644 --- a/Octokit.Reactive/IObservableGitHubClient.cs +++ b/Octokit.Reactive/IObservableGitHubClient.cs @@ -18,6 +18,7 @@ public interface IObservableGitHubClient : IApiInfoProvider IObservableAuthorizationsClient Authorization { get; } IObservableActivitiesClient Activity { get; } + IObservableInstallationsClient Installations { get; } IObservableIssuesClient Issue { get; } IObservableMiscellaneousClient Miscellaneous { get; } IObservableOauthClient Oauth { get; } diff --git a/Octokit.Reactive/ObservableGitHubClient.cs b/Octokit.Reactive/ObservableGitHubClient.cs index 11cba00e31..413ad71fdf 100644 --- a/Octokit.Reactive/ObservableGitHubClient.cs +++ b/Octokit.Reactive/ObservableGitHubClient.cs @@ -33,6 +33,7 @@ public ObservableGitHubClient(IGitHubClient gitHubClient) _gitHubClient = gitHubClient; Authorization = new ObservableAuthorizationsClient(gitHubClient); Activity = new ObservableActivitiesClient(gitHubClient); + Installations = new ObservableInstallationsClient(gitHubClient); Issue = new ObservableIssuesClient(gitHubClient); Miscellaneous = new ObservableMiscellaneousClient(gitHubClient); Oauth = new ObservableOauthClient(gitHubClient); @@ -69,6 +70,7 @@ public void SetRequestTimeout(TimeSpan timeout) public IObservableAuthorizationsClient Authorization { get; private set; } public IObservableActivitiesClient Activity { get; private set; } + public IObservableInstallationsClient Installations { get; private set; } public IObservableIssuesClient Issue { get; private set; } public IObservableMiscellaneousClient Miscellaneous { get; private set; } public IObservableOauthClient Oauth { get; private set; } diff --git a/Octokit/Models/Response/AccessToken.cs b/Octokit/Models/Response/AccessToken.cs index 04d8c41605..319eb3351c 100644 --- a/Octokit/Models/Response/AccessToken.cs +++ b/Octokit/Models/Response/AccessToken.cs @@ -1,10 +1,29 @@ using System; +using System.Diagnostics; +using System.Globalization; namespace Octokit { + [DebuggerDisplay("{DebuggerDisplay,nq}")] public class AccessToken { - public string Token { get; set; } - public DateTime ExpiresAt { get; set; } + public AccessToken() { } + + public AccessToken(string token, DateTime expiresAt) + { + Token = token; + ExpiresAt = expiresAt; + } + + public string Token { get; protected set; } + public DateTime ExpiresAt { get; protected set; } + + internal string DebuggerDisplay + { + get + { + return string.Format(CultureInfo.InvariantCulture, "Token: {0}, ExpiresAt: {1}", Token, ExpiresAt); + } + } } } From 9c27c0082369503ca9fcbf54f147e8c1080c9a82 Mon Sep 17 00:00:00 2001 From: Itai Bar-Haim Date: Mon, 1 Jan 2018 17:17:42 +0200 Subject: [PATCH 04/84] added support for DateTime serialized as FileTime --- Octokit/SimpleJson.cs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Octokit/SimpleJson.cs b/Octokit/SimpleJson.cs index 40dca76cd2..9efbf7e912 100644 --- a/Octokit/SimpleJson.cs +++ b/Octokit/SimpleJson.cs @@ -1429,6 +1429,14 @@ public virtual object DeserializeObject(object value, Type type) return value; if ((valueIsDouble && type != typeof(double)) || (valueIsLong && type != typeof(long))) { + if (valueIsLong && (type == typeof(DateTimeOffset) || type == typeof(DateTimeOffset?))) + { + return DateTimeOffset.FromFileTime((long)value); + } + else if (valueIsLong && (type == typeof(DateTime) || type == typeof(DateTime?))) + { + return DateTime.FromFileTime((long)value); + } obj = type == typeof(int) || type == typeof(long) || type == typeof(double) || type == typeof(float) || type == typeof(bool) || type == typeof(decimal) || type == typeof(byte) || type == typeof(short) ? Convert.ChangeType(value, type, CultureInfo.InvariantCulture) : value; From f987709dba72fb4b45974d0df143eeab3607be6c Mon Sep 17 00:00:00 2001 From: Itai Bar-Haim Date: Tue, 2 Jan 2018 14:51:54 +0200 Subject: [PATCH 05/84] added support for StatusEventPayload --- .../ActivityPayloads/StatusEventPayload.cs | 72 +++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 Octokit/Models/Response/ActivityPayloads/StatusEventPayload.cs diff --git a/Octokit/Models/Response/ActivityPayloads/StatusEventPayload.cs b/Octokit/Models/Response/ActivityPayloads/StatusEventPayload.cs new file mode 100644 index 0000000000..f3e39749b9 --- /dev/null +++ b/Octokit/Models/Response/ActivityPayloads/StatusEventPayload.cs @@ -0,0 +1,72 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; + +namespace Octokit +{ + [DebuggerDisplay("{DebuggerDisplay,nq}")] + public class StatusEventPayload : ActivityPayload + { + /// + /// The name of the repository. + /// + public string Name { get; protected set; } + + /// + /// The SHA of the reference. + /// + public string Sha { get; protected set; } + + /// + /// The date the commit status was created. + /// + public DateTimeOffset CreatedAt { get; protected set; } + + /// + /// The date the commit status was updated. + /// + public DateTimeOffset UpdatedAt { get; protected set; } + + /// + /// The state of the commit + /// + public StringEnum State { get; protected set; } + + /// + /// URL associated with this status. GitHub.com displays this URL as a link to allow users to easily see the + /// ‘source’ of the Status. + /// + public string TargetUrl { get; protected set; } + + /// + /// Short description of the status. + /// + public string Description { get; protected set; } + + /// + /// A string label to differentiate this status from the status of other systems. + /// + public string Context { get; protected set; } + + /// + /// The unique identifier of the status. + /// + public long Id { get; protected set; } + + /// + /// The relevant commit. + /// + public GitHubCommit Commit { get; protected set; } + + /// + /// The organization associated with the event. + /// + public Organization Organization { get; protected set; } + + /// + /// The branches involved. + /// + public IReadOnlyList Branches { get; protected set; } + + } +} From fc4e7b256b6c40ad449baacab3daa114ca883196 Mon Sep 17 00:00:00 2001 From: Itai Bar-Haim Date: Tue, 2 Jan 2018 14:59:03 +0200 Subject: [PATCH 06/84] added support for StatusEventPayload --- .../ActivityPayloads/StatusEventPayload.cs | 72 +++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 Octokit/Models/Response/ActivityPayloads/StatusEventPayload.cs diff --git a/Octokit/Models/Response/ActivityPayloads/StatusEventPayload.cs b/Octokit/Models/Response/ActivityPayloads/StatusEventPayload.cs new file mode 100644 index 0000000000..f3e39749b9 --- /dev/null +++ b/Octokit/Models/Response/ActivityPayloads/StatusEventPayload.cs @@ -0,0 +1,72 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; + +namespace Octokit +{ + [DebuggerDisplay("{DebuggerDisplay,nq}")] + public class StatusEventPayload : ActivityPayload + { + /// + /// The name of the repository. + /// + public string Name { get; protected set; } + + /// + /// The SHA of the reference. + /// + public string Sha { get; protected set; } + + /// + /// The date the commit status was created. + /// + public DateTimeOffset CreatedAt { get; protected set; } + + /// + /// The date the commit status was updated. + /// + public DateTimeOffset UpdatedAt { get; protected set; } + + /// + /// The state of the commit + /// + public StringEnum State { get; protected set; } + + /// + /// URL associated with this status. GitHub.com displays this URL as a link to allow users to easily see the + /// ‘source’ of the Status. + /// + public string TargetUrl { get; protected set; } + + /// + /// Short description of the status. + /// + public string Description { get; protected set; } + + /// + /// A string label to differentiate this status from the status of other systems. + /// + public string Context { get; protected set; } + + /// + /// The unique identifier of the status. + /// + public long Id { get; protected set; } + + /// + /// The relevant commit. + /// + public GitHubCommit Commit { get; protected set; } + + /// + /// The organization associated with the event. + /// + public Organization Organization { get; protected set; } + + /// + /// The branches involved. + /// + public IReadOnlyList Branches { get; protected set; } + + } +} From d60be44e953f0048abaa0ebf5a2760e6019dcbb4 Mon Sep 17 00:00:00 2001 From: Itai Bar-Haim Date: Thu, 4 Jan 2018 16:54:12 +0200 Subject: [PATCH 07/84] Added test for StatusEventPayload and fixed serializer to return that event payload type. --- Octokit.Tests/Clients/EventsClientTests.cs | 50 ++++++++++++++++++++++ Octokit/Http/SimpleJsonSerializer.cs | 2 + 2 files changed, 52 insertions(+) diff --git a/Octokit.Tests/Clients/EventsClientTests.cs b/Octokit.Tests/Clients/EventsClientTests.cs index 8be648f6f6..ccce328bbf 100644 --- a/Octokit.Tests/Clients/EventsClientTests.cs +++ b/Octokit.Tests/Clients/EventsClientTests.cs @@ -560,6 +560,7 @@ public async Task EnsuresNonNullArguments() {"PullRequestEvent", typeof(PullRequestEventPayload)}, {"PullRequestReviewCommentEvent", typeof(PullRequestCommentPayload)}, {"PushEvent", typeof(PushEventPayload)}, + {"StatusEvent", typeof(StatusEventPayload)}, {"WatchEvent", typeof(StarredEventPayload)}, {"unknown", typeof(ActivityPayload)} }; @@ -810,6 +811,55 @@ public async Task DeserializesPushEventCorrectly() Assert.Equal("message", payload.Commits.FirstOrDefault().Message); } + [Fact] + public async Task DeserializesStatusEventCorrectly() + { + var jsonObj = new JsonObject + { + { "type", "StatusEvent" }, + { + "payload", new + { + id = 214015194, + sha = "9049f1265b7d61be4a8904a9a27120d2064dab3b", + name = "baxterthehacker/public-repo", + target_url = "https://www.some_target_url.com", + context = "default", + description = "some human readable text", + state = "success", + branches = new [] + { + new + { + name = "master", + commit = new + { + sha = "9049f1265b7d61be4a8904a9a27120d2064dab3b", + url = "https://api.github.com/repos/baxterthehacker/public-repo/commits/9049f1265b7d61be4a8904a9a27120d2064dab3b" + } + } + }, + created_at = "2015-05-05T23:40:39Z" + } + } + }; + + var client = GetTestingEventsClient(jsonObj); + var activities = await client.GetAll(); + Assert.Equal(1, activities.Count); + + var payload = activities.FirstOrDefault().Payload as StatusEventPayload; + Assert.Equal(214015194, payload.Id); + Assert.Equal("9049f1265b7d61be4a8904a9a27120d2064dab3b", payload.Sha); + Assert.Equal("baxterthehacker/public-repo", payload.Name); + Assert.Equal("https://www.some_target_url.com", payload.TargetUrl); + Assert.Equal("default", payload.Context); + Assert.Equal("some human readable text", payload.Description); + Assert.Equal(CommitState.Success, payload.State.Value); + Assert.Equal(1, payload.Branches.Count); + Assert.Equal(new DateTimeOffset(2015, 05, 05, 23, 40, 39, TimeSpan.Zero), payload.CreatedAt); + } + [Fact] public async Task DeserializesStarredEventCorrectly() { diff --git a/Octokit/Http/SimpleJsonSerializer.cs b/Octokit/Http/SimpleJsonSerializer.cs index 429e9d4090..e450d66c1f 100644 --- a/Octokit/Http/SimpleJsonSerializer.cs +++ b/Octokit/Http/SimpleJsonSerializer.cs @@ -225,6 +225,8 @@ private static Type GetPayloadType(string activityType) return typeof(PullRequestCommentPayload); case "PushEvent": return typeof(PushEventPayload); + case "StatusEvent": + return typeof(StatusEventPayload); case "WatchEvent": return typeof(StarredEventPayload); } From 81e178a1168657ed5ce34795a33ff2ae2b6aa4f0 Mon Sep 17 00:00:00 2001 From: Itai Bar-Haim Date: Mon, 8 Jan 2018 17:06:38 +0200 Subject: [PATCH 08/84] WIP - added ApplicationClient and related Api Urls. --- Octokit/Clients/ApplicationClient.cs | 16 ++++++++++++++++ Octokit/Clients/IApplicationClient.cs | 9 +++++++++ Octokit/GitHubClient.cs | 9 +++++++++ Octokit/Helpers/AcceptHeaders.cs | 2 ++ Octokit/Helpers/ApiUrls.cs | 26 ++++++++++++++++++++++++++ 5 files changed, 62 insertions(+) create mode 100644 Octokit/Clients/ApplicationClient.cs create mode 100644 Octokit/Clients/IApplicationClient.cs diff --git a/Octokit/Clients/ApplicationClient.cs b/Octokit/Clients/ApplicationClient.cs new file mode 100644 index 0000000000..bb67c3e536 --- /dev/null +++ b/Octokit/Clients/ApplicationClient.cs @@ -0,0 +1,16 @@ +using System.Threading.Tasks; + +namespace Octokit +{ + public class ApplicationClient : ApiClient, IApplicationClient + { + public ApplicationClient(IApiConnection apiConnection) : base(apiConnection) + { + } + + public Task Create() + { + return ApiConnection.Get(ApiUrls.App(), null, AcceptHeaders.MachineManPreview); + } + } +} \ No newline at end of file diff --git a/Octokit/Clients/IApplicationClient.cs b/Octokit/Clients/IApplicationClient.cs new file mode 100644 index 0000000000..242bb0adb7 --- /dev/null +++ b/Octokit/Clients/IApplicationClient.cs @@ -0,0 +1,9 @@ +using System.Threading.Tasks; + +namespace Octokit +{ + public interface IApplicationClient + { + Task Create(); + } +} \ No newline at end of file diff --git a/Octokit/GitHubClient.cs b/Octokit/GitHubClient.cs index 3623a7da97..43edca7e2a 100644 --- a/Octokit/GitHubClient.cs +++ b/Octokit/GitHubClient.cs @@ -87,6 +87,7 @@ public GitHubClient(IConnection connection) Enterprise = new EnterpriseClient(apiConnection); Gist = new GistsClient(apiConnection); Git = new GitDatabaseClient(apiConnection); + Application = new ApplicationClient(apiConnection); Installations = new InstallationsClient(apiConnection); Issue = new IssuesClient(apiConnection); Migration = new MigrationClient(apiConnection); @@ -255,6 +256,14 @@ public Uri BaseAddress /// public IGitDatabaseClient Git { get; private set; } + /// + /// Access GitHub's Apps API. + /// + /// + /// Refer to the API documentation for more information: https://developer.github.com/v3/git/ + /// + public IApplicationClient Application { get; private set; } + /// /// Access GitHub's Search API. /// diff --git a/Octokit/Helpers/AcceptHeaders.cs b/Octokit/Helpers/AcceptHeaders.cs index afd058d779..d72ec9af8e 100644 --- a/Octokit/Helpers/AcceptHeaders.cs +++ b/Octokit/Helpers/AcceptHeaders.cs @@ -50,5 +50,7 @@ public static class AcceptHeaders public const string OrganizationMembershipPreview = "application/vnd.github.korra-preview+json"; public const string NestedTeamsPreview = "application/vnd.github.hellcat-preview+json"; + + public const string MachineManPreview = "application/vnd.github.machine-man-preview+json"; } } diff --git a/Octokit/Helpers/ApiUrls.cs b/Octokit/Helpers/ApiUrls.cs index c7602e99c8..a7e0da87e2 100644 --- a/Octokit/Helpers/ApiUrls.cs +++ b/Octokit/Helpers/ApiUrls.cs @@ -298,6 +298,32 @@ public static Uri AccessTokens(int installationId) return "installations/{0}/access_tokens".FormatUri(installationId); } + /// + /// Returns the that creates a github app. + /// + public static Uri App() + { + return "app".FormatUri(); + } + + /// + /// Returns the that returns all the installations of the authenticated application. + /// + /// + public static Uri Installations() + { + return "app/installations".FormatUri(); + } + + /// + /// Returns the that returns a single installation of the authenticated application. + /// + /// + public static Uri Installation(int installationId) + { + return "app/installations/{0}".FormatUri(installationId); + } + /// /// Returns the that returns all of the issues across all the authenticated user’s visible /// repositories including owned repositories, member repositories, and organization repositories: From 038b48f47d60772d7b3844c38cfdeca3de8cbde1 Mon Sep 17 00:00:00 2001 From: Itai Bar-Haim Date: Thu, 11 Jan 2018 13:33:34 +0200 Subject: [PATCH 09/84] Continued implementing Installations support. --- Octokit/Clients/IInstallationsClient.cs | 6 ++- Octokit/Clients/InstallationsClient.cs | 10 ++++- Octokit/Http/ApiConnection.cs | 2 +- Octokit/Http/Connection.cs | 6 +-- Octokit/Http/Credentials.cs | 10 ++--- Octokit/Http/IConnection.cs | 3 +- Octokit/Models/Response/Installation.cs | 53 +++++++++++++++++++++++++ 7 files changed, 76 insertions(+), 14 deletions(-) create mode 100644 Octokit/Models/Response/Installation.cs diff --git a/Octokit/Clients/IInstallationsClient.cs b/Octokit/Clients/IInstallationsClient.cs index 66253f8d1b..c64b9964c7 100644 --- a/Octokit/Clients/IInstallationsClient.cs +++ b/Octokit/Clients/IInstallationsClient.cs @@ -1,7 +1,11 @@ -namespace Octokit +using System.Collections.Generic; +using System.Threading.Tasks; + +namespace Octokit { public interface IInstallationsClient { + Task> GetInstallations(); IAccessTokensClient AccessTokens { get; } } } diff --git a/Octokit/Clients/InstallationsClient.cs b/Octokit/Clients/InstallationsClient.cs index d25da7664f..26f6ec5db6 100644 --- a/Octokit/Clients/InstallationsClient.cs +++ b/Octokit/Clients/InstallationsClient.cs @@ -1,4 +1,7 @@ -namespace Octokit +using System.Collections.Generic; +using System.Threading.Tasks; + +namespace Octokit { class InstallationsClient : ApiClient, IInstallationsClient { @@ -8,5 +11,10 @@ public InstallationsClient(IApiConnection apiConnection) : base(apiConnection) } public IAccessTokensClient AccessTokens { get; private set; } + + public Task> GetInstallations() + { + return ApiConnection.GetAll(ApiUrls.Installations(), null, AcceptHeaders.MachineManPreview); + } } } diff --git a/Octokit/Http/ApiConnection.cs b/Octokit/Http/ApiConnection.cs index 2c6194aaf5..0149185082 100644 --- a/Octokit/Http/ApiConnection.cs +++ b/Octokit/Http/ApiConnection.cs @@ -268,7 +268,7 @@ public Task Post(Uri uri, object data, string accepts) public async Task Post(Uri uri, object data, string accepts, string contentType) { Ensure.ArgumentNotNull(uri, "uri"); - Ensure.ArgumentNotNull(data, "data"); + //Ensure.ArgumentNotNull(data, "data"); var response = await Connection.Post(uri, data, accepts, contentType).ConfigureAwait(false); return response.Body; diff --git a/Octokit/Http/Connection.cs b/Octokit/Http/Connection.cs index 021d5be8f0..9a66da02bb 100644 --- a/Octokit/Http/Connection.cs +++ b/Octokit/Http/Connection.cs @@ -238,12 +238,12 @@ public Task> Post(Uri uri) return SendData(uri, HttpMethod.Post, null, null, null, CancellationToken.None); } - public Task> Post(Uri uri, object body, string accepts, string contentType) + public Task> Post(Uri uri, object body, string accepts, string contentType, IDictionary parameters = null) { Ensure.ArgumentNotNull(uri, "uri"); - Ensure.ArgumentNotNull(body, "body"); + //Ensure.ArgumentNotNull(body, "body"); - return SendData(uri, HttpMethod.Post, body, accepts, contentType, CancellationToken.None); + return SendData(uri.ApplyParameters(parameters), HttpMethod.Post, body, accepts, contentType, CancellationToken.None); } /// diff --git a/Octokit/Http/Credentials.cs b/Octokit/Http/Credentials.cs index e4cd21b508..24d82af24c 100644 --- a/Octokit/Http/Credentials.cs +++ b/Octokit/Http/Credentials.cs @@ -13,21 +13,17 @@ private Credentials() AuthenticationType = AuthenticationType.Anonymous; } - public Credentials(string token) : this(token, AuthenticationType.Oauth) - { - } - - public Credentials(string login, string password) + public Credentials(string login, string password, AuthenticationType authenticationType = AuthenticationType.Basic) { Ensure.ArgumentNotNullOrEmptyString(login, "login"); Ensure.ArgumentNotNullOrEmptyString(password, "password"); Login = login; Password = password; - AuthenticationType = AuthenticationType.Basic; + AuthenticationType = authenticationType; } - public Credentials(string token, AuthenticationType authenticationType) + public Credentials(string token, AuthenticationType authenticationType = AuthenticationType.Oauth) { Ensure.ArgumentNotNullOrEmptyString(token, "token"); diff --git a/Octokit/Http/IConnection.cs b/Octokit/Http/IConnection.cs index 98c0380c0f..08755cb0ee 100644 --- a/Octokit/Http/IConnection.cs +++ b/Octokit/Http/IConnection.cs @@ -126,8 +126,9 @@ public interface IConnection : IApiInfoProvider /// The object to serialize as the body of the request /// Specifies accepted response media types. /// Specifies the media type of the request body + /// Extra parameters for authentication. /// representing the received HTTP response - Task> Post(Uri uri, object body, string accepts, string contentType); + Task> Post(Uri uri, object body, string accepts, string contentType, IDictionary parameters = null); /// /// Performs an asynchronous HTTP POST request. diff --git a/Octokit/Models/Response/Installation.cs b/Octokit/Models/Response/Installation.cs new file mode 100644 index 0000000000..ab53658b98 --- /dev/null +++ b/Octokit/Models/Response/Installation.cs @@ -0,0 +1,53 @@ +using System.Diagnostics; +using System.Globalization; + +namespace Octokit +{ + /// + /// Represents an application installation. + /// + /// + /// For more information see https://developer.github.com/v3/apps/#find-installations + /// + [DebuggerDisplay("{DebuggerDisplay,nq}")] + public class Installation + { + public Installation() { } + + public Installation(int id, // Account account, + string accessTokenUrl, string repositoriesUrl, string htmlUrl, + int appId, int targetId, AccountType targetType, + string singleFileName, string repositorySelection) + { + Id = id; + // Account = account; + AccessTokensUrl = accessTokenUrl; + RepositoriesUrl = repositoriesUrl; + HtmlUrl = htmlUrl; + AppId = appId; + TargetId = targetId; + TargetType = targetType; + SingleFileName = singleFileName; + RepositorySelection = repositorySelection; + } + + public int Id { get; protected set; } + // public Account Account { get; protected set; } + public string AccessTokensUrl { get; protected set; } + public string RepositoriesUrl { get; protected set; } + public string HtmlUrl { get; protected set; } + + public int AppId { get; protected set; } + public int TargetId { get; protected set; } + public AccountType TargetType { get; protected set; } + // TODO - add permissions + // TODO - add events + public string SingleFileName { get; protected set; } + public string RepositorySelection { get; protected set; } + + internal string DebuggerDisplay + { + get { return string.Format(CultureInfo.InvariantCulture, "Installation Id: {0} ; App Id: {1}", Id, AppId); } + } + } +} From 8c81b8bfd9cbefadd8e45d928c599ba50bc6f585 Mon Sep 17 00:00:00 2001 From: Itai Bar-Haim Date: Thu, 11 Jan 2018 15:45:41 +0200 Subject: [PATCH 10/84] Fixing build (WIP) --- .../Clients/IObservableInstallationsClient.cs | 6 +++++- .../Clients/ObservableInstallationsClient.cs | 19 +++++++++++++++++-- Octokit/Clients/AccessTokensClient.cs | 2 +- Octokit/Clients/IInstallationsClient.cs | 4 +++- Octokit/Clients/InstallationsClient.cs | 9 ++++++++- Octokit/Http/ApiConnection.cs | 2 +- Octokit/Http/Connection.cs | 2 +- Octokit/Models/Response/Installation.cs | 2 +- 8 files changed, 37 insertions(+), 9 deletions(-) diff --git a/Octokit.Reactive/Clients/IObservableInstallationsClient.cs b/Octokit.Reactive/Clients/IObservableInstallationsClient.cs index 7bffda2775..41c66d37c4 100644 --- a/Octokit.Reactive/Clients/IObservableInstallationsClient.cs +++ b/Octokit.Reactive/Clients/IObservableInstallationsClient.cs @@ -1,7 +1,11 @@ -namespace Octokit.Reactive +using System; + +namespace Octokit.Reactive { public interface IObservableInstallationsClient { IObservableAccessTokensClient AccessTokens { get; } + IObservable GetAll(); + IObservable GetAll(ApiOptions options); } } diff --git a/Octokit.Reactive/Clients/ObservableInstallationsClient.cs b/Octokit.Reactive/Clients/ObservableInstallationsClient.cs index c03d9fe6fa..401d62ffc7 100644 --- a/Octokit.Reactive/Clients/ObservableInstallationsClient.cs +++ b/Octokit.Reactive/Clients/ObservableInstallationsClient.cs @@ -1,4 +1,7 @@ -namespace Octokit.Reactive +using System; +using Octokit.Reactive.Internal; + +namespace Octokit.Reactive { class ObservableInstallationsClient : IObservableInstallationsClient { @@ -13,7 +16,19 @@ public ObservableInstallationsClient(IGitHubClient client) _connection = client.Connection; AccessTokens = new ObservableAccessTokensClient(client); } - + public IObservableAccessTokensClient AccessTokens { get; } + + public IObservable GetAll() + { + return _connection.GetAndFlattenAllPages(ApiUrls.Installations(), null, AcceptHeaders.MachineManPreview); + } + + public IObservable GetAll(ApiOptions options) + { + Ensure.ArgumentNotNull(options, "options"); + + return _connection.GetAndFlattenAllPages(ApiUrls.Installations(), null, AcceptHeaders.MachineManPreview, options); + } } } diff --git a/Octokit/Clients/AccessTokensClient.cs b/Octokit/Clients/AccessTokensClient.cs index 098674e9ea..d92ef7b58c 100644 --- a/Octokit/Clients/AccessTokensClient.cs +++ b/Octokit/Clients/AccessTokensClient.cs @@ -12,7 +12,7 @@ public AccessTokensClient(IApiConnection apiConnection) : base(apiConnection) public Task Create(int installationId) { - return ApiConnection.Post(ApiUrls.AccessTokens(installationId), null, AcceptHeader); + return ApiConnection.Post(ApiUrls.AccessTokens(installationId), "", AcceptHeader); } } } diff --git a/Octokit/Clients/IInstallationsClient.cs b/Octokit/Clients/IInstallationsClient.cs index c64b9964c7..0730b6edba 100644 --- a/Octokit/Clients/IInstallationsClient.cs +++ b/Octokit/Clients/IInstallationsClient.cs @@ -5,7 +5,9 @@ namespace Octokit { public interface IInstallationsClient { - Task> GetInstallations(); IAccessTokensClient AccessTokens { get; } + + Task> GetAll(); + Task> GetAll(ApiOptions options); } } diff --git a/Octokit/Clients/InstallationsClient.cs b/Octokit/Clients/InstallationsClient.cs index 26f6ec5db6..fec0b470c5 100644 --- a/Octokit/Clients/InstallationsClient.cs +++ b/Octokit/Clients/InstallationsClient.cs @@ -12,9 +12,16 @@ public InstallationsClient(IApiConnection apiConnection) : base(apiConnection) public IAccessTokensClient AccessTokens { get; private set; } - public Task> GetInstallations() + public Task> GetAll() { return ApiConnection.GetAll(ApiUrls.Installations(), null, AcceptHeaders.MachineManPreview); } + + public Task> GetAll(ApiOptions options) + { + Ensure.ArgumentNotNull(options, "options"); + + return ApiConnection.GetAll(ApiUrls.Installations(), null, AcceptHeaders.MachineManPreview, options); + } } } diff --git a/Octokit/Http/ApiConnection.cs b/Octokit/Http/ApiConnection.cs index 0149185082..2c6194aaf5 100644 --- a/Octokit/Http/ApiConnection.cs +++ b/Octokit/Http/ApiConnection.cs @@ -268,7 +268,7 @@ public Task Post(Uri uri, object data, string accepts) public async Task Post(Uri uri, object data, string accepts, string contentType) { Ensure.ArgumentNotNull(uri, "uri"); - //Ensure.ArgumentNotNull(data, "data"); + Ensure.ArgumentNotNull(data, "data"); var response = await Connection.Post(uri, data, accepts, contentType).ConfigureAwait(false); return response.Body; diff --git a/Octokit/Http/Connection.cs b/Octokit/Http/Connection.cs index 9a66da02bb..18d5825366 100644 --- a/Octokit/Http/Connection.cs +++ b/Octokit/Http/Connection.cs @@ -241,7 +241,7 @@ public Task> Post(Uri uri) public Task> Post(Uri uri, object body, string accepts, string contentType, IDictionary parameters = null) { Ensure.ArgumentNotNull(uri, "uri"); - //Ensure.ArgumentNotNull(body, "body"); + Ensure.ArgumentNotNull(body, "body"); return SendData(uri.ApplyParameters(parameters), HttpMethod.Post, body, accepts, contentType, CancellationToken.None); } diff --git a/Octokit/Models/Response/Installation.cs b/Octokit/Models/Response/Installation.cs index ab53658b98..06094c418c 100644 --- a/Octokit/Models/Response/Installation.cs +++ b/Octokit/Models/Response/Installation.cs @@ -39,7 +39,7 @@ public Installation(int id, // Account account, public int AppId { get; protected set; } public int TargetId { get; protected set; } - public AccountType TargetType { get; protected set; } + public StringEnum TargetType { get; protected set; } // TODO - add permissions // TODO - add events public string SingleFileName { get; protected set; } From fb4f58aa771f6d3a57344ba80905caa60f85978b Mon Sep 17 00:00:00 2001 From: Itai Bar-Haim Date: Thu, 11 Jan 2018 16:22:56 +0200 Subject: [PATCH 11/84] fixed build --- .../Clients/IObservableApplicationClient.cs | 9 ++++++++ .../Clients/ObservableApplicationClient.cs | 22 +++++++++++++++++++ Octokit.Reactive/IObservableGitHubClient.cs | 1 + Octokit.Reactive/ObservableGitHubClient.cs | 2 ++ Octokit/IGitHubClient.cs | 2 ++ 5 files changed, 36 insertions(+) create mode 100644 Octokit.Reactive/Clients/IObservableApplicationClient.cs create mode 100644 Octokit.Reactive/Clients/ObservableApplicationClient.cs diff --git a/Octokit.Reactive/Clients/IObservableApplicationClient.cs b/Octokit.Reactive/Clients/IObservableApplicationClient.cs new file mode 100644 index 0000000000..9c4da50a04 --- /dev/null +++ b/Octokit.Reactive/Clients/IObservableApplicationClient.cs @@ -0,0 +1,9 @@ +using System; + +namespace Octokit.Reactive +{ + public interface IObservableApplicationClient + { + IObservable Create(); + } +} diff --git a/Octokit.Reactive/Clients/ObservableApplicationClient.cs b/Octokit.Reactive/Clients/ObservableApplicationClient.cs new file mode 100644 index 0000000000..202f34f556 --- /dev/null +++ b/Octokit.Reactive/Clients/ObservableApplicationClient.cs @@ -0,0 +1,22 @@ +using System; +using System.Reactive.Threading.Tasks; + +namespace Octokit.Reactive +{ + public class ObservableApplicationClient : IObservableApplicationClient + { + private IApplicationClient _client; + + public ObservableApplicationClient(IGitHubClient client) + { + Ensure.ArgumentNotNull(client, "client"); + + _client = client.Application; + } + + public IObservable Create() + { + return _client.Create().ToObservable(); + } + } +} diff --git a/Octokit.Reactive/IObservableGitHubClient.cs b/Octokit.Reactive/IObservableGitHubClient.cs index f6b712c00b..e7982d834c 100644 --- a/Octokit.Reactive/IObservableGitHubClient.cs +++ b/Octokit.Reactive/IObservableGitHubClient.cs @@ -18,6 +18,7 @@ public interface IObservableGitHubClient : IApiInfoProvider IObservableAuthorizationsClient Authorization { get; } IObservableActivitiesClient Activity { get; } + IObservableApplicationClient Application { get; } IObservableInstallationsClient Installations { get; } IObservableIssuesClient Issue { get; } IObservableMiscellaneousClient Miscellaneous { get; } diff --git a/Octokit.Reactive/ObservableGitHubClient.cs b/Octokit.Reactive/ObservableGitHubClient.cs index 413ad71fdf..77c63be8d3 100644 --- a/Octokit.Reactive/ObservableGitHubClient.cs +++ b/Octokit.Reactive/ObservableGitHubClient.cs @@ -33,6 +33,7 @@ public ObservableGitHubClient(IGitHubClient gitHubClient) _gitHubClient = gitHubClient; Authorization = new ObservableAuthorizationsClient(gitHubClient); Activity = new ObservableActivitiesClient(gitHubClient); + Application = new ObservableApplicationClient(gitHubClient); Installations = new ObservableInstallationsClient(gitHubClient); Issue = new ObservableIssuesClient(gitHubClient); Miscellaneous = new ObservableMiscellaneousClient(gitHubClient); @@ -70,6 +71,7 @@ public void SetRequestTimeout(TimeSpan timeout) public IObservableAuthorizationsClient Authorization { get; private set; } public IObservableActivitiesClient Activity { get; private set; } + public IObservableApplicationClient Application { get; private set; } public IObservableInstallationsClient Installations { get; private set; } public IObservableIssuesClient Issue { get; private set; } public IObservableMiscellaneousClient Miscellaneous { get; private set; } diff --git a/Octokit/IGitHubClient.cs b/Octokit/IGitHubClient.cs index 5d2b7f594e..bc515db8b8 100644 --- a/Octokit/IGitHubClient.cs +++ b/Octokit/IGitHubClient.cs @@ -38,6 +38,8 @@ public interface IGitHubClient : IApiInfoProvider /// IActivitiesClient Activity { get; } + IApplicationClient Application { get; } + IInstallationsClient Installations { get; } /// From a09786983632d141ac967e49da02d24b705b4c85 Mon Sep 17 00:00:00 2001 From: Itai Bar-Haim Date: Sun, 14 Jan 2018 11:04:15 +0200 Subject: [PATCH 12/84] added Account property to Installation. prefer nameof(x) over literal "x". --- Octokit.Reactive/Clients/ObservableInstallationsClient.cs | 2 +- Octokit/Clients/InstallationsClient.cs | 2 +- Octokit/Models/Response/Installation.cs | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Octokit.Reactive/Clients/ObservableInstallationsClient.cs b/Octokit.Reactive/Clients/ObservableInstallationsClient.cs index 401d62ffc7..e6a86f6f84 100644 --- a/Octokit.Reactive/Clients/ObservableInstallationsClient.cs +++ b/Octokit.Reactive/Clients/ObservableInstallationsClient.cs @@ -26,7 +26,7 @@ public IObservable GetAll() public IObservable GetAll(ApiOptions options) { - Ensure.ArgumentNotNull(options, "options"); + Ensure.ArgumentNotNull(options, nameof(options)); return _connection.GetAndFlattenAllPages(ApiUrls.Installations(), null, AcceptHeaders.MachineManPreview, options); } diff --git a/Octokit/Clients/InstallationsClient.cs b/Octokit/Clients/InstallationsClient.cs index fec0b470c5..89106e6c2f 100644 --- a/Octokit/Clients/InstallationsClient.cs +++ b/Octokit/Clients/InstallationsClient.cs @@ -19,7 +19,7 @@ public Task> GetAll() public Task> GetAll(ApiOptions options) { - Ensure.ArgumentNotNull(options, "options"); + Ensure.ArgumentNotNull(options, nameof(options)); return ApiConnection.GetAll(ApiUrls.Installations(), null, AcceptHeaders.MachineManPreview, options); } diff --git a/Octokit/Models/Response/Installation.cs b/Octokit/Models/Response/Installation.cs index 06094c418c..7571126dff 100644 --- a/Octokit/Models/Response/Installation.cs +++ b/Octokit/Models/Response/Installation.cs @@ -14,13 +14,13 @@ public class Installation { public Installation() { } - public Installation(int id, // Account account, + public Installation(int id, User account, string accessTokenUrl, string repositoriesUrl, string htmlUrl, int appId, int targetId, AccountType targetType, string singleFileName, string repositorySelection) { Id = id; - // Account = account; + Account = account; AccessTokensUrl = accessTokenUrl; RepositoriesUrl = repositoriesUrl; HtmlUrl = htmlUrl; @@ -32,7 +32,7 @@ public Installation(int id, // Account account, } public int Id { get; protected set; } - // public Account Account { get; protected set; } + public User Account { get; protected set; } public string AccessTokensUrl { get; protected set; } public string RepositoriesUrl { get; protected set; } public string HtmlUrl { get; protected set; } From c3efb73e81e7fc24f76b1ebe0ba7e318d4656428 Mon Sep 17 00:00:00 2001 From: Itai Bar-Haim Date: Thu, 18 Jan 2018 14:01:58 +0200 Subject: [PATCH 13/84] fixed according to code review. --- .../Clients/ObservableAccessTokensClient.cs | 2 +- .../Clients/ObservableApplicationClient.cs | 2 +- .../Clients/ObservableInstallationsClient.cs | 2 +- Octokit.Reactive/IObservableGitHubClient.cs | 2 +- Octokit.Reactive/ObservableGitHubClient.cs | 4 +- .../BearerTokenAuthenticator.cs | 6 +- ...icationClient.cs => ApplicationsClient.cs} | 4 +- ...cationClient.cs => IApplicationsClient.cs} | 2 +- Octokit/GitHubClient.cs | 15 ++-- Octokit/Http/Connection.cs | 78 ++++++++++--------- Octokit/Http/Credentials.cs | 14 ++-- Octokit/IGitHubClient.cs | 4 +- 12 files changed, 76 insertions(+), 59 deletions(-) rename Octokit/Clients/{ApplicationClient.cs => ApplicationsClient.cs} (62%) rename Octokit/Clients/{IApplicationClient.cs => IApplicationsClient.cs} (71%) diff --git a/Octokit.Reactive/Clients/ObservableAccessTokensClient.cs b/Octokit.Reactive/Clients/ObservableAccessTokensClient.cs index 56f38ac7e9..1ec3888441 100644 --- a/Octokit.Reactive/Clients/ObservableAccessTokensClient.cs +++ b/Octokit.Reactive/Clients/ObservableAccessTokensClient.cs @@ -12,7 +12,7 @@ public ObservableAccessTokensClient(IGitHubClient client) { Ensure.ArgumentNotNull(client, "client"); - _client = client.Installations.AccessTokens; + _client = client.Installation.AccessTokens; _connection = client.Connection; } diff --git a/Octokit.Reactive/Clients/ObservableApplicationClient.cs b/Octokit.Reactive/Clients/ObservableApplicationClient.cs index 202f34f556..163417f9bd 100644 --- a/Octokit.Reactive/Clients/ObservableApplicationClient.cs +++ b/Octokit.Reactive/Clients/ObservableApplicationClient.cs @@ -5,7 +5,7 @@ namespace Octokit.Reactive { public class ObservableApplicationClient : IObservableApplicationClient { - private IApplicationClient _client; + private IApplicationsClient _client; public ObservableApplicationClient(IGitHubClient client) { diff --git a/Octokit.Reactive/Clients/ObservableInstallationsClient.cs b/Octokit.Reactive/Clients/ObservableInstallationsClient.cs index e6a86f6f84..61fd1bd801 100644 --- a/Octokit.Reactive/Clients/ObservableInstallationsClient.cs +++ b/Octokit.Reactive/Clients/ObservableInstallationsClient.cs @@ -12,7 +12,7 @@ public ObservableInstallationsClient(IGitHubClient client) { Ensure.ArgumentNotNull(client, "client"); - _client = client.Installations; + _client = client.Installation; _connection = client.Connection; AccessTokens = new ObservableAccessTokensClient(client); } diff --git a/Octokit.Reactive/IObservableGitHubClient.cs b/Octokit.Reactive/IObservableGitHubClient.cs index e7982d834c..7e38dfc093 100644 --- a/Octokit.Reactive/IObservableGitHubClient.cs +++ b/Octokit.Reactive/IObservableGitHubClient.cs @@ -19,7 +19,7 @@ public interface IObservableGitHubClient : IApiInfoProvider IObservableAuthorizationsClient Authorization { get; } IObservableActivitiesClient Activity { get; } IObservableApplicationClient Application { get; } - IObservableInstallationsClient Installations { get; } + IObservableInstallationsClient Installation { get; } IObservableIssuesClient Issue { get; } IObservableMiscellaneousClient Miscellaneous { get; } IObservableOauthClient Oauth { get; } diff --git a/Octokit.Reactive/ObservableGitHubClient.cs b/Octokit.Reactive/ObservableGitHubClient.cs index 77c63be8d3..fd635ba9aa 100644 --- a/Octokit.Reactive/ObservableGitHubClient.cs +++ b/Octokit.Reactive/ObservableGitHubClient.cs @@ -34,7 +34,7 @@ public ObservableGitHubClient(IGitHubClient gitHubClient) Authorization = new ObservableAuthorizationsClient(gitHubClient); Activity = new ObservableActivitiesClient(gitHubClient); Application = new ObservableApplicationClient(gitHubClient); - Installations = new ObservableInstallationsClient(gitHubClient); + Installation = new ObservableInstallationsClient(gitHubClient); Issue = new ObservableIssuesClient(gitHubClient); Miscellaneous = new ObservableMiscellaneousClient(gitHubClient); Oauth = new ObservableOauthClient(gitHubClient); @@ -72,7 +72,7 @@ public void SetRequestTimeout(TimeSpan timeout) public IObservableAuthorizationsClient Authorization { get; private set; } public IObservableActivitiesClient Activity { get; private set; } public IObservableApplicationClient Application { get; private set; } - public IObservableInstallationsClient Installations { get; private set; } + public IObservableInstallationsClient Installation { get; private set; } public IObservableIssuesClient Issue { get; private set; } public IObservableMiscellaneousClient Miscellaneous { get; private set; } public IObservableOauthClient Oauth { get; private set; } diff --git a/Octokit/Authentication/BearerTokenAuthenticator.cs b/Octokit/Authentication/BearerTokenAuthenticator.cs index c8fe0953f6..42757b502a 100644 --- a/Octokit/Authentication/BearerTokenAuthenticator.cs +++ b/Octokit/Authentication/BearerTokenAuthenticator.cs @@ -7,9 +7,9 @@ class BearerTokenAuthenticator: IAuthenticationHandler { public void Authenticate(IRequest request, Credentials credentials) { - Ensure.ArgumentNotNull(request, "request"); - Ensure.ArgumentNotNull(credentials, "credentials"); - Ensure.ArgumentNotNull(credentials.Password, "credentials.Password"); + Ensure.ArgumentNotNull(request, nameof(request)); + Ensure.ArgumentNotNull(credentials, nameof(credentials)); + Ensure.ArgumentNotNull(credentials.Password, nameof(credentials.Password)); if (credentials.Login != null) { diff --git a/Octokit/Clients/ApplicationClient.cs b/Octokit/Clients/ApplicationsClient.cs similarity index 62% rename from Octokit/Clients/ApplicationClient.cs rename to Octokit/Clients/ApplicationsClient.cs index bb67c3e536..814427ecf9 100644 --- a/Octokit/Clients/ApplicationClient.cs +++ b/Octokit/Clients/ApplicationsClient.cs @@ -2,9 +2,9 @@ namespace Octokit { - public class ApplicationClient : ApiClient, IApplicationClient + public class ApplicationsClient : ApiClient, IApplicationsClient { - public ApplicationClient(IApiConnection apiConnection) : base(apiConnection) + public ApplicationsClient(IApiConnection apiConnection) : base(apiConnection) { } diff --git a/Octokit/Clients/IApplicationClient.cs b/Octokit/Clients/IApplicationsClient.cs similarity index 71% rename from Octokit/Clients/IApplicationClient.cs rename to Octokit/Clients/IApplicationsClient.cs index 242bb0adb7..bf7491db2f 100644 --- a/Octokit/Clients/IApplicationClient.cs +++ b/Octokit/Clients/IApplicationsClient.cs @@ -2,7 +2,7 @@ namespace Octokit { - public interface IApplicationClient + public interface IApplicationsClient { Task Create(); } diff --git a/Octokit/GitHubClient.cs b/Octokit/GitHubClient.cs index 43edca7e2a..3630bc1085 100644 --- a/Octokit/GitHubClient.cs +++ b/Octokit/GitHubClient.cs @@ -87,8 +87,8 @@ public GitHubClient(IConnection connection) Enterprise = new EnterpriseClient(apiConnection); Gist = new GistsClient(apiConnection); Git = new GitDatabaseClient(apiConnection); - Application = new ApplicationClient(apiConnection); - Installations = new InstallationsClient(apiConnection); + Application = new ApplicationsClient(apiConnection); + Installation = new InstallationsClient(apiConnection); Issue = new IssuesClient(apiConnection); Migration = new MigrationClient(apiConnection); Miscellaneous = new MiscellaneousClient(connection); @@ -173,8 +173,13 @@ public Uri BaseAddress /// public IActivitiesClient Activity { get; private set; } - public IInstallationsClient Installations { get; private set; } - + /// + /// Access GitHub's App Installation API. + /// + /// + /// Refer to the API documentation for more information: https://developer.github.com/v3/apps/installations/ + /// + public IInstallationsClient Installation { get; private set; } /// /// Access GitHub's Issue API. @@ -262,7 +267,7 @@ public Uri BaseAddress /// /// Refer to the API documentation for more information: https://developer.github.com/v3/git/ /// - public IApplicationClient Application { get; private set; } + public IApplicationsClient Application { get; private set; } /// /// Access GitHub's Search API. diff --git a/Octokit/Http/Connection.cs b/Octokit/Http/Connection.cs index 18d5825366..04c4e3daf0 100644 --- a/Octokit/Http/Connection.cs +++ b/Octokit/Http/Connection.cs @@ -120,17 +120,17 @@ public Connection( IHttpClient httpClient, IJsonSerializer serializer) { - Ensure.ArgumentNotNull(productInformation, "productInformation"); - Ensure.ArgumentNotNull(baseAddress, "baseAddress"); - Ensure.ArgumentNotNull(credentialStore, "credentialStore"); - Ensure.ArgumentNotNull(httpClient, "httpClient"); - Ensure.ArgumentNotNull(serializer, "serializer"); + Ensure.ArgumentNotNull(productInformation, nameof(productInformation)); + Ensure.ArgumentNotNull(baseAddress, nameof(baseAddress)); + Ensure.ArgumentNotNull(credentialStore, nameof(credentialStore)); + Ensure.ArgumentNotNull(httpClient, nameof(httpClient)); + Ensure.ArgumentNotNull(serializer, nameof(serializer)); if (!baseAddress.IsAbsoluteUri) { throw new ArgumentException( string.Format(CultureInfo.InvariantCulture, "The base address '{0}' must be an absolute URI", - baseAddress), "baseAddress"); + baseAddress), nameof(baseAddress)); } UserAgent = FormatUserAgent(productInformation); @@ -156,21 +156,21 @@ public ApiInfo GetLastApiInfo() public Task> Get(Uri uri, IDictionary parameters, string accepts) { - Ensure.ArgumentNotNull(uri, "uri"); + Ensure.ArgumentNotNull(uri, nameof(uri)); return SendData(uri.ApplyParameters(parameters), HttpMethod.Get, null, accepts, null, CancellationToken.None); } public Task> Get(Uri uri, IDictionary parameters, string accepts, CancellationToken cancellationToken) { - Ensure.ArgumentNotNull(uri, "uri"); + Ensure.ArgumentNotNull(uri, nameof(uri)); return SendData(uri.ApplyParameters(parameters), HttpMethod.Get, null, accepts, null, cancellationToken); } public Task> Get(Uri uri, TimeSpan timeout) { - Ensure.ArgumentNotNull(uri, "uri"); + Ensure.ArgumentNotNull(uri, nameof(uri)); return SendData(uri, HttpMethod.Get, null, null, null, timeout, CancellationToken.None); } @@ -183,7 +183,7 @@ public Task> Get(Uri uri, TimeSpan timeout) /// representing the received HTTP response public Task> GetHtml(Uri uri, IDictionary parameters) { - Ensure.ArgumentNotNull(uri, "uri"); + Ensure.ArgumentNotNull(uri, nameof(uri)); return GetHtml(new Request { @@ -195,17 +195,17 @@ public Task> GetHtml(Uri uri, IDictionary p public Task> Patch(Uri uri, object body) { - Ensure.ArgumentNotNull(uri, "uri"); - Ensure.ArgumentNotNull(body, "body"); + Ensure.ArgumentNotNull(uri, nameof(uri)); + Ensure.ArgumentNotNull(body, nameof(body)); return SendData(uri, HttpVerb.Patch, body, null, null, CancellationToken.None); } public Task> Patch(Uri uri, object body, string accepts) { - Ensure.ArgumentNotNull(uri, "uri"); - Ensure.ArgumentNotNull(body, "body"); - Ensure.ArgumentNotNull(accepts, "accepts"); + Ensure.ArgumentNotNull(uri, nameof(uri)); + Ensure.ArgumentNotNull(body, nameof(body)); + Ensure.ArgumentNotNull(accepts, nameof(accepts)); return SendData(uri, HttpVerb.Patch, body, accepts, null, CancellationToken.None); } @@ -217,7 +217,7 @@ public Task> Patch(Uri uri, object body, string accepts) /// representing the received HTTP response public async Task Post(Uri uri) { - Ensure.ArgumentNotNull(uri, "uri"); + Ensure.ArgumentNotNull(uri, nameof(uri)); var response = await SendData(uri, HttpMethod.Post, null, null, null, CancellationToken.None).ConfigureAwait(false); return response.HttpResponse.StatusCode; @@ -225,7 +225,7 @@ public async Task Post(Uri uri) public async Task Post(Uri uri, object body, string accepts) { - Ensure.ArgumentNotNull(uri, "uri"); + Ensure.ArgumentNotNull(uri, nameof(uri)); var response = await SendData(uri, HttpMethod.Post, body, accepts, null, CancellationToken.None).ConfigureAwait(false); return response.HttpResponse.StatusCode; @@ -233,15 +233,23 @@ public async Task Post(Uri uri, object body, string accepts) public Task> Post(Uri uri) { - Ensure.ArgumentNotNull(uri, "uri"); + Ensure.ArgumentNotNull(uri, nameof(uri)); return SendData(uri, HttpMethod.Post, null, null, null, CancellationToken.None); } - public Task> Post(Uri uri, object body, string accepts, string contentType, IDictionary parameters = null) + public Task> Post(Uri uri, object body, string accepts, string contentType) { - Ensure.ArgumentNotNull(uri, "uri"); - Ensure.ArgumentNotNull(body, "body"); + Ensure.ArgumentNotNull(uri, nameof(uri)); + Ensure.ArgumentNotNull(body, nameof(body)); + + return SendData(uri, HttpMethod.Post, body, accepts, contentType, CancellationToken.None); + } + + public Task> Post(Uri uri, object body, string accepts, string contentType, IDictionary parameters) + { + Ensure.ArgumentNotNull(uri, nameof(uri)); + Ensure.ArgumentNotNull(body, nameof(body)); return SendData(uri.ApplyParameters(parameters), HttpMethod.Post, body, accepts, contentType, CancellationToken.None); } @@ -259,25 +267,25 @@ public Task> Post(Uri uri, object body, string accepts, strin /// representing the received HTTP response public Task> Post(Uri uri, object body, string accepts, string contentType, string twoFactorAuthenticationCode) { - Ensure.ArgumentNotNull(uri, "uri"); - Ensure.ArgumentNotNull(body, "body"); - Ensure.ArgumentNotNullOrEmptyString(twoFactorAuthenticationCode, "twoFactorAuthenticationCode"); + Ensure.ArgumentNotNull(uri, nameof(uri)); + Ensure.ArgumentNotNull(body, nameof(body)); + Ensure.ArgumentNotNullOrEmptyString(twoFactorAuthenticationCode, nameof(twoFactorAuthenticationCode)); return SendData(uri, HttpMethod.Post, body, accepts, contentType, CancellationToken.None, twoFactorAuthenticationCode); } public Task> Post(Uri uri, object body, string accepts, string contentType, TimeSpan timeout) { - Ensure.ArgumentNotNull(uri, "uri"); - Ensure.ArgumentNotNull(body, "body"); + Ensure.ArgumentNotNull(uri, nameof(uri)); + Ensure.ArgumentNotNull(body, nameof(body)); return SendData(uri, HttpMethod.Post, body, accepts, contentType, timeout, CancellationToken.None); } public Task> Post(Uri uri, object body, string accepts, string contentType, Uri baseAddress) { - Ensure.ArgumentNotNull(uri, "uri"); - Ensure.ArgumentNotNull(body, "body"); + Ensure.ArgumentNotNull(uri, nameof(uri)); + Ensure.ArgumentNotNull(body, nameof(body)); return SendData(uri, HttpMethod.Post, body, accepts, contentType, CancellationToken.None, baseAddress: baseAddress); } @@ -320,8 +328,8 @@ Task> SendData( string twoFactorAuthenticationCode = null, Uri baseAddress = null) { - Ensure.ArgumentNotNull(uri, "uri"); - Ensure.GreaterThanZero(timeout, "timeout"); + Ensure.ArgumentNotNull(uri, nameof(uri)); + Ensure.GreaterThanZero(timeout, nameof(timeout)); var request = new Request { @@ -344,7 +352,7 @@ Task> SendData( string twoFactorAuthenticationCode = null, Uri baseAddress = null) { - Ensure.ArgumentNotNull(uri, "uri"); + Ensure.ArgumentNotNull(uri, nameof(uri)); var request = new Request { @@ -385,7 +393,7 @@ Task> SendDataInternal(object body, string accepts, string co /// representing the received HTTP response public async Task Patch(Uri uri) { - Ensure.ArgumentNotNull(uri, "uri"); + Ensure.ArgumentNotNull(uri, nameof(uri)); var request = new Request { @@ -405,8 +413,8 @@ public async Task Patch(Uri uri) /// representing the received HTTP response public async Task Patch(Uri uri, string accepts) { - Ensure.ArgumentNotNull(uri, "uri"); - Ensure.ArgumentNotNull(accepts, "accepts"); + Ensure.ArgumentNotNull(uri, nameof(uri)); + Ensure.ArgumentNotNull(accepts, nameof(accepts)); var response = await SendData(uri, new HttpMethod("PATCH"), null, accepts, null, CancellationToken.None).ConfigureAwait(false); return response.HttpResponse.StatusCode; @@ -419,7 +427,7 @@ public async Task Patch(Uri uri, string accepts) /// The returned public async Task Put(Uri uri) { - Ensure.ArgumentNotNull(uri, "uri"); + Ensure.ArgumentNotNull(uri, nameof(uri)); var request = new Request { diff --git a/Octokit/Http/Credentials.cs b/Octokit/Http/Credentials.cs index 24d82af24c..14a45d61ba 100644 --- a/Octokit/Http/Credentials.cs +++ b/Octokit/Http/Credentials.cs @@ -13,19 +13,23 @@ private Credentials() AuthenticationType = AuthenticationType.Anonymous; } - public Credentials(string login, string password, AuthenticationType authenticationType = AuthenticationType.Basic) + public Credentials(string login, string password) : this(login, password, AuthenticationType.Basic) { } + + public Credentials(string login, string password, AuthenticationType authenticationType) { - Ensure.ArgumentNotNullOrEmptyString(login, "login"); - Ensure.ArgumentNotNullOrEmptyString(password, "password"); + Ensure.ArgumentNotNullOrEmptyString(login, nameof(login)); + Ensure.ArgumentNotNullOrEmptyString(password, nameof(password)); Login = login; Password = password; AuthenticationType = authenticationType; } - public Credentials(string token, AuthenticationType authenticationType = AuthenticationType.Oauth) + public Credentials(string token) : this(token, AuthenticationType.Oauth) { } + + public Credentials(string token, AuthenticationType authenticationType) { - Ensure.ArgumentNotNullOrEmptyString(token, "token"); + Ensure.ArgumentNotNullOrEmptyString(token, nameof(token)); Login = null; Password = token; diff --git a/Octokit/IGitHubClient.cs b/Octokit/IGitHubClient.cs index bc515db8b8..adc73623b0 100644 --- a/Octokit/IGitHubClient.cs +++ b/Octokit/IGitHubClient.cs @@ -38,9 +38,9 @@ public interface IGitHubClient : IApiInfoProvider /// IActivitiesClient Activity { get; } - IApplicationClient Application { get; } + IApplicationsClient Application { get; } - IInstallationsClient Installations { get; } + IInstallationsClient Installation { get; } /// /// Access GitHub's Issue API. From a5551b9c3cb4cddc953bd76c804dbf98a92acc6f Mon Sep 17 00:00:00 2001 From: Itai Bar-Haim Date: Thu, 18 Jan 2018 15:35:29 +0200 Subject: [PATCH 14/84] fixed build. --- ...eApplicationClient.cs => IObservableApplicationsClient.cs} | 2 +- ...leApplicationClient.cs => ObservableApplicationsClient.cs} | 4 ++-- Octokit.Reactive/IObservableGitHubClient.cs | 2 +- Octokit.Reactive/ObservableGitHubClient.cs | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) rename Octokit.Reactive/Clients/{IObservableApplicationClient.cs => IObservableApplicationsClient.cs} (67%) rename Octokit.Reactive/Clients/{ObservableApplicationClient.cs => ObservableApplicationsClient.cs} (72%) diff --git a/Octokit.Reactive/Clients/IObservableApplicationClient.cs b/Octokit.Reactive/Clients/IObservableApplicationsClient.cs similarity index 67% rename from Octokit.Reactive/Clients/IObservableApplicationClient.cs rename to Octokit.Reactive/Clients/IObservableApplicationsClient.cs index 9c4da50a04..5e3f60348b 100644 --- a/Octokit.Reactive/Clients/IObservableApplicationClient.cs +++ b/Octokit.Reactive/Clients/IObservableApplicationsClient.cs @@ -2,7 +2,7 @@ namespace Octokit.Reactive { - public interface IObservableApplicationClient + public interface IObservableApplicationsClient { IObservable Create(); } diff --git a/Octokit.Reactive/Clients/ObservableApplicationClient.cs b/Octokit.Reactive/Clients/ObservableApplicationsClient.cs similarity index 72% rename from Octokit.Reactive/Clients/ObservableApplicationClient.cs rename to Octokit.Reactive/Clients/ObservableApplicationsClient.cs index 163417f9bd..e710289c18 100644 --- a/Octokit.Reactive/Clients/ObservableApplicationClient.cs +++ b/Octokit.Reactive/Clients/ObservableApplicationsClient.cs @@ -3,11 +3,11 @@ namespace Octokit.Reactive { - public class ObservableApplicationClient : IObservableApplicationClient + public class ObservableApplicationsClient : IObservableApplicationsClient { private IApplicationsClient _client; - public ObservableApplicationClient(IGitHubClient client) + public ObservableApplicationsClient(IGitHubClient client) { Ensure.ArgumentNotNull(client, "client"); diff --git a/Octokit.Reactive/IObservableGitHubClient.cs b/Octokit.Reactive/IObservableGitHubClient.cs index 7e38dfc093..2dbff95ca7 100644 --- a/Octokit.Reactive/IObservableGitHubClient.cs +++ b/Octokit.Reactive/IObservableGitHubClient.cs @@ -18,7 +18,7 @@ public interface IObservableGitHubClient : IApiInfoProvider IObservableAuthorizationsClient Authorization { get; } IObservableActivitiesClient Activity { get; } - IObservableApplicationClient Application { get; } + IObservableApplicationsClient Application { get; } IObservableInstallationsClient Installation { get; } IObservableIssuesClient Issue { get; } IObservableMiscellaneousClient Miscellaneous { get; } diff --git a/Octokit.Reactive/ObservableGitHubClient.cs b/Octokit.Reactive/ObservableGitHubClient.cs index fd635ba9aa..b3cd7ec7b7 100644 --- a/Octokit.Reactive/ObservableGitHubClient.cs +++ b/Octokit.Reactive/ObservableGitHubClient.cs @@ -33,7 +33,7 @@ public ObservableGitHubClient(IGitHubClient gitHubClient) _gitHubClient = gitHubClient; Authorization = new ObservableAuthorizationsClient(gitHubClient); Activity = new ObservableActivitiesClient(gitHubClient); - Application = new ObservableApplicationClient(gitHubClient); + Application = new ObservableApplicationsClient(gitHubClient); Installation = new ObservableInstallationsClient(gitHubClient); Issue = new ObservableIssuesClient(gitHubClient); Miscellaneous = new ObservableMiscellaneousClient(gitHubClient); @@ -71,7 +71,7 @@ public void SetRequestTimeout(TimeSpan timeout) public IObservableAuthorizationsClient Authorization { get; private set; } public IObservableActivitiesClient Activity { get; private set; } - public IObservableApplicationClient Application { get; private set; } + public IObservableApplicationsClient Application { get; private set; } public IObservableInstallationsClient Installation { get; private set; } public IObservableIssuesClient Issue { get; private set; } public IObservableMiscellaneousClient Miscellaneous { get; private set; } From e41209984dc62d65cbe4fcd427aecc65ae76c7d6 Mon Sep 17 00:00:00 2001 From: Itai Bar-Haim Date: Mon, 22 Jan 2018 15:33:08 +0200 Subject: [PATCH 15/84] switched Installation ID from int to long. --- .../Clients/IObservableAccessTokensClient.cs | 2 +- .../Clients/ObservableAccessTokensClient.cs | 2 +- Octokit/Clients/AccessTokensClient.cs | 2 +- Octokit/Clients/IAccessTokensClient.cs | 2 +- Octokit/Helpers/ApiUrls.cs | 2 +- Octokit/Models/Response/Installation.cs | 10 +++++----- 6 files changed, 10 insertions(+), 10 deletions(-) diff --git a/Octokit.Reactive/Clients/IObservableAccessTokensClient.cs b/Octokit.Reactive/Clients/IObservableAccessTokensClient.cs index 629e37378f..6194dcddb4 100644 --- a/Octokit.Reactive/Clients/IObservableAccessTokensClient.cs +++ b/Octokit.Reactive/Clients/IObservableAccessTokensClient.cs @@ -4,6 +4,6 @@ namespace Octokit.Reactive { public interface IObservableAccessTokensClient { - IObservable Create(int installationId); + IObservable Create(long installationId); } } diff --git a/Octokit.Reactive/Clients/ObservableAccessTokensClient.cs b/Octokit.Reactive/Clients/ObservableAccessTokensClient.cs index 1ec3888441..70684c7202 100644 --- a/Octokit.Reactive/Clients/ObservableAccessTokensClient.cs +++ b/Octokit.Reactive/Clients/ObservableAccessTokensClient.cs @@ -16,7 +16,7 @@ public ObservableAccessTokensClient(IGitHubClient client) _connection = client.Connection; } - public IObservable Create(int installationId) + public IObservable Create(long installationId) { return _client.Create(installationId).ToObservable(); } diff --git a/Octokit/Clients/AccessTokensClient.cs b/Octokit/Clients/AccessTokensClient.cs index d92ef7b58c..af3cbae8ed 100644 --- a/Octokit/Clients/AccessTokensClient.cs +++ b/Octokit/Clients/AccessTokensClient.cs @@ -10,7 +10,7 @@ public AccessTokensClient(IApiConnection apiConnection) : base(apiConnection) { } - public Task Create(int installationId) + public Task Create(long installationId) { return ApiConnection.Post(ApiUrls.AccessTokens(installationId), "", AcceptHeader); } diff --git a/Octokit/Clients/IAccessTokensClient.cs b/Octokit/Clients/IAccessTokensClient.cs index 46f18cb7aa..12857169a6 100644 --- a/Octokit/Clients/IAccessTokensClient.cs +++ b/Octokit/Clients/IAccessTokensClient.cs @@ -4,6 +4,6 @@ namespace Octokit { public interface IAccessTokensClient { - Task Create(int installationId); + Task Create(long installationId); } } diff --git a/Octokit/Helpers/ApiUrls.cs b/Octokit/Helpers/ApiUrls.cs index d0ef49e770..6c87778858 100644 --- a/Octokit/Helpers/ApiUrls.cs +++ b/Octokit/Helpers/ApiUrls.cs @@ -291,7 +291,7 @@ public static Uri NotificationSubscription(int id) return "notifications/threads/{0}/subscription".FormatUri(id); } - public static Uri AccessTokens(int installationId) + public static Uri AccessTokens(long installationId) { return "installations/{0}/access_tokens".FormatUri(installationId); } diff --git a/Octokit/Models/Response/Installation.cs b/Octokit/Models/Response/Installation.cs index 7571126dff..3e23122e2e 100644 --- a/Octokit/Models/Response/Installation.cs +++ b/Octokit/Models/Response/Installation.cs @@ -14,9 +14,9 @@ public class Installation { public Installation() { } - public Installation(int id, User account, + public Installation(long id, User account, string accessTokenUrl, string repositoriesUrl, string htmlUrl, - int appId, int targetId, AccountType targetType, + long appId, long targetId, AccountType targetType, string singleFileName, string repositorySelection) { Id = id; @@ -31,14 +31,14 @@ public Installation(int id, User account, RepositorySelection = repositorySelection; } - public int Id { get; protected set; } + public long Id { get; protected set; } public User Account { get; protected set; } public string AccessTokensUrl { get; protected set; } public string RepositoriesUrl { get; protected set; } public string HtmlUrl { get; protected set; } - public int AppId { get; protected set; } - public int TargetId { get; protected set; } + public long AppId { get; protected set; } + public long TargetId { get; protected set; } public StringEnum TargetType { get; protected set; } // TODO - add permissions // TODO - add events From 0b0eee94573fa12a3601357afceb12e5e709bc43 Mon Sep 17 00:00:00 2001 From: Itai Bar-Haim Date: Mon, 22 Jan 2018 15:34:13 +0200 Subject: [PATCH 16/84] added Permissions and Events properties to Installation. --- Octokit/Models/Response/Installation.cs | 9 ++++++--- Octokit/Models/Response/Permissions.cs | 19 +++++++++++++++++++ 2 files changed, 25 insertions(+), 3 deletions(-) create mode 100644 Octokit/Models/Response/Permissions.cs diff --git a/Octokit/Models/Response/Installation.cs b/Octokit/Models/Response/Installation.cs index 3e23122e2e..65dc01392d 100644 --- a/Octokit/Models/Response/Installation.cs +++ b/Octokit/Models/Response/Installation.cs @@ -1,4 +1,5 @@ -using System.Diagnostics; +using System.Collections.Generic; +using System.Diagnostics; using System.Globalization; namespace Octokit @@ -40,8 +41,10 @@ public Installation(long id, User account, public long AppId { get; protected set; } public long TargetId { get; protected set; } public StringEnum TargetType { get; protected set; } - // TODO - add permissions - // TODO - add events + + public Permissions Permissions { get; private set; } + public IReadOnlyList Events { get; private set; } + public string SingleFileName { get; protected set; } public string RepositorySelection { get; protected set; } diff --git a/Octokit/Models/Response/Permissions.cs b/Octokit/Models/Response/Permissions.cs new file mode 100644 index 0000000000..5a3b62218a --- /dev/null +++ b/Octokit/Models/Response/Permissions.cs @@ -0,0 +1,19 @@ +using System.Diagnostics; +using System.Globalization; + +namespace Octokit +{ + [DebuggerDisplay("{DebuggerDisplay,nq}")] + public class Permissions + { + public StringEnum Metadata { get; protected set; } + public StringEnum Contents { get; protected set; } + public StringEnum Issues { get; protected set; } + public StringEnum SingleFile { get; protected set; } + + internal string DebuggerDisplay + { + get { return string.Format(CultureInfo.InvariantCulture, "Metadata: {0}, Contents: {1}, Issues: {2}, Single File: {3}", Metadata, Contents, Issues, SingleFile); } + } + } +} \ No newline at end of file From 0e6a3707747c79b23da3f2fcdd8c64f5e863ac88 Mon Sep 17 00:00:00 2001 From: Itai Bar-Haim Date: Mon, 22 Jan 2018 15:34:54 +0200 Subject: [PATCH 17/84] added documentation to Application and Installation properties in IGitHubClient. --- Octokit/IGitHubClient.cs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Octokit/IGitHubClient.cs b/Octokit/IGitHubClient.cs index adc73623b0..a2d5bfe5d6 100644 --- a/Octokit/IGitHubClient.cs +++ b/Octokit/IGitHubClient.cs @@ -38,8 +38,20 @@ public interface IGitHubClient : IApiInfoProvider /// IActivitiesClient Activity { get; } + /// + /// Access GitHub's Application API. + /// + /// + /// Refer to the API documentation for more information: https://developer.github.com/v3/apps/ + /// IApplicationsClient Application { get; } + /// + /// Access GitHub's Application Installation API. + /// + /// + /// Refer to the API documentation for more information: https://developer.github.com/v3/apps/installations/ + /// IInstallationsClient Installation { get; } /// From 788b6923712a3003aa85640e6d8c3d8495ec7ec5 Mon Sep 17 00:00:00 2001 From: Itai Bar-Haim Date: Sun, 28 Jan 2018 21:17:24 +0200 Subject: [PATCH 18/84] wip - added tests to new clients --- .../Clients/AccessTokensClientTests.cs | 34 +++++++++++++++++++ .../Clients/ApplicationClientTests.cs | 33 ++++++++++++++++++ .../Clients/InstallationsClientTests.cs | 17 ++++++++++ 3 files changed, 84 insertions(+) create mode 100644 Octokit.Tests/Clients/AccessTokensClientTests.cs create mode 100644 Octokit.Tests/Clients/ApplicationClientTests.cs create mode 100644 Octokit.Tests/Clients/InstallationsClientTests.cs diff --git a/Octokit.Tests/Clients/AccessTokensClientTests.cs b/Octokit.Tests/Clients/AccessTokensClientTests.cs new file mode 100644 index 0000000000..e415cd07f9 --- /dev/null +++ b/Octokit.Tests/Clients/AccessTokensClientTests.cs @@ -0,0 +1,34 @@ +using System; +using NSubstitute; +using Xunit; + +namespace Octokit.Tests.Clients +{ + public class AccessTokensClientTests + { + public class TheCtor + { + [Fact] + public void EnsuresNonNullArguments() + { + Assert.Throws(() => new AccessTokensClient(null)); + } + } + + public class TheCreateMethod + { + [Fact] + public void PostsToCorrectUrl() + { + var connection = Substitute.For(); + var client = new AccessTokensClient(connection); + + int fakeInstallationId = 3141; + + client.Create(fakeInstallationId); + + connection.Received().Post(Arg.Is(u => u.ToString() == "installations/3141/access_tokens")); + } + } + } +} diff --git a/Octokit.Tests/Clients/ApplicationClientTests.cs b/Octokit.Tests/Clients/ApplicationClientTests.cs new file mode 100644 index 0000000000..c87b9ededc --- /dev/null +++ b/Octokit.Tests/Clients/ApplicationClientTests.cs @@ -0,0 +1,33 @@ +using System; +using NSubstitute; +using Xunit; + +namespace Octokit.Tests.Clients +{ + public class ApplicationClientTests + { + public class TheCtor + { + [Fact] + public void EnsuresNonNullArguments() + { + Assert.Throws(() => new ApplicationClient(null)); + } + } + + public class TheCreateMethod + { + [Fact] + public void GetFromCorrectUrl() + { + var connection = Substitute.For(); + var client = new ApplicationClient(connection); + + client.Create(); + + connection.Received().Get(Arg.Is(u => u.ToString() == "app")); + } + } + + } +} diff --git a/Octokit.Tests/Clients/InstallationsClientTests.cs b/Octokit.Tests/Clients/InstallationsClientTests.cs new file mode 100644 index 0000000000..bb379c28d8 --- /dev/null +++ b/Octokit.Tests/Clients/InstallationsClientTests.cs @@ -0,0 +1,17 @@ +using System; +using Xunit; + +namespace Octokit.Tests.Clients +{ + public class InstallationsClientTests + { + public class TheCtor + { + [Fact] + public void EnsuresNonNullArguments() + { + Assert.Throws(() => new InstallationsClient(null)); + } + } + } +} From e888b9093d26cb2adeeb5eacb9c9a4f64817f00e Mon Sep 17 00:00:00 2001 From: Itai Bar-Haim Date: Sun, 28 Jan 2018 21:56:11 +0200 Subject: [PATCH 19/84] wip - fix build --- .../{ApplicationClientTests.cs => ApplicationsClientTests.cs} | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) rename Octokit.Tests/Clients/{ApplicationClientTests.cs => ApplicationsClientTests.cs} (88%) diff --git a/Octokit.Tests/Clients/ApplicationClientTests.cs b/Octokit.Tests/Clients/ApplicationsClientTests.cs similarity index 88% rename from Octokit.Tests/Clients/ApplicationClientTests.cs rename to Octokit.Tests/Clients/ApplicationsClientTests.cs index c87b9ededc..c43aa46fc5 100644 --- a/Octokit.Tests/Clients/ApplicationClientTests.cs +++ b/Octokit.Tests/Clients/ApplicationsClientTests.cs @@ -11,7 +11,7 @@ public class TheCtor [Fact] public void EnsuresNonNullArguments() { - Assert.Throws(() => new ApplicationClient(null)); + Assert.Throws(() => new ApplicationsClient(null)); } } @@ -21,7 +21,7 @@ public class TheCreateMethod public void GetFromCorrectUrl() { var connection = Substitute.For(); - var client = new ApplicationClient(connection); + var client = new ApplicationsClient(connection); client.Create(); From faa94b3c7af70111419560e03930c883955dabd9 Mon Sep 17 00:00:00 2001 From: Itai Bar-Haim Date: Mon, 29 Jan 2018 13:07:04 +0200 Subject: [PATCH 20/84] wip - fixed build. --- Octokit.Tests/Clients/AccessTokensClientTests.cs | 2 +- Octokit.Tests/Clients/ApplicationsClientTests.cs | 2 +- Octokit/Clients/AccessTokensClient.cs | 4 +--- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/Octokit.Tests/Clients/AccessTokensClientTests.cs b/Octokit.Tests/Clients/AccessTokensClientTests.cs index e415cd07f9..362fbc6fd8 100644 --- a/Octokit.Tests/Clients/AccessTokensClientTests.cs +++ b/Octokit.Tests/Clients/AccessTokensClientTests.cs @@ -27,7 +27,7 @@ public void PostsToCorrectUrl() client.Create(fakeInstallationId); - connection.Received().Post(Arg.Is(u => u.ToString() == "installations/3141/access_tokens")); + connection.Received().Post(Arg.Is(u => u.ToString() == "installations/3141/access_tokens"), string.Empty, AcceptHeaders.MachineManPreview); } } } diff --git a/Octokit.Tests/Clients/ApplicationsClientTests.cs b/Octokit.Tests/Clients/ApplicationsClientTests.cs index c43aa46fc5..1e38eea3d5 100644 --- a/Octokit.Tests/Clients/ApplicationsClientTests.cs +++ b/Octokit.Tests/Clients/ApplicationsClientTests.cs @@ -25,7 +25,7 @@ public void GetFromCorrectUrl() client.Create(); - connection.Received().Get(Arg.Is(u => u.ToString() == "app")); + connection.Received().Get(Arg.Is(u => u.ToString() == "app"), null, AcceptHeaders.MachineManPreview); } } diff --git a/Octokit/Clients/AccessTokensClient.cs b/Octokit/Clients/AccessTokensClient.cs index af3cbae8ed..78d31be46b 100644 --- a/Octokit/Clients/AccessTokensClient.cs +++ b/Octokit/Clients/AccessTokensClient.cs @@ -4,15 +4,13 @@ namespace Octokit { class AccessTokensClient : ApiClient, IAccessTokensClient { - private const string AcceptHeader = "application/vnd.github.machine-man-preview+json"; - public AccessTokensClient(IApiConnection apiConnection) : base(apiConnection) { } public Task Create(long installationId) { - return ApiConnection.Post(ApiUrls.AccessTokens(installationId), "", AcceptHeader); + return ApiConnection.Post(ApiUrls.AccessTokens(installationId), string.Empty, AcceptHeaders.MachineManPreview); } } } From 7189a504aa2a7a5df6ab94785a24017381038d05 Mon Sep 17 00:00:00 2001 From: Itai Bar-Haim Date: Mon, 29 Jan 2018 18:09:26 +0200 Subject: [PATCH 21/84] added InstallationsClient tests. --- .../Clients/InstallationsClientTests.cs | 48 ++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) diff --git a/Octokit.Tests/Clients/InstallationsClientTests.cs b/Octokit.Tests/Clients/InstallationsClientTests.cs index bb379c28d8..fbc4fe487f 100644 --- a/Octokit.Tests/Clients/InstallationsClientTests.cs +++ b/Octokit.Tests/Clients/InstallationsClientTests.cs @@ -1,4 +1,6 @@ -using System; +using NSubstitute; +using System; +using System.Threading.Tasks; using Xunit; namespace Octokit.Tests.Clients @@ -12,6 +14,50 @@ public void EnsuresNonNullArguments() { Assert.Throws(() => new InstallationsClient(null)); } + + public class TheGetAllMethod + { + [Fact] + public async Task EnsuresNonNullArguments() + { + var connection = Substitute.For(); + var client = new InstallationsClient(connection); + + Assert.ThrowsAsync(() => client.GetAll(null)); + } + + [Fact] + public async Task RequestsCorrectUrl() + { + var connection = Substitute.For(); + var client = new InstallationsClient(connection); + + client.GetAll(); + + connection.Received().GetAll(Arg.Is(u => u.ToString() == "app/installations"), null, AcceptHeaders.MachineManPreview); + } + + + [Fact] + public void RequestsTheCorrectUrlWithApiOptions() + { + var connection = Substitute.For(); + var client = new InstallationsClient(connection); + + var options = new ApiOptions + { + PageSize = 1, + PageCount = 1, + StartPage = 1 + }; + + client.GetAll(options); + + connection.Received().GetAll(Arg.Is(u => u.ToString() == "app/installations"), null, AcceptHeaders.MachineManPreview, options); + } + + } + } } } From 43132da9d0e17dca3ffeb5f88477ef0d6478be70 Mon Sep 17 00:00:00 2001 From: Itai Bar-Haim Date: Mon, 29 Jan 2018 18:52:43 +0200 Subject: [PATCH 22/84] added integration test for InstallationsClient. --- .../Clients/InstallationsClientTests.cs | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 Octokit.Tests.Integration/Clients/InstallationsClientTests.cs diff --git a/Octokit.Tests.Integration/Clients/InstallationsClientTests.cs b/Octokit.Tests.Integration/Clients/InstallationsClientTests.cs new file mode 100644 index 0000000000..57a8e9285c --- /dev/null +++ b/Octokit.Tests.Integration/Clients/InstallationsClientTests.cs @@ -0,0 +1,42 @@ +using Octokit.Tests.Integration.Helpers; +using System; +using System.Threading.Tasks; +using Xunit; + +namespace Octokit.Tests.Integration.Clients +{ + public class InstallationsClientTests + { + public class TheGetAllMethod : IDisposable + { + IGitHubClient _github; + RepositoryContext _context; + + public TheGetAllMethod() + { + _github = Helper.GetAuthenticatedClient(); + var repoName = Helper.MakeNameWithTimestamp("public-repo"); + + _context = _github.CreateRepositoryContext(new NewRepository(repoName)).Result; + } + + [IntegrationTest] + public async Task GetsAllInstallations() + { + var result = await _github.Installation.GetAll(); + + // TODO - find a way to run this test, and see the results. + + //Assert.Equal(2, result.Count); + //Assert.True(result.FirstOrDefault(x => x.Id == card1.Id).Id == card1.Id); + //Assert.True(result.FirstOrDefault(x => x.Id == card2.Id).Id == card2.Id); + } + + public void Dispose() + { + if (_context != null) + _context.Dispose(); + } + } + } +} From 3211fc7fdfb98ee074a11ed16972b26759b6cce4 Mon Sep 17 00:00:00 2001 From: Itai Bar-Haim Date: Wed, 31 Jan 2018 15:58:11 +0200 Subject: [PATCH 23/84] changes requested in code review. --- .../Clients/IObservableAccessTokensClient.cs | 9 -- .../Clients/IObservableApplicationsClient.cs | 9 -- .../Clients/IObservableGitHubAppsClient.cs | 12 +++ .../Clients/IObservableInstallationsClient.cs | 11 --- .../Clients/ObservableAccessTokensClient.cs | 24 ----- .../Clients/ObservableApplicationsClient.cs | 22 ----- .../Clients/ObservableGitHubAppsClient.cs | 42 +++++++++ .../Clients/ObservableInstallationsClient.cs | 34 ------- Octokit.Reactive/IObservableGitHubClient.cs | 3 +- Octokit.Reactive/ObservableGitHubClient.cs | 6 +- ...lientTests.cs => GitHubAppsClientTests.cs} | 9 +- .../Clients/AccessTokensClientTests.cs | 34 ------- .../Clients/ApplicationsClientTests.cs | 33 ------- .../Clients/GitHubAppsClientTests.cs | 93 +++++++++++++++++++ .../Clients/InstallationsClientTests.cs | 63 ------------- .../ApplicationAuthenticator.cs | 23 +++++ Octokit/Clients/AccessTokensClient.cs | 16 ---- Octokit/Clients/ApplicationsClient.cs | 16 ---- Octokit/Clients/GitHubAppsClient.cs | 34 +++++++ Octokit/Clients/IAccessTokensClient.cs | 9 -- Octokit/Clients/IApplicationsClient.cs | 9 -- Octokit/Clients/IGitHubAppsClient.cs | 13 +++ Octokit/Clients/IInstallationsClient.cs | 13 --- Octokit/Clients/InstallationsClient.cs | 27 ------ Octokit/GitHubClient.cs | 15 +-- Octokit/IGitHubClient.cs | 10 +- 26 files changed, 228 insertions(+), 361 deletions(-) delete mode 100644 Octokit.Reactive/Clients/IObservableAccessTokensClient.cs delete mode 100644 Octokit.Reactive/Clients/IObservableApplicationsClient.cs create mode 100644 Octokit.Reactive/Clients/IObservableGitHubAppsClient.cs delete mode 100644 Octokit.Reactive/Clients/IObservableInstallationsClient.cs delete mode 100644 Octokit.Reactive/Clients/ObservableAccessTokensClient.cs delete mode 100644 Octokit.Reactive/Clients/ObservableApplicationsClient.cs create mode 100644 Octokit.Reactive/Clients/ObservableGitHubAppsClient.cs delete mode 100644 Octokit.Reactive/Clients/ObservableInstallationsClient.cs rename Octokit.Tests.Integration/Clients/{InstallationsClientTests.cs => GitHubAppsClientTests.cs} (80%) delete mode 100644 Octokit.Tests/Clients/AccessTokensClientTests.cs delete mode 100644 Octokit.Tests/Clients/ApplicationsClientTests.cs create mode 100644 Octokit.Tests/Clients/GitHubAppsClientTests.cs delete mode 100644 Octokit.Tests/Clients/InstallationsClientTests.cs create mode 100644 Octokit/Authentication/ApplicationAuthenticator.cs delete mode 100644 Octokit/Clients/AccessTokensClient.cs delete mode 100644 Octokit/Clients/ApplicationsClient.cs create mode 100644 Octokit/Clients/GitHubAppsClient.cs delete mode 100644 Octokit/Clients/IAccessTokensClient.cs delete mode 100644 Octokit/Clients/IApplicationsClient.cs create mode 100644 Octokit/Clients/IGitHubAppsClient.cs delete mode 100644 Octokit/Clients/IInstallationsClient.cs delete mode 100644 Octokit/Clients/InstallationsClient.cs diff --git a/Octokit.Reactive/Clients/IObservableAccessTokensClient.cs b/Octokit.Reactive/Clients/IObservableAccessTokensClient.cs deleted file mode 100644 index 6194dcddb4..0000000000 --- a/Octokit.Reactive/Clients/IObservableAccessTokensClient.cs +++ /dev/null @@ -1,9 +0,0 @@ -using System; - -namespace Octokit.Reactive -{ - public interface IObservableAccessTokensClient - { - IObservable Create(long installationId); - } -} diff --git a/Octokit.Reactive/Clients/IObservableApplicationsClient.cs b/Octokit.Reactive/Clients/IObservableApplicationsClient.cs deleted file mode 100644 index 5e3f60348b..0000000000 --- a/Octokit.Reactive/Clients/IObservableApplicationsClient.cs +++ /dev/null @@ -1,9 +0,0 @@ -using System; - -namespace Octokit.Reactive -{ - public interface IObservableApplicationsClient - { - IObservable Create(); - } -} diff --git a/Octokit.Reactive/Clients/IObservableGitHubAppsClient.cs b/Octokit.Reactive/Clients/IObservableGitHubAppsClient.cs new file mode 100644 index 0000000000..d933ec9642 --- /dev/null +++ b/Octokit.Reactive/Clients/IObservableGitHubAppsClient.cs @@ -0,0 +1,12 @@ +using System; + +namespace Octokit.Reactive +{ + public interface IObservableGitHubAppsClient + { + IObservable GetCurrent(); + IObservable CreateInstallationToken(long installationId); + IObservable GetAllInstallationsForCurrent(); + IObservable GetAllInstallationsForCurrent(ApiOptions options); + } +} diff --git a/Octokit.Reactive/Clients/IObservableInstallationsClient.cs b/Octokit.Reactive/Clients/IObservableInstallationsClient.cs deleted file mode 100644 index 41c66d37c4..0000000000 --- a/Octokit.Reactive/Clients/IObservableInstallationsClient.cs +++ /dev/null @@ -1,11 +0,0 @@ -using System; - -namespace Octokit.Reactive -{ - public interface IObservableInstallationsClient - { - IObservableAccessTokensClient AccessTokens { get; } - IObservable GetAll(); - IObservable GetAll(ApiOptions options); - } -} diff --git a/Octokit.Reactive/Clients/ObservableAccessTokensClient.cs b/Octokit.Reactive/Clients/ObservableAccessTokensClient.cs deleted file mode 100644 index 70684c7202..0000000000 --- a/Octokit.Reactive/Clients/ObservableAccessTokensClient.cs +++ /dev/null @@ -1,24 +0,0 @@ -using System; -using System.Reactive.Threading.Tasks; - -namespace Octokit.Reactive -{ - class ObservableAccessTokensClient : IObservableAccessTokensClient - { - readonly IAccessTokensClient _client; - readonly IConnection _connection; - - public ObservableAccessTokensClient(IGitHubClient client) - { - Ensure.ArgumentNotNull(client, "client"); - - _client = client.Installation.AccessTokens; - _connection = client.Connection; - } - - public IObservable Create(long installationId) - { - return _client.Create(installationId).ToObservable(); - } - } -} diff --git a/Octokit.Reactive/Clients/ObservableApplicationsClient.cs b/Octokit.Reactive/Clients/ObservableApplicationsClient.cs deleted file mode 100644 index e710289c18..0000000000 --- a/Octokit.Reactive/Clients/ObservableApplicationsClient.cs +++ /dev/null @@ -1,22 +0,0 @@ -using System; -using System.Reactive.Threading.Tasks; - -namespace Octokit.Reactive -{ - public class ObservableApplicationsClient : IObservableApplicationsClient - { - private IApplicationsClient _client; - - public ObservableApplicationsClient(IGitHubClient client) - { - Ensure.ArgumentNotNull(client, "client"); - - _client = client.Application; - } - - public IObservable Create() - { - return _client.Create().ToObservable(); - } - } -} diff --git a/Octokit.Reactive/Clients/ObservableGitHubAppsClient.cs b/Octokit.Reactive/Clients/ObservableGitHubAppsClient.cs new file mode 100644 index 0000000000..0b706670d1 --- /dev/null +++ b/Octokit.Reactive/Clients/ObservableGitHubAppsClient.cs @@ -0,0 +1,42 @@ +using Octokit.Reactive.Internal; +using System; +using System.Reactive.Threading.Tasks; + +namespace Octokit.Reactive +{ + public class ObservableGitHubAppsClient : IObservableGitHubAppsClient + { + private IGitHubAppsClient _client; + private readonly IConnection _connection; + + public ObservableGitHubAppsClient(IGitHubClient client) + { + Ensure.ArgumentNotNull(client, "client"); + + _client = client.GitHubApps; + _connection = client.Connection; + } + + public IObservable GetCurrent() + { + return _client.GetCurrent().ToObservable(); + } + + public IObservable CreateInstallationToken(long installationId) + { + return _client.CreateInstallationToken(installationId).ToObservable(); + } + + public IObservable GetAllInstallationsForCurrent() + { + return _connection.GetAndFlattenAllPages(ApiUrls.Installations(), null, AcceptHeaders.MachineManPreview); + } + + public IObservable GetAllInstallationsForCurrent(ApiOptions options) + { + Ensure.ArgumentNotNull(options, nameof(options)); + + return _connection.GetAndFlattenAllPages(ApiUrls.Installations(), null, AcceptHeaders.MachineManPreview, options); + } + } +} diff --git a/Octokit.Reactive/Clients/ObservableInstallationsClient.cs b/Octokit.Reactive/Clients/ObservableInstallationsClient.cs deleted file mode 100644 index 61fd1bd801..0000000000 --- a/Octokit.Reactive/Clients/ObservableInstallationsClient.cs +++ /dev/null @@ -1,34 +0,0 @@ -using System; -using Octokit.Reactive.Internal; - -namespace Octokit.Reactive -{ - class ObservableInstallationsClient : IObservableInstallationsClient - { - readonly IInstallationsClient _client; - readonly IConnection _connection; - - public ObservableInstallationsClient(IGitHubClient client) - { - Ensure.ArgumentNotNull(client, "client"); - - _client = client.Installation; - _connection = client.Connection; - AccessTokens = new ObservableAccessTokensClient(client); - } - - public IObservableAccessTokensClient AccessTokens { get; } - - public IObservable GetAll() - { - return _connection.GetAndFlattenAllPages(ApiUrls.Installations(), null, AcceptHeaders.MachineManPreview); - } - - public IObservable GetAll(ApiOptions options) - { - Ensure.ArgumentNotNull(options, nameof(options)); - - return _connection.GetAndFlattenAllPages(ApiUrls.Installations(), null, AcceptHeaders.MachineManPreview, options); - } - } -} diff --git a/Octokit.Reactive/IObservableGitHubClient.cs b/Octokit.Reactive/IObservableGitHubClient.cs index 2dbff95ca7..2de5664e3e 100644 --- a/Octokit.Reactive/IObservableGitHubClient.cs +++ b/Octokit.Reactive/IObservableGitHubClient.cs @@ -18,8 +18,7 @@ public interface IObservableGitHubClient : IApiInfoProvider IObservableAuthorizationsClient Authorization { get; } IObservableActivitiesClient Activity { get; } - IObservableApplicationsClient Application { get; } - IObservableInstallationsClient Installation { get; } + IObservableGitHubAppsClient GitHubApps { get; } IObservableIssuesClient Issue { get; } IObservableMiscellaneousClient Miscellaneous { get; } IObservableOauthClient Oauth { get; } diff --git a/Octokit.Reactive/ObservableGitHubClient.cs b/Octokit.Reactive/ObservableGitHubClient.cs index b3cd7ec7b7..a767eed348 100644 --- a/Octokit.Reactive/ObservableGitHubClient.cs +++ b/Octokit.Reactive/ObservableGitHubClient.cs @@ -33,8 +33,7 @@ public ObservableGitHubClient(IGitHubClient gitHubClient) _gitHubClient = gitHubClient; Authorization = new ObservableAuthorizationsClient(gitHubClient); Activity = new ObservableActivitiesClient(gitHubClient); - Application = new ObservableApplicationsClient(gitHubClient); - Installation = new ObservableInstallationsClient(gitHubClient); + GitHubApps = new ObservableGitHubAppsClient(gitHubClient); Issue = new ObservableIssuesClient(gitHubClient); Miscellaneous = new ObservableMiscellaneousClient(gitHubClient); Oauth = new ObservableOauthClient(gitHubClient); @@ -71,8 +70,7 @@ public void SetRequestTimeout(TimeSpan timeout) public IObservableAuthorizationsClient Authorization { get; private set; } public IObservableActivitiesClient Activity { get; private set; } - public IObservableApplicationsClient Application { get; private set; } - public IObservableInstallationsClient Installation { get; private set; } + public IObservableGitHubAppsClient GitHubApps { get; private set; } public IObservableIssuesClient Issue { get; private set; } public IObservableMiscellaneousClient Miscellaneous { get; private set; } public IObservableOauthClient Oauth { get; private set; } diff --git a/Octokit.Tests.Integration/Clients/InstallationsClientTests.cs b/Octokit.Tests.Integration/Clients/GitHubAppsClientTests.cs similarity index 80% rename from Octokit.Tests.Integration/Clients/InstallationsClientTests.cs rename to Octokit.Tests.Integration/Clients/GitHubAppsClientTests.cs index 57a8e9285c..a168c10f85 100644 --- a/Octokit.Tests.Integration/Clients/InstallationsClientTests.cs +++ b/Octokit.Tests.Integration/Clients/GitHubAppsClientTests.cs @@ -1,18 +1,17 @@ using Octokit.Tests.Integration.Helpers; using System; using System.Threading.Tasks; -using Xunit; namespace Octokit.Tests.Integration.Clients { - public class InstallationsClientTests + public class GitHubAppsClientTests { - public class TheGetAllMethod : IDisposable + public class TheGetAllInstallationsForCurrentMethod : IDisposable { IGitHubClient _github; RepositoryContext _context; - public TheGetAllMethod() + public TheGetAllInstallationsForCurrentMethod() { _github = Helper.GetAuthenticatedClient(); var repoName = Helper.MakeNameWithTimestamp("public-repo"); @@ -23,7 +22,7 @@ public TheGetAllMethod() [IntegrationTest] public async Task GetsAllInstallations() { - var result = await _github.Installation.GetAll(); + var result = await _github.GitHubApps.GetAllInstallationsForCurrent(); // TODO - find a way to run this test, and see the results. diff --git a/Octokit.Tests/Clients/AccessTokensClientTests.cs b/Octokit.Tests/Clients/AccessTokensClientTests.cs deleted file mode 100644 index 362fbc6fd8..0000000000 --- a/Octokit.Tests/Clients/AccessTokensClientTests.cs +++ /dev/null @@ -1,34 +0,0 @@ -using System; -using NSubstitute; -using Xunit; - -namespace Octokit.Tests.Clients -{ - public class AccessTokensClientTests - { - public class TheCtor - { - [Fact] - public void EnsuresNonNullArguments() - { - Assert.Throws(() => new AccessTokensClient(null)); - } - } - - public class TheCreateMethod - { - [Fact] - public void PostsToCorrectUrl() - { - var connection = Substitute.For(); - var client = new AccessTokensClient(connection); - - int fakeInstallationId = 3141; - - client.Create(fakeInstallationId); - - connection.Received().Post(Arg.Is(u => u.ToString() == "installations/3141/access_tokens"), string.Empty, AcceptHeaders.MachineManPreview); - } - } - } -} diff --git a/Octokit.Tests/Clients/ApplicationsClientTests.cs b/Octokit.Tests/Clients/ApplicationsClientTests.cs deleted file mode 100644 index 1e38eea3d5..0000000000 --- a/Octokit.Tests/Clients/ApplicationsClientTests.cs +++ /dev/null @@ -1,33 +0,0 @@ -using System; -using NSubstitute; -using Xunit; - -namespace Octokit.Tests.Clients -{ - public class ApplicationClientTests - { - public class TheCtor - { - [Fact] - public void EnsuresNonNullArguments() - { - Assert.Throws(() => new ApplicationsClient(null)); - } - } - - public class TheCreateMethod - { - [Fact] - public void GetFromCorrectUrl() - { - var connection = Substitute.For(); - var client = new ApplicationsClient(connection); - - client.Create(); - - connection.Received().Get(Arg.Is(u => u.ToString() == "app"), null, AcceptHeaders.MachineManPreview); - } - } - - } -} diff --git a/Octokit.Tests/Clients/GitHubAppsClientTests.cs b/Octokit.Tests/Clients/GitHubAppsClientTests.cs new file mode 100644 index 0000000000..21e2859d50 --- /dev/null +++ b/Octokit.Tests/Clients/GitHubAppsClientTests.cs @@ -0,0 +1,93 @@ +using System; +using System.Threading.Tasks; +using NSubstitute; +using Xunit; + +namespace Octokit.Tests.Clients +{ + public class GitHubAppsClientTests + { + public class TheCtor + { + [Fact] + public void EnsuresNonNullArguments() + { + Assert.Throws(() => new GitHubAppsClient(null)); + } + } + + public class TheGetCurrentMethod + { + [Fact] + public void GetFromCorrectUrl() + { + var connection = Substitute.For(); + var client = new GitHubAppsClient(connection); + + client.GetCurrent(); + + connection.Received().Get(Arg.Is(u => u.ToString() == "app"), null, AcceptHeaders.MachineManPreview); + } + } + + public class TheCreateInstallationTokenMethod + { + [Fact] + public void PostsToCorrectUrl() + { + var connection = Substitute.For(); + var client = new GitHubAppsClient(connection); + + int fakeInstallationId = 3141; + + client.CreateInstallationToken(fakeInstallationId); + + connection.Received().Post(Arg.Is(u => u.ToString() == "installations/3141/access_tokens"), string.Empty, AcceptHeaders.MachineManPreview); + } + } + + public class TheGetAllInstallationsForCurrentMethod + { + [Fact] + public async Task EnsuresNonNullArguments() + { + var connection = Substitute.For(); + var client = new GitHubAppsClient(connection); + + Assert.ThrowsAsync(() => client.GetAllInstallationsForCurrent(null)); + } + + [Fact] + public async Task RequestsCorrectUrl() + { + var connection = Substitute.For(); + var client = new GitHubAppsClient(connection); + + client.GetAllInstallationsForCurrent(); + + connection.Received().GetAll(Arg.Is(u => u.ToString() == "app/installations"), null, AcceptHeaders.MachineManPreview); + } + + + [Fact] + public void RequestsTheCorrectUrlWithApiOptions() + { + var connection = Substitute.For(); + var client = new GitHubAppsClient(connection); + + var options = new ApiOptions + { + PageSize = 1, + PageCount = 1, + StartPage = 1 + }; + + client.GetAllInstallationsForCurrent(options); + + connection.Received().GetAll(Arg.Is(u => u.ToString() == "app/installations"), null, AcceptHeaders.MachineManPreview, options); + } + + } + + } +} diff --git a/Octokit.Tests/Clients/InstallationsClientTests.cs b/Octokit.Tests/Clients/InstallationsClientTests.cs deleted file mode 100644 index fbc4fe487f..0000000000 --- a/Octokit.Tests/Clients/InstallationsClientTests.cs +++ /dev/null @@ -1,63 +0,0 @@ -using NSubstitute; -using System; -using System.Threading.Tasks; -using Xunit; - -namespace Octokit.Tests.Clients -{ - public class InstallationsClientTests - { - public class TheCtor - { - [Fact] - public void EnsuresNonNullArguments() - { - Assert.Throws(() => new InstallationsClient(null)); - } - - public class TheGetAllMethod - { - [Fact] - public async Task EnsuresNonNullArguments() - { - var connection = Substitute.For(); - var client = new InstallationsClient(connection); - - Assert.ThrowsAsync(() => client.GetAll(null)); - } - - [Fact] - public async Task RequestsCorrectUrl() - { - var connection = Substitute.For(); - var client = new InstallationsClient(connection); - - client.GetAll(); - - connection.Received().GetAll(Arg.Is(u => u.ToString() == "app/installations"), null, AcceptHeaders.MachineManPreview); - } - - - [Fact] - public void RequestsTheCorrectUrlWithApiOptions() - { - var connection = Substitute.For(); - var client = new InstallationsClient(connection); - - var options = new ApiOptions - { - PageSize = 1, - PageCount = 1, - StartPage = 1 - }; - - client.GetAll(options); - - connection.Received().GetAll(Arg.Is(u => u.ToString() == "app/installations"), null, AcceptHeaders.MachineManPreview, options); - } - - } - - } - } -} diff --git a/Octokit/Authentication/ApplicationAuthenticator.cs b/Octokit/Authentication/ApplicationAuthenticator.cs new file mode 100644 index 0000000000..9e079539ea --- /dev/null +++ b/Octokit/Authentication/ApplicationAuthenticator.cs @@ -0,0 +1,23 @@ +using System.Collections.Generic; + +namespace Octokit.Internal +{ + class ApplicationAuthenticator : IAuthenticationHandler + { + public void Authenticate(IRequest request, Credentials credentials) + { + Ensure.ArgumentNotNull(request, nameof(request)); + Ensure.ArgumentNotNull(credentials, nameof(credentials)); + Ensure.ArgumentNotNull(credentials.Login, nameof(credentials.Login)); + Ensure.ArgumentNotNull(credentials.Password, nameof(credentials.Password)); + + Dictionary parameters = new Dictionary + { + { "client_id", credentials.Login }, + { "client_secret", credentials.Password } + }; + + ((Request)request).Endpoint = request.Endpoint.ApplyParameters(parameters); + } + } +} diff --git a/Octokit/Clients/AccessTokensClient.cs b/Octokit/Clients/AccessTokensClient.cs deleted file mode 100644 index 78d31be46b..0000000000 --- a/Octokit/Clients/AccessTokensClient.cs +++ /dev/null @@ -1,16 +0,0 @@ -using System.Threading.Tasks; - -namespace Octokit -{ - class AccessTokensClient : ApiClient, IAccessTokensClient - { - public AccessTokensClient(IApiConnection apiConnection) : base(apiConnection) - { - } - - public Task Create(long installationId) - { - return ApiConnection.Post(ApiUrls.AccessTokens(installationId), string.Empty, AcceptHeaders.MachineManPreview); - } - } -} diff --git a/Octokit/Clients/ApplicationsClient.cs b/Octokit/Clients/ApplicationsClient.cs deleted file mode 100644 index 814427ecf9..0000000000 --- a/Octokit/Clients/ApplicationsClient.cs +++ /dev/null @@ -1,16 +0,0 @@ -using System.Threading.Tasks; - -namespace Octokit -{ - public class ApplicationsClient : ApiClient, IApplicationsClient - { - public ApplicationsClient(IApiConnection apiConnection) : base(apiConnection) - { - } - - public Task Create() - { - return ApiConnection.Get(ApiUrls.App(), null, AcceptHeaders.MachineManPreview); - } - } -} \ No newline at end of file diff --git a/Octokit/Clients/GitHubAppsClient.cs b/Octokit/Clients/GitHubAppsClient.cs new file mode 100644 index 0000000000..57413eb803 --- /dev/null +++ b/Octokit/Clients/GitHubAppsClient.cs @@ -0,0 +1,34 @@ +using System.Collections.Generic; +using System.Threading.Tasks; + +namespace Octokit +{ + public class GitHubAppsClient : ApiClient, IGitHubAppsClient + { + public GitHubAppsClient(IApiConnection apiConnection) : base(apiConnection) + { + } + + public Task GetCurrent() + { + return ApiConnection.Get(ApiUrls.App(), null, AcceptHeaders.MachineManPreview); + } + + public Task CreateInstallationToken(long installationId) + { + return ApiConnection.Post(ApiUrls.AccessTokens(installationId), string.Empty, AcceptHeaders.MachineManPreview); + } + + public Task> GetAllInstallationsForCurrent() + { + return ApiConnection.GetAll(ApiUrls.Installations(), null, AcceptHeaders.MachineManPreview); + } + + public Task> GetAllInstallationsForCurrent(ApiOptions options) + { + Ensure.ArgumentNotNull(options, nameof(options)); + + return ApiConnection.GetAll(ApiUrls.Installations(), null, AcceptHeaders.MachineManPreview, options); + } + } +} \ No newline at end of file diff --git a/Octokit/Clients/IAccessTokensClient.cs b/Octokit/Clients/IAccessTokensClient.cs deleted file mode 100644 index 12857169a6..0000000000 --- a/Octokit/Clients/IAccessTokensClient.cs +++ /dev/null @@ -1,9 +0,0 @@ -using System.Threading.Tasks; - -namespace Octokit -{ - public interface IAccessTokensClient - { - Task Create(long installationId); - } -} diff --git a/Octokit/Clients/IApplicationsClient.cs b/Octokit/Clients/IApplicationsClient.cs deleted file mode 100644 index bf7491db2f..0000000000 --- a/Octokit/Clients/IApplicationsClient.cs +++ /dev/null @@ -1,9 +0,0 @@ -using System.Threading.Tasks; - -namespace Octokit -{ - public interface IApplicationsClient - { - Task Create(); - } -} \ No newline at end of file diff --git a/Octokit/Clients/IGitHubAppsClient.cs b/Octokit/Clients/IGitHubAppsClient.cs new file mode 100644 index 0000000000..9113f0b7d6 --- /dev/null +++ b/Octokit/Clients/IGitHubAppsClient.cs @@ -0,0 +1,13 @@ +using System.Collections.Generic; +using System.Threading.Tasks; + +namespace Octokit +{ + public interface IGitHubAppsClient + { + Task GetCurrent(); + Task CreateInstallationToken(long installationId); + Task> GetAllInstallationsForCurrent(); + Task> GetAllInstallationsForCurrent(ApiOptions options); + } +} \ No newline at end of file diff --git a/Octokit/Clients/IInstallationsClient.cs b/Octokit/Clients/IInstallationsClient.cs deleted file mode 100644 index 0730b6edba..0000000000 --- a/Octokit/Clients/IInstallationsClient.cs +++ /dev/null @@ -1,13 +0,0 @@ -using System.Collections.Generic; -using System.Threading.Tasks; - -namespace Octokit -{ - public interface IInstallationsClient - { - IAccessTokensClient AccessTokens { get; } - - Task> GetAll(); - Task> GetAll(ApiOptions options); - } -} diff --git a/Octokit/Clients/InstallationsClient.cs b/Octokit/Clients/InstallationsClient.cs deleted file mode 100644 index 89106e6c2f..0000000000 --- a/Octokit/Clients/InstallationsClient.cs +++ /dev/null @@ -1,27 +0,0 @@ -using System.Collections.Generic; -using System.Threading.Tasks; - -namespace Octokit -{ - class InstallationsClient : ApiClient, IInstallationsClient - { - public InstallationsClient(IApiConnection apiConnection) : base(apiConnection) - { - AccessTokens = new AccessTokensClient(apiConnection); - } - - public IAccessTokensClient AccessTokens { get; private set; } - - public Task> GetAll() - { - return ApiConnection.GetAll(ApiUrls.Installations(), null, AcceptHeaders.MachineManPreview); - } - - public Task> GetAll(ApiOptions options) - { - Ensure.ArgumentNotNull(options, nameof(options)); - - return ApiConnection.GetAll(ApiUrls.Installations(), null, AcceptHeaders.MachineManPreview, options); - } - } -} diff --git a/Octokit/GitHubClient.cs b/Octokit/GitHubClient.cs index 3630bc1085..968e603c7c 100644 --- a/Octokit/GitHubClient.cs +++ b/Octokit/GitHubClient.cs @@ -87,8 +87,7 @@ public GitHubClient(IConnection connection) Enterprise = new EnterpriseClient(apiConnection); Gist = new GistsClient(apiConnection); Git = new GitDatabaseClient(apiConnection); - Application = new ApplicationsClient(apiConnection); - Installation = new InstallationsClient(apiConnection); + GitHubApps = new GitHubAppsClient(apiConnection); Issue = new IssuesClient(apiConnection); Migration = new MigrationClient(apiConnection); Miscellaneous = new MiscellaneousClient(connection); @@ -173,14 +172,6 @@ public Uri BaseAddress /// public IActivitiesClient Activity { get; private set; } - /// - /// Access GitHub's App Installation API. - /// - /// - /// Refer to the API documentation for more information: https://developer.github.com/v3/apps/installations/ - /// - public IInstallationsClient Installation { get; private set; } - /// /// Access GitHub's Issue API. /// @@ -265,9 +256,9 @@ public Uri BaseAddress /// Access GitHub's Apps API. /// /// - /// Refer to the API documentation for more information: https://developer.github.com/v3/git/ + /// Refer to the API documentation for more information: https://developer.github.com/v3/apps/ /// - public IApplicationsClient Application { get; private set; } + public IGitHubAppsClient GitHubApps { get; private set; } /// /// Access GitHub's Search API. diff --git a/Octokit/IGitHubClient.cs b/Octokit/IGitHubClient.cs index a2d5bfe5d6..a9298a3ddc 100644 --- a/Octokit/IGitHubClient.cs +++ b/Octokit/IGitHubClient.cs @@ -44,15 +44,7 @@ public interface IGitHubClient : IApiInfoProvider /// /// Refer to the API documentation for more information: https://developer.github.com/v3/apps/ /// - IApplicationsClient Application { get; } - - /// - /// Access GitHub's Application Installation API. - /// - /// - /// Refer to the API documentation for more information: https://developer.github.com/v3/apps/installations/ - /// - IInstallationsClient Installation { get; } + IGitHubAppsClient GitHubApps { get; } /// /// Access GitHub's Issue API. From e085b1ac15c3b1b3d0e1f017333906f456fc4082 Mon Sep 17 00:00:00 2001 From: Ryan Gribble Date: Wed, 28 Feb 2018 08:32:40 +1000 Subject: [PATCH 24/84] add Get method for App --- .../Clients/GitHubAppsClientTests.cs | 19 +++++++++++++++++++ Octokit/Clients/GitHubAppsClient.cs | 5 +++++ Octokit/Clients/IGitHubAppsClient.cs | 1 + Octokit/Helpers/ApiUrls.cs | 8 ++++++++ 4 files changed, 33 insertions(+) diff --git a/Octokit.Tests.Integration/Clients/GitHubAppsClientTests.cs b/Octokit.Tests.Integration/Clients/GitHubAppsClientTests.cs index a168c10f85..b50b778205 100644 --- a/Octokit.Tests.Integration/Clients/GitHubAppsClientTests.cs +++ b/Octokit.Tests.Integration/Clients/GitHubAppsClientTests.cs @@ -1,11 +1,30 @@ using Octokit.Tests.Integration.Helpers; using System; using System.Threading.Tasks; +using Xunit; namespace Octokit.Tests.Integration.Clients { public class GitHubAppsClientTests { + public class TheGetMethod + { + IGitHubClient _github; + + public TheGetMethod() + { + _github = Helper.GetAuthenticatedClient(); + } + + [IntegrationTest] + public async Task GetsApp() + { + var result = await _github.GitHubApps.Get("MyGitHub"); + + Assert.Equal("MyGitHub", result.Name); + } + } + public class TheGetAllInstallationsForCurrentMethod : IDisposable { IGitHubClient _github; diff --git a/Octokit/Clients/GitHubAppsClient.cs b/Octokit/Clients/GitHubAppsClient.cs index 57413eb803..1513c6e4de 100644 --- a/Octokit/Clients/GitHubAppsClient.cs +++ b/Octokit/Clients/GitHubAppsClient.cs @@ -9,6 +9,11 @@ public GitHubAppsClient(IApiConnection apiConnection) : base(apiConnection) { } + public Task Get(string slug) + { + return ApiConnection.Get(ApiUrls.App(slug), null, AcceptHeaders.MachineManPreview); + } + public Task GetCurrent() { return ApiConnection.Get(ApiUrls.App(), null, AcceptHeaders.MachineManPreview); diff --git a/Octokit/Clients/IGitHubAppsClient.cs b/Octokit/Clients/IGitHubAppsClient.cs index 9113f0b7d6..8cfd0a8747 100644 --- a/Octokit/Clients/IGitHubAppsClient.cs +++ b/Octokit/Clients/IGitHubAppsClient.cs @@ -5,6 +5,7 @@ namespace Octokit { public interface IGitHubAppsClient { + Task Get(string slug); Task GetCurrent(); Task CreateInstallationToken(long installationId); Task> GetAllInstallationsForCurrent(); diff --git a/Octokit/Helpers/ApiUrls.cs b/Octokit/Helpers/ApiUrls.cs index 6c87778858..a24cb75968 100644 --- a/Octokit/Helpers/ApiUrls.cs +++ b/Octokit/Helpers/ApiUrls.cs @@ -304,6 +304,14 @@ public static Uri App() return "app".FormatUri(); } + /// + /// Returns the that creates a github app. + /// + public static Uri App(string slug) + { + return "apps/{0}".FormatUri(slug); + } + /// /// Returns the that returns all the installations of the authenticated application. /// From 8fde9116617d524137bb3ca22caab617baf2a03a Mon Sep 17 00:00:00 2001 From: Ryan Gribble Date: Wed, 28 Feb 2018 08:33:12 +1000 Subject: [PATCH 25/84] Create GitHubApp response model instead of re-using existing Application response model --- .../Clients/IObservableGitHubAppsClient.cs | 2 +- .../Clients/ObservableGitHubAppsClient.cs | 2 +- Octokit/Clients/GitHubAppsClient.cs | 8 ++--- Octokit/Clients/IGitHubAppsClient.cs | 4 +-- Octokit/Models/Response/GitHubApp.cs | 36 +++++++++++++++++++ 5 files changed, 44 insertions(+), 8 deletions(-) create mode 100644 Octokit/Models/Response/GitHubApp.cs diff --git a/Octokit.Reactive/Clients/IObservableGitHubAppsClient.cs b/Octokit.Reactive/Clients/IObservableGitHubAppsClient.cs index d933ec9642..cc633b276d 100644 --- a/Octokit.Reactive/Clients/IObservableGitHubAppsClient.cs +++ b/Octokit.Reactive/Clients/IObservableGitHubAppsClient.cs @@ -4,7 +4,7 @@ namespace Octokit.Reactive { public interface IObservableGitHubAppsClient { - IObservable GetCurrent(); + IObservable GetCurrent(); IObservable CreateInstallationToken(long installationId); IObservable GetAllInstallationsForCurrent(); IObservable GetAllInstallationsForCurrent(ApiOptions options); diff --git a/Octokit.Reactive/Clients/ObservableGitHubAppsClient.cs b/Octokit.Reactive/Clients/ObservableGitHubAppsClient.cs index 0b706670d1..67042c2577 100644 --- a/Octokit.Reactive/Clients/ObservableGitHubAppsClient.cs +++ b/Octokit.Reactive/Clients/ObservableGitHubAppsClient.cs @@ -17,7 +17,7 @@ public ObservableGitHubAppsClient(IGitHubClient client) _connection = client.Connection; } - public IObservable GetCurrent() + public IObservable GetCurrent() { return _client.GetCurrent().ToObservable(); } diff --git a/Octokit/Clients/GitHubAppsClient.cs b/Octokit/Clients/GitHubAppsClient.cs index 1513c6e4de..72a8d91609 100644 --- a/Octokit/Clients/GitHubAppsClient.cs +++ b/Octokit/Clients/GitHubAppsClient.cs @@ -9,14 +9,14 @@ public GitHubAppsClient(IApiConnection apiConnection) : base(apiConnection) { } - public Task Get(string slug) + public Task Get(string slug) { - return ApiConnection.Get(ApiUrls.App(slug), null, AcceptHeaders.MachineManPreview); + return ApiConnection.Get(ApiUrls.App(slug), null, AcceptHeaders.MachineManPreview); } - public Task GetCurrent() + public Task GetCurrent() { - return ApiConnection.Get(ApiUrls.App(), null, AcceptHeaders.MachineManPreview); + return ApiConnection.Get(ApiUrls.App(), null, AcceptHeaders.MachineManPreview); } public Task CreateInstallationToken(long installationId) diff --git a/Octokit/Clients/IGitHubAppsClient.cs b/Octokit/Clients/IGitHubAppsClient.cs index 8cfd0a8747..6d49b401e3 100644 --- a/Octokit/Clients/IGitHubAppsClient.cs +++ b/Octokit/Clients/IGitHubAppsClient.cs @@ -5,8 +5,8 @@ namespace Octokit { public interface IGitHubAppsClient { - Task Get(string slug); - Task GetCurrent(); + Task Get(string slug); + Task GetCurrent(); Task CreateInstallationToken(long installationId); Task> GetAllInstallationsForCurrent(); Task> GetAllInstallationsForCurrent(ApiOptions options); diff --git a/Octokit/Models/Response/GitHubApp.cs b/Octokit/Models/Response/GitHubApp.cs new file mode 100644 index 0000000000..e2e2df9d7c --- /dev/null +++ b/Octokit/Models/Response/GitHubApp.cs @@ -0,0 +1,36 @@ +using System; +using System.Diagnostics; +using System.Globalization; + +namespace Octokit +{ + /// + /// Represents an oauth application. + /// + [DebuggerDisplay("{DebuggerDisplay,nq}")] + public class GitHubApp + { + public GitHubApp() { } + + public long Id { get; protected set; } + + public string Name { get; protected set; } + + public User Owner { get; protected set; } + + public string Description { get; protected set; } + + public string ExternalUrl { get; protected set; } + + public string HtmlUrl { get; protected set; } + + public DateTimeOffset CreatedAt { get; protected set; } + + public DateTimeOffset UpdatedAt { get; protected set; } + + internal string DebuggerDisplay + { + get { return string.Format(CultureInfo.InvariantCulture, "Id: {0} Name: {1}", Id, Name); } + } + } +} From d1a4603e5df03d51bcdf6eb046e48364ce7cf875 Mon Sep 17 00:00:00 2001 From: Ryan Gribble Date: Wed, 28 Feb 2018 08:40:36 +1000 Subject: [PATCH 26/84] add Get method to observable client --- Octokit.Reactive/Clients/IObservableGitHubAppsClient.cs | 1 + Octokit.Reactive/Clients/ObservableGitHubAppsClient.cs | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/Octokit.Reactive/Clients/IObservableGitHubAppsClient.cs b/Octokit.Reactive/Clients/IObservableGitHubAppsClient.cs index cc633b276d..006168c404 100644 --- a/Octokit.Reactive/Clients/IObservableGitHubAppsClient.cs +++ b/Octokit.Reactive/Clients/IObservableGitHubAppsClient.cs @@ -4,6 +4,7 @@ namespace Octokit.Reactive { public interface IObservableGitHubAppsClient { + IObservable Get(string slug); IObservable GetCurrent(); IObservable CreateInstallationToken(long installationId); IObservable GetAllInstallationsForCurrent(); diff --git a/Octokit.Reactive/Clients/ObservableGitHubAppsClient.cs b/Octokit.Reactive/Clients/ObservableGitHubAppsClient.cs index 67042c2577..94c79ca51c 100644 --- a/Octokit.Reactive/Clients/ObservableGitHubAppsClient.cs +++ b/Octokit.Reactive/Clients/ObservableGitHubAppsClient.cs @@ -17,6 +17,11 @@ public ObservableGitHubAppsClient(IGitHubClient client) _connection = client.Connection; } + public IObservable Get(string slug) + { + return _client.Get(slug).ToObservable(); + } + public IObservable GetCurrent() { return _client.GetCurrent().ToObservable(); From 0e49287097629a99e3955307338024ec0a734fe3 Mon Sep 17 00:00:00 2001 From: Itai Bar-Haim Date: Wed, 28 Feb 2018 10:42:18 +0200 Subject: [PATCH 27/84] fixed build (both locally and failed test). --- Octokit.Tests.Integration/Octokit.Tests.Integration.csproj | 5 +++++ Octokit.Tests/Clients/GitHubAppsClientTests.cs | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj b/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj index 0a690798d5..f8be48398c 100644 --- a/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj +++ b/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj @@ -39,6 +39,11 @@ + + + + + diff --git a/Octokit.Tests/Clients/GitHubAppsClientTests.cs b/Octokit.Tests/Clients/GitHubAppsClientTests.cs index 21e2859d50..36991ed983 100644 --- a/Octokit.Tests/Clients/GitHubAppsClientTests.cs +++ b/Octokit.Tests/Clients/GitHubAppsClientTests.cs @@ -26,7 +26,7 @@ public void GetFromCorrectUrl() client.GetCurrent(); - connection.Received().Get(Arg.Is(u => u.ToString() == "app"), null, AcceptHeaders.MachineManPreview); + connection.Received().Get(Arg.Is(u => u.ToString() == "app"), null, AcceptHeaders.MachineManPreview); } } From 7c494e6238dbcc56d91ee872fae58cc50bd2a894 Mon Sep 17 00:00:00 2001 From: Itai Bar-Haim Date: Mon, 5 Mar 2018 10:42:36 +0200 Subject: [PATCH 28/84] Fixed documentation and added some missing XML docs. --- Octokit/Clients/GitHubAppsClient.cs | 29 ++++++++++++++++++++++++ Octokit/Clients/IGitHubAppsClient.cs | 33 ++++++++++++++++++++++++++++ Octokit/Helpers/ApiUrls.cs | 5 ++++- Octokit/Models/Response/GitHubApp.cs | 2 +- 4 files changed, 67 insertions(+), 2 deletions(-) diff --git a/Octokit/Clients/GitHubAppsClient.cs b/Octokit/Clients/GitHubAppsClient.cs index 72a8d91609..fb5a755310 100644 --- a/Octokit/Clients/GitHubAppsClient.cs +++ b/Octokit/Clients/GitHubAppsClient.cs @@ -3,32 +3,61 @@ namespace Octokit { + /// + /// A client for GitHub Applications API. Provides the methods required to get GitHub applications and installations. + /// + /// + /// See the GitHub Apps API documentation for more information. + /// public class GitHubAppsClient : ApiClient, IGitHubAppsClient { public GitHubAppsClient(IApiConnection apiConnection) : base(apiConnection) { } + /// + /// Get a single GitHub App + /// + /// The URL-friendly name of your GitHub App. You can find this on the settings page for your GitHub App. + /// The GitHub App public Task Get(string slug) { return ApiConnection.Get(ApiUrls.App(slug), null, AcceptHeaders.MachineManPreview); } + /// + /// Returns the GitHub App associated with the authentication credentials used. + /// + /// The GitHub App associated with the authentication credentials used. public Task GetCurrent() { return ApiConnection.Get(ApiUrls.App(), null, AcceptHeaders.MachineManPreview); } + /// + /// Create a new installation token + /// + /// The Id of the GitHub App installation. + /// The GitHub App installation access token. public Task CreateInstallationToken(long installationId) { return ApiConnection.Post(ApiUrls.AccessTokens(installationId), string.Empty, AcceptHeaders.MachineManPreview); } + /// + /// List installations that are accessible to the authenticated user. + /// + /// A list (read-only) that includes all the GitHub App installations accessible to the current authenticated user. public Task> GetAllInstallationsForCurrent() { return ApiConnection.GetAll(ApiUrls.Installations(), null, AcceptHeaders.MachineManPreview); } + /// + /// List installations that are accessible to the authenticated user. + /// + /// + /// A list (read-only) that includes all the GitHub App installations accessible to the current authenticated user. public Task> GetAllInstallationsForCurrent(ApiOptions options) { Ensure.ArgumentNotNull(options, nameof(options)); diff --git a/Octokit/Clients/IGitHubAppsClient.cs b/Octokit/Clients/IGitHubAppsClient.cs index 6d49b401e3..761be187c0 100644 --- a/Octokit/Clients/IGitHubAppsClient.cs +++ b/Octokit/Clients/IGitHubAppsClient.cs @@ -3,12 +3,45 @@ namespace Octokit { + /// + /// A client for GitHub Applications API. Provides the methods required to get GitHub applications and installations. + /// + /// + /// See the GitHub Apps API documentation for more information. + /// public interface IGitHubAppsClient { + /// + /// Get a single GitHub App + /// + /// The URL-friendly name of your GitHub App. You can find this on the settings page for your GitHub App. + /// The GitHub App Task Get(string slug); + + /// + /// Returns the GitHub App associated with the authentication credentials used. + /// + /// The GitHub App associated with the authentication credentials used. Task GetCurrent(); + + /// + /// Create a new installation token + /// + /// The Id of the GitHub App installation. + /// The GitHub App installation access token. Task CreateInstallationToken(long installationId); + + /// + /// List installations that are accessible to the authenticated user. + /// + /// A list (read-only) that includes all the GitHub App installations accessible to the current authenticated user. Task> GetAllInstallationsForCurrent(); + + /// + /// List installations that are accessible to the authenticated user. + /// + /// + /// A list (read-only) that includes all the GitHub App installations accessible to the current authenticated user. Task> GetAllInstallationsForCurrent(ApiOptions options); } } \ No newline at end of file diff --git a/Octokit/Helpers/ApiUrls.cs b/Octokit/Helpers/ApiUrls.cs index ca6bade12f..a3512a06a6 100644 --- a/Octokit/Helpers/ApiUrls.cs +++ b/Octokit/Helpers/ApiUrls.cs @@ -285,12 +285,15 @@ public static Uri Notification(int id) /// Returns the for the specified notification's subscription status. /// /// The Id of the notification. - /// public static Uri NotificationSubscription(int id) { return "notifications/threads/{0}/subscription".FormatUri(id); } + /// + /// Returns the for creating a new installation token. + /// + /// The Id of the GitHub App installation. public static Uri AccessTokens(long installationId) { return "installations/{0}/access_tokens".FormatUri(installationId); diff --git a/Octokit/Models/Response/GitHubApp.cs b/Octokit/Models/Response/GitHubApp.cs index e2e2df9d7c..c25593b8b2 100644 --- a/Octokit/Models/Response/GitHubApp.cs +++ b/Octokit/Models/Response/GitHubApp.cs @@ -5,7 +5,7 @@ namespace Octokit { /// - /// Represents an oauth application. + /// Represents a GitHub application. /// [DebuggerDisplay("{DebuggerDisplay,nq}")] public class GitHubApp From f001908554b15f642d4322ca8e20f4048df1c0aa Mon Sep 17 00:00:00 2001 From: Itai Bar-Haim Date: Tue, 6 Mar 2018 10:30:20 +0200 Subject: [PATCH 29/84] added DebuggerDisplay to StatusEventPayload --- .../Response/ActivityPayloads/StatusEventPayload.cs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Octokit/Models/Response/ActivityPayloads/StatusEventPayload.cs b/Octokit/Models/Response/ActivityPayloads/StatusEventPayload.cs index 1c8d3db1a6..e6f472e1fb 100644 --- a/Octokit/Models/Response/ActivityPayloads/StatusEventPayload.cs +++ b/Octokit/Models/Response/ActivityPayloads/StatusEventPayload.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Diagnostics; +using System.Globalization; namespace Octokit { @@ -67,5 +68,13 @@ public class StatusEventPayload : ActivityPayload /// The branches involved. /// public IReadOnlyList Branches { get; protected set; } + + internal string DebuggerDisplay + { + get + { + return string.Format(CultureInfo.InvariantCulture, "Context: {0}, State: {1}, Description: {2}", Context, State, Description); + } + } } } From 76a8860f468ae86ab7f6d4a73faf0fbe2942e3d5 Mon Sep 17 00:00:00 2001 From: Itai Bar-Haim Date: Tue, 6 Mar 2018 11:26:47 +0200 Subject: [PATCH 30/84] updated XML docs and added some missing bits. prefer nameof(x) over literal "x". --- .../Clients/IObservableProjectsClient.cs | 8 +-- .../IObservablePullRequestReviewsClient.cs | 2 + .../IObservableRepositoryBranchesClient.cs | 2 + .../Clients/IObservableTeamsClient.cs | 1 + .../Clients/ObservableProjectsClient.cs | 50 +++++++++---------- ...PullRequestReviewCommentReactionsClient.cs | 10 ++-- .../ObservableRepositoryBranchesClient.cs | 34 +++++++------ Octokit/Clients/GitHubAppsClient.cs | 4 ++ ...IOrganizationOutsideCollaboratorsClient.cs | 6 +++ Octokit/Clients/IProjectsClient.cs | 8 +-- Octokit/Clients/IRepositoryBranchesClient.cs | 2 + Octokit/Clients/ITeamsClient.cs | 1 + Octokit/Clients/ProjectsClient.cs | 4 +- Octokit/Clients/RepositoryBranchesClient.cs | 2 + Octokit/Exceptions/ApiException.cs | 3 ++ .../Exceptions/LegalRestrictionException.cs | 3 ++ ...PrivateRepositoryQuotaExceededException.cs | 3 ++ .../PullRequestNotMergeableException.cs | 3 ++ .../Exceptions/RepositoryFormatException.cs | 3 ++ .../TwoFactorChallengeFailedException.cs | 3 ++ Octokit/Http/ReadOnlyPagedCollection.cs | 4 +- .../Models/Request/PullRequestReviewSubmit.cs | 4 +- .../ActivityPayloads/StatusEventPayload.cs | 2 +- Octokit/Models/Response/Commit.cs | 2 +- Octokit/Models/Response/GitHubApp.cs | 6 +++ 25 files changed, 111 insertions(+), 59 deletions(-) diff --git a/Octokit.Reactive/Clients/IObservableProjectsClient.cs b/Octokit.Reactive/Clients/IObservableProjectsClient.cs index dea4dca868..2172e0868f 100644 --- a/Octokit.Reactive/Clients/IObservableProjectsClient.cs +++ b/Octokit.Reactive/Clients/IObservableProjectsClient.cs @@ -18,7 +18,7 @@ public interface IObservableProjectsClient /// See the API documentation for more information. /// /// The owner of the repository - /// The name of the repository + /// The name of the repository IObservable GetAllForRepository(string owner, string name); /// @@ -28,7 +28,7 @@ public interface IObservableProjectsClient /// See the API documentation for more information. /// /// The owner of the repository - /// The name of the repository + /// The name of the repository /// Used to filter the list of projects returned IObservable GetAllForRepository(string owner, string name, ProjectRequest request); @@ -58,7 +58,7 @@ public interface IObservableProjectsClient /// See the API documentation for more information. /// /// The owner of the repository - /// The name of the repository + /// The name of the repository /// Options for changing the API response IObservable GetAllForRepository(string owner, string name, ApiOptions options); @@ -69,7 +69,7 @@ public interface IObservableProjectsClient /// See the API documentation for more information. /// /// The owner of the repository - /// The name of the repository + /// The name of the repository /// Used to filter the list of projects returned /// Options for changing the API response IObservable GetAllForRepository(string owner, string name, ProjectRequest request, ApiOptions options); diff --git a/Octokit.Reactive/Clients/IObservablePullRequestReviewsClient.cs b/Octokit.Reactive/Clients/IObservablePullRequestReviewsClient.cs index 92a2b17ade..607d224f19 100644 --- a/Octokit.Reactive/Clients/IObservablePullRequestReviewsClient.cs +++ b/Octokit.Reactive/Clients/IObservablePullRequestReviewsClient.cs @@ -173,6 +173,7 @@ public interface IObservablePullRequestReviewsClient /// The name of the repository /// The pull request number /// The pull request review number + /// Options for changing the API response IObservable GetAllComments(string owner, string name, int number, long reviewId, ApiOptions options); /// @@ -182,6 +183,7 @@ public interface IObservablePullRequestReviewsClient /// The Id of the repository /// The pull request number /// The pull request review number + /// Options for changing the API response IObservable GetAllComments(long repositoryId, int number, long reviewId, ApiOptions options); } } diff --git a/Octokit.Reactive/Clients/IObservableRepositoryBranchesClient.cs b/Octokit.Reactive/Clients/IObservableRepositoryBranchesClient.cs index 01e953f513..e28df249f7 100644 --- a/Octokit.Reactive/Clients/IObservableRepositoryBranchesClient.cs +++ b/Octokit.Reactive/Clients/IObservableRepositoryBranchesClient.cs @@ -348,6 +348,7 @@ public interface IObservableRepositoryBranchesClient /// The owner of the repository /// The name of the repository /// The name of the branch + /// Required reviews IObservable UpdateReviewEnforcement(string owner, string name, string branch, BranchProtectionRequiredReviewsUpdate update); /// @@ -358,6 +359,7 @@ public interface IObservableRepositoryBranchesClient /// /// The Id of the repository /// The name of the branch + /// Required reviews IObservable UpdateReviewEnforcement(long repositoryId, string branch, BranchProtectionRequiredReviewsUpdate update); /// diff --git a/Octokit.Reactive/Clients/IObservableTeamsClient.cs b/Octokit.Reactive/Clients/IObservableTeamsClient.cs index 11aba6f496..b95a98c013 100644 --- a/Octokit.Reactive/Clients/IObservableTeamsClient.cs +++ b/Octokit.Reactive/Clients/IObservableTeamsClient.cs @@ -71,6 +71,7 @@ public interface IObservableTeamsClient /// Returns all child teams of the given team. /// /// The team identifier + /// Options to change API behaviour. /// /// https://developer.github.com/v3/orgs/teams/#list-child-teams /// diff --git a/Octokit.Reactive/Clients/ObservableProjectsClient.cs b/Octokit.Reactive/Clients/ObservableProjectsClient.cs index 608c7f70a1..9b9c5fe82f 100644 --- a/Octokit.Reactive/Clients/ObservableProjectsClient.cs +++ b/Octokit.Reactive/Clients/ObservableProjectsClient.cs @@ -34,7 +34,7 @@ public ObservableProjectsClient(IGitHubClient client) /// See the API documentation for more information. /// /// The owner of the repository - /// The name of the repository + /// The name of the repository public IObservable GetAllForRepository(string owner, string name) { return GetAllForRepository(owner, name, ApiOptions.None); @@ -47,12 +47,13 @@ public IObservable GetAllForRepository(string owner, string name) /// See the API documentation for more information. /// /// The owner of the repository - /// The name of the repository + /// The name of the repository + /// Options to change API behaviour public IObservable GetAllForRepository(string owner, string name, ApiOptions options) { - Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); - Ensure.ArgumentNotNullOrEmptyString(name, "name"); - Ensure.ArgumentNotNull(options, "options"); + Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); + Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); + Ensure.ArgumentNotNull(options, nameof(options)); var url = ApiUrls.RepositoryProjects(owner, name); @@ -66,7 +67,7 @@ public IObservable GetAllForRepository(string owner, string name, ApiOp /// See the API documentation for more information. /// /// The owner of the repository - /// The name of the repository + /// The name of the repository /// Used to filter the list of projects returned public IObservable GetAllForRepository(string owner, string name, ProjectRequest request) { @@ -80,15 +81,15 @@ public IObservable GetAllForRepository(string owner, string name, Proje /// See the API documentation for more information. /// /// The owner of the repository - /// The name of the repository + /// The name of the repository /// Used to filter the list of projects returned /// Options for changing the API response public IObservable GetAllForRepository(string owner, string name, ProjectRequest request, ApiOptions options) { - Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); - Ensure.ArgumentNotNullOrEmptyString(name, "name"); - Ensure.ArgumentNotNull(request, "request"); - Ensure.ArgumentNotNull(options, "options"); + Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); + Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); + Ensure.ArgumentNotNull(request, nameof(request)); + Ensure.ArgumentNotNull(options, nameof(options)); var url = ApiUrls.RepositoryProjects(owner, name); @@ -113,12 +114,11 @@ public IObservable GetAllForRepository(long repositoryId) /// /// See the API documentation for more information. /// - /// The owner of the repository - /// The name of the repository + /// The Id of the repository /// Options for changing the API response public IObservable GetAllForRepository(long repositoryId, ApiOptions options) { - Ensure.ArgumentNotNull(options, "options"); + Ensure.ArgumentNotNull(options, nameof(options)); var url = ApiUrls.RepositoryProjects(repositoryId); @@ -149,8 +149,8 @@ public IObservable GetAllForRepository(long repositoryId, ProjectReques /// Options for changing the API response public IObservable GetAllForRepository(long repositoryId, ProjectRequest request, ApiOptions options) { - Ensure.ArgumentNotNull(request, "request"); - Ensure.ArgumentNotNull(options, "options"); + Ensure.ArgumentNotNull(request, nameof(request)); + Ensure.ArgumentNotNull(options, nameof(options)); var url = ApiUrls.RepositoryProjects(repositoryId); @@ -179,8 +179,8 @@ public IObservable GetAllForOrganization(string organization) /// Options for changing the API response public IObservable GetAllForOrganization(string organization, ApiOptions options) { - Ensure.ArgumentNotNullOrEmptyString(organization, "organization"); - Ensure.ArgumentNotNull(options, "options"); + Ensure.ArgumentNotNullOrEmptyString(organization, nameof(organization)); + Ensure.ArgumentNotNull(options, nameof(options)); var url = ApiUrls.OrganizationProjects(organization); @@ -211,9 +211,9 @@ public IObservable GetAllForOrganization(string organization, ProjectRe /// Options for changing the API response public IObservable GetAllForOrganization(string organization, ProjectRequest request, ApiOptions options) { - Ensure.ArgumentNotNullOrEmptyString(organization, "organization"); - Ensure.ArgumentNotNull(request, "request"); - Ensure.ArgumentNotNull(options, "options"); + Ensure.ArgumentNotNullOrEmptyString(organization, nameof(organization)); + Ensure.ArgumentNotNull(request, nameof(request)); + Ensure.ArgumentNotNull(options, nameof(options)); var url = ApiUrls.OrganizationProjects(organization); @@ -243,7 +243,7 @@ public IObservable Get(int id) /// The new project to create for the specified repository public IObservable CreateForRepository(long repositoryId, NewProject newProject) { - Ensure.ArgumentNotNull(newProject, "newProject"); + Ensure.ArgumentNotNull(newProject, nameof(newProject)); return _client.CreateForRepository(repositoryId, newProject).ToObservable(); } @@ -258,8 +258,8 @@ public IObservable CreateForRepository(long repositoryId, NewProject ne /// The new project to create for the specified repository public IObservable CreateForOrganization(string organization, NewProject newProject) { - Ensure.ArgumentNotNullOrEmptyString(organization, "organization"); - Ensure.ArgumentNotNull(newProject, "newProject"); + Ensure.ArgumentNotNullOrEmptyString(organization, nameof(organization)); + Ensure.ArgumentNotNull(newProject, nameof(newProject)); return _client.CreateForOrganization(organization, newProject).ToObservable(); } @@ -274,7 +274,7 @@ public IObservable CreateForOrganization(string organization, NewProjec /// The modified project public IObservable Update(int id, ProjectUpdate projectUpdate) { - Ensure.ArgumentNotNull(projectUpdate, "projectUpdate"); + Ensure.ArgumentNotNull(projectUpdate, nameof(projectUpdate)); return _client.Update(id, projectUpdate).ToObservable(); } diff --git a/Octokit.Reactive/Clients/ObservablePullRequestReviewCommentReactionsClient.cs b/Octokit.Reactive/Clients/ObservablePullRequestReviewCommentReactionsClient.cs index 54b47a6ef8..a2ee0d9b5d 100644 --- a/Octokit.Reactive/Clients/ObservablePullRequestReviewCommentReactionsClient.cs +++ b/Octokit.Reactive/Clients/ObservablePullRequestReviewCommentReactionsClient.cs @@ -15,9 +15,13 @@ public class ObservablePullRequestReviewCommentReactionsClient : IObservablePull readonly IPullRequestReviewCommentReactionsClient _client; readonly IConnection _connection; + /// + /// Initializes a new GitHub Reactions API client. + /// + /// A GitHubClient. public ObservablePullRequestReviewCommentReactionsClient(IGitHubClient client) { - Ensure.ArgumentNotNull(client, "client"); + Ensure.ArgumentNotNull(client, nameof(client)); _client = client.Reaction.PullRequestReviewComment; _connection = client.Connection; @@ -32,8 +36,8 @@ public ObservablePullRequestReviewCommentReactionsClient(IGitHubClient client) /// The comment id public IObservable GetAll(string owner, string name, int number) { - Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); - Ensure.ArgumentNotNullOrEmptyString(name, "name"); + Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); + Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); return _connection.GetAndFlattenAllPages(ApiUrls.PullRequestReviewCommentReaction(owner, name, number), null, AcceptHeaders.ReactionsPreview); } diff --git a/Octokit.Reactive/Clients/ObservableRepositoryBranchesClient.cs b/Octokit.Reactive/Clients/ObservableRepositoryBranchesClient.cs index cda1284de5..a16427294a 100644 --- a/Octokit.Reactive/Clients/ObservableRepositoryBranchesClient.cs +++ b/Octokit.Reactive/Clients/ObservableRepositoryBranchesClient.cs @@ -537,6 +537,7 @@ public IObservable GetReviewEnforcement(long re /// The owner of the repository /// The name of the repository /// The name of the branch + /// The required reviews public IObservable UpdateReviewEnforcement(string owner, string name, string branch, BranchProtectionRequiredReviewsUpdate update) { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); @@ -555,6 +556,7 @@ public IObservable UpdateReviewEnforcement(stri /// /// The Id of the repository /// The name of the branch + /// The required reviews public IObservable UpdateReviewEnforcement(long repositoryId, string branch, BranchProtectionRequiredReviewsUpdate update) { Ensure.ArgumentNotNullOrEmptyString(branch, "branch"); @@ -706,9 +708,9 @@ public IObservable RemoveAdminEnforcement(long repositoryId, string branch /// The name of the branch public IObservable GetProtectedBranchRestrictions(string owner, string name, string branch) { - Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); - Ensure.ArgumentNotNullOrEmptyString(name, "name"); - Ensure.ArgumentNotNullOrEmptyString(branch, "branch"); + Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); + Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); + Ensure.ArgumentNotNullOrEmptyString(branch, nameof(branch)); return _client.GetProtectedBranchRestrictions(owner, name, branch).ToObservable(); } @@ -723,7 +725,7 @@ public IObservable GetProtectedBranchRestricti /// The name of the branch public IObservable GetProtectedBranchRestrictions(long repositoryId, string branch) { - Ensure.ArgumentNotNullOrEmptyString(branch, "branch"); + Ensure.ArgumentNotNullOrEmptyString(branch, nameof(branch)); return _client.GetProtectedBranchRestrictions(repositoryId, branch).ToObservable(); } @@ -739,9 +741,9 @@ public IObservable GetProtectedBranchRestricti /// The name of the branch public IObservable DeleteProtectedBranchRestrictions(string owner, string name, string branch) { - Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); - Ensure.ArgumentNotNullOrEmptyString(name, "name"); - Ensure.ArgumentNotNullOrEmptyString(branch, "branch"); + Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); + Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); + Ensure.ArgumentNotNullOrEmptyString(branch, nameof(branch)); return _client.DeleteProtectedBranchRestrictions(owner, name, branch).ToObservable(); } @@ -756,7 +758,7 @@ public IObservable DeleteProtectedBranchRestrictions(string owner, string /// The name of the branch public IObservable DeleteProtectedBranchRestrictions(long repositoryId, string branch) { - Ensure.ArgumentNotNullOrEmptyString(branch, "branch"); + Ensure.ArgumentNotNullOrEmptyString(branch, nameof(branch)); return _client.DeleteProtectedBranchRestrictions(repositoryId, branch).ToObservable(); } @@ -801,9 +803,9 @@ public IObservable GetProtectedBranchTeamRestrictions(long repositoryId, s /// The name of the branch public IObservable GetAllProtectedBranchTeamRestrictions(string owner, string name, string branch) { - Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); - Ensure.ArgumentNotNullOrEmptyString(name, "name"); - Ensure.ArgumentNotNullOrEmptyString(branch, "branch"); + Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); + Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); + Ensure.ArgumentNotNullOrEmptyString(branch, nameof(branch)); return _client.GetAllProtectedBranchTeamRestrictions(owner, name, branch).ToObservable().SelectMany(x => x); } @@ -818,7 +820,7 @@ public IObservable GetAllProtectedBranchTeamRestrictions(string owner, str /// The name of the branch public IObservable GetAllProtectedBranchTeamRestrictions(long repositoryId, string branch) { - Ensure.ArgumentNotNullOrEmptyString(branch, "branch"); + Ensure.ArgumentNotNullOrEmptyString(branch, nameof(branch)); return _client.GetAllProtectedBranchTeamRestrictions(repositoryId, branch).ToObservable().SelectMany(x => x); } @@ -835,10 +837,10 @@ public IObservable GetAllProtectedBranchTeamRestrictions(long repositoryId /// List of teams with push access public IObservable UpdateProtectedBranchTeamRestrictions(string owner, string name, string branch, BranchProtectionTeamCollection teams) { - Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); - Ensure.ArgumentNotNullOrEmptyString(name, "name"); - Ensure.ArgumentNotNullOrEmptyString(branch, "branch"); - Ensure.ArgumentNotNull(teams, "teams"); + Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); + Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); + Ensure.ArgumentNotNullOrEmptyString(branch, nameof(branch)); + Ensure.ArgumentNotNull(teams, nameof(teams)); return _client.UpdateProtectedBranchTeamRestrictions(owner, name, branch, teams).ToObservable().SelectMany(x => x); } diff --git a/Octokit/Clients/GitHubAppsClient.cs b/Octokit/Clients/GitHubAppsClient.cs index fb5a755310..2e8a7c4ef7 100644 --- a/Octokit/Clients/GitHubAppsClient.cs +++ b/Octokit/Clients/GitHubAppsClient.cs @@ -11,6 +11,10 @@ namespace Octokit /// public class GitHubAppsClient : ApiClient, IGitHubAppsClient { + /// + /// Instantiates a new GitHub Apps API client. + /// + /// An API connection public GitHubAppsClient(IApiConnection apiConnection) : base(apiConnection) { } diff --git a/Octokit/Clients/IOrganizationOutsideCollaboratorsClient.cs b/Octokit/Clients/IOrganizationOutsideCollaboratorsClient.cs index 1ad12ad7e3..4e5e32a0d6 100644 --- a/Octokit/Clients/IOrganizationOutsideCollaboratorsClient.cs +++ b/Octokit/Clients/IOrganizationOutsideCollaboratorsClient.cs @@ -3,6 +3,12 @@ namespace Octokit { + /// + /// A client for GitHub's Organization Outside Collaborators API. + /// + /// + /// See the Outside Collaborators API documentation for more information. + /// public interface IOrganizationOutsideCollaboratorsClient { /// diff --git a/Octokit/Clients/IProjectsClient.cs b/Octokit/Clients/IProjectsClient.cs index c3edd5ae7c..3e75e2f35f 100644 --- a/Octokit/Clients/IProjectsClient.cs +++ b/Octokit/Clients/IProjectsClient.cs @@ -19,7 +19,7 @@ public interface IProjectsClient /// See the API documentation for more information. /// /// The owner of the repository - /// The name of the repository + /// The name of the repository Task> GetAllForRepository(string owner, string name); /// @@ -29,7 +29,7 @@ public interface IProjectsClient /// See the API documentation for more information. /// /// The owner of the repository - /// The name of the repository + /// The name of the repository /// Used to filter the list of projects returned Task> GetAllForRepository(string owner, string name, ProjectRequest request); @@ -59,7 +59,7 @@ public interface IProjectsClient /// See the API documentation for more information. /// /// The owner of the repository - /// The name of the repository + /// The name of the repository /// Options for changing the API response Task> GetAllForRepository(string owner, string name, ApiOptions options); @@ -70,7 +70,7 @@ public interface IProjectsClient /// See the API documentation for more information. /// /// The owner of the repository - /// The name of the repository + /// The name of the repository /// Used to filter the list of projects returned /// Options for changing the API response Task> GetAllForRepository(string owner, string name, ProjectRequest request, ApiOptions options); diff --git a/Octokit/Clients/IRepositoryBranchesClient.cs b/Octokit/Clients/IRepositoryBranchesClient.cs index fc2655eecd..8ac239f03b 100644 --- a/Octokit/Clients/IRepositoryBranchesClient.cs +++ b/Octokit/Clients/IRepositoryBranchesClient.cs @@ -352,6 +352,7 @@ public interface IRepositoryBranchesClient /// The owner of the repository /// The name of the repository /// The name of the branch + /// Required reviews Task UpdateReviewEnforcement(string owner, string name, string branch, BranchProtectionRequiredReviewsUpdate update); /// @@ -362,6 +363,7 @@ public interface IRepositoryBranchesClient /// /// The Id of the repository /// The name of the branch + /// Required reviews Task UpdateReviewEnforcement(long repositoryId, string branch, BranchProtectionRequiredReviewsUpdate update); /// diff --git a/Octokit/Clients/ITeamsClient.cs b/Octokit/Clients/ITeamsClient.cs index ebe939db30..3269a01891 100644 --- a/Octokit/Clients/ITeamsClient.cs +++ b/Octokit/Clients/ITeamsClient.cs @@ -72,6 +72,7 @@ public interface ITeamsClient /// Returns all child teams of the given team. /// /// The team identifier + /// Options to change API behaviour. /// /// https://developer.github.com/v3/orgs/teams/#list-child-teams /// diff --git a/Octokit/Clients/ProjectsClient.cs b/Octokit/Clients/ProjectsClient.cs index 630f987f60..2e7c0d651a 100644 --- a/Octokit/Clients/ProjectsClient.cs +++ b/Octokit/Clients/ProjectsClient.cs @@ -27,7 +27,7 @@ public ProjectsClient(IApiConnection apiConnection) : /// See the API documentation for more information. /// /// The owner of the repository - /// The name of the repository + /// The name of the repository public Task> GetAllForRepository(string owner, string name) { return GetAllForRepository(owner, name, ApiOptions.None); @@ -40,7 +40,7 @@ public Task> GetAllForRepository(string owner, string nam /// See the API documentation for more information. /// /// The owner of the repository - /// The name of the repository + /// The name of the repository /// Options for changing the API response public Task> GetAllForRepository(string owner, string name, ApiOptions options) { diff --git a/Octokit/Clients/RepositoryBranchesClient.cs b/Octokit/Clients/RepositoryBranchesClient.cs index baee963d6f..65e5926221 100644 --- a/Octokit/Clients/RepositoryBranchesClient.cs +++ b/Octokit/Clients/RepositoryBranchesClient.cs @@ -576,6 +576,7 @@ public Task GetReviewEnforcement(long repositor /// The owner of the repository /// The name of the repository /// The name of the branch + /// Required reviews public Task UpdateReviewEnforcement(string owner, string name, string branch, BranchProtectionRequiredReviewsUpdate update) { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); @@ -594,6 +595,7 @@ public Task UpdateReviewEnforcement(string owne /// /// The Id of the repository /// The name of the branch + /// Required reviews public Task UpdateReviewEnforcement(long repositoryId, string branch, BranchProtectionRequiredReviewsUpdate update) { Ensure.ArgumentNotNullOrEmptyString(branch, "branch"); diff --git a/Octokit/Exceptions/ApiException.cs b/Octokit/Exceptions/ApiException.cs index ce2c15e90a..f5281189de 100644 --- a/Octokit/Exceptions/ApiException.cs +++ b/Octokit/Exceptions/ApiException.cs @@ -103,6 +103,9 @@ protected ApiException(ApiError apiError, HttpStatusCode statusCode, Exception i public IResponse HttpResponse { get; private set; } + /// + /// The error message + /// public override string Message { get { return ApiErrorMessageSafe ?? "An error occurred with this API request"; } diff --git a/Octokit/Exceptions/LegalRestrictionException.cs b/Octokit/Exceptions/LegalRestrictionException.cs index d7ac60c22e..685ce4b143 100644 --- a/Octokit/Exceptions/LegalRestrictionException.cs +++ b/Octokit/Exceptions/LegalRestrictionException.cs @@ -20,6 +20,9 @@ namespace Octokit Justification = "These exceptions are specific to the GitHub API and not general purpose exceptions")] public class LegalRestrictionException : ApiException { + /// + /// The error message + /// public override string Message { get { return ApiErrorMessageSafe ?? "Resource taken down due to a DMCA notice."; } diff --git a/Octokit/Exceptions/PrivateRepositoryQuotaExceededException.cs b/Octokit/Exceptions/PrivateRepositoryQuotaExceededException.cs index c811b1ffa3..9511a95aae 100644 --- a/Octokit/Exceptions/PrivateRepositoryQuotaExceededException.cs +++ b/Octokit/Exceptions/PrivateRepositoryQuotaExceededException.cs @@ -26,6 +26,9 @@ public PrivateRepositoryQuotaExceededException(ApiValidationException innerExcep { } + /// + /// The error message + /// public override string Message { get diff --git a/Octokit/Exceptions/PullRequestNotMergeableException.cs b/Octokit/Exceptions/PullRequestNotMergeableException.cs index 89ce79e158..157dfbc0f5 100644 --- a/Octokit/Exceptions/PullRequestNotMergeableException.cs +++ b/Octokit/Exceptions/PullRequestNotMergeableException.cs @@ -39,6 +39,9 @@ public PullRequestNotMergeableException(IResponse response, Exception innerExcep "PullRequestNotMergeableException created with the wrong HTTP status code"); } + /// + /// The error message + /// public override string Message { //https://developer.github.com/v3/pulls/#response-if-merge-cannot-be-performed diff --git a/Octokit/Exceptions/RepositoryFormatException.cs b/Octokit/Exceptions/RepositoryFormatException.cs index c0ab53b515..c71074458b 100644 --- a/Octokit/Exceptions/RepositoryFormatException.cs +++ b/Octokit/Exceptions/RepositoryFormatException.cs @@ -27,6 +27,9 @@ public RepositoryFormatException(IEnumerable invalidRepositories) parameterList); } + /// + /// The error message + /// public override string Message { get diff --git a/Octokit/Exceptions/TwoFactorChallengeFailedException.cs b/Octokit/Exceptions/TwoFactorChallengeFailedException.cs index 3e1b799f54..59708ef82d 100644 --- a/Octokit/Exceptions/TwoFactorChallengeFailedException.cs +++ b/Octokit/Exceptions/TwoFactorChallengeFailedException.cs @@ -37,6 +37,9 @@ public TwoFactorChallengeFailedException( AuthorizationCode = authorizationCode; } + /// + /// The error message + /// public override string Message { get { return "The two-factor authentication code supplied is not correct"; } diff --git a/Octokit/Http/ReadOnlyPagedCollection.cs b/Octokit/Http/ReadOnlyPagedCollection.cs index 520f107b33..c75c76b28b 100644 --- a/Octokit/Http/ReadOnlyPagedCollection.cs +++ b/Octokit/Http/ReadOnlyPagedCollection.cs @@ -13,8 +13,8 @@ public class ReadOnlyPagedCollection : ReadOnlyCollection, IReadOnlyPagedC public ReadOnlyPagedCollection(IApiResponse> response, Func>>> nextPageFunc) : base(response != null ? response.Body ?? new List() : new List()) { - Ensure.ArgumentNotNull(response, "response"); - Ensure.ArgumentNotNull(nextPageFunc, "nextPageFunc"); + Ensure.ArgumentNotNull(response, nameof(response)); + Ensure.ArgumentNotNull(nextPageFunc, nameof(nextPageFunc)); _nextPageFunc = nextPageFunc; if (response != null) diff --git a/Octokit/Models/Request/PullRequestReviewSubmit.cs b/Octokit/Models/Request/PullRequestReviewSubmit.cs index 99a136a61b..c3019a1823 100644 --- a/Octokit/Models/Request/PullRequestReviewSubmit.cs +++ b/Octokit/Models/Request/PullRequestReviewSubmit.cs @@ -1,7 +1,6 @@ using System.Diagnostics; using System.Globalization; using Octokit.Internal; -using System.Collections.Generic; namespace Octokit { @@ -11,6 +10,9 @@ namespace Octokit [DebuggerDisplay("{DebuggerDisplay,nq}")] public class PullRequestReviewSubmit : RequestParameters { + /// + /// Initializes a new empty Pull Request Review. + /// public PullRequestReviewSubmit() { } diff --git a/Octokit/Models/Response/ActivityPayloads/StatusEventPayload.cs b/Octokit/Models/Response/ActivityPayloads/StatusEventPayload.cs index e6f472e1fb..78e08c7029 100644 --- a/Octokit/Models/Response/ActivityPayloads/StatusEventPayload.cs +++ b/Octokit/Models/Response/ActivityPayloads/StatusEventPayload.cs @@ -69,7 +69,7 @@ public class StatusEventPayload : ActivityPayload /// public IReadOnlyList Branches { get; protected set; } - internal string DebuggerDisplay + internal new string DebuggerDisplay { get { diff --git a/Octokit/Models/Response/Commit.cs b/Octokit/Models/Response/Commit.cs index 7023193790..7d85fbc3f8 100644 --- a/Octokit/Models/Response/Commit.cs +++ b/Octokit/Models/Response/Commit.cs @@ -13,7 +13,7 @@ public Commit() { } public Commit(string url, string label, string @ref, string sha, User user, Repository repository, string message, Committer author, Committer committer, GitReference tree, IEnumerable parents, int commentCount) : base(url, label, @ref, sha, user, repository) { - Ensure.ArgumentNotNull(parents, "parents"); + Ensure.ArgumentNotNull(parents, nameof(parents)); Message = message; Author = author; diff --git a/Octokit/Models/Response/GitHubApp.cs b/Octokit/Models/Response/GitHubApp.cs index c25593b8b2..54197ec3b3 100644 --- a/Octokit/Models/Response/GitHubApp.cs +++ b/Octokit/Models/Response/GitHubApp.cs @@ -10,8 +10,14 @@ namespace Octokit [DebuggerDisplay("{DebuggerDisplay,nq}")] public class GitHubApp { + /// + /// Initialize a new empty GitHubApp object ready for deserialization. + /// public GitHubApp() { } + /// + /// The GitHubApp Id. Should be the same as in the GitHubApp -> Settings -> About page. + /// public long Id { get; protected set; } public string Name { get; protected set; } From 6032ca3265622ea1be4c119974cdbc9477b10211 Mon Sep 17 00:00:00 2001 From: Ryan Gribble Date: Tue, 6 Mar 2018 21:04:29 +1000 Subject: [PATCH 31/84] Add xml comments to AccessToken response model and use DateTimeOffset rather than DateTime --- Octokit/Models/Response/AccessToken.cs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/Octokit/Models/Response/AccessToken.cs b/Octokit/Models/Response/AccessToken.cs index 319eb3351c..182a555322 100644 --- a/Octokit/Models/Response/AccessToken.cs +++ b/Octokit/Models/Response/AccessToken.cs @@ -9,14 +9,21 @@ public class AccessToken { public AccessToken() { } - public AccessToken(string token, DateTime expiresAt) + public AccessToken(string token, DateTimeOffset expiresAt) { Token = token; ExpiresAt = expiresAt; } + /// + /// The access token + /// public string Token { get; protected set; } - public DateTime ExpiresAt { get; protected set; } + + /// + /// The expiration date + /// + public DateTimeOffset ExpiresAt { get; protected set; } internal string DebuggerDisplay { From 6bd5ac4c0f98be2e56814089ca466ca516bb191f Mon Sep 17 00:00:00 2001 From: Ryan Gribble Date: Tue, 6 Mar 2018 21:10:29 +1000 Subject: [PATCH 32/84] Tidy up XmlComments and make consistent across client and observable client and interfaces --- .../Clients/IObservableGitHubAppsClient.cs | 39 ++++++++++++++++- .../Clients/ObservableGitHubAppsClient.cs | 38 ++++++++++++++--- Octokit/Clients/GitHubAppsClient.cs | 42 ++++++++++--------- Octokit/Clients/IGitHubAppsClient.cs | 34 ++++++++------- 4 files changed, 113 insertions(+), 40 deletions(-) diff --git a/Octokit.Reactive/Clients/IObservableGitHubAppsClient.cs b/Octokit.Reactive/Clients/IObservableGitHubAppsClient.cs index 006168c404..dc9167da06 100644 --- a/Octokit.Reactive/Clients/IObservableGitHubAppsClient.cs +++ b/Octokit.Reactive/Clients/IObservableGitHubAppsClient.cs @@ -2,12 +2,49 @@ namespace Octokit.Reactive { + /// + /// A client for GitHub Applications API. Provides the methods required to get GitHub applications and installations. + /// + /// + /// See the GitHub Apps API documentation for more information. + /// public interface IObservableGitHubAppsClient { + /// + /// Get a single GitHub App. + /// + /// https://developer.github.com/v3/apps/#get-a-single-github-app + /// The URL-friendly name of your GitHub App. You can find this on the settings page for your GitHub App. IObservable Get(string slug); + + /// + /// Returns the GitHub App associated with the authentication credentials used (requires GitHubApp JWT token auth). + /// + /// https://developer.github.com/v3/apps/#get-the-authenticated-github-app IObservable GetCurrent(); - IObservable CreateInstallationToken(long installationId); + + /// + /// List installations of the authenticated GitHub App (requires GitHubApp JWT token auth). + /// + /// https://developer.github.com/v3/apps/#find-installations IObservable GetAllInstallationsForCurrent(); + + /// + /// List installations of the authenticated GitHub App (requires GitHubApp JWT token auth). + /// + /// Options for changing the API response + /// https://developer.github.com/v3/apps/#find-installations IObservable GetAllInstallationsForCurrent(ApiOptions options); + + /// + /// Create a time bound access token for a GitHubApp Installation that can be used to access other API endpoints (requires GitHubApp JWT token auth). + /// + /// + /// https://developer.github.com/v3/apps/#create-a-new-installation-token + /// https://developer.github.com/apps/building-github-apps/authentication-options-for-github-apps/#authenticating-as-an-installation + /// https://developer.github.com/v3/apps/available-endpoints/ + /// + /// The Id of the GitHub App Installation + IObservable CreateInstallationToken(long installationId); } } diff --git a/Octokit.Reactive/Clients/ObservableGitHubAppsClient.cs b/Octokit.Reactive/Clients/ObservableGitHubAppsClient.cs index 94c79ca51c..3192887d16 100644 --- a/Octokit.Reactive/Clients/ObservableGitHubAppsClient.cs +++ b/Octokit.Reactive/Clients/ObservableGitHubAppsClient.cs @@ -4,6 +4,12 @@ namespace Octokit.Reactive { + /// + /// A client for GitHub Applications API. Provides the methods required to get GitHub applications and installations. + /// + /// + /// See the GitHub Apps API documentation for more information. + /// public class ObservableGitHubAppsClient : IObservableGitHubAppsClient { private IGitHubAppsClient _client; @@ -22,26 +28,48 @@ public IObservable Get(string slug) return _client.Get(slug).ToObservable(); } + /// + /// Returns the GitHub App associated with the authentication credentials used (requires GitHubApp JWT token auth). + /// + /// https://developer.github.com/v3/apps/#get-the-authenticated-github-app public IObservable GetCurrent() { return _client.GetCurrent().ToObservable(); } - public IObservable CreateInstallationToken(long installationId) - { - return _client.CreateInstallationToken(installationId).ToObservable(); - } - + /// + /// List installations of the authenticated GitHub App (requires GitHubApp JWT token auth). + /// + /// https://developer.github.com/v3/apps/#find-installations public IObservable GetAllInstallationsForCurrent() { return _connection.GetAndFlattenAllPages(ApiUrls.Installations(), null, AcceptHeaders.MachineManPreview); } + /// + /// List installations of the authenticated GitHub App (requires GitHubApp JWT token auth). + /// + /// Options for changing the API response + /// https://developer.github.com/v3/apps/#find-installations public IObservable GetAllInstallationsForCurrent(ApiOptions options) { Ensure.ArgumentNotNull(options, nameof(options)); return _connection.GetAndFlattenAllPages(ApiUrls.Installations(), null, AcceptHeaders.MachineManPreview, options); } + + /// + /// Create a time bound access token for a GitHubApp Installation that can be used to access other API endpoints (requires GitHubApp JWT token auth). + /// + /// + /// https://developer.github.com/v3/apps/#create-a-new-installation-token + /// https://developer.github.com/apps/building-github-apps/authentication-options-for-github-apps/#authenticating-as-an-installation + /// https://developer.github.com/v3/apps/available-endpoints/ + /// + /// The Id of the GitHub App Installation + public IObservable CreateInstallationToken(long installationId) + { + return _client.CreateInstallationToken(installationId).ToObservable(); + } } } diff --git a/Octokit/Clients/GitHubAppsClient.cs b/Octokit/Clients/GitHubAppsClient.cs index 2e8a7c4ef7..5cefa88a06 100644 --- a/Octokit/Clients/GitHubAppsClient.cs +++ b/Octokit/Clients/GitHubAppsClient.cs @@ -20,53 +20,57 @@ public GitHubAppsClient(IApiConnection apiConnection) : base(apiConnection) } /// - /// Get a single GitHub App + /// Get a single GitHub App. /// + /// https://developer.github.com/v3/apps/#get-a-single-github-app /// The URL-friendly name of your GitHub App. You can find this on the settings page for your GitHub App. - /// The GitHub App public Task Get(string slug) { return ApiConnection.Get(ApiUrls.App(slug), null, AcceptHeaders.MachineManPreview); } /// - /// Returns the GitHub App associated with the authentication credentials used. + /// Returns the GitHub App associated with the authentication credentials used (requires GitHubApp JWT token auth). /// - /// The GitHub App associated with the authentication credentials used. + /// https://developer.github.com/v3/apps/#get-the-authenticated-github-app public Task GetCurrent() { return ApiConnection.Get(ApiUrls.App(), null, AcceptHeaders.MachineManPreview); } /// - /// Create a new installation token + /// List installations of the authenticated GitHub App (requires GitHubApp JWT token auth). /// - /// The Id of the GitHub App installation. - /// The GitHub App installation access token. - public Task CreateInstallationToken(long installationId) - { - return ApiConnection.Post(ApiUrls.AccessTokens(installationId), string.Empty, AcceptHeaders.MachineManPreview); - } - - /// - /// List installations that are accessible to the authenticated user. - /// - /// A list (read-only) that includes all the GitHub App installations accessible to the current authenticated user. + /// https://developer.github.com/v3/apps/#find-installations public Task> GetAllInstallationsForCurrent() { return ApiConnection.GetAll(ApiUrls.Installations(), null, AcceptHeaders.MachineManPreview); } /// - /// List installations that are accessible to the authenticated user. + /// List installations of the authenticated GitHub App (requires GitHubApp JWT token auth). /// - /// - /// A list (read-only) that includes all the GitHub App installations accessible to the current authenticated user. + /// Options for changing the API response + /// https://developer.github.com/v3/apps/#find-installations public Task> GetAllInstallationsForCurrent(ApiOptions options) { Ensure.ArgumentNotNull(options, nameof(options)); return ApiConnection.GetAll(ApiUrls.Installations(), null, AcceptHeaders.MachineManPreview, options); } + + /// + /// Create a time bound access token for a GitHubApp Installation that can be used to access other API endpoints (requires GitHubApp JWT token auth). + /// + /// + /// https://developer.github.com/v3/apps/#create-a-new-installation-token + /// https://developer.github.com/apps/building-github-apps/authentication-options-for-github-apps/#authenticating-as-an-installation + /// https://developer.github.com/v3/apps/available-endpoints/ + /// + /// The Id of the GitHub App Installation + public Task CreateInstallationToken(long installationId) + { + return ApiConnection.Post(ApiUrls.AccessTokens(installationId), string.Empty, AcceptHeaders.MachineManPreview); + } } } \ No newline at end of file diff --git a/Octokit/Clients/IGitHubAppsClient.cs b/Octokit/Clients/IGitHubAppsClient.cs index 761be187c0..d4af9c91b1 100644 --- a/Octokit/Clients/IGitHubAppsClient.cs +++ b/Octokit/Clients/IGitHubAppsClient.cs @@ -12,36 +12,40 @@ namespace Octokit public interface IGitHubAppsClient { /// - /// Get a single GitHub App + /// Get a single GitHub App. /// + /// https://developer.github.com/v3/apps/#get-a-single-github-app /// The URL-friendly name of your GitHub App. You can find this on the settings page for your GitHub App. - /// The GitHub App Task Get(string slug); /// - /// Returns the GitHub App associated with the authentication credentials used. + /// Returns the GitHub App associated with the authentication credentials used (requires GitHubApp JWT token auth). /// - /// The GitHub App associated with the authentication credentials used. + /// https://developer.github.com/v3/apps/#get-the-authenticated-github-app Task GetCurrent(); /// - /// Create a new installation token + /// List installations of the authenticated GitHub App (requires GitHubApp JWT token auth). /// - /// The Id of the GitHub App installation. - /// The GitHub App installation access token. - Task CreateInstallationToken(long installationId); + /// https://developer.github.com/v3/apps/#find-installations + Task> GetAllInstallationsForCurrent(); /// - /// List installations that are accessible to the authenticated user. + /// List installations of the authenticated GitHub App (requires GitHubApp JWT token auth). /// - /// A list (read-only) that includes all the GitHub App installations accessible to the current authenticated user. - Task> GetAllInstallationsForCurrent(); + /// Options for changing the API response + /// https://developer.github.com/v3/apps/#find-installations + Task> GetAllInstallationsForCurrent(ApiOptions options); /// - /// List installations that are accessible to the authenticated user. + /// Create a time bound access token for a GitHubApp Installation that can be used to access other API endpoints (requires GitHubApp JWT token auth). /// - /// - /// A list (read-only) that includes all the GitHub App installations accessible to the current authenticated user. - Task> GetAllInstallationsForCurrent(ApiOptions options); + /// + /// https://developer.github.com/v3/apps/#create-a-new-installation-token + /// https://developer.github.com/apps/building-github-apps/authentication-options-for-github-apps/#authenticating-as-an-installation + /// https://developer.github.com/v3/apps/available-endpoints/ + /// + /// The Id of the GitHub App Installation + Task CreateInstallationToken(long installationId); } } \ No newline at end of file From 5d48e64afc5422bcbf1fa7b82f8ea717bb31d2bb Mon Sep 17 00:00:00 2001 From: Ryan Gribble Date: Tue, 6 Mar 2018 21:19:42 +1000 Subject: [PATCH 33/84] fixup unit tests to independently verify preview header --- .../Clients/GitHubAppsClientTests.cs | 39 +++++++++---------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/Octokit.Tests/Clients/GitHubAppsClientTests.cs b/Octokit.Tests/Clients/GitHubAppsClientTests.cs index 36991ed983..36e9779901 100644 --- a/Octokit.Tests/Clients/GitHubAppsClientTests.cs +++ b/Octokit.Tests/Clients/GitHubAppsClientTests.cs @@ -19,30 +19,14 @@ public void EnsuresNonNullArguments() public class TheGetCurrentMethod { [Fact] - public void GetFromCorrectUrl() + public void GetsFromCorrectUrl() { var connection = Substitute.For(); var client = new GitHubAppsClient(connection); client.GetCurrent(); - connection.Received().Get(Arg.Is(u => u.ToString() == "app"), null, AcceptHeaders.MachineManPreview); - } - } - - public class TheCreateInstallationTokenMethod - { - [Fact] - public void PostsToCorrectUrl() - { - var connection = Substitute.For(); - var client = new GitHubAppsClient(connection); - - int fakeInstallationId = 3141; - - client.CreateInstallationToken(fakeInstallationId); - - connection.Received().Post(Arg.Is(u => u.ToString() == "installations/3141/access_tokens"), string.Empty, AcceptHeaders.MachineManPreview); + connection.Received().Get(Arg.Is(u => u.ToString() == "app"), null, "application/vnd.github.machine-man-preview+json"); } } @@ -65,7 +49,7 @@ public async Task RequestsCorrectUrl() client.GetAllInstallationsForCurrent(); - connection.Received().GetAll(Arg.Is(u => u.ToString() == "app/installations"), null, AcceptHeaders.MachineManPreview); + connection.Received().GetAll(Arg.Is(u => u.ToString() == "app/installations"), null, "application/vnd.github.machine-man-preview+json"); } @@ -84,10 +68,25 @@ public void RequestsTheCorrectUrlWithApiOptions() client.GetAllInstallationsForCurrent(options); - connection.Received().GetAll(Arg.Is(u => u.ToString() == "app/installations"), null, AcceptHeaders.MachineManPreview, options); + connection.Received().GetAll(Arg.Is(u => u.ToString() == "app/installations"), null, "application/vnd.github.machine-man-preview+json", options); } } + public class TheCreateInstallationTokenMethod + { + [Fact] + public void PostsToCorrectUrl() + { + var connection = Substitute.For(); + var client = new GitHubAppsClient(connection); + + int fakeInstallationId = 3141; + + client.CreateInstallationToken(fakeInstallationId); + + connection.Received().Post(Arg.Is(u => u.ToString() == "installations/3141/access_tokens"), string.Empty, "application/vnd.github.machine-man-preview+json"); + } + } } } From de3b659eabf50be89b4ec0a3c16dd4d91f2daf75 Mon Sep 17 00:00:00 2001 From: Ryan Gribble Date: Tue, 6 Mar 2018 21:19:56 +1000 Subject: [PATCH 34/84] Implement GetInstallation method --- .../Clients/IObservableGitHubAppsClient.cs | 7 +++++++ .../Clients/ObservableGitHubAppsClient.cs | 10 ++++++++++ Octokit.Tests/Clients/GitHubAppsClientTests.cs | 13 +++++++++++++ Octokit/Clients/GitHubAppsClient.cs | 10 ++++++++++ Octokit/Clients/IGitHubAppsClient.cs | 7 +++++++ Octokit/Helpers/ApiUrls.cs | 2 +- 6 files changed, 48 insertions(+), 1 deletion(-) diff --git a/Octokit.Reactive/Clients/IObservableGitHubAppsClient.cs b/Octokit.Reactive/Clients/IObservableGitHubAppsClient.cs index dc9167da06..65f4ba4aa0 100644 --- a/Octokit.Reactive/Clients/IObservableGitHubAppsClient.cs +++ b/Octokit.Reactive/Clients/IObservableGitHubAppsClient.cs @@ -36,6 +36,13 @@ public interface IObservableGitHubAppsClient /// https://developer.github.com/v3/apps/#find-installations IObservable GetAllInstallationsForCurrent(ApiOptions options); + /// + /// Get a single GitHub App Installation (requires GitHubApp JWT token auth). + /// + /// https://developer.github.com/v3/apps/#get-a-single-installation + /// The Id of the GitHub App Installation + IObservable GetInstallation(long installationId); + /// /// Create a time bound access token for a GitHubApp Installation that can be used to access other API endpoints (requires GitHubApp JWT token auth). /// diff --git a/Octokit.Reactive/Clients/ObservableGitHubAppsClient.cs b/Octokit.Reactive/Clients/ObservableGitHubAppsClient.cs index 3192887d16..8621b5b34b 100644 --- a/Octokit.Reactive/Clients/ObservableGitHubAppsClient.cs +++ b/Octokit.Reactive/Clients/ObservableGitHubAppsClient.cs @@ -58,6 +58,16 @@ public IObservable GetAllInstallationsForCurrent(ApiOptions option return _connection.GetAndFlattenAllPages(ApiUrls.Installations(), null, AcceptHeaders.MachineManPreview, options); } + /// + /// Get a single GitHub App Installation (requires GitHubApp JWT token auth). + /// + /// https://developer.github.com/v3/apps/#get-a-single-installation + /// The Id of the GitHub App Installation + public IObservable GetInstallation(long installationId) + { + return _client.GetInstallation(installationId).ToObservable(); + } + /// /// Create a time bound access token for a GitHubApp Installation that can be used to access other API endpoints (requires GitHubApp JWT token auth). /// diff --git a/Octokit.Tests/Clients/GitHubAppsClientTests.cs b/Octokit.Tests/Clients/GitHubAppsClientTests.cs index 36e9779901..c2e081e920 100644 --- a/Octokit.Tests/Clients/GitHubAppsClientTests.cs +++ b/Octokit.Tests/Clients/GitHubAppsClientTests.cs @@ -70,7 +70,20 @@ public void RequestsTheCorrectUrlWithApiOptions() connection.Received().GetAll(Arg.Is(u => u.ToString() == "app/installations"), null, "application/vnd.github.machine-man-preview+json", options); } + } + + public class TheGetInstallationMethod + { + [Fact] + public void GetsFromCorrectUrl() + { + var connection = Substitute.For(); + var client = new GitHubAppsClient(connection); + client.GetInstallation(123); + + connection.Received().Get(Arg.Is(u => u.ToString() == "app/installations/123"), null, "application/vnd.github.machine-man-preview+json"); + } } public class TheCreateInstallationTokenMethod diff --git a/Octokit/Clients/GitHubAppsClient.cs b/Octokit/Clients/GitHubAppsClient.cs index 5cefa88a06..a5cbe60651 100644 --- a/Octokit/Clients/GitHubAppsClient.cs +++ b/Octokit/Clients/GitHubAppsClient.cs @@ -59,6 +59,16 @@ public Task> GetAllInstallationsForCurrent(ApiOption return ApiConnection.GetAll(ApiUrls.Installations(), null, AcceptHeaders.MachineManPreview, options); } + /// + /// Get a single GitHub App Installation (requires GitHubApp JWT token auth). + /// + /// https://developer.github.com/v3/apps/#get-a-single-installation + /// The Id of the GitHub App Installation + public Task GetInstallation(long installationId) + { + return ApiConnection.Get(ApiUrls.Installation(installationId), null, AcceptHeaders.MachineManPreview); + } + /// /// Create a time bound access token for a GitHubApp Installation that can be used to access other API endpoints (requires GitHubApp JWT token auth). /// diff --git a/Octokit/Clients/IGitHubAppsClient.cs b/Octokit/Clients/IGitHubAppsClient.cs index d4af9c91b1..71802151f7 100644 --- a/Octokit/Clients/IGitHubAppsClient.cs +++ b/Octokit/Clients/IGitHubAppsClient.cs @@ -37,6 +37,13 @@ public interface IGitHubAppsClient /// https://developer.github.com/v3/apps/#find-installations Task> GetAllInstallationsForCurrent(ApiOptions options); + /// + /// Get a single GitHub App Installation (requires GitHubApp JWT token auth). + /// + /// https://developer.github.com/v3/apps/#get-a-single-installation + /// The Id of the GitHub App Installation + Task GetInstallation(long installationId); + /// /// Create a time bound access token for a GitHubApp Installation that can be used to access other API endpoints (requires GitHubApp JWT token auth). /// diff --git a/Octokit/Helpers/ApiUrls.cs b/Octokit/Helpers/ApiUrls.cs index a3512a06a6..a086592107 100644 --- a/Octokit/Helpers/ApiUrls.cs +++ b/Octokit/Helpers/ApiUrls.cs @@ -328,7 +328,7 @@ public static Uri Installations() /// Returns the that returns a single installation of the authenticated application. /// /// - public static Uri Installation(int installationId) + public static Uri Installation(long installationId) { return "app/installations/{0}".FormatUri(installationId); } From 11b1d8dd4098ddf5db98dede1ade847c4ca2cb69 Mon Sep 17 00:00:00 2001 From: Ryan Gribble Date: Tue, 6 Mar 2018 21:39:50 +1000 Subject: [PATCH 35/84] revert commits unrelated to GitHubApps - these can be done on a separate PR if required --- .../Clients/IObservableProjectsClient.cs | 8 +-- .../IObservablePullRequestReviewsClient.cs | 2 - .../IObservableRepositoryBranchesClient.cs | 2 - .../Clients/IObservableTeamsClient.cs | 1 - .../Clients/ObservableProjectsClient.cs | 50 +++++++++---------- ...PullRequestReviewCommentReactionsClient.cs | 10 ++-- .../ObservableRepositoryBranchesClient.cs | 34 ++++++------- Octokit/Clients/GitHubAppsClient.cs | 4 -- ...IOrganizationOutsideCollaboratorsClient.cs | 6 --- Octokit/Clients/IProjectsClient.cs | 8 +-- Octokit/Clients/IRepositoryBranchesClient.cs | 2 - Octokit/Clients/ITeamsClient.cs | 1 - Octokit/Clients/ProjectsClient.cs | 4 +- Octokit/Clients/RepositoryBranchesClient.cs | 2 - Octokit/Exceptions/ApiException.cs | 3 -- .../Exceptions/LegalRestrictionException.cs | 3 -- ...PrivateRepositoryQuotaExceededException.cs | 3 -- .../PullRequestNotMergeableException.cs | 3 -- .../Exceptions/RepositoryFormatException.cs | 3 -- .../TwoFactorChallengeFailedException.cs | 3 -- Octokit/Http/ReadOnlyPagedCollection.cs | 4 +- .../Models/Request/PullRequestReviewSubmit.cs | 4 +- .../ActivityPayloads/StatusEventPayload.cs | 9 ---- Octokit/Models/Response/Commit.cs | 2 +- 24 files changed, 58 insertions(+), 113 deletions(-) diff --git a/Octokit.Reactive/Clients/IObservableProjectsClient.cs b/Octokit.Reactive/Clients/IObservableProjectsClient.cs index 2172e0868f..dea4dca868 100644 --- a/Octokit.Reactive/Clients/IObservableProjectsClient.cs +++ b/Octokit.Reactive/Clients/IObservableProjectsClient.cs @@ -18,7 +18,7 @@ public interface IObservableProjectsClient /// See the API documentation for more information. /// /// The owner of the repository - /// The name of the repository + /// The name of the repository IObservable GetAllForRepository(string owner, string name); /// @@ -28,7 +28,7 @@ public interface IObservableProjectsClient /// See the API documentation for more information. /// /// The owner of the repository - /// The name of the repository + /// The name of the repository /// Used to filter the list of projects returned IObservable GetAllForRepository(string owner, string name, ProjectRequest request); @@ -58,7 +58,7 @@ public interface IObservableProjectsClient /// See the API documentation for more information. /// /// The owner of the repository - /// The name of the repository + /// The name of the repository /// Options for changing the API response IObservable GetAllForRepository(string owner, string name, ApiOptions options); @@ -69,7 +69,7 @@ public interface IObservableProjectsClient /// See the API documentation for more information. /// /// The owner of the repository - /// The name of the repository + /// The name of the repository /// Used to filter the list of projects returned /// Options for changing the API response IObservable GetAllForRepository(string owner, string name, ProjectRequest request, ApiOptions options); diff --git a/Octokit.Reactive/Clients/IObservablePullRequestReviewsClient.cs b/Octokit.Reactive/Clients/IObservablePullRequestReviewsClient.cs index 607d224f19..92a2b17ade 100644 --- a/Octokit.Reactive/Clients/IObservablePullRequestReviewsClient.cs +++ b/Octokit.Reactive/Clients/IObservablePullRequestReviewsClient.cs @@ -173,7 +173,6 @@ public interface IObservablePullRequestReviewsClient /// The name of the repository /// The pull request number /// The pull request review number - /// Options for changing the API response IObservable GetAllComments(string owner, string name, int number, long reviewId, ApiOptions options); /// @@ -183,7 +182,6 @@ public interface IObservablePullRequestReviewsClient /// The Id of the repository /// The pull request number /// The pull request review number - /// Options for changing the API response IObservable GetAllComments(long repositoryId, int number, long reviewId, ApiOptions options); } } diff --git a/Octokit.Reactive/Clients/IObservableRepositoryBranchesClient.cs b/Octokit.Reactive/Clients/IObservableRepositoryBranchesClient.cs index e28df249f7..01e953f513 100644 --- a/Octokit.Reactive/Clients/IObservableRepositoryBranchesClient.cs +++ b/Octokit.Reactive/Clients/IObservableRepositoryBranchesClient.cs @@ -348,7 +348,6 @@ public interface IObservableRepositoryBranchesClient /// The owner of the repository /// The name of the repository /// The name of the branch - /// Required reviews IObservable UpdateReviewEnforcement(string owner, string name, string branch, BranchProtectionRequiredReviewsUpdate update); /// @@ -359,7 +358,6 @@ public interface IObservableRepositoryBranchesClient /// /// The Id of the repository /// The name of the branch - /// Required reviews IObservable UpdateReviewEnforcement(long repositoryId, string branch, BranchProtectionRequiredReviewsUpdate update); /// diff --git a/Octokit.Reactive/Clients/IObservableTeamsClient.cs b/Octokit.Reactive/Clients/IObservableTeamsClient.cs index b95a98c013..11aba6f496 100644 --- a/Octokit.Reactive/Clients/IObservableTeamsClient.cs +++ b/Octokit.Reactive/Clients/IObservableTeamsClient.cs @@ -71,7 +71,6 @@ public interface IObservableTeamsClient /// Returns all child teams of the given team. /// /// The team identifier - /// Options to change API behaviour. /// /// https://developer.github.com/v3/orgs/teams/#list-child-teams /// diff --git a/Octokit.Reactive/Clients/ObservableProjectsClient.cs b/Octokit.Reactive/Clients/ObservableProjectsClient.cs index 9b9c5fe82f..608c7f70a1 100644 --- a/Octokit.Reactive/Clients/ObservableProjectsClient.cs +++ b/Octokit.Reactive/Clients/ObservableProjectsClient.cs @@ -34,7 +34,7 @@ public ObservableProjectsClient(IGitHubClient client) /// See the API documentation for more information. /// /// The owner of the repository - /// The name of the repository + /// The name of the repository public IObservable GetAllForRepository(string owner, string name) { return GetAllForRepository(owner, name, ApiOptions.None); @@ -47,13 +47,12 @@ public IObservable GetAllForRepository(string owner, string name) /// See the API documentation for more information. /// /// The owner of the repository - /// The name of the repository - /// Options to change API behaviour + /// The name of the repository public IObservable GetAllForRepository(string owner, string name, ApiOptions options) { - Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); - Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); - Ensure.ArgumentNotNull(options, nameof(options)); + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + Ensure.ArgumentNotNull(options, "options"); var url = ApiUrls.RepositoryProjects(owner, name); @@ -67,7 +66,7 @@ public IObservable GetAllForRepository(string owner, string name, ApiOp /// See the API documentation for more information. /// /// The owner of the repository - /// The name of the repository + /// The name of the repository /// Used to filter the list of projects returned public IObservable GetAllForRepository(string owner, string name, ProjectRequest request) { @@ -81,15 +80,15 @@ public IObservable GetAllForRepository(string owner, string name, Proje /// See the API documentation for more information. /// /// The owner of the repository - /// The name of the repository + /// The name of the repository /// Used to filter the list of projects returned /// Options for changing the API response public IObservable GetAllForRepository(string owner, string name, ProjectRequest request, ApiOptions options) { - Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); - Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); - Ensure.ArgumentNotNull(request, nameof(request)); - Ensure.ArgumentNotNull(options, nameof(options)); + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + Ensure.ArgumentNotNull(request, "request"); + Ensure.ArgumentNotNull(options, "options"); var url = ApiUrls.RepositoryProjects(owner, name); @@ -114,11 +113,12 @@ public IObservable GetAllForRepository(long repositoryId) /// /// See the API documentation for more information. /// - /// The Id of the repository + /// The owner of the repository + /// The name of the repository /// Options for changing the API response public IObservable GetAllForRepository(long repositoryId, ApiOptions options) { - Ensure.ArgumentNotNull(options, nameof(options)); + Ensure.ArgumentNotNull(options, "options"); var url = ApiUrls.RepositoryProjects(repositoryId); @@ -149,8 +149,8 @@ public IObservable GetAllForRepository(long repositoryId, ProjectReques /// Options for changing the API response public IObservable GetAllForRepository(long repositoryId, ProjectRequest request, ApiOptions options) { - Ensure.ArgumentNotNull(request, nameof(request)); - Ensure.ArgumentNotNull(options, nameof(options)); + Ensure.ArgumentNotNull(request, "request"); + Ensure.ArgumentNotNull(options, "options"); var url = ApiUrls.RepositoryProjects(repositoryId); @@ -179,8 +179,8 @@ public IObservable GetAllForOrganization(string organization) /// Options for changing the API response public IObservable GetAllForOrganization(string organization, ApiOptions options) { - Ensure.ArgumentNotNullOrEmptyString(organization, nameof(organization)); - Ensure.ArgumentNotNull(options, nameof(options)); + Ensure.ArgumentNotNullOrEmptyString(organization, "organization"); + Ensure.ArgumentNotNull(options, "options"); var url = ApiUrls.OrganizationProjects(organization); @@ -211,9 +211,9 @@ public IObservable GetAllForOrganization(string organization, ProjectRe /// Options for changing the API response public IObservable GetAllForOrganization(string organization, ProjectRequest request, ApiOptions options) { - Ensure.ArgumentNotNullOrEmptyString(organization, nameof(organization)); - Ensure.ArgumentNotNull(request, nameof(request)); - Ensure.ArgumentNotNull(options, nameof(options)); + Ensure.ArgumentNotNullOrEmptyString(organization, "organization"); + Ensure.ArgumentNotNull(request, "request"); + Ensure.ArgumentNotNull(options, "options"); var url = ApiUrls.OrganizationProjects(organization); @@ -243,7 +243,7 @@ public IObservable Get(int id) /// The new project to create for the specified repository public IObservable CreateForRepository(long repositoryId, NewProject newProject) { - Ensure.ArgumentNotNull(newProject, nameof(newProject)); + Ensure.ArgumentNotNull(newProject, "newProject"); return _client.CreateForRepository(repositoryId, newProject).ToObservable(); } @@ -258,8 +258,8 @@ public IObservable CreateForRepository(long repositoryId, NewProject ne /// The new project to create for the specified repository public IObservable CreateForOrganization(string organization, NewProject newProject) { - Ensure.ArgumentNotNullOrEmptyString(organization, nameof(organization)); - Ensure.ArgumentNotNull(newProject, nameof(newProject)); + Ensure.ArgumentNotNullOrEmptyString(organization, "organization"); + Ensure.ArgumentNotNull(newProject, "newProject"); return _client.CreateForOrganization(organization, newProject).ToObservable(); } @@ -274,7 +274,7 @@ public IObservable CreateForOrganization(string organization, NewProjec /// The modified project public IObservable Update(int id, ProjectUpdate projectUpdate) { - Ensure.ArgumentNotNull(projectUpdate, nameof(projectUpdate)); + Ensure.ArgumentNotNull(projectUpdate, "projectUpdate"); return _client.Update(id, projectUpdate).ToObservable(); } diff --git a/Octokit.Reactive/Clients/ObservablePullRequestReviewCommentReactionsClient.cs b/Octokit.Reactive/Clients/ObservablePullRequestReviewCommentReactionsClient.cs index a2ee0d9b5d..54b47a6ef8 100644 --- a/Octokit.Reactive/Clients/ObservablePullRequestReviewCommentReactionsClient.cs +++ b/Octokit.Reactive/Clients/ObservablePullRequestReviewCommentReactionsClient.cs @@ -15,13 +15,9 @@ public class ObservablePullRequestReviewCommentReactionsClient : IObservablePull readonly IPullRequestReviewCommentReactionsClient _client; readonly IConnection _connection; - /// - /// Initializes a new GitHub Reactions API client. - /// - /// A GitHubClient. public ObservablePullRequestReviewCommentReactionsClient(IGitHubClient client) { - Ensure.ArgumentNotNull(client, nameof(client)); + Ensure.ArgumentNotNull(client, "client"); _client = client.Reaction.PullRequestReviewComment; _connection = client.Connection; @@ -36,8 +32,8 @@ public ObservablePullRequestReviewCommentReactionsClient(IGitHubClient client) /// The comment id public IObservable GetAll(string owner, string name, int number) { - Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); - Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); return _connection.GetAndFlattenAllPages(ApiUrls.PullRequestReviewCommentReaction(owner, name, number), null, AcceptHeaders.ReactionsPreview); } diff --git a/Octokit.Reactive/Clients/ObservableRepositoryBranchesClient.cs b/Octokit.Reactive/Clients/ObservableRepositoryBranchesClient.cs index a16427294a..cda1284de5 100644 --- a/Octokit.Reactive/Clients/ObservableRepositoryBranchesClient.cs +++ b/Octokit.Reactive/Clients/ObservableRepositoryBranchesClient.cs @@ -537,7 +537,6 @@ public IObservable GetReviewEnforcement(long re /// The owner of the repository /// The name of the repository /// The name of the branch - /// The required reviews public IObservable UpdateReviewEnforcement(string owner, string name, string branch, BranchProtectionRequiredReviewsUpdate update) { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); @@ -556,7 +555,6 @@ public IObservable UpdateReviewEnforcement(stri /// /// The Id of the repository /// The name of the branch - /// The required reviews public IObservable UpdateReviewEnforcement(long repositoryId, string branch, BranchProtectionRequiredReviewsUpdate update) { Ensure.ArgumentNotNullOrEmptyString(branch, "branch"); @@ -708,9 +706,9 @@ public IObservable RemoveAdminEnforcement(long repositoryId, string branch /// The name of the branch public IObservable GetProtectedBranchRestrictions(string owner, string name, string branch) { - Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); - Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); - Ensure.ArgumentNotNullOrEmptyString(branch, nameof(branch)); + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + Ensure.ArgumentNotNullOrEmptyString(branch, "branch"); return _client.GetProtectedBranchRestrictions(owner, name, branch).ToObservable(); } @@ -725,7 +723,7 @@ public IObservable GetProtectedBranchRestricti /// The name of the branch public IObservable GetProtectedBranchRestrictions(long repositoryId, string branch) { - Ensure.ArgumentNotNullOrEmptyString(branch, nameof(branch)); + Ensure.ArgumentNotNullOrEmptyString(branch, "branch"); return _client.GetProtectedBranchRestrictions(repositoryId, branch).ToObservable(); } @@ -741,9 +739,9 @@ public IObservable GetProtectedBranchRestricti /// The name of the branch public IObservable DeleteProtectedBranchRestrictions(string owner, string name, string branch) { - Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); - Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); - Ensure.ArgumentNotNullOrEmptyString(branch, nameof(branch)); + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + Ensure.ArgumentNotNullOrEmptyString(branch, "branch"); return _client.DeleteProtectedBranchRestrictions(owner, name, branch).ToObservable(); } @@ -758,7 +756,7 @@ public IObservable DeleteProtectedBranchRestrictions(string owner, string /// The name of the branch public IObservable DeleteProtectedBranchRestrictions(long repositoryId, string branch) { - Ensure.ArgumentNotNullOrEmptyString(branch, nameof(branch)); + Ensure.ArgumentNotNullOrEmptyString(branch, "branch"); return _client.DeleteProtectedBranchRestrictions(repositoryId, branch).ToObservable(); } @@ -803,9 +801,9 @@ public IObservable GetProtectedBranchTeamRestrictions(long repositoryId, s /// The name of the branch public IObservable GetAllProtectedBranchTeamRestrictions(string owner, string name, string branch) { - Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); - Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); - Ensure.ArgumentNotNullOrEmptyString(branch, nameof(branch)); + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + Ensure.ArgumentNotNullOrEmptyString(branch, "branch"); return _client.GetAllProtectedBranchTeamRestrictions(owner, name, branch).ToObservable().SelectMany(x => x); } @@ -820,7 +818,7 @@ public IObservable GetAllProtectedBranchTeamRestrictions(string owner, str /// The name of the branch public IObservable GetAllProtectedBranchTeamRestrictions(long repositoryId, string branch) { - Ensure.ArgumentNotNullOrEmptyString(branch, nameof(branch)); + Ensure.ArgumentNotNullOrEmptyString(branch, "branch"); return _client.GetAllProtectedBranchTeamRestrictions(repositoryId, branch).ToObservable().SelectMany(x => x); } @@ -837,10 +835,10 @@ public IObservable GetAllProtectedBranchTeamRestrictions(long repositoryId /// List of teams with push access public IObservable UpdateProtectedBranchTeamRestrictions(string owner, string name, string branch, BranchProtectionTeamCollection teams) { - Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); - Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); - Ensure.ArgumentNotNullOrEmptyString(branch, nameof(branch)); - Ensure.ArgumentNotNull(teams, nameof(teams)); + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + Ensure.ArgumentNotNullOrEmptyString(branch, "branch"); + Ensure.ArgumentNotNull(teams, "teams"); return _client.UpdateProtectedBranchTeamRestrictions(owner, name, branch, teams).ToObservable().SelectMany(x => x); } diff --git a/Octokit/Clients/GitHubAppsClient.cs b/Octokit/Clients/GitHubAppsClient.cs index a5cbe60651..708ff69281 100644 --- a/Octokit/Clients/GitHubAppsClient.cs +++ b/Octokit/Clients/GitHubAppsClient.cs @@ -11,10 +11,6 @@ namespace Octokit /// public class GitHubAppsClient : ApiClient, IGitHubAppsClient { - /// - /// Instantiates a new GitHub Apps API client. - /// - /// An API connection public GitHubAppsClient(IApiConnection apiConnection) : base(apiConnection) { } diff --git a/Octokit/Clients/IOrganizationOutsideCollaboratorsClient.cs b/Octokit/Clients/IOrganizationOutsideCollaboratorsClient.cs index 4e5e32a0d6..1ad12ad7e3 100644 --- a/Octokit/Clients/IOrganizationOutsideCollaboratorsClient.cs +++ b/Octokit/Clients/IOrganizationOutsideCollaboratorsClient.cs @@ -3,12 +3,6 @@ namespace Octokit { - /// - /// A client for GitHub's Organization Outside Collaborators API. - /// - /// - /// See the Outside Collaborators API documentation for more information. - /// public interface IOrganizationOutsideCollaboratorsClient { /// diff --git a/Octokit/Clients/IProjectsClient.cs b/Octokit/Clients/IProjectsClient.cs index 3e75e2f35f..c3edd5ae7c 100644 --- a/Octokit/Clients/IProjectsClient.cs +++ b/Octokit/Clients/IProjectsClient.cs @@ -19,7 +19,7 @@ public interface IProjectsClient /// See the API documentation for more information. /// /// The owner of the repository - /// The name of the repository + /// The name of the repository Task> GetAllForRepository(string owner, string name); /// @@ -29,7 +29,7 @@ public interface IProjectsClient /// See the API documentation for more information. /// /// The owner of the repository - /// The name of the repository + /// The name of the repository /// Used to filter the list of projects returned Task> GetAllForRepository(string owner, string name, ProjectRequest request); @@ -59,7 +59,7 @@ public interface IProjectsClient /// See the API documentation for more information. /// /// The owner of the repository - /// The name of the repository + /// The name of the repository /// Options for changing the API response Task> GetAllForRepository(string owner, string name, ApiOptions options); @@ -70,7 +70,7 @@ public interface IProjectsClient /// See the API documentation for more information. /// /// The owner of the repository - /// The name of the repository + /// The name of the repository /// Used to filter the list of projects returned /// Options for changing the API response Task> GetAllForRepository(string owner, string name, ProjectRequest request, ApiOptions options); diff --git a/Octokit/Clients/IRepositoryBranchesClient.cs b/Octokit/Clients/IRepositoryBranchesClient.cs index 8ac239f03b..fc2655eecd 100644 --- a/Octokit/Clients/IRepositoryBranchesClient.cs +++ b/Octokit/Clients/IRepositoryBranchesClient.cs @@ -352,7 +352,6 @@ public interface IRepositoryBranchesClient /// The owner of the repository /// The name of the repository /// The name of the branch - /// Required reviews Task UpdateReviewEnforcement(string owner, string name, string branch, BranchProtectionRequiredReviewsUpdate update); /// @@ -363,7 +362,6 @@ public interface IRepositoryBranchesClient /// /// The Id of the repository /// The name of the branch - /// Required reviews Task UpdateReviewEnforcement(long repositoryId, string branch, BranchProtectionRequiredReviewsUpdate update); /// diff --git a/Octokit/Clients/ITeamsClient.cs b/Octokit/Clients/ITeamsClient.cs index 3269a01891..ebe939db30 100644 --- a/Octokit/Clients/ITeamsClient.cs +++ b/Octokit/Clients/ITeamsClient.cs @@ -72,7 +72,6 @@ public interface ITeamsClient /// Returns all child teams of the given team. /// /// The team identifier - /// Options to change API behaviour. /// /// https://developer.github.com/v3/orgs/teams/#list-child-teams /// diff --git a/Octokit/Clients/ProjectsClient.cs b/Octokit/Clients/ProjectsClient.cs index 2e7c0d651a..630f987f60 100644 --- a/Octokit/Clients/ProjectsClient.cs +++ b/Octokit/Clients/ProjectsClient.cs @@ -27,7 +27,7 @@ public ProjectsClient(IApiConnection apiConnection) : /// See the API documentation for more information. /// /// The owner of the repository - /// The name of the repository + /// The name of the repository public Task> GetAllForRepository(string owner, string name) { return GetAllForRepository(owner, name, ApiOptions.None); @@ -40,7 +40,7 @@ public Task> GetAllForRepository(string owner, string nam /// See the API documentation for more information. /// /// The owner of the repository - /// The name of the repository + /// The name of the repository /// Options for changing the API response public Task> GetAllForRepository(string owner, string name, ApiOptions options) { diff --git a/Octokit/Clients/RepositoryBranchesClient.cs b/Octokit/Clients/RepositoryBranchesClient.cs index 65e5926221..baee963d6f 100644 --- a/Octokit/Clients/RepositoryBranchesClient.cs +++ b/Octokit/Clients/RepositoryBranchesClient.cs @@ -576,7 +576,6 @@ public Task GetReviewEnforcement(long repositor /// The owner of the repository /// The name of the repository /// The name of the branch - /// Required reviews public Task UpdateReviewEnforcement(string owner, string name, string branch, BranchProtectionRequiredReviewsUpdate update) { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); @@ -595,7 +594,6 @@ public Task UpdateReviewEnforcement(string owne /// /// The Id of the repository /// The name of the branch - /// Required reviews public Task UpdateReviewEnforcement(long repositoryId, string branch, BranchProtectionRequiredReviewsUpdate update) { Ensure.ArgumentNotNullOrEmptyString(branch, "branch"); diff --git a/Octokit/Exceptions/ApiException.cs b/Octokit/Exceptions/ApiException.cs index f5281189de..ce2c15e90a 100644 --- a/Octokit/Exceptions/ApiException.cs +++ b/Octokit/Exceptions/ApiException.cs @@ -103,9 +103,6 @@ protected ApiException(ApiError apiError, HttpStatusCode statusCode, Exception i public IResponse HttpResponse { get; private set; } - /// - /// The error message - /// public override string Message { get { return ApiErrorMessageSafe ?? "An error occurred with this API request"; } diff --git a/Octokit/Exceptions/LegalRestrictionException.cs b/Octokit/Exceptions/LegalRestrictionException.cs index 685ce4b143..d7ac60c22e 100644 --- a/Octokit/Exceptions/LegalRestrictionException.cs +++ b/Octokit/Exceptions/LegalRestrictionException.cs @@ -20,9 +20,6 @@ namespace Octokit Justification = "These exceptions are specific to the GitHub API and not general purpose exceptions")] public class LegalRestrictionException : ApiException { - /// - /// The error message - /// public override string Message { get { return ApiErrorMessageSafe ?? "Resource taken down due to a DMCA notice."; } diff --git a/Octokit/Exceptions/PrivateRepositoryQuotaExceededException.cs b/Octokit/Exceptions/PrivateRepositoryQuotaExceededException.cs index 9511a95aae..c811b1ffa3 100644 --- a/Octokit/Exceptions/PrivateRepositoryQuotaExceededException.cs +++ b/Octokit/Exceptions/PrivateRepositoryQuotaExceededException.cs @@ -26,9 +26,6 @@ public PrivateRepositoryQuotaExceededException(ApiValidationException innerExcep { } - /// - /// The error message - /// public override string Message { get diff --git a/Octokit/Exceptions/PullRequestNotMergeableException.cs b/Octokit/Exceptions/PullRequestNotMergeableException.cs index 157dfbc0f5..89ce79e158 100644 --- a/Octokit/Exceptions/PullRequestNotMergeableException.cs +++ b/Octokit/Exceptions/PullRequestNotMergeableException.cs @@ -39,9 +39,6 @@ public PullRequestNotMergeableException(IResponse response, Exception innerExcep "PullRequestNotMergeableException created with the wrong HTTP status code"); } - /// - /// The error message - /// public override string Message { //https://developer.github.com/v3/pulls/#response-if-merge-cannot-be-performed diff --git a/Octokit/Exceptions/RepositoryFormatException.cs b/Octokit/Exceptions/RepositoryFormatException.cs index c71074458b..c0ab53b515 100644 --- a/Octokit/Exceptions/RepositoryFormatException.cs +++ b/Octokit/Exceptions/RepositoryFormatException.cs @@ -27,9 +27,6 @@ public RepositoryFormatException(IEnumerable invalidRepositories) parameterList); } - /// - /// The error message - /// public override string Message { get diff --git a/Octokit/Exceptions/TwoFactorChallengeFailedException.cs b/Octokit/Exceptions/TwoFactorChallengeFailedException.cs index 59708ef82d..3e1b799f54 100644 --- a/Octokit/Exceptions/TwoFactorChallengeFailedException.cs +++ b/Octokit/Exceptions/TwoFactorChallengeFailedException.cs @@ -37,9 +37,6 @@ public TwoFactorChallengeFailedException( AuthorizationCode = authorizationCode; } - /// - /// The error message - /// public override string Message { get { return "The two-factor authentication code supplied is not correct"; } diff --git a/Octokit/Http/ReadOnlyPagedCollection.cs b/Octokit/Http/ReadOnlyPagedCollection.cs index c75c76b28b..520f107b33 100644 --- a/Octokit/Http/ReadOnlyPagedCollection.cs +++ b/Octokit/Http/ReadOnlyPagedCollection.cs @@ -13,8 +13,8 @@ public class ReadOnlyPagedCollection : ReadOnlyCollection, IReadOnlyPagedC public ReadOnlyPagedCollection(IApiResponse> response, Func>>> nextPageFunc) : base(response != null ? response.Body ?? new List() : new List()) { - Ensure.ArgumentNotNull(response, nameof(response)); - Ensure.ArgumentNotNull(nextPageFunc, nameof(nextPageFunc)); + Ensure.ArgumentNotNull(response, "response"); + Ensure.ArgumentNotNull(nextPageFunc, "nextPageFunc"); _nextPageFunc = nextPageFunc; if (response != null) diff --git a/Octokit/Models/Request/PullRequestReviewSubmit.cs b/Octokit/Models/Request/PullRequestReviewSubmit.cs index c3019a1823..99a136a61b 100644 --- a/Octokit/Models/Request/PullRequestReviewSubmit.cs +++ b/Octokit/Models/Request/PullRequestReviewSubmit.cs @@ -1,6 +1,7 @@ using System.Diagnostics; using System.Globalization; using Octokit.Internal; +using System.Collections.Generic; namespace Octokit { @@ -10,9 +11,6 @@ namespace Octokit [DebuggerDisplay("{DebuggerDisplay,nq}")] public class PullRequestReviewSubmit : RequestParameters { - /// - /// Initializes a new empty Pull Request Review. - /// public PullRequestReviewSubmit() { } diff --git a/Octokit/Models/Response/ActivityPayloads/StatusEventPayload.cs b/Octokit/Models/Response/ActivityPayloads/StatusEventPayload.cs index 78e08c7029..1c8d3db1a6 100644 --- a/Octokit/Models/Response/ActivityPayloads/StatusEventPayload.cs +++ b/Octokit/Models/Response/ActivityPayloads/StatusEventPayload.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using System.Diagnostics; -using System.Globalization; namespace Octokit { @@ -68,13 +67,5 @@ public class StatusEventPayload : ActivityPayload /// The branches involved. /// public IReadOnlyList Branches { get; protected set; } - - internal new string DebuggerDisplay - { - get - { - return string.Format(CultureInfo.InvariantCulture, "Context: {0}, State: {1}, Description: {2}", Context, State, Description); - } - } } } diff --git a/Octokit/Models/Response/Commit.cs b/Octokit/Models/Response/Commit.cs index 7d85fbc3f8..7023193790 100644 --- a/Octokit/Models/Response/Commit.cs +++ b/Octokit/Models/Response/Commit.cs @@ -13,7 +13,7 @@ public Commit() { } public Commit(string url, string label, string @ref, string sha, User user, Repository repository, string message, Committer author, Committer committer, GitReference tree, IEnumerable parents, int commentCount) : base(url, label, @ref, sha, user, repository) { - Ensure.ArgumentNotNull(parents, nameof(parents)); + Ensure.ArgumentNotNull(parents, "parents"); Message = message; Author = author; From a21103ac39565bcd72f5c93f41048122388ffa69 Mon Sep 17 00:00:00 2001 From: Ryan Gribble Date: Tue, 6 Mar 2018 22:36:50 +1000 Subject: [PATCH 36/84] this extra authenticator class doesnt appear to be used anywhere --- .../ApplicationAuthenticator.cs | 23 ------------------- 1 file changed, 23 deletions(-) delete mode 100644 Octokit/Authentication/ApplicationAuthenticator.cs diff --git a/Octokit/Authentication/ApplicationAuthenticator.cs b/Octokit/Authentication/ApplicationAuthenticator.cs deleted file mode 100644 index 9e079539ea..0000000000 --- a/Octokit/Authentication/ApplicationAuthenticator.cs +++ /dev/null @@ -1,23 +0,0 @@ -using System.Collections.Generic; - -namespace Octokit.Internal -{ - class ApplicationAuthenticator : IAuthenticationHandler - { - public void Authenticate(IRequest request, Credentials credentials) - { - Ensure.ArgumentNotNull(request, nameof(request)); - Ensure.ArgumentNotNull(credentials, nameof(credentials)); - Ensure.ArgumentNotNull(credentials.Login, nameof(credentials.Login)); - Ensure.ArgumentNotNull(credentials.Password, nameof(credentials.Password)); - - Dictionary parameters = new Dictionary - { - { "client_id", credentials.Login }, - { "client_secret", credentials.Password } - }; - - ((Request)request).Endpoint = request.Endpoint.ApplyParameters(parameters); - } - } -} From 513874ad62d102e7bac3051a9ce1dd66036aea42 Mon Sep 17 00:00:00 2001 From: Ryan Gribble Date: Tue, 6 Mar 2018 22:43:23 +1000 Subject: [PATCH 37/84] undo project file change as it doesnt appear to be necessary --- Octokit.Tests.Integration/Octokit.Tests.Integration.csproj | 5 ----- 1 file changed, 5 deletions(-) diff --git a/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj b/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj index f8be48398c..0a690798d5 100644 --- a/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj +++ b/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj @@ -39,11 +39,6 @@ - - - - - From 02d52b8adf814b6945c60cb59a907a8cd34b1ce7 Mon Sep 17 00:00:00 2001 From: Itai Bar-Haim Date: Wed, 7 Mar 2018 09:30:14 +0200 Subject: [PATCH 38/84] Revert "Merge remote-tracking branch 'remote/GitHubApps' into GitHubApps" This reverts commit c53cc110b8d807f62fdfeaa7df19e1532d050007, reversing changes made to 0c9e413d420a4725738644ea5b13af6ec102d456. --- .../Clients/IObservableGitHubAppsClient.cs | 46 +-------------- .../Clients/IObservableProjectsClient.cs | 8 +-- .../IObservablePullRequestReviewsClient.cs | 2 + .../Clients/ObservableGitHubAppsClient.cs | 48 ++-------------- ...PullRequestReviewCommentReactionsClient.cs | 10 +++- .../Octokit.Tests.Integration.csproj | 5 ++ .../Clients/GitHubAppsClientTests.cs | 52 +++++++---------- .../ApplicationAuthenticator.cs | 23 ++++++++ Octokit/Clients/GitHubAppsClient.cs | 56 ++++++++----------- Octokit/Clients/IGitHubAppsClient.cs | 41 +++++--------- ...IOrganizationOutsideCollaboratorsClient.cs | 6 ++ Octokit/Clients/IProjectsClient.cs | 8 +-- Octokit/Clients/ProjectsClient.cs | 4 +- Octokit/Exceptions/ApiException.cs | 3 + .../Exceptions/LegalRestrictionException.cs | 3 + ...PrivateRepositoryQuotaExceededException.cs | 3 + .../PullRequestNotMergeableException.cs | 3 + .../Exceptions/RepositoryFormatException.cs | 3 + .../TwoFactorChallengeFailedException.cs | 3 + Octokit/Helpers/ApiUrls.cs | 2 +- Octokit/Http/ReadOnlyPagedCollection.cs | 4 +- .../Models/Request/PullRequestReviewSubmit.cs | 4 +- Octokit/Models/Response/AccessToken.cs | 11 +--- .../ActivityPayloads/StatusEventPayload.cs | 9 +++ Octokit/Models/Response/Commit.cs | 2 +- 25 files changed, 153 insertions(+), 206 deletions(-) create mode 100644 Octokit/Authentication/ApplicationAuthenticator.cs diff --git a/Octokit.Reactive/Clients/IObservableGitHubAppsClient.cs b/Octokit.Reactive/Clients/IObservableGitHubAppsClient.cs index 65f4ba4aa0..006168c404 100644 --- a/Octokit.Reactive/Clients/IObservableGitHubAppsClient.cs +++ b/Octokit.Reactive/Clients/IObservableGitHubAppsClient.cs @@ -2,56 +2,12 @@ namespace Octokit.Reactive { - /// - /// A client for GitHub Applications API. Provides the methods required to get GitHub applications and installations. - /// - /// - /// See the GitHub Apps API documentation for more information. - /// public interface IObservableGitHubAppsClient { - /// - /// Get a single GitHub App. - /// - /// https://developer.github.com/v3/apps/#get-a-single-github-app - /// The URL-friendly name of your GitHub App. You can find this on the settings page for your GitHub App. IObservable Get(string slug); - - /// - /// Returns the GitHub App associated with the authentication credentials used (requires GitHubApp JWT token auth). - /// - /// https://developer.github.com/v3/apps/#get-the-authenticated-github-app IObservable GetCurrent(); - - /// - /// List installations of the authenticated GitHub App (requires GitHubApp JWT token auth). - /// - /// https://developer.github.com/v3/apps/#find-installations + IObservable CreateInstallationToken(long installationId); IObservable GetAllInstallationsForCurrent(); - - /// - /// List installations of the authenticated GitHub App (requires GitHubApp JWT token auth). - /// - /// Options for changing the API response - /// https://developer.github.com/v3/apps/#find-installations IObservable GetAllInstallationsForCurrent(ApiOptions options); - - /// - /// Get a single GitHub App Installation (requires GitHubApp JWT token auth). - /// - /// https://developer.github.com/v3/apps/#get-a-single-installation - /// The Id of the GitHub App Installation - IObservable GetInstallation(long installationId); - - /// - /// Create a time bound access token for a GitHubApp Installation that can be used to access other API endpoints (requires GitHubApp JWT token auth). - /// - /// - /// https://developer.github.com/v3/apps/#create-a-new-installation-token - /// https://developer.github.com/apps/building-github-apps/authentication-options-for-github-apps/#authenticating-as-an-installation - /// https://developer.github.com/v3/apps/available-endpoints/ - /// - /// The Id of the GitHub App Installation - IObservable CreateInstallationToken(long installationId); } } diff --git a/Octokit.Reactive/Clients/IObservableProjectsClient.cs b/Octokit.Reactive/Clients/IObservableProjectsClient.cs index dea4dca868..2172e0868f 100644 --- a/Octokit.Reactive/Clients/IObservableProjectsClient.cs +++ b/Octokit.Reactive/Clients/IObservableProjectsClient.cs @@ -18,7 +18,7 @@ public interface IObservableProjectsClient /// See the API documentation for more information. /// /// The owner of the repository - /// The name of the repository + /// The name of the repository IObservable GetAllForRepository(string owner, string name); /// @@ -28,7 +28,7 @@ public interface IObservableProjectsClient /// See the API documentation for more information. /// /// The owner of the repository - /// The name of the repository + /// The name of the repository /// Used to filter the list of projects returned IObservable GetAllForRepository(string owner, string name, ProjectRequest request); @@ -58,7 +58,7 @@ public interface IObservableProjectsClient /// See the API documentation for more information. /// /// The owner of the repository - /// The name of the repository + /// The name of the repository /// Options for changing the API response IObservable GetAllForRepository(string owner, string name, ApiOptions options); @@ -69,7 +69,7 @@ public interface IObservableProjectsClient /// See the API documentation for more information. /// /// The owner of the repository - /// The name of the repository + /// The name of the repository /// Used to filter the list of projects returned /// Options for changing the API response IObservable GetAllForRepository(string owner, string name, ProjectRequest request, ApiOptions options); diff --git a/Octokit.Reactive/Clients/IObservablePullRequestReviewsClient.cs b/Octokit.Reactive/Clients/IObservablePullRequestReviewsClient.cs index 92a2b17ade..607d224f19 100644 --- a/Octokit.Reactive/Clients/IObservablePullRequestReviewsClient.cs +++ b/Octokit.Reactive/Clients/IObservablePullRequestReviewsClient.cs @@ -173,6 +173,7 @@ public interface IObservablePullRequestReviewsClient /// The name of the repository /// The pull request number /// The pull request review number + /// Options for changing the API response IObservable GetAllComments(string owner, string name, int number, long reviewId, ApiOptions options); /// @@ -182,6 +183,7 @@ public interface IObservablePullRequestReviewsClient /// The Id of the repository /// The pull request number /// The pull request review number + /// Options for changing the API response IObservable GetAllComments(long repositoryId, int number, long reviewId, ApiOptions options); } } diff --git a/Octokit.Reactive/Clients/ObservableGitHubAppsClient.cs b/Octokit.Reactive/Clients/ObservableGitHubAppsClient.cs index 8621b5b34b..94c79ca51c 100644 --- a/Octokit.Reactive/Clients/ObservableGitHubAppsClient.cs +++ b/Octokit.Reactive/Clients/ObservableGitHubAppsClient.cs @@ -4,12 +4,6 @@ namespace Octokit.Reactive { - /// - /// A client for GitHub Applications API. Provides the methods required to get GitHub applications and installations. - /// - /// - /// See the GitHub Apps API documentation for more information. - /// public class ObservableGitHubAppsClient : IObservableGitHubAppsClient { private IGitHubAppsClient _client; @@ -28,58 +22,26 @@ public IObservable Get(string slug) return _client.Get(slug).ToObservable(); } - /// - /// Returns the GitHub App associated with the authentication credentials used (requires GitHubApp JWT token auth). - /// - /// https://developer.github.com/v3/apps/#get-the-authenticated-github-app public IObservable GetCurrent() { return _client.GetCurrent().ToObservable(); } - /// - /// List installations of the authenticated GitHub App (requires GitHubApp JWT token auth). - /// - /// https://developer.github.com/v3/apps/#find-installations + public IObservable CreateInstallationToken(long installationId) + { + return _client.CreateInstallationToken(installationId).ToObservable(); + } + public IObservable GetAllInstallationsForCurrent() { return _connection.GetAndFlattenAllPages(ApiUrls.Installations(), null, AcceptHeaders.MachineManPreview); } - /// - /// List installations of the authenticated GitHub App (requires GitHubApp JWT token auth). - /// - /// Options for changing the API response - /// https://developer.github.com/v3/apps/#find-installations public IObservable GetAllInstallationsForCurrent(ApiOptions options) { Ensure.ArgumentNotNull(options, nameof(options)); return _connection.GetAndFlattenAllPages(ApiUrls.Installations(), null, AcceptHeaders.MachineManPreview, options); } - - /// - /// Get a single GitHub App Installation (requires GitHubApp JWT token auth). - /// - /// https://developer.github.com/v3/apps/#get-a-single-installation - /// The Id of the GitHub App Installation - public IObservable GetInstallation(long installationId) - { - return _client.GetInstallation(installationId).ToObservable(); - } - - /// - /// Create a time bound access token for a GitHubApp Installation that can be used to access other API endpoints (requires GitHubApp JWT token auth). - /// - /// - /// https://developer.github.com/v3/apps/#create-a-new-installation-token - /// https://developer.github.com/apps/building-github-apps/authentication-options-for-github-apps/#authenticating-as-an-installation - /// https://developer.github.com/v3/apps/available-endpoints/ - /// - /// The Id of the GitHub App Installation - public IObservable CreateInstallationToken(long installationId) - { - return _client.CreateInstallationToken(installationId).ToObservable(); - } } } diff --git a/Octokit.Reactive/Clients/ObservablePullRequestReviewCommentReactionsClient.cs b/Octokit.Reactive/Clients/ObservablePullRequestReviewCommentReactionsClient.cs index 54b47a6ef8..a2ee0d9b5d 100644 --- a/Octokit.Reactive/Clients/ObservablePullRequestReviewCommentReactionsClient.cs +++ b/Octokit.Reactive/Clients/ObservablePullRequestReviewCommentReactionsClient.cs @@ -15,9 +15,13 @@ public class ObservablePullRequestReviewCommentReactionsClient : IObservablePull readonly IPullRequestReviewCommentReactionsClient _client; readonly IConnection _connection; + /// + /// Initializes a new GitHub Reactions API client. + /// + /// A GitHubClient. public ObservablePullRequestReviewCommentReactionsClient(IGitHubClient client) { - Ensure.ArgumentNotNull(client, "client"); + Ensure.ArgumentNotNull(client, nameof(client)); _client = client.Reaction.PullRequestReviewComment; _connection = client.Connection; @@ -32,8 +36,8 @@ public ObservablePullRequestReviewCommentReactionsClient(IGitHubClient client) /// The comment id public IObservable GetAll(string owner, string name, int number) { - Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); - Ensure.ArgumentNotNullOrEmptyString(name, "name"); + Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); + Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); return _connection.GetAndFlattenAllPages(ApiUrls.PullRequestReviewCommentReaction(owner, name, number), null, AcceptHeaders.ReactionsPreview); } diff --git a/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj b/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj index 0a690798d5..f8be48398c 100644 --- a/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj +++ b/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj @@ -39,6 +39,11 @@ + + + + + diff --git a/Octokit.Tests/Clients/GitHubAppsClientTests.cs b/Octokit.Tests/Clients/GitHubAppsClientTests.cs index c2e081e920..36991ed983 100644 --- a/Octokit.Tests/Clients/GitHubAppsClientTests.cs +++ b/Octokit.Tests/Clients/GitHubAppsClientTests.cs @@ -19,14 +19,30 @@ public void EnsuresNonNullArguments() public class TheGetCurrentMethod { [Fact] - public void GetsFromCorrectUrl() + public void GetFromCorrectUrl() { var connection = Substitute.For(); var client = new GitHubAppsClient(connection); client.GetCurrent(); - connection.Received().Get(Arg.Is(u => u.ToString() == "app"), null, "application/vnd.github.machine-man-preview+json"); + connection.Received().Get(Arg.Is(u => u.ToString() == "app"), null, AcceptHeaders.MachineManPreview); + } + } + + public class TheCreateInstallationTokenMethod + { + [Fact] + public void PostsToCorrectUrl() + { + var connection = Substitute.For(); + var client = new GitHubAppsClient(connection); + + int fakeInstallationId = 3141; + + client.CreateInstallationToken(fakeInstallationId); + + connection.Received().Post(Arg.Is(u => u.ToString() == "installations/3141/access_tokens"), string.Empty, AcceptHeaders.MachineManPreview); } } @@ -49,7 +65,7 @@ public async Task RequestsCorrectUrl() client.GetAllInstallationsForCurrent(); - connection.Received().GetAll(Arg.Is(u => u.ToString() == "app/installations"), null, "application/vnd.github.machine-man-preview+json"); + connection.Received().GetAll(Arg.Is(u => u.ToString() == "app/installations"), null, AcceptHeaders.MachineManPreview); } @@ -68,38 +84,10 @@ public void RequestsTheCorrectUrlWithApiOptions() client.GetAllInstallationsForCurrent(options); - connection.Received().GetAll(Arg.Is(u => u.ToString() == "app/installations"), null, "application/vnd.github.machine-man-preview+json", options); + connection.Received().GetAll(Arg.Is(u => u.ToString() == "app/installations"), null, AcceptHeaders.MachineManPreview, options); } - } - - public class TheGetInstallationMethod - { - [Fact] - public void GetsFromCorrectUrl() - { - var connection = Substitute.For(); - var client = new GitHubAppsClient(connection); - client.GetInstallation(123); - - connection.Received().Get(Arg.Is(u => u.ToString() == "app/installations/123"), null, "application/vnd.github.machine-man-preview+json"); - } } - public class TheCreateInstallationTokenMethod - { - [Fact] - public void PostsToCorrectUrl() - { - var connection = Substitute.For(); - var client = new GitHubAppsClient(connection); - - int fakeInstallationId = 3141; - - client.CreateInstallationToken(fakeInstallationId); - - connection.Received().Post(Arg.Is(u => u.ToString() == "installations/3141/access_tokens"), string.Empty, "application/vnd.github.machine-man-preview+json"); - } - } } } diff --git a/Octokit/Authentication/ApplicationAuthenticator.cs b/Octokit/Authentication/ApplicationAuthenticator.cs new file mode 100644 index 0000000000..9e079539ea --- /dev/null +++ b/Octokit/Authentication/ApplicationAuthenticator.cs @@ -0,0 +1,23 @@ +using System.Collections.Generic; + +namespace Octokit.Internal +{ + class ApplicationAuthenticator : IAuthenticationHandler + { + public void Authenticate(IRequest request, Credentials credentials) + { + Ensure.ArgumentNotNull(request, nameof(request)); + Ensure.ArgumentNotNull(credentials, nameof(credentials)); + Ensure.ArgumentNotNull(credentials.Login, nameof(credentials.Login)); + Ensure.ArgumentNotNull(credentials.Password, nameof(credentials.Password)); + + Dictionary parameters = new Dictionary + { + { "client_id", credentials.Login }, + { "client_secret", credentials.Password } + }; + + ((Request)request).Endpoint = request.Endpoint.ApplyParameters(parameters); + } + } +} diff --git a/Octokit/Clients/GitHubAppsClient.cs b/Octokit/Clients/GitHubAppsClient.cs index 708ff69281..2e8a7c4ef7 100644 --- a/Octokit/Clients/GitHubAppsClient.cs +++ b/Octokit/Clients/GitHubAppsClient.cs @@ -11,72 +11,62 @@ namespace Octokit /// public class GitHubAppsClient : ApiClient, IGitHubAppsClient { + /// + /// Instantiates a new GitHub Apps API client. + /// + /// An API connection public GitHubAppsClient(IApiConnection apiConnection) : base(apiConnection) { } /// - /// Get a single GitHub App. + /// Get a single GitHub App /// - /// https://developer.github.com/v3/apps/#get-a-single-github-app /// The URL-friendly name of your GitHub App. You can find this on the settings page for your GitHub App. + /// The GitHub App public Task Get(string slug) { return ApiConnection.Get(ApiUrls.App(slug), null, AcceptHeaders.MachineManPreview); } /// - /// Returns the GitHub App associated with the authentication credentials used (requires GitHubApp JWT token auth). + /// Returns the GitHub App associated with the authentication credentials used. /// - /// https://developer.github.com/v3/apps/#get-the-authenticated-github-app + /// The GitHub App associated with the authentication credentials used. public Task GetCurrent() { return ApiConnection.Get(ApiUrls.App(), null, AcceptHeaders.MachineManPreview); } /// - /// List installations of the authenticated GitHub App (requires GitHubApp JWT token auth). + /// Create a new installation token /// - /// https://developer.github.com/v3/apps/#find-installations - public Task> GetAllInstallationsForCurrent() + /// The Id of the GitHub App installation. + /// The GitHub App installation access token. + public Task CreateInstallationToken(long installationId) { - return ApiConnection.GetAll(ApiUrls.Installations(), null, AcceptHeaders.MachineManPreview); + return ApiConnection.Post(ApiUrls.AccessTokens(installationId), string.Empty, AcceptHeaders.MachineManPreview); } /// - /// List installations of the authenticated GitHub App (requires GitHubApp JWT token auth). + /// List installations that are accessible to the authenticated user. /// - /// Options for changing the API response - /// https://developer.github.com/v3/apps/#find-installations - public Task> GetAllInstallationsForCurrent(ApiOptions options) + /// A list (read-only) that includes all the GitHub App installations accessible to the current authenticated user. + public Task> GetAllInstallationsForCurrent() { - Ensure.ArgumentNotNull(options, nameof(options)); - - return ApiConnection.GetAll(ApiUrls.Installations(), null, AcceptHeaders.MachineManPreview, options); + return ApiConnection.GetAll(ApiUrls.Installations(), null, AcceptHeaders.MachineManPreview); } /// - /// Get a single GitHub App Installation (requires GitHubApp JWT token auth). + /// List installations that are accessible to the authenticated user. /// - /// https://developer.github.com/v3/apps/#get-a-single-installation - /// The Id of the GitHub App Installation - public Task GetInstallation(long installationId) + /// + /// A list (read-only) that includes all the GitHub App installations accessible to the current authenticated user. + public Task> GetAllInstallationsForCurrent(ApiOptions options) { - return ApiConnection.Get(ApiUrls.Installation(installationId), null, AcceptHeaders.MachineManPreview); - } + Ensure.ArgumentNotNull(options, nameof(options)); - /// - /// Create a time bound access token for a GitHubApp Installation that can be used to access other API endpoints (requires GitHubApp JWT token auth). - /// - /// - /// https://developer.github.com/v3/apps/#create-a-new-installation-token - /// https://developer.github.com/apps/building-github-apps/authentication-options-for-github-apps/#authenticating-as-an-installation - /// https://developer.github.com/v3/apps/available-endpoints/ - /// - /// The Id of the GitHub App Installation - public Task CreateInstallationToken(long installationId) - { - return ApiConnection.Post(ApiUrls.AccessTokens(installationId), string.Empty, AcceptHeaders.MachineManPreview); + return ApiConnection.GetAll(ApiUrls.Installations(), null, AcceptHeaders.MachineManPreview, options); } } } \ No newline at end of file diff --git a/Octokit/Clients/IGitHubAppsClient.cs b/Octokit/Clients/IGitHubAppsClient.cs index 71802151f7..761be187c0 100644 --- a/Octokit/Clients/IGitHubAppsClient.cs +++ b/Octokit/Clients/IGitHubAppsClient.cs @@ -12,47 +12,36 @@ namespace Octokit public interface IGitHubAppsClient { /// - /// Get a single GitHub App. + /// Get a single GitHub App /// - /// https://developer.github.com/v3/apps/#get-a-single-github-app /// The URL-friendly name of your GitHub App. You can find this on the settings page for your GitHub App. + /// The GitHub App Task Get(string slug); /// - /// Returns the GitHub App associated with the authentication credentials used (requires GitHubApp JWT token auth). + /// Returns the GitHub App associated with the authentication credentials used. /// - /// https://developer.github.com/v3/apps/#get-the-authenticated-github-app + /// The GitHub App associated with the authentication credentials used. Task GetCurrent(); /// - /// List installations of the authenticated GitHub App (requires GitHubApp JWT token auth). + /// Create a new installation token /// - /// https://developer.github.com/v3/apps/#find-installations - Task> GetAllInstallationsForCurrent(); - - /// - /// List installations of the authenticated GitHub App (requires GitHubApp JWT token auth). - /// - /// Options for changing the API response - /// https://developer.github.com/v3/apps/#find-installations - Task> GetAllInstallationsForCurrent(ApiOptions options); + /// The Id of the GitHub App installation. + /// The GitHub App installation access token. + Task CreateInstallationToken(long installationId); /// - /// Get a single GitHub App Installation (requires GitHubApp JWT token auth). + /// List installations that are accessible to the authenticated user. /// - /// https://developer.github.com/v3/apps/#get-a-single-installation - /// The Id of the GitHub App Installation - Task GetInstallation(long installationId); + /// A list (read-only) that includes all the GitHub App installations accessible to the current authenticated user. + Task> GetAllInstallationsForCurrent(); /// - /// Create a time bound access token for a GitHubApp Installation that can be used to access other API endpoints (requires GitHubApp JWT token auth). + /// List installations that are accessible to the authenticated user. /// - /// - /// https://developer.github.com/v3/apps/#create-a-new-installation-token - /// https://developer.github.com/apps/building-github-apps/authentication-options-for-github-apps/#authenticating-as-an-installation - /// https://developer.github.com/v3/apps/available-endpoints/ - /// - /// The Id of the GitHub App Installation - Task CreateInstallationToken(long installationId); + /// + /// A list (read-only) that includes all the GitHub App installations accessible to the current authenticated user. + Task> GetAllInstallationsForCurrent(ApiOptions options); } } \ No newline at end of file diff --git a/Octokit/Clients/IOrganizationOutsideCollaboratorsClient.cs b/Octokit/Clients/IOrganizationOutsideCollaboratorsClient.cs index 1ad12ad7e3..4e5e32a0d6 100644 --- a/Octokit/Clients/IOrganizationOutsideCollaboratorsClient.cs +++ b/Octokit/Clients/IOrganizationOutsideCollaboratorsClient.cs @@ -3,6 +3,12 @@ namespace Octokit { + /// + /// A client for GitHub's Organization Outside Collaborators API. + /// + /// + /// See the Outside Collaborators API documentation for more information. + /// public interface IOrganizationOutsideCollaboratorsClient { /// diff --git a/Octokit/Clients/IProjectsClient.cs b/Octokit/Clients/IProjectsClient.cs index c3edd5ae7c..3e75e2f35f 100644 --- a/Octokit/Clients/IProjectsClient.cs +++ b/Octokit/Clients/IProjectsClient.cs @@ -19,7 +19,7 @@ public interface IProjectsClient /// See the API documentation for more information. /// /// The owner of the repository - /// The name of the repository + /// The name of the repository Task> GetAllForRepository(string owner, string name); /// @@ -29,7 +29,7 @@ public interface IProjectsClient /// See the API documentation for more information. /// /// The owner of the repository - /// The name of the repository + /// The name of the repository /// Used to filter the list of projects returned Task> GetAllForRepository(string owner, string name, ProjectRequest request); @@ -59,7 +59,7 @@ public interface IProjectsClient /// See the API documentation for more information. /// /// The owner of the repository - /// The name of the repository + /// The name of the repository /// Options for changing the API response Task> GetAllForRepository(string owner, string name, ApiOptions options); @@ -70,7 +70,7 @@ public interface IProjectsClient /// See the API documentation for more information. /// /// The owner of the repository - /// The name of the repository + /// The name of the repository /// Used to filter the list of projects returned /// Options for changing the API response Task> GetAllForRepository(string owner, string name, ProjectRequest request, ApiOptions options); diff --git a/Octokit/Clients/ProjectsClient.cs b/Octokit/Clients/ProjectsClient.cs index f21e75fcf0..862ac82ccc 100644 --- a/Octokit/Clients/ProjectsClient.cs +++ b/Octokit/Clients/ProjectsClient.cs @@ -27,7 +27,7 @@ public ProjectsClient(IApiConnection apiConnection) : /// See the API documentation for more information. /// /// The owner of the repository - /// The name of the repository + /// The name of the repository public Task> GetAllForRepository(string owner, string name) { return GetAllForRepository(owner, name, ApiOptions.None); @@ -40,7 +40,7 @@ public Task> GetAllForRepository(string owner, string nam /// See the API documentation for more information. /// /// The owner of the repository - /// The name of the repository + /// The name of the repository /// Options for changing the API response public Task> GetAllForRepository(string owner, string name, ApiOptions options) { diff --git a/Octokit/Exceptions/ApiException.cs b/Octokit/Exceptions/ApiException.cs index ce2c15e90a..f5281189de 100644 --- a/Octokit/Exceptions/ApiException.cs +++ b/Octokit/Exceptions/ApiException.cs @@ -103,6 +103,9 @@ protected ApiException(ApiError apiError, HttpStatusCode statusCode, Exception i public IResponse HttpResponse { get; private set; } + /// + /// The error message + /// public override string Message { get { return ApiErrorMessageSafe ?? "An error occurred with this API request"; } diff --git a/Octokit/Exceptions/LegalRestrictionException.cs b/Octokit/Exceptions/LegalRestrictionException.cs index d7ac60c22e..685ce4b143 100644 --- a/Octokit/Exceptions/LegalRestrictionException.cs +++ b/Octokit/Exceptions/LegalRestrictionException.cs @@ -20,6 +20,9 @@ namespace Octokit Justification = "These exceptions are specific to the GitHub API and not general purpose exceptions")] public class LegalRestrictionException : ApiException { + /// + /// The error message + /// public override string Message { get { return ApiErrorMessageSafe ?? "Resource taken down due to a DMCA notice."; } diff --git a/Octokit/Exceptions/PrivateRepositoryQuotaExceededException.cs b/Octokit/Exceptions/PrivateRepositoryQuotaExceededException.cs index c811b1ffa3..9511a95aae 100644 --- a/Octokit/Exceptions/PrivateRepositoryQuotaExceededException.cs +++ b/Octokit/Exceptions/PrivateRepositoryQuotaExceededException.cs @@ -26,6 +26,9 @@ public PrivateRepositoryQuotaExceededException(ApiValidationException innerExcep { } + /// + /// The error message + /// public override string Message { get diff --git a/Octokit/Exceptions/PullRequestNotMergeableException.cs b/Octokit/Exceptions/PullRequestNotMergeableException.cs index 89ce79e158..157dfbc0f5 100644 --- a/Octokit/Exceptions/PullRequestNotMergeableException.cs +++ b/Octokit/Exceptions/PullRequestNotMergeableException.cs @@ -39,6 +39,9 @@ public PullRequestNotMergeableException(IResponse response, Exception innerExcep "PullRequestNotMergeableException created with the wrong HTTP status code"); } + /// + /// The error message + /// public override string Message { //https://developer.github.com/v3/pulls/#response-if-merge-cannot-be-performed diff --git a/Octokit/Exceptions/RepositoryFormatException.cs b/Octokit/Exceptions/RepositoryFormatException.cs index c0ab53b515..c71074458b 100644 --- a/Octokit/Exceptions/RepositoryFormatException.cs +++ b/Octokit/Exceptions/RepositoryFormatException.cs @@ -27,6 +27,9 @@ public RepositoryFormatException(IEnumerable invalidRepositories) parameterList); } + /// + /// The error message + /// public override string Message { get diff --git a/Octokit/Exceptions/TwoFactorChallengeFailedException.cs b/Octokit/Exceptions/TwoFactorChallengeFailedException.cs index 3e1b799f54..59708ef82d 100644 --- a/Octokit/Exceptions/TwoFactorChallengeFailedException.cs +++ b/Octokit/Exceptions/TwoFactorChallengeFailedException.cs @@ -37,6 +37,9 @@ public TwoFactorChallengeFailedException( AuthorizationCode = authorizationCode; } + /// + /// The error message + /// public override string Message { get { return "The two-factor authentication code supplied is not correct"; } diff --git a/Octokit/Helpers/ApiUrls.cs b/Octokit/Helpers/ApiUrls.cs index a086592107..a3512a06a6 100644 --- a/Octokit/Helpers/ApiUrls.cs +++ b/Octokit/Helpers/ApiUrls.cs @@ -328,7 +328,7 @@ public static Uri Installations() /// Returns the that returns a single installation of the authenticated application. /// /// - public static Uri Installation(long installationId) + public static Uri Installation(int installationId) { return "app/installations/{0}".FormatUri(installationId); } diff --git a/Octokit/Http/ReadOnlyPagedCollection.cs b/Octokit/Http/ReadOnlyPagedCollection.cs index 520f107b33..c75c76b28b 100644 --- a/Octokit/Http/ReadOnlyPagedCollection.cs +++ b/Octokit/Http/ReadOnlyPagedCollection.cs @@ -13,8 +13,8 @@ public class ReadOnlyPagedCollection : ReadOnlyCollection, IReadOnlyPagedC public ReadOnlyPagedCollection(IApiResponse> response, Func>>> nextPageFunc) : base(response != null ? response.Body ?? new List() : new List()) { - Ensure.ArgumentNotNull(response, "response"); - Ensure.ArgumentNotNull(nextPageFunc, "nextPageFunc"); + Ensure.ArgumentNotNull(response, nameof(response)); + Ensure.ArgumentNotNull(nextPageFunc, nameof(nextPageFunc)); _nextPageFunc = nextPageFunc; if (response != null) diff --git a/Octokit/Models/Request/PullRequestReviewSubmit.cs b/Octokit/Models/Request/PullRequestReviewSubmit.cs index 99a136a61b..c3019a1823 100644 --- a/Octokit/Models/Request/PullRequestReviewSubmit.cs +++ b/Octokit/Models/Request/PullRequestReviewSubmit.cs @@ -1,7 +1,6 @@ using System.Diagnostics; using System.Globalization; using Octokit.Internal; -using System.Collections.Generic; namespace Octokit { @@ -11,6 +10,9 @@ namespace Octokit [DebuggerDisplay("{DebuggerDisplay,nq}")] public class PullRequestReviewSubmit : RequestParameters { + /// + /// Initializes a new empty Pull Request Review. + /// public PullRequestReviewSubmit() { } diff --git a/Octokit/Models/Response/AccessToken.cs b/Octokit/Models/Response/AccessToken.cs index 182a555322..319eb3351c 100644 --- a/Octokit/Models/Response/AccessToken.cs +++ b/Octokit/Models/Response/AccessToken.cs @@ -9,21 +9,14 @@ public class AccessToken { public AccessToken() { } - public AccessToken(string token, DateTimeOffset expiresAt) + public AccessToken(string token, DateTime expiresAt) { Token = token; ExpiresAt = expiresAt; } - /// - /// The access token - /// public string Token { get; protected set; } - - /// - /// The expiration date - /// - public DateTimeOffset ExpiresAt { get; protected set; } + public DateTime ExpiresAt { get; protected set; } internal string DebuggerDisplay { diff --git a/Octokit/Models/Response/ActivityPayloads/StatusEventPayload.cs b/Octokit/Models/Response/ActivityPayloads/StatusEventPayload.cs index 1c8d3db1a6..78e08c7029 100644 --- a/Octokit/Models/Response/ActivityPayloads/StatusEventPayload.cs +++ b/Octokit/Models/Response/ActivityPayloads/StatusEventPayload.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Diagnostics; +using System.Globalization; namespace Octokit { @@ -67,5 +68,13 @@ public class StatusEventPayload : ActivityPayload /// The branches involved. /// public IReadOnlyList Branches { get; protected set; } + + internal new string DebuggerDisplay + { + get + { + return string.Format(CultureInfo.InvariantCulture, "Context: {0}, State: {1}, Description: {2}", Context, State, Description); + } + } } } diff --git a/Octokit/Models/Response/Commit.cs b/Octokit/Models/Response/Commit.cs index 7023193790..7d85fbc3f8 100644 --- a/Octokit/Models/Response/Commit.cs +++ b/Octokit/Models/Response/Commit.cs @@ -13,7 +13,7 @@ public Commit() { } public Commit(string url, string label, string @ref, string sha, User user, Repository repository, string message, Committer author, Committer committer, GitReference tree, IEnumerable parents, int commentCount) : base(url, label, @ref, sha, user, repository) { - Ensure.ArgumentNotNull(parents, "parents"); + Ensure.ArgumentNotNull(parents, nameof(parents)); Message = message; Author = author; From e0d5b99b913653918ede843a5334d190ed2aa1f8 Mon Sep 17 00:00:00 2001 From: Ryan Gribble Date: Wed, 7 Mar 2018 20:15:00 +1000 Subject: [PATCH 39/84] Revert "Revert "Merge remote-tracking branch 'remote/GitHubApps' into GitHubApps"" This reverts commit 02d52b8adf814b6945c60cb59a907a8cd34b1ce7. --- .../Clients/IObservableGitHubAppsClient.cs | 46 ++++++++++++++- .../Clients/IObservableProjectsClient.cs | 8 +-- .../IObservablePullRequestReviewsClient.cs | 2 - .../Clients/ObservableGitHubAppsClient.cs | 48 ++++++++++++++-- ...PullRequestReviewCommentReactionsClient.cs | 10 +--- .../Octokit.Tests.Integration.csproj | 5 -- .../Clients/GitHubAppsClientTests.cs | 52 ++++++++++------- .../ApplicationAuthenticator.cs | 23 -------- Octokit/Clients/GitHubAppsClient.cs | 56 +++++++++++-------- Octokit/Clients/IGitHubAppsClient.cs | 41 +++++++++----- ...IOrganizationOutsideCollaboratorsClient.cs | 6 -- Octokit/Clients/IProjectsClient.cs | 8 +-- Octokit/Clients/ProjectsClient.cs | 4 +- Octokit/Exceptions/ApiException.cs | 3 - .../Exceptions/LegalRestrictionException.cs | 3 - ...PrivateRepositoryQuotaExceededException.cs | 3 - .../PullRequestNotMergeableException.cs | 3 - .../Exceptions/RepositoryFormatException.cs | 3 - .../TwoFactorChallengeFailedException.cs | 3 - Octokit/Helpers/ApiUrls.cs | 2 +- Octokit/Http/ReadOnlyPagedCollection.cs | 4 +- .../Models/Request/PullRequestReviewSubmit.cs | 4 +- Octokit/Models/Response/AccessToken.cs | 11 +++- .../ActivityPayloads/StatusEventPayload.cs | 9 --- Octokit/Models/Response/Commit.cs | 2 +- 25 files changed, 206 insertions(+), 153 deletions(-) delete mode 100644 Octokit/Authentication/ApplicationAuthenticator.cs diff --git a/Octokit.Reactive/Clients/IObservableGitHubAppsClient.cs b/Octokit.Reactive/Clients/IObservableGitHubAppsClient.cs index 006168c404..65f4ba4aa0 100644 --- a/Octokit.Reactive/Clients/IObservableGitHubAppsClient.cs +++ b/Octokit.Reactive/Clients/IObservableGitHubAppsClient.cs @@ -2,12 +2,56 @@ namespace Octokit.Reactive { + /// + /// A client for GitHub Applications API. Provides the methods required to get GitHub applications and installations. + /// + /// + /// See the GitHub Apps API documentation for more information. + /// public interface IObservableGitHubAppsClient { + /// + /// Get a single GitHub App. + /// + /// https://developer.github.com/v3/apps/#get-a-single-github-app + /// The URL-friendly name of your GitHub App. You can find this on the settings page for your GitHub App. IObservable Get(string slug); + + /// + /// Returns the GitHub App associated with the authentication credentials used (requires GitHubApp JWT token auth). + /// + /// https://developer.github.com/v3/apps/#get-the-authenticated-github-app IObservable GetCurrent(); - IObservable CreateInstallationToken(long installationId); + + /// + /// List installations of the authenticated GitHub App (requires GitHubApp JWT token auth). + /// + /// https://developer.github.com/v3/apps/#find-installations IObservable GetAllInstallationsForCurrent(); + + /// + /// List installations of the authenticated GitHub App (requires GitHubApp JWT token auth). + /// + /// Options for changing the API response + /// https://developer.github.com/v3/apps/#find-installations IObservable GetAllInstallationsForCurrent(ApiOptions options); + + /// + /// Get a single GitHub App Installation (requires GitHubApp JWT token auth). + /// + /// https://developer.github.com/v3/apps/#get-a-single-installation + /// The Id of the GitHub App Installation + IObservable GetInstallation(long installationId); + + /// + /// Create a time bound access token for a GitHubApp Installation that can be used to access other API endpoints (requires GitHubApp JWT token auth). + /// + /// + /// https://developer.github.com/v3/apps/#create-a-new-installation-token + /// https://developer.github.com/apps/building-github-apps/authentication-options-for-github-apps/#authenticating-as-an-installation + /// https://developer.github.com/v3/apps/available-endpoints/ + /// + /// The Id of the GitHub App Installation + IObservable CreateInstallationToken(long installationId); } } diff --git a/Octokit.Reactive/Clients/IObservableProjectsClient.cs b/Octokit.Reactive/Clients/IObservableProjectsClient.cs index 2172e0868f..dea4dca868 100644 --- a/Octokit.Reactive/Clients/IObservableProjectsClient.cs +++ b/Octokit.Reactive/Clients/IObservableProjectsClient.cs @@ -18,7 +18,7 @@ public interface IObservableProjectsClient /// See the API documentation for more information. /// /// The owner of the repository - /// The name of the repository + /// The name of the repository IObservable GetAllForRepository(string owner, string name); /// @@ -28,7 +28,7 @@ public interface IObservableProjectsClient /// See the API documentation for more information. /// /// The owner of the repository - /// The name of the repository + /// The name of the repository /// Used to filter the list of projects returned IObservable GetAllForRepository(string owner, string name, ProjectRequest request); @@ -58,7 +58,7 @@ public interface IObservableProjectsClient /// See the API documentation for more information. /// /// The owner of the repository - /// The name of the repository + /// The name of the repository /// Options for changing the API response IObservable GetAllForRepository(string owner, string name, ApiOptions options); @@ -69,7 +69,7 @@ public interface IObservableProjectsClient /// See the API documentation for more information. /// /// The owner of the repository - /// The name of the repository + /// The name of the repository /// Used to filter the list of projects returned /// Options for changing the API response IObservable GetAllForRepository(string owner, string name, ProjectRequest request, ApiOptions options); diff --git a/Octokit.Reactive/Clients/IObservablePullRequestReviewsClient.cs b/Octokit.Reactive/Clients/IObservablePullRequestReviewsClient.cs index 607d224f19..92a2b17ade 100644 --- a/Octokit.Reactive/Clients/IObservablePullRequestReviewsClient.cs +++ b/Octokit.Reactive/Clients/IObservablePullRequestReviewsClient.cs @@ -173,7 +173,6 @@ public interface IObservablePullRequestReviewsClient /// The name of the repository /// The pull request number /// The pull request review number - /// Options for changing the API response IObservable GetAllComments(string owner, string name, int number, long reviewId, ApiOptions options); /// @@ -183,7 +182,6 @@ public interface IObservablePullRequestReviewsClient /// The Id of the repository /// The pull request number /// The pull request review number - /// Options for changing the API response IObservable GetAllComments(long repositoryId, int number, long reviewId, ApiOptions options); } } diff --git a/Octokit.Reactive/Clients/ObservableGitHubAppsClient.cs b/Octokit.Reactive/Clients/ObservableGitHubAppsClient.cs index 94c79ca51c..8621b5b34b 100644 --- a/Octokit.Reactive/Clients/ObservableGitHubAppsClient.cs +++ b/Octokit.Reactive/Clients/ObservableGitHubAppsClient.cs @@ -4,6 +4,12 @@ namespace Octokit.Reactive { + /// + /// A client for GitHub Applications API. Provides the methods required to get GitHub applications and installations. + /// + /// + /// See the GitHub Apps API documentation for more information. + /// public class ObservableGitHubAppsClient : IObservableGitHubAppsClient { private IGitHubAppsClient _client; @@ -22,26 +28,58 @@ public IObservable Get(string slug) return _client.Get(slug).ToObservable(); } + /// + /// Returns the GitHub App associated with the authentication credentials used (requires GitHubApp JWT token auth). + /// + /// https://developer.github.com/v3/apps/#get-the-authenticated-github-app public IObservable GetCurrent() { return _client.GetCurrent().ToObservable(); } - public IObservable CreateInstallationToken(long installationId) - { - return _client.CreateInstallationToken(installationId).ToObservable(); - } - + /// + /// List installations of the authenticated GitHub App (requires GitHubApp JWT token auth). + /// + /// https://developer.github.com/v3/apps/#find-installations public IObservable GetAllInstallationsForCurrent() { return _connection.GetAndFlattenAllPages(ApiUrls.Installations(), null, AcceptHeaders.MachineManPreview); } + /// + /// List installations of the authenticated GitHub App (requires GitHubApp JWT token auth). + /// + /// Options for changing the API response + /// https://developer.github.com/v3/apps/#find-installations public IObservable GetAllInstallationsForCurrent(ApiOptions options) { Ensure.ArgumentNotNull(options, nameof(options)); return _connection.GetAndFlattenAllPages(ApiUrls.Installations(), null, AcceptHeaders.MachineManPreview, options); } + + /// + /// Get a single GitHub App Installation (requires GitHubApp JWT token auth). + /// + /// https://developer.github.com/v3/apps/#get-a-single-installation + /// The Id of the GitHub App Installation + public IObservable GetInstallation(long installationId) + { + return _client.GetInstallation(installationId).ToObservable(); + } + + /// + /// Create a time bound access token for a GitHubApp Installation that can be used to access other API endpoints (requires GitHubApp JWT token auth). + /// + /// + /// https://developer.github.com/v3/apps/#create-a-new-installation-token + /// https://developer.github.com/apps/building-github-apps/authentication-options-for-github-apps/#authenticating-as-an-installation + /// https://developer.github.com/v3/apps/available-endpoints/ + /// + /// The Id of the GitHub App Installation + public IObservable CreateInstallationToken(long installationId) + { + return _client.CreateInstallationToken(installationId).ToObservable(); + } } } diff --git a/Octokit.Reactive/Clients/ObservablePullRequestReviewCommentReactionsClient.cs b/Octokit.Reactive/Clients/ObservablePullRequestReviewCommentReactionsClient.cs index a2ee0d9b5d..54b47a6ef8 100644 --- a/Octokit.Reactive/Clients/ObservablePullRequestReviewCommentReactionsClient.cs +++ b/Octokit.Reactive/Clients/ObservablePullRequestReviewCommentReactionsClient.cs @@ -15,13 +15,9 @@ public class ObservablePullRequestReviewCommentReactionsClient : IObservablePull readonly IPullRequestReviewCommentReactionsClient _client; readonly IConnection _connection; - /// - /// Initializes a new GitHub Reactions API client. - /// - /// A GitHubClient. public ObservablePullRequestReviewCommentReactionsClient(IGitHubClient client) { - Ensure.ArgumentNotNull(client, nameof(client)); + Ensure.ArgumentNotNull(client, "client"); _client = client.Reaction.PullRequestReviewComment; _connection = client.Connection; @@ -36,8 +32,8 @@ public ObservablePullRequestReviewCommentReactionsClient(IGitHubClient client) /// The comment id public IObservable GetAll(string owner, string name, int number) { - Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); - Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); return _connection.GetAndFlattenAllPages(ApiUrls.PullRequestReviewCommentReaction(owner, name, number), null, AcceptHeaders.ReactionsPreview); } diff --git a/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj b/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj index f8be48398c..0a690798d5 100644 --- a/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj +++ b/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj @@ -39,11 +39,6 @@ - - - - - diff --git a/Octokit.Tests/Clients/GitHubAppsClientTests.cs b/Octokit.Tests/Clients/GitHubAppsClientTests.cs index 36991ed983..c2e081e920 100644 --- a/Octokit.Tests/Clients/GitHubAppsClientTests.cs +++ b/Octokit.Tests/Clients/GitHubAppsClientTests.cs @@ -19,30 +19,14 @@ public void EnsuresNonNullArguments() public class TheGetCurrentMethod { [Fact] - public void GetFromCorrectUrl() + public void GetsFromCorrectUrl() { var connection = Substitute.For(); var client = new GitHubAppsClient(connection); client.GetCurrent(); - connection.Received().Get(Arg.Is(u => u.ToString() == "app"), null, AcceptHeaders.MachineManPreview); - } - } - - public class TheCreateInstallationTokenMethod - { - [Fact] - public void PostsToCorrectUrl() - { - var connection = Substitute.For(); - var client = new GitHubAppsClient(connection); - - int fakeInstallationId = 3141; - - client.CreateInstallationToken(fakeInstallationId); - - connection.Received().Post(Arg.Is(u => u.ToString() == "installations/3141/access_tokens"), string.Empty, AcceptHeaders.MachineManPreview); + connection.Received().Get(Arg.Is(u => u.ToString() == "app"), null, "application/vnd.github.machine-man-preview+json"); } } @@ -65,7 +49,7 @@ public async Task RequestsCorrectUrl() client.GetAllInstallationsForCurrent(); - connection.Received().GetAll(Arg.Is(u => u.ToString() == "app/installations"), null, AcceptHeaders.MachineManPreview); + connection.Received().GetAll(Arg.Is(u => u.ToString() == "app/installations"), null, "application/vnd.github.machine-man-preview+json"); } @@ -84,10 +68,38 @@ public void RequestsTheCorrectUrlWithApiOptions() client.GetAllInstallationsForCurrent(options); - connection.Received().GetAll(Arg.Is(u => u.ToString() == "app/installations"), null, AcceptHeaders.MachineManPreview, options); + connection.Received().GetAll(Arg.Is(u => u.ToString() == "app/installations"), null, "application/vnd.github.machine-man-preview+json", options); } + } + + public class TheGetInstallationMethod + { + [Fact] + public void GetsFromCorrectUrl() + { + var connection = Substitute.For(); + var client = new GitHubAppsClient(connection); + client.GetInstallation(123); + + connection.Received().Get(Arg.Is(u => u.ToString() == "app/installations/123"), null, "application/vnd.github.machine-man-preview+json"); + } } + public class TheCreateInstallationTokenMethod + { + [Fact] + public void PostsToCorrectUrl() + { + var connection = Substitute.For(); + var client = new GitHubAppsClient(connection); + + int fakeInstallationId = 3141; + + client.CreateInstallationToken(fakeInstallationId); + + connection.Received().Post(Arg.Is(u => u.ToString() == "installations/3141/access_tokens"), string.Empty, "application/vnd.github.machine-man-preview+json"); + } + } } } diff --git a/Octokit/Authentication/ApplicationAuthenticator.cs b/Octokit/Authentication/ApplicationAuthenticator.cs deleted file mode 100644 index 9e079539ea..0000000000 --- a/Octokit/Authentication/ApplicationAuthenticator.cs +++ /dev/null @@ -1,23 +0,0 @@ -using System.Collections.Generic; - -namespace Octokit.Internal -{ - class ApplicationAuthenticator : IAuthenticationHandler - { - public void Authenticate(IRequest request, Credentials credentials) - { - Ensure.ArgumentNotNull(request, nameof(request)); - Ensure.ArgumentNotNull(credentials, nameof(credentials)); - Ensure.ArgumentNotNull(credentials.Login, nameof(credentials.Login)); - Ensure.ArgumentNotNull(credentials.Password, nameof(credentials.Password)); - - Dictionary parameters = new Dictionary - { - { "client_id", credentials.Login }, - { "client_secret", credentials.Password } - }; - - ((Request)request).Endpoint = request.Endpoint.ApplyParameters(parameters); - } - } -} diff --git a/Octokit/Clients/GitHubAppsClient.cs b/Octokit/Clients/GitHubAppsClient.cs index 2e8a7c4ef7..708ff69281 100644 --- a/Octokit/Clients/GitHubAppsClient.cs +++ b/Octokit/Clients/GitHubAppsClient.cs @@ -11,62 +11,72 @@ namespace Octokit /// public class GitHubAppsClient : ApiClient, IGitHubAppsClient { - /// - /// Instantiates a new GitHub Apps API client. - /// - /// An API connection public GitHubAppsClient(IApiConnection apiConnection) : base(apiConnection) { } /// - /// Get a single GitHub App + /// Get a single GitHub App. /// + /// https://developer.github.com/v3/apps/#get-a-single-github-app /// The URL-friendly name of your GitHub App. You can find this on the settings page for your GitHub App. - /// The GitHub App public Task Get(string slug) { return ApiConnection.Get(ApiUrls.App(slug), null, AcceptHeaders.MachineManPreview); } /// - /// Returns the GitHub App associated with the authentication credentials used. + /// Returns the GitHub App associated with the authentication credentials used (requires GitHubApp JWT token auth). /// - /// The GitHub App associated with the authentication credentials used. + /// https://developer.github.com/v3/apps/#get-the-authenticated-github-app public Task GetCurrent() { return ApiConnection.Get(ApiUrls.App(), null, AcceptHeaders.MachineManPreview); } /// - /// Create a new installation token + /// List installations of the authenticated GitHub App (requires GitHubApp JWT token auth). /// - /// The Id of the GitHub App installation. - /// The GitHub App installation access token. - public Task CreateInstallationToken(long installationId) - { - return ApiConnection.Post(ApiUrls.AccessTokens(installationId), string.Empty, AcceptHeaders.MachineManPreview); - } - - /// - /// List installations that are accessible to the authenticated user. - /// - /// A list (read-only) that includes all the GitHub App installations accessible to the current authenticated user. + /// https://developer.github.com/v3/apps/#find-installations public Task> GetAllInstallationsForCurrent() { return ApiConnection.GetAll(ApiUrls.Installations(), null, AcceptHeaders.MachineManPreview); } /// - /// List installations that are accessible to the authenticated user. + /// List installations of the authenticated GitHub App (requires GitHubApp JWT token auth). /// - /// - /// A list (read-only) that includes all the GitHub App installations accessible to the current authenticated user. + /// Options for changing the API response + /// https://developer.github.com/v3/apps/#find-installations public Task> GetAllInstallationsForCurrent(ApiOptions options) { Ensure.ArgumentNotNull(options, nameof(options)); return ApiConnection.GetAll(ApiUrls.Installations(), null, AcceptHeaders.MachineManPreview, options); } + + /// + /// Get a single GitHub App Installation (requires GitHubApp JWT token auth). + /// + /// https://developer.github.com/v3/apps/#get-a-single-installation + /// The Id of the GitHub App Installation + public Task GetInstallation(long installationId) + { + return ApiConnection.Get(ApiUrls.Installation(installationId), null, AcceptHeaders.MachineManPreview); + } + + /// + /// Create a time bound access token for a GitHubApp Installation that can be used to access other API endpoints (requires GitHubApp JWT token auth). + /// + /// + /// https://developer.github.com/v3/apps/#create-a-new-installation-token + /// https://developer.github.com/apps/building-github-apps/authentication-options-for-github-apps/#authenticating-as-an-installation + /// https://developer.github.com/v3/apps/available-endpoints/ + /// + /// The Id of the GitHub App Installation + public Task CreateInstallationToken(long installationId) + { + return ApiConnection.Post(ApiUrls.AccessTokens(installationId), string.Empty, AcceptHeaders.MachineManPreview); + } } } \ No newline at end of file diff --git a/Octokit/Clients/IGitHubAppsClient.cs b/Octokit/Clients/IGitHubAppsClient.cs index 761be187c0..71802151f7 100644 --- a/Octokit/Clients/IGitHubAppsClient.cs +++ b/Octokit/Clients/IGitHubAppsClient.cs @@ -12,36 +12,47 @@ namespace Octokit public interface IGitHubAppsClient { /// - /// Get a single GitHub App + /// Get a single GitHub App. /// + /// https://developer.github.com/v3/apps/#get-a-single-github-app /// The URL-friendly name of your GitHub App. You can find this on the settings page for your GitHub App. - /// The GitHub App Task Get(string slug); /// - /// Returns the GitHub App associated with the authentication credentials used. + /// Returns the GitHub App associated with the authentication credentials used (requires GitHubApp JWT token auth). /// - /// The GitHub App associated with the authentication credentials used. + /// https://developer.github.com/v3/apps/#get-the-authenticated-github-app Task GetCurrent(); /// - /// Create a new installation token + /// List installations of the authenticated GitHub App (requires GitHubApp JWT token auth). /// - /// The Id of the GitHub App installation. - /// The GitHub App installation access token. - Task CreateInstallationToken(long installationId); + /// https://developer.github.com/v3/apps/#find-installations + Task> GetAllInstallationsForCurrent(); /// - /// List installations that are accessible to the authenticated user. + /// List installations of the authenticated GitHub App (requires GitHubApp JWT token auth). /// - /// A list (read-only) that includes all the GitHub App installations accessible to the current authenticated user. - Task> GetAllInstallationsForCurrent(); + /// Options for changing the API response + /// https://developer.github.com/v3/apps/#find-installations + Task> GetAllInstallationsForCurrent(ApiOptions options); /// - /// List installations that are accessible to the authenticated user. + /// Get a single GitHub App Installation (requires GitHubApp JWT token auth). /// - /// - /// A list (read-only) that includes all the GitHub App installations accessible to the current authenticated user. - Task> GetAllInstallationsForCurrent(ApiOptions options); + /// https://developer.github.com/v3/apps/#get-a-single-installation + /// The Id of the GitHub App Installation + Task GetInstallation(long installationId); + + /// + /// Create a time bound access token for a GitHubApp Installation that can be used to access other API endpoints (requires GitHubApp JWT token auth). + /// + /// + /// https://developer.github.com/v3/apps/#create-a-new-installation-token + /// https://developer.github.com/apps/building-github-apps/authentication-options-for-github-apps/#authenticating-as-an-installation + /// https://developer.github.com/v3/apps/available-endpoints/ + /// + /// The Id of the GitHub App Installation + Task CreateInstallationToken(long installationId); } } \ No newline at end of file diff --git a/Octokit/Clients/IOrganizationOutsideCollaboratorsClient.cs b/Octokit/Clients/IOrganizationOutsideCollaboratorsClient.cs index 4e5e32a0d6..1ad12ad7e3 100644 --- a/Octokit/Clients/IOrganizationOutsideCollaboratorsClient.cs +++ b/Octokit/Clients/IOrganizationOutsideCollaboratorsClient.cs @@ -3,12 +3,6 @@ namespace Octokit { - /// - /// A client for GitHub's Organization Outside Collaborators API. - /// - /// - /// See the Outside Collaborators API documentation for more information. - /// public interface IOrganizationOutsideCollaboratorsClient { /// diff --git a/Octokit/Clients/IProjectsClient.cs b/Octokit/Clients/IProjectsClient.cs index 3e75e2f35f..c3edd5ae7c 100644 --- a/Octokit/Clients/IProjectsClient.cs +++ b/Octokit/Clients/IProjectsClient.cs @@ -19,7 +19,7 @@ public interface IProjectsClient /// See the API documentation for more information. /// /// The owner of the repository - /// The name of the repository + /// The name of the repository Task> GetAllForRepository(string owner, string name); /// @@ -29,7 +29,7 @@ public interface IProjectsClient /// See the API documentation for more information. /// /// The owner of the repository - /// The name of the repository + /// The name of the repository /// Used to filter the list of projects returned Task> GetAllForRepository(string owner, string name, ProjectRequest request); @@ -59,7 +59,7 @@ public interface IProjectsClient /// See the API documentation for more information. /// /// The owner of the repository - /// The name of the repository + /// The name of the repository /// Options for changing the API response Task> GetAllForRepository(string owner, string name, ApiOptions options); @@ -70,7 +70,7 @@ public interface IProjectsClient /// See the API documentation for more information. /// /// The owner of the repository - /// The name of the repository + /// The name of the repository /// Used to filter the list of projects returned /// Options for changing the API response Task> GetAllForRepository(string owner, string name, ProjectRequest request, ApiOptions options); diff --git a/Octokit/Clients/ProjectsClient.cs b/Octokit/Clients/ProjectsClient.cs index 862ac82ccc..f21e75fcf0 100644 --- a/Octokit/Clients/ProjectsClient.cs +++ b/Octokit/Clients/ProjectsClient.cs @@ -27,7 +27,7 @@ public ProjectsClient(IApiConnection apiConnection) : /// See the API documentation for more information. /// /// The owner of the repository - /// The name of the repository + /// The name of the repository public Task> GetAllForRepository(string owner, string name) { return GetAllForRepository(owner, name, ApiOptions.None); @@ -40,7 +40,7 @@ public Task> GetAllForRepository(string owner, string nam /// See the API documentation for more information. /// /// The owner of the repository - /// The name of the repository + /// The name of the repository /// Options for changing the API response public Task> GetAllForRepository(string owner, string name, ApiOptions options) { diff --git a/Octokit/Exceptions/ApiException.cs b/Octokit/Exceptions/ApiException.cs index f5281189de..ce2c15e90a 100644 --- a/Octokit/Exceptions/ApiException.cs +++ b/Octokit/Exceptions/ApiException.cs @@ -103,9 +103,6 @@ protected ApiException(ApiError apiError, HttpStatusCode statusCode, Exception i public IResponse HttpResponse { get; private set; } - /// - /// The error message - /// public override string Message { get { return ApiErrorMessageSafe ?? "An error occurred with this API request"; } diff --git a/Octokit/Exceptions/LegalRestrictionException.cs b/Octokit/Exceptions/LegalRestrictionException.cs index 685ce4b143..d7ac60c22e 100644 --- a/Octokit/Exceptions/LegalRestrictionException.cs +++ b/Octokit/Exceptions/LegalRestrictionException.cs @@ -20,9 +20,6 @@ namespace Octokit Justification = "These exceptions are specific to the GitHub API and not general purpose exceptions")] public class LegalRestrictionException : ApiException { - /// - /// The error message - /// public override string Message { get { return ApiErrorMessageSafe ?? "Resource taken down due to a DMCA notice."; } diff --git a/Octokit/Exceptions/PrivateRepositoryQuotaExceededException.cs b/Octokit/Exceptions/PrivateRepositoryQuotaExceededException.cs index 9511a95aae..c811b1ffa3 100644 --- a/Octokit/Exceptions/PrivateRepositoryQuotaExceededException.cs +++ b/Octokit/Exceptions/PrivateRepositoryQuotaExceededException.cs @@ -26,9 +26,6 @@ public PrivateRepositoryQuotaExceededException(ApiValidationException innerExcep { } - /// - /// The error message - /// public override string Message { get diff --git a/Octokit/Exceptions/PullRequestNotMergeableException.cs b/Octokit/Exceptions/PullRequestNotMergeableException.cs index 157dfbc0f5..89ce79e158 100644 --- a/Octokit/Exceptions/PullRequestNotMergeableException.cs +++ b/Octokit/Exceptions/PullRequestNotMergeableException.cs @@ -39,9 +39,6 @@ public PullRequestNotMergeableException(IResponse response, Exception innerExcep "PullRequestNotMergeableException created with the wrong HTTP status code"); } - /// - /// The error message - /// public override string Message { //https://developer.github.com/v3/pulls/#response-if-merge-cannot-be-performed diff --git a/Octokit/Exceptions/RepositoryFormatException.cs b/Octokit/Exceptions/RepositoryFormatException.cs index c71074458b..c0ab53b515 100644 --- a/Octokit/Exceptions/RepositoryFormatException.cs +++ b/Octokit/Exceptions/RepositoryFormatException.cs @@ -27,9 +27,6 @@ public RepositoryFormatException(IEnumerable invalidRepositories) parameterList); } - /// - /// The error message - /// public override string Message { get diff --git a/Octokit/Exceptions/TwoFactorChallengeFailedException.cs b/Octokit/Exceptions/TwoFactorChallengeFailedException.cs index 59708ef82d..3e1b799f54 100644 --- a/Octokit/Exceptions/TwoFactorChallengeFailedException.cs +++ b/Octokit/Exceptions/TwoFactorChallengeFailedException.cs @@ -37,9 +37,6 @@ public TwoFactorChallengeFailedException( AuthorizationCode = authorizationCode; } - /// - /// The error message - /// public override string Message { get { return "The two-factor authentication code supplied is not correct"; } diff --git a/Octokit/Helpers/ApiUrls.cs b/Octokit/Helpers/ApiUrls.cs index a3512a06a6..a086592107 100644 --- a/Octokit/Helpers/ApiUrls.cs +++ b/Octokit/Helpers/ApiUrls.cs @@ -328,7 +328,7 @@ public static Uri Installations() /// Returns the that returns a single installation of the authenticated application. /// /// - public static Uri Installation(int installationId) + public static Uri Installation(long installationId) { return "app/installations/{0}".FormatUri(installationId); } diff --git a/Octokit/Http/ReadOnlyPagedCollection.cs b/Octokit/Http/ReadOnlyPagedCollection.cs index c75c76b28b..520f107b33 100644 --- a/Octokit/Http/ReadOnlyPagedCollection.cs +++ b/Octokit/Http/ReadOnlyPagedCollection.cs @@ -13,8 +13,8 @@ public class ReadOnlyPagedCollection : ReadOnlyCollection, IReadOnlyPagedC public ReadOnlyPagedCollection(IApiResponse> response, Func>>> nextPageFunc) : base(response != null ? response.Body ?? new List() : new List()) { - Ensure.ArgumentNotNull(response, nameof(response)); - Ensure.ArgumentNotNull(nextPageFunc, nameof(nextPageFunc)); + Ensure.ArgumentNotNull(response, "response"); + Ensure.ArgumentNotNull(nextPageFunc, "nextPageFunc"); _nextPageFunc = nextPageFunc; if (response != null) diff --git a/Octokit/Models/Request/PullRequestReviewSubmit.cs b/Octokit/Models/Request/PullRequestReviewSubmit.cs index c3019a1823..99a136a61b 100644 --- a/Octokit/Models/Request/PullRequestReviewSubmit.cs +++ b/Octokit/Models/Request/PullRequestReviewSubmit.cs @@ -1,6 +1,7 @@ using System.Diagnostics; using System.Globalization; using Octokit.Internal; +using System.Collections.Generic; namespace Octokit { @@ -10,9 +11,6 @@ namespace Octokit [DebuggerDisplay("{DebuggerDisplay,nq}")] public class PullRequestReviewSubmit : RequestParameters { - /// - /// Initializes a new empty Pull Request Review. - /// public PullRequestReviewSubmit() { } diff --git a/Octokit/Models/Response/AccessToken.cs b/Octokit/Models/Response/AccessToken.cs index 319eb3351c..182a555322 100644 --- a/Octokit/Models/Response/AccessToken.cs +++ b/Octokit/Models/Response/AccessToken.cs @@ -9,14 +9,21 @@ public class AccessToken { public AccessToken() { } - public AccessToken(string token, DateTime expiresAt) + public AccessToken(string token, DateTimeOffset expiresAt) { Token = token; ExpiresAt = expiresAt; } + /// + /// The access token + /// public string Token { get; protected set; } - public DateTime ExpiresAt { get; protected set; } + + /// + /// The expiration date + /// + public DateTimeOffset ExpiresAt { get; protected set; } internal string DebuggerDisplay { diff --git a/Octokit/Models/Response/ActivityPayloads/StatusEventPayload.cs b/Octokit/Models/Response/ActivityPayloads/StatusEventPayload.cs index 78e08c7029..1c8d3db1a6 100644 --- a/Octokit/Models/Response/ActivityPayloads/StatusEventPayload.cs +++ b/Octokit/Models/Response/ActivityPayloads/StatusEventPayload.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using System.Diagnostics; -using System.Globalization; namespace Octokit { @@ -68,13 +67,5 @@ public class StatusEventPayload : ActivityPayload /// The branches involved. /// public IReadOnlyList Branches { get; protected set; } - - internal new string DebuggerDisplay - { - get - { - return string.Format(CultureInfo.InvariantCulture, "Context: {0}, State: {1}, Description: {2}", Context, State, Description); - } - } } } diff --git a/Octokit/Models/Response/Commit.cs b/Octokit/Models/Response/Commit.cs index 7d85fbc3f8..7023193790 100644 --- a/Octokit/Models/Response/Commit.cs +++ b/Octokit/Models/Response/Commit.cs @@ -13,7 +13,7 @@ public Commit() { } public Commit(string url, string label, string @ref, string sha, User user, Repository repository, string message, Committer author, Committer committer, GitReference tree, IEnumerable parents, int commentCount) : base(url, label, @ref, sha, user, repository) { - Ensure.ArgumentNotNull(parents, nameof(parents)); + Ensure.ArgumentNotNull(parents, "parents"); Message = message; Author = author; From 1b48ce4e7a8540c8b7b8bd26d3124411ff6ad374 Mon Sep 17 00:00:00 2001 From: Ryan Gribble Date: Wed, 7 Mar 2018 21:58:42 +1000 Subject: [PATCH 40/84] add XmlDoc comments to response models and flesh out installation permissions --- Octokit/Models/Response/GitHubApp.cs | 38 +++++- Octokit/Models/Response/Installation.cs | 61 +++++++-- .../Response/InstallationPermissions.cs | 121 ++++++++++++++++++ Octokit/Models/Response/Permissions.cs | 19 --- 4 files changed, 206 insertions(+), 33 deletions(-) create mode 100644 Octokit/Models/Response/InstallationPermissions.cs delete mode 100644 Octokit/Models/Response/Permissions.cs diff --git a/Octokit/Models/Response/GitHubApp.cs b/Octokit/Models/Response/GitHubApp.cs index 54197ec3b3..b96efa82db 100644 --- a/Octokit/Models/Response/GitHubApp.cs +++ b/Octokit/Models/Response/GitHubApp.cs @@ -10,28 +10,58 @@ namespace Octokit [DebuggerDisplay("{DebuggerDisplay,nq}")] public class GitHubApp { - /// - /// Initialize a new empty GitHubApp object ready for deserialization. - /// public GitHubApp() { } + public GitHubApp(long id, string name, User owner, string description, string externalUrl, string htmlUrl, DateTimeOffset createdAt, DateTimeOffset updatedAt) + { + Id = id; + Name = name; + Owner = owner; + Description = description; + ExternalUrl = externalUrl; + HtmlUrl = htmlUrl; + CreatedAt = createdAt; + UpdatedAt = updatedAt; + } + /// - /// The GitHubApp Id. Should be the same as in the GitHubApp -> Settings -> About page. + /// The Id of the GitHub App. /// public long Id { get; protected set; } + /// + /// The Name of the GitHub App. + /// public string Name { get; protected set; } + /// + /// The Owner of the GitHub App. + /// public User Owner { get; protected set; } + /// + /// The Description of the GitHub App. + /// public string Description { get; protected set; } + /// + /// The URL to the GitHub App's external website. + /// public string ExternalUrl { get; protected set; } + /// + /// The URL to view the GitHub App on GitHub + /// public string HtmlUrl { get; protected set; } + /// + /// Date the GitHub App was created. + /// public DateTimeOffset CreatedAt { get; protected set; } + /// + /// Date the GitHub App was last updated. + /// public DateTimeOffset UpdatedAt { get; protected set; } internal string DebuggerDisplay diff --git a/Octokit/Models/Response/Installation.cs b/Octokit/Models/Response/Installation.cs index 65dc01392d..80118a8681 100644 --- a/Octokit/Models/Response/Installation.cs +++ b/Octokit/Models/Response/Installation.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using System.Diagnostics; using System.Globalization; +using Octokit.Internal; namespace Octokit { @@ -15,42 +16,82 @@ public class Installation { public Installation() { } - public Installation(long id, User account, - string accessTokenUrl, string repositoriesUrl, string htmlUrl, - long appId, long targetId, AccountType targetType, - string singleFileName, string repositorySelection) + public Installation(long id, User account, string accessTokenUrl, string repositoriesUrl, string htmlUrl, long appId, long targetId, AccountType targetType, InstallationPermissions permissions, IReadOnlyList events, string singleFileName, string repositorySelection) { Id = id; Account = account; - AccessTokensUrl = accessTokenUrl; - RepositoriesUrl = repositoriesUrl; HtmlUrl = htmlUrl; AppId = appId; TargetId = targetId; TargetType = targetType; + Permissions = permissions; + Events = events; SingleFileName = singleFileName; RepositorySelection = repositorySelection; } + /// + /// The Installation Id. + /// public long Id { get; protected set; } + + /// + /// The Account associated with the Installation. + /// public User Account { get; protected set; } - public string AccessTokensUrl { get; protected set; } - public string RepositoriesUrl { get; protected set; } + + /// + /// The URL to view the Installation on GitHub. + /// public string HtmlUrl { get; protected set; } + /// + /// The Id of the associated GitHub App. + /// public long AppId { get; protected set; } + + /// + /// The Id of the target user/organization + /// public long TargetId { get; protected set; } + + /// + /// The type of the target (User or Organization) + /// public StringEnum TargetType { get; protected set; } - public Permissions Permissions { get; private set; } + /// + /// The Permissions granted to the Installation + /// + public InstallationPermissions Permissions { get; private set; } + + /// + /// The Events subscribed to by the Installation + /// public IReadOnlyList Events { get; private set; } + /// + /// The single file the GitHub App can managem (when Permissions.SingleFile is set to read or write) + /// public string SingleFileName { get; protected set; } - public string RepositorySelection { get; protected set; } + + /// + /// The choice of repositories the installation is on. Can be either "selected" or "all". + /// + public StringEnum RepositorySelection { get; protected set; } internal string DebuggerDisplay { get { return string.Format(CultureInfo.InvariantCulture, "Installation Id: {0} ; App Id: {1}", Id, AppId); } } } + + public enum InstallationRepositorySelection + { + [Parameter(Value = "all")] + All, + + [Parameter(Value = "selected")] + Selected + } } diff --git a/Octokit/Models/Response/InstallationPermissions.cs b/Octokit/Models/Response/InstallationPermissions.cs new file mode 100644 index 0000000000..6aa0d548df --- /dev/null +++ b/Octokit/Models/Response/InstallationPermissions.cs @@ -0,0 +1,121 @@ +using System.Diagnostics; +using System.Globalization; +using Octokit.Internal; + +namespace Octokit +{ + [DebuggerDisplay("{DebuggerDisplay,nq}")] + public class InstallationPermissions + { + public InstallationPermissions() { } + + public InstallationPermissions(InstallationPermissionLevel? metadata, InstallationPermissionLevel? administration, InstallationPermissionLevel? statuses, InstallationPermissionLevel? deployments, InstallationPermissionLevel? issues, InstallationPermissionLevel? pages, InstallationPermissionLevel? pullRequests, InstallationPermissionLevel? contents, InstallationPermissionLevel? singleFile, InstallationPermissionLevel? repositoryProjects, InstallationPermissionLevel? members, InstallationPermissionLevel? organizationProjects, InstallationPermissionLevel? teamDiscussions) + { + Metadata = metadata; + Administration = administration; + Statuses = statuses; + Deployments = deployments; + Issues = issues; + Pages = pages; + PullRequests = pullRequests; + Contents = contents; + SingleFile = singleFile; + RepositoryProjects = repositoryProjects; + Members = members; + OrganizationProjects = organizationProjects; + TeamDiscussions = teamDiscussions; + } + + /// + /// Repository metadata + /// Search repositories, list collaborators, and access repository metadata. + /// + public StringEnum? Metadata { get; protected set; } + + /// + /// Repository administration + /// Repository creation, deletion, settings, teams, and collaborators. + /// + public StringEnum? Administration { get; protected set; } + + /// + /// Commit statuses + /// Commit statuses. + /// + public StringEnum? Statuses { get; protected set; } + + /// + /// Deployments + /// Deployments and deployment statuses. + /// + public StringEnum? Deployments { get; protected set; } + + /// + /// Issues + /// Issues and related comments, assignees, labels, and milestones. + /// + public StringEnum? Issues { get; protected set; } + + /// + /// Pages + /// Retrieve Pages statuses, configuration, and builds, as well as create new builds. + /// + public StringEnum? Pages { get; protected set; } + + /// + /// Pull requests + /// Pull requests and related comments, assignees, labels, milestones, and merges. + /// + public StringEnum? PullRequests { get; protected set; } + + /// + /// Repository contents + /// Repository contents, commits, branches, downloads, releases, and merges. + /// + public StringEnum? Contents { get; protected set; } + + /// + /// Single file + /// Manage just a single file. + /// + public StringEnum? SingleFile { get; protected set; } + + /// + /// Repository projects + /// Manage repository projects, columns, and cards. + /// + public StringEnum? RepositoryProjects { get; protected set; } + + /// + /// Organization members (only applicable when installed for an Organization ) + /// Organization members and teams. + /// + public StringEnum? Members { get; protected set; } + + /// + /// Organization projects (only applicable when installed for an Organization ) + /// Manage organization projects, columns, and cards. + /// + public StringEnum? OrganizationProjects { get; protected set; } + + /// + /// Team discussions (only applicable when installed for an Organization ) + /// Team discussions. + /// + public StringEnum? TeamDiscussions { get; protected set; } + + internal string DebuggerDisplay + { + get { return string.Format(CultureInfo.InvariantCulture, "Metadata: {0}, Contents: {1}, Issues: {2}, Single File: {3}", Metadata, Contents, Issues, SingleFile); } + } + } + + public enum InstallationPermissionLevel + { + [Parameter(Value = "read")] + Read, + + [Parameter(Value = "write")] + Write + } +} \ No newline at end of file diff --git a/Octokit/Models/Response/Permissions.cs b/Octokit/Models/Response/Permissions.cs deleted file mode 100644 index 5a3b62218a..0000000000 --- a/Octokit/Models/Response/Permissions.cs +++ /dev/null @@ -1,19 +0,0 @@ -using System.Diagnostics; -using System.Globalization; - -namespace Octokit -{ - [DebuggerDisplay("{DebuggerDisplay,nq}")] - public class Permissions - { - public StringEnum Metadata { get; protected set; } - public StringEnum Contents { get; protected set; } - public StringEnum Issues { get; protected set; } - public StringEnum SingleFile { get; protected set; } - - internal string DebuggerDisplay - { - get { return string.Format(CultureInfo.InvariantCulture, "Metadata: {0}, Contents: {1}, Issues: {2}, Single File: {3}", Metadata, Contents, Issues, SingleFile); } - } - } -} \ No newline at end of file From d590250051e8f25d5ef08ad74e562cff0babe93e Mon Sep 17 00:00:00 2001 From: Ryan Gribble Date: Wed, 7 Mar 2018 21:59:42 +1000 Subject: [PATCH 41/84] name AcceptHeaders member consistently --- .../Clients/ObservableGitHubAppsClient.cs | 4 ++-- Octokit/Clients/GitHubAppsClient.cs | 12 ++++++------ Octokit/Helpers/AcceptHeaders.cs | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Octokit.Reactive/Clients/ObservableGitHubAppsClient.cs b/Octokit.Reactive/Clients/ObservableGitHubAppsClient.cs index 8621b5b34b..6e52d53803 100644 --- a/Octokit.Reactive/Clients/ObservableGitHubAppsClient.cs +++ b/Octokit.Reactive/Clients/ObservableGitHubAppsClient.cs @@ -43,7 +43,7 @@ public IObservable GetCurrent() /// https://developer.github.com/v3/apps/#find-installations public IObservable GetAllInstallationsForCurrent() { - return _connection.GetAndFlattenAllPages(ApiUrls.Installations(), null, AcceptHeaders.MachineManPreview); + return _connection.GetAndFlattenAllPages(ApiUrls.Installations(), null, AcceptHeaders.GitHubAppsPreview); } /// @@ -55,7 +55,7 @@ public IObservable GetAllInstallationsForCurrent(ApiOptions option { Ensure.ArgumentNotNull(options, nameof(options)); - return _connection.GetAndFlattenAllPages(ApiUrls.Installations(), null, AcceptHeaders.MachineManPreview, options); + return _connection.GetAndFlattenAllPages(ApiUrls.Installations(), null, AcceptHeaders.GitHubAppsPreview, options); } /// diff --git a/Octokit/Clients/GitHubAppsClient.cs b/Octokit/Clients/GitHubAppsClient.cs index 708ff69281..0a865fb1b7 100644 --- a/Octokit/Clients/GitHubAppsClient.cs +++ b/Octokit/Clients/GitHubAppsClient.cs @@ -22,7 +22,7 @@ public GitHubAppsClient(IApiConnection apiConnection) : base(apiConnection) /// The URL-friendly name of your GitHub App. You can find this on the settings page for your GitHub App. public Task Get(string slug) { - return ApiConnection.Get(ApiUrls.App(slug), null, AcceptHeaders.MachineManPreview); + return ApiConnection.Get(ApiUrls.App(slug), null, AcceptHeaders.GitHubAppsPreview); } /// @@ -31,7 +31,7 @@ public Task Get(string slug) /// https://developer.github.com/v3/apps/#get-the-authenticated-github-app public Task GetCurrent() { - return ApiConnection.Get(ApiUrls.App(), null, AcceptHeaders.MachineManPreview); + return ApiConnection.Get(ApiUrls.App(), null, AcceptHeaders.GitHubAppsPreview); } /// @@ -40,7 +40,7 @@ public Task GetCurrent() /// https://developer.github.com/v3/apps/#find-installations public Task> GetAllInstallationsForCurrent() { - return ApiConnection.GetAll(ApiUrls.Installations(), null, AcceptHeaders.MachineManPreview); + return ApiConnection.GetAll(ApiUrls.Installations(), null, AcceptHeaders.GitHubAppsPreview); } /// @@ -52,7 +52,7 @@ public Task> GetAllInstallationsForCurrent(ApiOption { Ensure.ArgumentNotNull(options, nameof(options)); - return ApiConnection.GetAll(ApiUrls.Installations(), null, AcceptHeaders.MachineManPreview, options); + return ApiConnection.GetAll(ApiUrls.Installations(), null, AcceptHeaders.GitHubAppsPreview, options); } /// @@ -62,7 +62,7 @@ public Task> GetAllInstallationsForCurrent(ApiOption /// The Id of the GitHub App Installation public Task GetInstallation(long installationId) { - return ApiConnection.Get(ApiUrls.Installation(installationId), null, AcceptHeaders.MachineManPreview); + return ApiConnection.Get(ApiUrls.Installation(installationId), null, AcceptHeaders.GitHubAppsPreview); } /// @@ -76,7 +76,7 @@ public Task GetInstallation(long installationId) /// The Id of the GitHub App Installation public Task CreateInstallationToken(long installationId) { - return ApiConnection.Post(ApiUrls.AccessTokens(installationId), string.Empty, AcceptHeaders.MachineManPreview); + return ApiConnection.Post(ApiUrls.AccessTokens(installationId), string.Empty, AcceptHeaders.GitHubAppsPreview); } } } \ No newline at end of file diff --git a/Octokit/Helpers/AcceptHeaders.cs b/Octokit/Helpers/AcceptHeaders.cs index 3b1a95b229..e8389ee76a 100644 --- a/Octokit/Helpers/AcceptHeaders.cs +++ b/Octokit/Helpers/AcceptHeaders.cs @@ -55,7 +55,7 @@ public static class AcceptHeaders public const string NestedTeamsPreview = "application/vnd.github.hellcat-preview+json"; - public const string MachineManPreview = "application/vnd.github.machine-man-preview+json"; + public const string GitHubAppsPreview = "application/vnd.github.machine-man-preview+json"; /// /// Combines multiple preview headers. GitHub API supports Accept header with multiple From 3ccfd42ccb4368dd03e67c40b29d82e10b3ed658 Mon Sep 17 00:00:00 2001 From: Ryan Gribble Date: Wed, 7 Mar 2018 22:40:45 +1000 Subject: [PATCH 42/84] accidentally lost changes to Credentials.cs --- Octokit/Http/Credentials.cs | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/Octokit/Http/Credentials.cs b/Octokit/Http/Credentials.cs index dbf014a121..14a45d61ba 100644 --- a/Octokit/Http/Credentials.cs +++ b/Octokit/Http/Credentials.cs @@ -13,23 +13,27 @@ private Credentials() AuthenticationType = AuthenticationType.Anonymous; } - public Credentials(string token) - { - Ensure.ArgumentNotNullOrEmptyString(token, nameof(token)); + public Credentials(string login, string password) : this(login, password, AuthenticationType.Basic) { } - Login = null; - Password = token; - AuthenticationType = AuthenticationType.Oauth; - } - - public Credentials(string login, string password) + public Credentials(string login, string password, AuthenticationType authenticationType) { Ensure.ArgumentNotNullOrEmptyString(login, nameof(login)); Ensure.ArgumentNotNullOrEmptyString(password, nameof(password)); Login = login; Password = password; - AuthenticationType = AuthenticationType.Basic; + AuthenticationType = authenticationType; + } + + public Credentials(string token) : this(token, AuthenticationType.Oauth) { } + + public Credentials(string token, AuthenticationType authenticationType) + { + Ensure.ArgumentNotNullOrEmptyString(token, nameof(token)); + + Login = null; + Password = token; + AuthenticationType = authenticationType; } public string Login From 9beec577ff516bd651ecac2f61f59baa7357bd82 Mon Sep 17 00:00:00 2001 From: Ryan Gribble Date: Wed, 7 Mar 2018 23:16:32 +1000 Subject: [PATCH 43/84] Enhance Intergation test framework to handle GitHubApp settings and discoer tests appropriately Get code ready for GitHubJWT nuget package but for now just hardcode a JWT in ENV VAR Add 1 integration test for each method and ensure they are working! --- .../Clients/GitHubAppsClientTests.cs | 104 +++++++++++++++--- Octokit.Tests.Integration/Helper.cs | 53 +++++++++ .../Helpers/GitHubAppsTestAttribute.cs | 46 ++++++++ Octokit/Models/Response/Installation.cs | 4 +- script/configure-integration-tests.ps1 | 6 + 5 files changed, 194 insertions(+), 19 deletions(-) create mode 100644 Octokit.Tests.Integration/Helpers/GitHubAppsTestAttribute.cs diff --git a/Octokit.Tests.Integration/Clients/GitHubAppsClientTests.cs b/Octokit.Tests.Integration/Clients/GitHubAppsClientTests.cs index b50b778205..79113beda8 100644 --- a/Octokit.Tests.Integration/Clients/GitHubAppsClientTests.cs +++ b/Octokit.Tests.Integration/Clients/GitHubAppsClientTests.cs @@ -1,5 +1,6 @@ using Octokit.Tests.Integration.Helpers; using System; +using System.Linq; using System.Threading.Tasks; using Xunit; @@ -13,47 +14,116 @@ public class TheGetMethod public TheGetMethod() { + // Regular authentication _github = Helper.GetAuthenticatedClient(); } - [IntegrationTest] + [GitHubAppsTest] public async Task GetsApp() { - var result = await _github.GitHubApps.Get("MyGitHub"); + var result = await _github.GitHubApps.Get(Helper.GitHubAppSlug); - Assert.Equal("MyGitHub", result.Name); + Assert.Equal(Helper.GitHubAppId, result.Id); + Assert.False(string.IsNullOrEmpty(result.Name)); + Assert.NotNull(result.Owner); } } - public class TheGetAllInstallationsForCurrentMethod : IDisposable + public class TheGetCurrentMethod { IGitHubClient _github; - RepositoryContext _context; - public TheGetAllInstallationsForCurrentMethod() + public TheGetCurrentMethod() { - _github = Helper.GetAuthenticatedClient(); - var repoName = Helper.MakeNameWithTimestamp("public-repo"); + // Authenticate as a GitHubApp + _github = Helper.GetAuthenticatedGitHubAppsClient(); + } + + [GitHubAppsTest] + public async Task GetsCurrentApp() + { + var result = await _github.GitHubApps.GetCurrent(); + + Assert.Equal(Helper.GitHubAppId, result.Id); + Assert.False(string.IsNullOrEmpty(result.Name)); + Assert.NotNull(result.Owner); + } + } - _context = _github.CreateRepositoryContext(new NewRepository(repoName)).Result; + public class TheGetAllInstallationsForCurrentMethod + { + IGitHubClient _github; + + public TheGetAllInstallationsForCurrentMethod() + { + // Authenticate as a GitHubApp + _github = Helper.GetAuthenticatedGitHubAppsClient(); } - [IntegrationTest] + [GitHubAppsTest] public async Task GetsAllInstallations() { var result = await _github.GitHubApps.GetAllInstallationsForCurrent(); - // TODO - find a way to run this test, and see the results. + Assert.True(result.Any(x => x.Id == Helper.GitHubAppInstallationId)); + foreach (var installation in result) + { + Assert.Equal(Helper.GitHubAppId, installation.AppId); + Assert.NotNull(installation.Account); + Assert.NotNull(installation.Permissions); + Assert.Equal(InstallationPermissionLevel.Read, installation.Permissions.Metadata); + Assert.False(string.IsNullOrEmpty(installation.HtmlUrl)); + Assert.NotEqual(0, installation.TargetId); + } + } + } + + public class TheGetInstallationMethod + { + IGitHubClient _github; + + public TheGetInstallationMethod() + { + // Authenticate as a GitHubApp + _github = Helper.GetAuthenticatedGitHubAppsClient(); + } + + [GitHubAppsTest] + public async Task GetsInstallation() + { + var installationId = Helper.GitHubAppInstallationId; + + var result = await _github.GitHubApps.GetInstallation(installationId); + + Assert.True(result.AppId == Helper.GitHubAppId); + Assert.Equal(Helper.GitHubAppId, result.AppId); + Assert.NotNull(result.Account); + Assert.NotNull(result.Permissions); + Assert.Equal(InstallationPermissionLevel.Read, result.Permissions.Metadata); + Assert.False(string.IsNullOrEmpty(result.HtmlUrl)); + Assert.NotEqual(0, result.TargetId); + } + } + + public class TheCreateInstallationTokenMethod + { + IGitHubClient _github; - //Assert.Equal(2, result.Count); - //Assert.True(result.FirstOrDefault(x => x.Id == card1.Id).Id == card1.Id); - //Assert.True(result.FirstOrDefault(x => x.Id == card2.Id).Id == card2.Id); + public TheCreateInstallationTokenMethod() + { + // Authenticate as a GitHubApp + _github = Helper.GetAuthenticatedGitHubAppsClient(); } - public void Dispose() + [GitHubAppsTest] + public async Task GetsInstallation() { - if (_context != null) - _context.Dispose(); + var installationId = Helper.GitHubAppInstallationId; + + var result = await _github.GitHubApps.CreateInstallationToken(installationId); + + Assert.NotNull(result.Token); + Assert.True(DateTimeOffset.Now < result.ExpiresAt); } } } diff --git a/Octokit.Tests.Integration/Helper.cs b/Octokit.Tests.Integration/Helper.cs index a18fabca8c..39a87d7ded 100644 --- a/Octokit.Tests.Integration/Helper.cs +++ b/Octokit.Tests.Integration/Helper.cs @@ -64,6 +64,32 @@ public static class Helper return new Credentials(githubUsername, githubPassword); }); + static readonly Lazy _gitHubAppsEnabled = new Lazy(() => + { + string enabled = Environment.GetEnvironmentVariable("OCTOKIT_GITHUBAPP_ENABLED"); + return !String.IsNullOrWhiteSpace(enabled); + }); + + static readonly Lazy _githubAppCredentials = new Lazy(() => + { +#if GITHUBJWT + var generator = new GitHubJwt.GitHubJwtFactory( + new GitHubJwt.FilePrivateKeySource(@"C:\Users\scarecrow420\Downloads\ryangribble-test2-app.2018-03-06.private-key.pem"), + new GitHubJwt.GitHubJwtFactoryOptions + { + AppIntegrationId = GitHubAppId, + ExpirationSeconds = 600 + } + ); + + var jwtToken = generator.CreateEncodedJwtToken(); +#else + // Until we can get GitHubJWT nuget package in, hardcode a JWT value via ENV VAR (painful since they can only last 10 minutes!) + var jwtToken = Environment.GetEnvironmentVariable("OCTOKIT_GITHUBAPP_JWT"); +#endif + return new Credentials(jwtToken, AuthenticationType.Bearer); + }); + static readonly Lazy _customUrl = new Lazy(() => { string uri = Environment.GetEnvironmentVariable("OCTOKIT_CUSTOMURL"); @@ -96,6 +122,8 @@ static Helper() public static Credentials BasicAuthCredentials { get { return _basicAuthCredentials.Value; } } + public static Credentials GitHubAppCredentials { get { return _githubAppCredentials.Value; } } + public static Uri CustomUrl { get { return _customUrl.Value; } } public static Uri TargetUrl { get { return CustomUrl ?? GitHubClient.GitHubApiUrl; } } @@ -126,6 +154,21 @@ public static string ClientSecret get { return Environment.GetEnvironmentVariable("OCTOKIT_CLIENTSECRET"); } } + public static long GitHubAppId + { + get { return Convert.ToInt64(Environment.GetEnvironmentVariable("OCTOKIT_GITHUBAPP_ID")); } + } + + public static string GitHubAppSlug + { + get { return Environment.GetEnvironmentVariable("OCTOKIT_GITHUBAPP_SLUG"); } + } + + public static long GitHubAppInstallationId + { + get { return Convert.ToInt64(Environment.GetEnvironmentVariable("OCTOKIT_GITHUBAPP_INSTALLATIONID")); } + } + public static void DeleteRepo(IConnection connection, Repository repository) { if (repository != null) @@ -244,6 +287,16 @@ public static IGitHubClient GetBadCredentialsClient() }; } + public static bool IsGitHubAppsEnabled { get { return _gitHubAppsEnabled.Value; } } + + public static GitHubClient GetAuthenticatedGitHubAppsClient() + { + return new GitHubClient(new ProductHeaderValue("OctokitTests"), TargetUrl) + { + Credentials = GitHubAppCredentials + }; + } + public static void DeleteInvitations(IConnection connection, List invitees, int teamId) { try diff --git a/Octokit.Tests.Integration/Helpers/GitHubAppsTestAttribute.cs b/Octokit.Tests.Integration/Helpers/GitHubAppsTestAttribute.cs new file mode 100644 index 0000000000..cdecf74ac7 --- /dev/null +++ b/Octokit.Tests.Integration/Helpers/GitHubAppsTestAttribute.cs @@ -0,0 +1,46 @@ +using System.Collections.Generic; +using System.Linq; +using Xunit; +using Xunit.Abstractions; +using Xunit.Sdk; + +namespace Octokit.Tests.Integration +{ + public class GitHubAppsTestDiscoverer : IXunitTestCaseDiscoverer + { + readonly IMessageSink diagnosticMessageSink; + + public GitHubAppsTestDiscoverer(IMessageSink diagnosticMessageSink) + { + this.diagnosticMessageSink = diagnosticMessageSink; + } + + public IEnumerable Discover(ITestFrameworkDiscoveryOptions discoveryOptions, ITestMethod testMethod, IAttributeInfo factAttribute) + { + if (!Helper.IsGitHubAppsEnabled) + return Enumerable.Empty(); + + Credentials creds = null; + try + { + // Make sure we can generate GitHub App credentials + creds = Helper.GitHubAppCredentials; + } + catch + { + } + + if (creds == null) + { + return Enumerable.Empty(); + } + + return new[] { new XunitTestCase(diagnosticMessageSink, discoveryOptions.MethodDisplayOrDefault(), testMethod) }; + } + } + + [XunitTestCaseDiscoverer("Octokit.Tests.Integration.GitHubAppsTestDiscoverer", "Octokit.Tests.Integration")] + public class GitHubAppsTestAttribute : FactAttribute + { + } +} \ No newline at end of file diff --git a/Octokit/Models/Response/Installation.cs b/Octokit/Models/Response/Installation.cs index 80118a8681..03f61564fa 100644 --- a/Octokit/Models/Response/Installation.cs +++ b/Octokit/Models/Response/Installation.cs @@ -36,7 +36,7 @@ public Installation(long id, User account, string accessTokenUrl, string reposit public long Id { get; protected set; } /// - /// The Account associated with the Installation. + /// The user who owns the Installation. /// public User Account { get; protected set; } @@ -51,7 +51,7 @@ public Installation(long id, User account, string accessTokenUrl, string reposit public long AppId { get; protected set; } /// - /// The Id of the target user/organization + /// The Id of the User/Organization the Installation is installed in /// public long TargetId { get; protected set; } diff --git a/script/configure-integration-tests.ps1 b/script/configure-integration-tests.ps1 index a8b2f42a27..ccc873bf9a 100644 --- a/script/configure-integration-tests.ps1 +++ b/script/configure-integration-tests.ps1 @@ -98,6 +98,12 @@ VerifyEnvironmentVariable "Override GitHub URL" "OCTOKIT_CUSTOMURL" $true VerifyEnvironmentVariable "application ClientID" "OCTOKIT_CLIENTID" $true VerifyEnvironmentVariable "application Secret" "OCTOKIT_CLIENTSECRET" $true +if (AskYesNoQuestion "Do you wish to setup GitHubApps integration test settings?" "OCTOKIT_GITHUBAPP_ENABLED") +{ + VerifyEnvironmentVariable "GitHub App ID" "OCTOKIT_GITHUBAPP_ID" + VerifyEnvironmentVariable "GitHub App SLUG" "OCTOKIT_GITHUBAPP_SLUG" + VerifyEnvironmentVariable "GitHub App Installation ID" "OCTOKIT_GITHUBAPP_INSTALLATIONID" +} if (AskYesNoQuestion "Do you wish to enable GitHub Enterprise (GHE) Integration Tests?" "OCTOKIT_GHE_ENABLED") { From 6e7a3ae5b71bbcc01641f9e5b06aaac0c7100227 Mon Sep 17 00:00:00 2001 From: Itai Bar-Haim Date: Mon, 12 Mar 2018 08:56:25 +0200 Subject: [PATCH 44/84] fixed compiler warnings. --- Octokit.Reactive/Clients/IObservableProjectsClient.cs | 8 ++++---- .../Clients/IObservablePullRequestReviewsClient.cs | 2 ++ .../Exception/InvalidUrlPropertyTypeException.cs | 2 +- Octokit/Clients/IProjectsClient.cs | 8 ++++---- Octokit/Clients/ProjectsClient.cs | 4 ++-- 5 files changed, 13 insertions(+), 11 deletions(-) diff --git a/Octokit.Reactive/Clients/IObservableProjectsClient.cs b/Octokit.Reactive/Clients/IObservableProjectsClient.cs index dea4dca868..2172e0868f 100644 --- a/Octokit.Reactive/Clients/IObservableProjectsClient.cs +++ b/Octokit.Reactive/Clients/IObservableProjectsClient.cs @@ -18,7 +18,7 @@ public interface IObservableProjectsClient /// See the API documentation for more information. /// /// The owner of the repository - /// The name of the repository + /// The name of the repository IObservable GetAllForRepository(string owner, string name); /// @@ -28,7 +28,7 @@ public interface IObservableProjectsClient /// See the API documentation for more information. /// /// The owner of the repository - /// The name of the repository + /// The name of the repository /// Used to filter the list of projects returned IObservable GetAllForRepository(string owner, string name, ProjectRequest request); @@ -58,7 +58,7 @@ public interface IObservableProjectsClient /// See the API documentation for more information. /// /// The owner of the repository - /// The name of the repository + /// The name of the repository /// Options for changing the API response IObservable GetAllForRepository(string owner, string name, ApiOptions options); @@ -69,7 +69,7 @@ public interface IObservableProjectsClient /// See the API documentation for more information. /// /// The owner of the repository - /// The name of the repository + /// The name of the repository /// Used to filter the list of projects returned /// Options for changing the API response IObservable GetAllForRepository(string owner, string name, ProjectRequest request, ApiOptions options); diff --git a/Octokit.Reactive/Clients/IObservablePullRequestReviewsClient.cs b/Octokit.Reactive/Clients/IObservablePullRequestReviewsClient.cs index 92a2b17ade..607d224f19 100644 --- a/Octokit.Reactive/Clients/IObservablePullRequestReviewsClient.cs +++ b/Octokit.Reactive/Clients/IObservablePullRequestReviewsClient.cs @@ -173,6 +173,7 @@ public interface IObservablePullRequestReviewsClient /// The name of the repository /// The pull request number /// The pull request review number + /// Options for changing the API response IObservable GetAllComments(string owner, string name, int number, long reviewId, ApiOptions options); /// @@ -182,6 +183,7 @@ public interface IObservablePullRequestReviewsClient /// The Id of the repository /// The pull request number /// The pull request review number + /// Options for changing the API response IObservable GetAllComments(long repositoryId, int number, long reviewId, ApiOptions options); } } diff --git a/Octokit.Tests.Conventions/Exception/InvalidUrlPropertyTypeException.cs b/Octokit.Tests.Conventions/Exception/InvalidUrlPropertyTypeException.cs index b3a091a1cc..b0e9410909 100644 --- a/Octokit.Tests.Conventions/Exception/InvalidUrlPropertyTypeException.cs +++ b/Octokit.Tests.Conventions/Exception/InvalidUrlPropertyTypeException.cs @@ -13,7 +13,7 @@ public InvalidUrlPropertyTypeException(Type modelType, IEnumerable static string CreateMessage(Type modelType, IEnumerable propertiesWithInvalidType) { - return string.Format("Model type '{0}' contains the following properties that are named or suffixed with 'Url' but are not of type String: {!}{2}", + return string.Format("Model type '{0}' contains the following properties that are named or suffixed with 'Url' but are not of type String: {1}{2}", modelType.FullName, Environment.NewLine, string.Join(Environment.NewLine, propertiesWithInvalidType.Select(x => x.Name))); diff --git a/Octokit/Clients/IProjectsClient.cs b/Octokit/Clients/IProjectsClient.cs index c3edd5ae7c..3e75e2f35f 100644 --- a/Octokit/Clients/IProjectsClient.cs +++ b/Octokit/Clients/IProjectsClient.cs @@ -19,7 +19,7 @@ public interface IProjectsClient /// See the API documentation for more information. /// /// The owner of the repository - /// The name of the repository + /// The name of the repository Task> GetAllForRepository(string owner, string name); /// @@ -29,7 +29,7 @@ public interface IProjectsClient /// See the API documentation for more information. /// /// The owner of the repository - /// The name of the repository + /// The name of the repository /// Used to filter the list of projects returned Task> GetAllForRepository(string owner, string name, ProjectRequest request); @@ -59,7 +59,7 @@ public interface IProjectsClient /// See the API documentation for more information. /// /// The owner of the repository - /// The name of the repository + /// The name of the repository /// Options for changing the API response Task> GetAllForRepository(string owner, string name, ApiOptions options); @@ -70,7 +70,7 @@ public interface IProjectsClient /// See the API documentation for more information. /// /// The owner of the repository - /// The name of the repository + /// The name of the repository /// Used to filter the list of projects returned /// Options for changing the API response Task> GetAllForRepository(string owner, string name, ProjectRequest request, ApiOptions options); diff --git a/Octokit/Clients/ProjectsClient.cs b/Octokit/Clients/ProjectsClient.cs index 04b11861ea..5afd714461 100644 --- a/Octokit/Clients/ProjectsClient.cs +++ b/Octokit/Clients/ProjectsClient.cs @@ -27,7 +27,7 @@ public ProjectsClient(IApiConnection apiConnection) : /// See the API documentation for more information. /// /// The owner of the repository - /// The name of the repository + /// The name of the repository public Task> GetAllForRepository(string owner, string name) { return GetAllForRepository(owner, name, ApiOptions.None); @@ -40,7 +40,7 @@ public Task> GetAllForRepository(string owner, string nam /// See the API documentation for more information. /// /// The owner of the repository - /// The name of the repository + /// The name of the repository /// Options for changing the API response public Task> GetAllForRepository(string owner, string name, ApiOptions options) { From e89d47473b83afc46de5439addbfa1033a94808f Mon Sep 17 00:00:00 2001 From: Itai Bar-Haim Date: Mon, 12 Mar 2018 09:00:34 +0200 Subject: [PATCH 45/84] Added support for Installation=>Id field that arrives in a Pull Request Event payload. (See the last field in the sample JSON of https://developer.github.com/v3/activity/events/types/#pullrequestevent) --- .../Response/ActivityPayloads/PullRequestEventPayload.cs | 2 ++ Octokit/Models/Response/Installation.cs | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/Octokit/Models/Response/ActivityPayloads/PullRequestEventPayload.cs b/Octokit/Models/Response/ActivityPayloads/PullRequestEventPayload.cs index ebaf48de57..8bd2c950af 100644 --- a/Octokit/Models/Response/ActivityPayloads/PullRequestEventPayload.cs +++ b/Octokit/Models/Response/ActivityPayloads/PullRequestEventPayload.cs @@ -9,5 +9,7 @@ public class PullRequestEventPayload : ActivityPayload public int Number { get; protected set; } public PullRequest PullRequest { get; protected set; } + + public Installation Installation { get; protected set; } } } diff --git a/Octokit/Models/Response/Installation.cs b/Octokit/Models/Response/Installation.cs index 03f61564fa..fda514737a 100644 --- a/Octokit/Models/Response/Installation.cs +++ b/Octokit/Models/Response/Installation.cs @@ -16,6 +16,11 @@ public class Installation { public Installation() { } + public Installation(long id) + { + Id = id; + } + public Installation(long id, User account, string accessTokenUrl, string repositoriesUrl, string htmlUrl, long appId, long targetId, AccountType targetType, InstallationPermissions permissions, IReadOnlyList events, string singleFileName, string repositorySelection) { Id = id; From a3ac9d5772162f724c13dc1ae9bc3d07f05630ea Mon Sep 17 00:00:00 2001 From: Ryan Gribble Date: Mon, 12 Mar 2018 20:54:59 +1000 Subject: [PATCH 46/84] Change integration test project to netcoreapp2.0 so we can use GitHubJwt nuget package in integration tests --- Octokit.Tests.Integration/Helper.cs | 19 ++- .../Octokit.Tests.Integration.csproj | 14 +- script/cibuild.ps1 | 127 ------------------ script/configure-integration-tests.ps1 | 1 + 4 files changed, 25 insertions(+), 136 deletions(-) delete mode 100644 script/cibuild.ps1 diff --git a/Octokit.Tests.Integration/Helper.cs b/Octokit.Tests.Integration/Helper.cs index 39a87d7ded..0d2c4cdd6b 100644 --- a/Octokit.Tests.Integration/Helper.cs +++ b/Octokit.Tests.Integration/Helper.cs @@ -72,22 +72,24 @@ public static class Helper static readonly Lazy _githubAppCredentials = new Lazy(() => { -#if GITHUBJWT + // GitHubJwt nuget package only available for netstandard2.0+ +#if GITHUBJWT_HELPER_AVAILABLE var generator = new GitHubJwt.GitHubJwtFactory( - new GitHubJwt.FilePrivateKeySource(@"C:\Users\scarecrow420\Downloads\ryangribble-test2-app.2018-03-06.private-key.pem"), + new GitHubJwt.FilePrivateKeySource(GitHubAppPemFile), new GitHubJwt.GitHubJwtFactoryOptions { - AppIntegrationId = GitHubAppId, + AppIntegrationId = Convert.ToInt32(GitHubAppId), ExpirationSeconds = 600 } ); var jwtToken = generator.CreateEncodedJwtToken(); + return new Credentials(jwtToken, AuthenticationType.Bearer); #else - // Until we can get GitHubJWT nuget package in, hardcode a JWT value via ENV VAR (painful since they can only last 10 minutes!) - var jwtToken = Environment.GetEnvironmentVariable("OCTOKIT_GITHUBAPP_JWT"); + // return null, which will cause the [GitHubAppTest]'s to not be discovered + return null; #endif - return new Credentials(jwtToken, AuthenticationType.Bearer); + }); static readonly Lazy _customUrl = new Lazy(() => @@ -159,6 +161,11 @@ public static long GitHubAppId get { return Convert.ToInt64(Environment.GetEnvironmentVariable("OCTOKIT_GITHUBAPP_ID")); } } + public static string GitHubAppPemFile + { + get { return Environment.GetEnvironmentVariable("OCTOKIT_GITHUBAPP_PEMFILE"); } + } + public static string GitHubAppSlug { get { return Environment.GetEnvironmentVariable("OCTOKIT_GITHUBAPP_SLUG"); } diff --git a/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj b/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj index 0a690798d5..a73a3c2236 100644 --- a/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj +++ b/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj @@ -4,13 +4,11 @@ Integration tests for Octokit Octokit.Tests.Integration GitHub - netcoreapp1.0;net452 + netcoreapp2.0;net452 $(NoWarn);CS4014;CS1998 Octokit.Tests.Integration Octokit.Tests.Integration true - 1.6.0 - 1.0.4 false false false @@ -21,6 +19,10 @@ false + + $(DefineConstants);GITHUBJWT_HELPER_AVAILABLE + + @@ -43,4 +45,10 @@ + + + 0.0.1 + + + diff --git a/script/cibuild.ps1 b/script/cibuild.ps1 deleted file mode 100644 index 71feefbbf3..0000000000 --- a/script/cibuild.ps1 +++ /dev/null @@ -1,127 +0,0 @@ -<# -.SYNOPSIS - Builds and tests Octokit -.DESCRIPTION - Janky runs this script after checking out a revision and cleaning its - working tree. -.PARAMETER Clean - When true, all untracked (and ignored) files will be removed from the work - tree. Defaults to false. -#> - -Param( - [switch] - $Clean = $false -) - -Set-StrictMode -Version Latest - -try { - # Make the output width reeeeeaaaaaly wide so our output doesn't get hard-wrapped. - # - $Host.UI.RawUI.BufferSize = New-Object Management.Automation.Host.Size -ArgumentList 5000, 25 -} catch { - # Most likely we were run in a cmd.exe terminal which won't allow setting - # the BufferSize to such a strange size. -} - -$rootDirectory = Split-Path (Split-Path $MyInvocation.MyCommand.Path) - -Push-Location $rootDirectory - -function Die-WithOutput($exitCode, $output) { - Write-Output $output - Write-Output "" - exit $exitCode -} - -function Dump-Error($output) { - $exitCode = $LastExitCode - - $errors = $output | Select-String ": error" - if ($errors) { - $output = "Likely errors:", $errors, "", "Full output:", $output - } - - Die-WithOutput $exitCode $output -} - -function Run-Command([scriptblock]$Command, [switch]$Fatal, [switch]$Quiet) { - $output = "" - if ($Quiet) { - $output = & $Command 2>&1 - } else { - & $Command - } - - if (!$Fatal) { - return - } - - $exitCode = 0 - if ($LastExitCode -ne 0) { - $exitCode = $LastExitCode - } elseif (!$?) { - $exitCode = 1 - } else { - return - } - - $error = "Error executing command ``$Command``." - if ($output) { - $error = "$error Output:", $output - } - Die-WithOutput $exitCode $error -} - -if ($Clean) { - Write-Output "Cleaning work tree..." - Write-Output "" - - Run-Command -Quiet -Fatal { git clean -xdf } -} - - -Write-Output "Installing FAKE..." -Write-Output "" -.\tools\nuget\nuget.exe "install" "FAKE.Core" "-OutputDirectory" "tools" "-ExcludeVersion" "-Version" "2.18.1" - -Write-Output "Building Octokit..." -Write-Output "" -$output = & .\tools\FAKE.Core\tools\Fake.exe "build.fsx" "target=BuildApp" "buildMode=Release" -if ($LastExitCode -ne 0) { - Dump-Error($output) -} - -Write-Output "Running unit tests..." -Write-Output "" -$output = & .\tools\FAKE.Core\tools\Fake.exe "build.fsx" "target=UnitTests" "buildMode=Release" -if ($LastExitCode -ne 0) { - Dump-Error($output) -} - - -Write-Output "Running convention tests..." -Write-Output "" -$output = & .\tools\FAKE.Core\tools\Fake.exe "build.fsx" "target=ConventionTests" "buildMode=Release" -if ($LastExitCode -ne 0) { - Dump-Error($output) -} - -Write-Output "Running integration tests..." -Write-Output "" -$output = & .\tools\FAKE.Core\tools\Fake.exe "build.fsx" "target=IntegrationTests" "buildMode=Release" -if ($LastExitCode -ne 0) { - Dump-Error($output) -} - -Write-Output "Creating NuGet packages..." -Write-Output "" -$output = & .\tools\FAKE.Core\tools\Fake.exe "build.fsx" "target=CreatePackages" "buildMode=Release" -if ($LastExitCode -ne 0) { - Dump-Error($output) -} - -$exitCode = 0 - -exit $exitCode diff --git a/script/configure-integration-tests.ps1 b/script/configure-integration-tests.ps1 index ccc873bf9a..c3943e5e0d 100644 --- a/script/configure-integration-tests.ps1 +++ b/script/configure-integration-tests.ps1 @@ -103,6 +103,7 @@ if (AskYesNoQuestion "Do you wish to setup GitHubApps integration test settings? VerifyEnvironmentVariable "GitHub App ID" "OCTOKIT_GITHUBAPP_ID" VerifyEnvironmentVariable "GitHub App SLUG" "OCTOKIT_GITHUBAPP_SLUG" VerifyEnvironmentVariable "GitHub App Installation ID" "OCTOKIT_GITHUBAPP_INSTALLATIONID" + VerifyEnvironmentVariable "GitHub App Pem File" "OCTOKIT_GITHUBAPP_PEMFILE" } if (AskYesNoQuestion "Do you wish to enable GitHub Enterprise (GHE) Integration Tests?" "OCTOKIT_GHE_ENABLED") From 7caef2427a6de188b1777a52e2e021a4df085db2 Mon Sep 17 00:00:00 2001 From: Ryan Gribble Date: Mon, 12 Mar 2018 21:59:14 +1000 Subject: [PATCH 47/84] First cut at some GitHubApp doco --- docs/github-apps.md | 90 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 docs/github-apps.md diff --git a/docs/github-apps.md b/docs/github-apps.md new file mode 100644 index 0000000000..594c258674 --- /dev/null +++ b/docs/github-apps.md @@ -0,0 +1,90 @@ +# Working with GitHub Apps + +## Overview +GitHub Apps are a new type of integration offering narrow, specific permissions, compared to OAuth apps or user authentication. + +To learn more, head to the GitHub Apps section under the GitHub Developer [Getting started with Building Apps](https://developer.github.com/apps/getting-started-with-building-apps/#using-github-apps) documentation. + +A GitHub App (known in Octokit as a `GitHubApp`) specifies permissions (read, write, none) it will be granted for various scopes. + +A GitHub App is installed in an `Organization` or `User` account (known in Octokit as an `Installation`) where it is further limited to nominated (or all) repositories for that account. + +The [GitHub Api Documentation](https://developer.github.com/v3/apps/) on GitHub Apps contains more detailed information. + +## Authentication + +The below walkthrough outlines how to authenticate as a `GitHubApp` and an `Installation` using Octokit.net. + +Be sure to see the [GitHub Api Documentation](https://developer.github.com/apps/building-github-apps/authentication-options-for-github-apps/#authentication-options-for-github-apps) on GitHub Apps authentication, if you require more details. + +## GitHub App Walkthrough + +Each GitHub App has a private certificate (PEM file) generated through the GitHub website and possessed by the owner of the GitHub App. Authentication occurs using a time based JWT token, signed by the GitHub App's private certificate. + +``` csharp +// A time based JWT token, signed by the GitHub App's private certificate +var jwtToken = @"eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOjE1MjA0Mjc3MTQsImV4cCI6MTUyMDQyODMxNCwiaXNzIjo5NzM1fQ.K-d3FKWKddMygFqvPZYWQusqhbF1LYfcIM0VbBq4uJsS9VkjhyXALlHmTJWjdblzx-U55lkZc_KWdJd6GlDxvoRb5w_9nrLcIFRbYVgi9XTYpCc3o5j7Qh3FvKxA1bzEs8XGrxjjE7-WJn_xi85ugFKTy9tlIRPa-PHeIOvNp4fz4ru8SFPoD4epiraeEyLfpU_ke-HYF7Ws7ar19zQkfJKRHSIFm1LxJ5MGKWT8pQBBUSGxGPgEG_tYI83aYw6cVx-DLV290bpr23LRUC684Wv_XabUDzXjPUYynAc01APZF6aN8B0LHdPbG8I6Yd74sQfmN-aHz5moz8ZNWLNm8Q +@"; + +var appClient = new GitHubClient(new ProductHeaderValue("MyApp")) +{ + Credentials = new Credentials(jwtToken, AuthenticationType.Bearer) +}; +``` + +The authenticated app can query various top level information about itself + +``` csharp +// Get the current authenticated GitHubApp +var app = await appClient.GetCurrent(); + +// Get a list of installations for the authenticated GitHubApp +var installations = await appClient.GetAllInstallationsForCurrent(); + +// Get a specific installation of the authenticated GitHubApp by it's installation Id +var installation = await appClient.GetInstallation(123); + +``` + +In order to do much more, a GitHubApp needs to create a temporary installation token for a specific Installation Id, and use that as further authentication: + +``` csharp +// Create an Installation token for Insallation Id 123 +var response = appClient.CreateInstallationToken(123); + +// The token will expire! +response.ExpiresAt; + +// Create a new GitHubClient using the installation token as authentication +var installationClient = new GitHubClient(new ProductHeaderValue("MyApp-Installation123")) +{ + Credentials = new Credentials(response.Token) +}; +``` + +Once authenticated as an `Installation`, a [subset of regular API endpoints](https://developer.github.com/v3/apps/available-endpoints/) can be queried, using the permissions of the `GitHubApp` and repository settings of the `Installation`: + +``` csharp +// Create a Comment on an Issue +// - Assuming the GitHub App has read/write permission for issues scope +// - Assuming we are operating on a repository that the Installation has access to +var response = await installationClient.Issue.Comment.Create("owner", "repo", 1, "Hello from my GitHubApp Installation!"); +``` + +## A Note on JWT Tokens +Octokit.net expects that you will pass in the appropriately signed JWT token required to authenticate the `GitHubApp`. + +Luckily one of our contributors [@adriangodong](https://github.com/adriangodong) has created a library `GitHubJwt` ([GitHub](https://github.com/adriangodong/githubjwt) [NuGet.org](https://www.nuget.org/packages/githubjwt)) which you can use to help with this (as long as you are targetting `netstandard2.0` or above). + +``` csharp +var generator = new GitHubJwt.GitHubJwtFactory( + new GitHubJwt.FilePrivateKeySource("/path/to/pem_file"), + new GitHubJwt.GitHubJwtFactoryOptions + { + AppIntegrationId = 123, // The GitHub App Id + ExpirationSeconds = 600 // 10 minutes is the maximum time allowed + } +); + +var jwtToken = generator.CreateEncodedJwtToken(); +``` \ No newline at end of file From be5df3d9d0612a2fbfd1ebd76adb299d7651fbf7 Mon Sep 17 00:00:00 2001 From: Ryan Gribble Date: Mon, 12 Mar 2018 22:07:48 +1000 Subject: [PATCH 48/84] update mkdocs config --- mkdocs.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mkdocs.yml b/mkdocs.yml index 3ac0cf6604..5fdb655b7b 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -24,12 +24,14 @@ pages: - 'Releases' : 'releases.md' - 'Search' : 'search.md' - 'Git Database' : 'git-database.md' + - 'GitHub Apps' : 'github-apps.md' - Samples: - 'Exploring Pull Requests' : 'demos/exploring-pull-requests.md' - Advanced: - 'API Options': 'extensibility.md' + - 'Working with Enums': 'working-with-enums.md' - 'Debugging from Source': 'debugging-source.md' - 'OAuth Flow': 'oauth-flow.md' - 'HttpClient': 'http-client.md' From 9478c0e3e218b18a255be2f61f44ddf726f0fa48 Mon Sep 17 00:00:00 2001 From: Itai Bar-Haim Date: Mon, 12 Mar 2018 16:13:39 +0200 Subject: [PATCH 49/84] Moved the Installation property to ActivityPayload, so it's available in all payloads. This feature is not undocumented, unfortunately, but valid: https://platform.github.community/t/determining-which-installation-an-event-came-from/539/11 --- Octokit/Models/Response/ActivityPayloads/ActivityPayload.cs | 1 + .../Models/Response/ActivityPayloads/PullRequestEventPayload.cs | 2 -- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/Octokit/Models/Response/ActivityPayloads/ActivityPayload.cs b/Octokit/Models/Response/ActivityPayloads/ActivityPayload.cs index 99a9639a02..f200bc2ee9 100644 --- a/Octokit/Models/Response/ActivityPayloads/ActivityPayload.cs +++ b/Octokit/Models/Response/ActivityPayloads/ActivityPayload.cs @@ -7,6 +7,7 @@ public class ActivityPayload { public Repository Repository { get; protected set; } public User Sender { get; protected set; } + public Installation Installation { get; protected set; } internal string DebuggerDisplay { diff --git a/Octokit/Models/Response/ActivityPayloads/PullRequestEventPayload.cs b/Octokit/Models/Response/ActivityPayloads/PullRequestEventPayload.cs index 8bd2c950af..ebaf48de57 100644 --- a/Octokit/Models/Response/ActivityPayloads/PullRequestEventPayload.cs +++ b/Octokit/Models/Response/ActivityPayloads/PullRequestEventPayload.cs @@ -9,7 +9,5 @@ public class PullRequestEventPayload : ActivityPayload public int Number { get; protected set; } public PullRequest PullRequest { get; protected set; } - - public Installation Installation { get; protected set; } } } From 8993f08044ec8aab4dec9cfb2f53c0ea96a6a762 Mon Sep 17 00:00:00 2001 From: Itai Bar-Haim Date: Tue, 13 Mar 2018 15:27:10 +0200 Subject: [PATCH 50/84] Split Installation to Installation and InstallationId, and added a comfort method for gaining its AccessToken. --- .../ActivityPayloads/ActivityPayload.cs | 2 +- Octokit/Models/Response/Installation.cs | 15 ++------ Octokit/Models/Response/InstallationId.cs | 35 +++++++++++++++++++ 3 files changed, 38 insertions(+), 14 deletions(-) create mode 100644 Octokit/Models/Response/InstallationId.cs diff --git a/Octokit/Models/Response/ActivityPayloads/ActivityPayload.cs b/Octokit/Models/Response/ActivityPayloads/ActivityPayload.cs index f200bc2ee9..1a8b8baf9f 100644 --- a/Octokit/Models/Response/ActivityPayloads/ActivityPayload.cs +++ b/Octokit/Models/Response/ActivityPayloads/ActivityPayload.cs @@ -7,7 +7,7 @@ public class ActivityPayload { public Repository Repository { get; protected set; } public User Sender { get; protected set; } - public Installation Installation { get; protected set; } + public InstallationId Installation { get; protected set; } internal string DebuggerDisplay { diff --git a/Octokit/Models/Response/Installation.cs b/Octokit/Models/Response/Installation.cs index fda514737a..5271e455b1 100644 --- a/Octokit/Models/Response/Installation.cs +++ b/Octokit/Models/Response/Installation.cs @@ -12,18 +12,12 @@ namespace Octokit /// For more information see https://developer.github.com/v3/apps/#find-installations /// [DebuggerDisplay("{DebuggerDisplay,nq}")] - public class Installation + public class Installation : InstallationId { public Installation() { } - public Installation(long id) + public Installation(long id, User account, string accessTokenUrl, string repositoriesUrl, string htmlUrl, long appId, long targetId, AccountType targetType, InstallationPermissions permissions, IReadOnlyList events, string singleFileName, string repositorySelection) : base(id) { - Id = id; - } - - public Installation(long id, User account, string accessTokenUrl, string repositoriesUrl, string htmlUrl, long appId, long targetId, AccountType targetType, InstallationPermissions permissions, IReadOnlyList events, string singleFileName, string repositorySelection) - { - Id = id; Account = account; HtmlUrl = htmlUrl; AppId = appId; @@ -35,11 +29,6 @@ public Installation(long id, User account, string accessTokenUrl, string reposit RepositorySelection = repositorySelection; } - /// - /// The Installation Id. - /// - public long Id { get; protected set; } - /// /// The user who owns the Installation. /// diff --git a/Octokit/Models/Response/InstallationId.cs b/Octokit/Models/Response/InstallationId.cs new file mode 100644 index 0000000000..7c01d3597f --- /dev/null +++ b/Octokit/Models/Response/InstallationId.cs @@ -0,0 +1,35 @@ +using System.Threading.Tasks; + +namespace Octokit +{ + public class InstallationId + { + public InstallationId() { } + + public InstallationId(long id) + { + Id = id; + } + + /// + /// The Installation Id. + /// + public long Id { get; private set; } + + /// + /// Create a time bound access token for this GitHubApp Installation that can be used to access other API endpoints. + /// + /// + /// https://developer.github.com/v3/apps/#create-a-new-installation-token + /// https://developer.github.com/apps/building-github-apps/authentication-options-for-github-apps/#authenticating-as-an-installation + /// https://developer.github.com/v3/apps/available-endpoints/ + /// + /// The client to use + public Task CreateAccessToken(IGitHubClient client) + { + Ensure.ArgumentNotNull(client, nameof(client)); + + return client.GitHubApps.CreateInstallationToken(Id); + } + } +} \ No newline at end of file From 2584f6049ceb4b780ddfbc6004ee426f593fb76f Mon Sep 17 00:00:00 2001 From: Itai Bar-Haim Date: Tue, 13 Mar 2018 16:11:53 +0200 Subject: [PATCH 51/84] fixed InstallationId CreateAccessToken to receive IGitHubAppsClient. added (and fixed) docs. --- Octokit/Models/Response/InstallationId.cs | 4 ++-- docs/github-apps.md | 24 ++++++++++++++++++++++- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/Octokit/Models/Response/InstallationId.cs b/Octokit/Models/Response/InstallationId.cs index 7c01d3597f..042b24a28d 100644 --- a/Octokit/Models/Response/InstallationId.cs +++ b/Octokit/Models/Response/InstallationId.cs @@ -25,11 +25,11 @@ public InstallationId(long id) /// https://developer.github.com/v3/apps/available-endpoints/ /// /// The client to use - public Task CreateAccessToken(IGitHubClient client) + public Task CreateAccessToken(IGitHubAppsClient client) { Ensure.ArgumentNotNull(client, nameof(client)); - return client.GitHubApps.CreateInstallationToken(Id); + return client.CreateInstallationToken(Id); } } } \ No newline at end of file diff --git a/docs/github-apps.md b/docs/github-apps.md index 594c258674..3bda517be1 100644 --- a/docs/github-apps.md +++ b/docs/github-apps.md @@ -26,10 +26,12 @@ Each GitHub App has a private certificate (PEM file) generated through the GitHu var jwtToken = @"eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOjE1MjA0Mjc3MTQsImV4cCI6MTUyMDQyODMxNCwiaXNzIjo5NzM1fQ.K-d3FKWKddMygFqvPZYWQusqhbF1LYfcIM0VbBq4uJsS9VkjhyXALlHmTJWjdblzx-U55lkZc_KWdJd6GlDxvoRb5w_9nrLcIFRbYVgi9XTYpCc3o5j7Qh3FvKxA1bzEs8XGrxjjE7-WJn_xi85ugFKTy9tlIRPa-PHeIOvNp4fz4ru8SFPoD4epiraeEyLfpU_ke-HYF7Ws7ar19zQkfJKRHSIFm1LxJ5MGKWT8pQBBUSGxGPgEG_tYI83aYw6cVx-DLV290bpr23LRUC684Wv_XabUDzXjPUYynAc01APZF6aN8B0LHdPbG8I6Yd74sQfmN-aHz5moz8ZNWLNm8Q @"; -var appClient = new GitHubClient(new ProductHeaderValue("MyApp")) +var gitHubClient = new GitHubClient(new ProductHeaderValue("MyApp")) { Credentials = new Credentials(jwtToken, AuthenticationType.Bearer) }; + +var appsClient = gitHubClient.GitHubApps; ``` The authenticated app can query various top level information about itself @@ -71,6 +73,26 @@ Once authenticated as an `Installation`, a [subset of regular API endpoints](htt var response = await installationClient.Issue.Comment.Create("owner", "repo", 1, "Hello from my GitHubApp Installation!"); ``` +## A Note on Installations +GitHub sends the specific installation id with every event payload. You can access it using, for instance: + +``` csharp +var payload = serializer_.Deserialize(json); +long installationId = payload.Installation.Id; +``` + +You can also get its access token if you have the GitHubClient: + +``` csharp +var token = await appClient.CreateInstallationToken(installationId); +``` + +Or in a more Object Oriented way: + +``` csharp +var token = await payload.Installation.CreateAccessToken(appClient); +``` + ## A Note on JWT Tokens Octokit.net expects that you will pass in the appropriately signed JWT token required to authenticate the `GitHubApp`. From 89824615924ae0f1ecca334d393189d9b873fe18 Mon Sep 17 00:00:00 2001 From: Itai Bar-Haim Date: Wed, 14 Mar 2018 10:09:30 +0200 Subject: [PATCH 52/84] reverted object-oriented style comfort method and it's docs. --- Octokit/Models/Response/InstallationId.cs | 20 +------------------- docs/github-apps.md | 8 +------- 2 files changed, 2 insertions(+), 26 deletions(-) diff --git a/Octokit/Models/Response/InstallationId.cs b/Octokit/Models/Response/InstallationId.cs index 042b24a28d..1f7f86cd98 100644 --- a/Octokit/Models/Response/InstallationId.cs +++ b/Octokit/Models/Response/InstallationId.cs @@ -1,6 +1,4 @@ -using System.Threading.Tasks; - -namespace Octokit +namespace Octokit { public class InstallationId { @@ -15,21 +13,5 @@ public InstallationId(long id) /// The Installation Id. /// public long Id { get; private set; } - - /// - /// Create a time bound access token for this GitHubApp Installation that can be used to access other API endpoints. - /// - /// - /// https://developer.github.com/v3/apps/#create-a-new-installation-token - /// https://developer.github.com/apps/building-github-apps/authentication-options-for-github-apps/#authenticating-as-an-installation - /// https://developer.github.com/v3/apps/available-endpoints/ - /// - /// The client to use - public Task CreateAccessToken(IGitHubAppsClient client) - { - Ensure.ArgumentNotNull(client, nameof(client)); - - return client.CreateInstallationToken(Id); - } } } \ No newline at end of file diff --git a/docs/github-apps.md b/docs/github-apps.md index 3bda517be1..113fc89347 100644 --- a/docs/github-apps.md +++ b/docs/github-apps.md @@ -81,18 +81,12 @@ var payload = serializer_.Deserialize(json); long installationId = payload.Installation.Id; ``` -You can also get its access token if you have the GitHubClient: +You can then get use the installation id to get an access token using the GitHubClient: ``` csharp var token = await appClient.CreateInstallationToken(installationId); ``` -Or in a more Object Oriented way: - -``` csharp -var token = await payload.Installation.CreateAccessToken(appClient); -``` - ## A Note on JWT Tokens Octokit.net expects that you will pass in the appropriately signed JWT token required to authenticate the `GitHubApp`. From 795993787b90583a9ed662e7d050d47d4e238216 Mon Sep 17 00:00:00 2001 From: Ryan Gribble Date: Wed, 14 Mar 2018 20:21:41 +1000 Subject: [PATCH 53/84] update all test projects to netcoreapp2.0 --- Octokit.Tests.Conventions/Octokit.Tests.Conventions.csproj | 2 +- Octokit.Tests/Octokit.Tests.csproj | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Octokit.Tests.Conventions/Octokit.Tests.Conventions.csproj b/Octokit.Tests.Conventions/Octokit.Tests.Conventions.csproj index 6c7a859b78..f563be0e00 100644 --- a/Octokit.Tests.Conventions/Octokit.Tests.Conventions.csproj +++ b/Octokit.Tests.Conventions/Octokit.Tests.Conventions.csproj @@ -4,7 +4,7 @@ Convention-based tests for Octokit Octokit.Tests.Conventions GitHub - netcoreapp1.0;net452 + netcoreapp2.0;net452 $(NoWarn);CS4014;CS1998 Octokit.Tests.Conventions Octokit.Tests.Conventions diff --git a/Octokit.Tests/Octokit.Tests.csproj b/Octokit.Tests/Octokit.Tests.csproj index ea1d63455e..6c6ffa63e0 100644 --- a/Octokit.Tests/Octokit.Tests.csproj +++ b/Octokit.Tests/Octokit.Tests.csproj @@ -4,7 +4,7 @@ Tests for Octokit Octokit.Tests GitHub - netcoreapp1.0;net452 + netcoreapp2.0;net452 $(NoWarn);CS4014;CS1998 Octokit.Tests Octokit.Tests @@ -34,7 +34,7 @@ - + $(DefineConstants);NO_SERIALIZABLE;HAS_TYPEINFO From 70fe467bac026953ec0b4e133e6b02cfa1fecd81 Mon Sep 17 00:00:00 2001 From: Ryan Gribble Date: Wed, 14 Mar 2018 20:22:18 +1000 Subject: [PATCH 54/84] tweak build configs to use 2.0.3 SDK --- .travis.yml | 4 ++-- build.ps1 | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.travis.yml b/.travis.yml index 9745633faa..18af34f695 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,10 +5,10 @@ matrix: - os: linux dist: trusty sudo: required - dotnet: 1.0.4 + dotnet: 2.0.3 - os: osx osx_image: xcode8 - dotnet: 1.0.4 + dotnet: 2.0.3 before_script: - if test "$TRAVIS_OS_NAME" == "osx"; then export FrameworkPathOverride=/Library/Frameworks/Mono.framework/Versions/Current/lib/mono/4.5/; else export FrameworkPathOverride=/usr/lib/mono/4.5/; fi diff --git a/build.ps1 b/build.ps1 index 8bc9e1839c..3efb86c2c4 100644 --- a/build.ps1 +++ b/build.ps1 @@ -32,9 +32,9 @@ Param( [string[]]$ScriptArgs ) -$DotNetChannel = "preview"; -$DotNetVersion = "1.0.1"; -$DotNetInstallerUri = "https://raw.githubusercontent.com/dotnet/cli/rel/1.0.1/scripts/obtain/dotnet-install.ps1"; +$DotNetChannel = "2.0"; +$DotNetVersion = "2.0.3"; +$DotNetInstallerUri = "https://dot.net/v1/dotnet-install.ps1"; $NugetUrl = "https://dist.nuget.org/win-x86-commandline/latest/nuget.exe" # Make sure tools folder exists @@ -65,7 +65,7 @@ if (Get-Command dotnet -ErrorAction SilentlyContinue) { $FoundDotNetCliVersion = dotnet --version; } -if($FoundDotNetCliVersion -ne $DotNetVersion) { +if($FoundDotNetCliVersion -lt $DotNetVersion) { $InstallPath = Join-Path $PSScriptRoot ".dotnet" if (!(Test-Path $InstallPath)) { mkdir -Force $InstallPath | Out-Null; @@ -113,7 +113,7 @@ if($LASTEXITCODE -ne 0) { exit $LASTEXITCODE; } Write-Host "Running build..." -Invoke-Expression "dotnet run -- $Arguments" +Invoke-Expression "dotnet run $Arguments" if($LASTEXITCODE -ne 0) { Pop-Location; exit $LASTEXITCODE; From cfacf51e5d5eb615f45ed02603de88984bb0ce5d Mon Sep 17 00:00:00 2001 From: Ryan Gribble Date: Wed, 14 Mar 2018 20:33:36 +1000 Subject: [PATCH 55/84] also need to update cake frosting build to netcoreapp2.0 --- build/.vscode/launch.json | 19 ++++++++++++------- build/.vscode/tasks.json | 13 ++++++------- build/Build.csproj | 2 +- 3 files changed, 19 insertions(+), 15 deletions(-) diff --git a/build/.vscode/launch.json b/build/.vscode/launch.json index 46d477c672..b097db5239 100644 --- a/build/.vscode/launch.json +++ b/build/.vscode/launch.json @@ -1,15 +1,20 @@ { - "version": "0.2.0", - "configurations": [ + // Use IntelliSense to find out which attributes exist for C# debugging + // Use hover for the description of the existing attributes + // For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md + "version": "0.2.0", + "configurations": [ { "name": ".NET Core Launch (console)", "type": "coreclr", "request": "launch", "preLaunchTask": "build", - "program": "${workspaceRoot}\\bin\\Debug\\netcoreapp1.0\\build.dll", + // If you have changed target frameworks, make sure to update the program path. + "program": "${workspaceFolder}/bin/Debug/netcoreapp2.0/Build.dll", "args": [], - "cwd": "${workspaceRoot}", - "externalConsole": false, + "cwd": "${workspaceFolder}", + // For more information about the 'console' field, see https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md#console-terminal-window + "console": "internalConsole", "stopAtEntry": false, "internalConsoleOptions": "openOnSessionStart" }, @@ -17,7 +22,7 @@ "name": ".NET Core Attach", "type": "coreclr", "request": "attach", - "processId": "${command.pickProcess}" + "processId": "${command:pickProcess}" } - ] + ,] } \ No newline at end of file diff --git a/build/.vscode/tasks.json b/build/.vscode/tasks.json index 9cd37c150c..eb37628fe7 100644 --- a/build/.vscode/tasks.json +++ b/build/.vscode/tasks.json @@ -1,15 +1,14 @@ { - "version": "0.1.0", - "command": "dotnet", - "isShellCommand": true, - "args": [], + "version": "2.0.0", "tasks": [ { - "taskName": "build", + "label": "build", + "command": "dotnet", + "type": "process", "args": [ - "${workspaceRoot}\\project.json" + "build", + "${workspaceFolder}/Build.csproj" ], - "isBuildCommand": true, "problemMatcher": "$msCompile" } ] diff --git a/build/Build.csproj b/build/Build.csproj index 725a902448..00ec86fa0a 100644 --- a/build/Build.csproj +++ b/build/Build.csproj @@ -2,7 +2,7 @@ Exe - netcoreapp1.1 + netcoreapp2.0 From 90241a1b406da44db9c9e73e180b8f1649313e09 Mon Sep 17 00:00:00 2001 From: Ryan Gribble Date: Wed, 14 Mar 2018 21:02:53 +1000 Subject: [PATCH 56/84] tweak docs some more --- docs/github-apps.md | 45 ++++++++++++++++++++++++++++++++++++--------- 1 file changed, 36 insertions(+), 9 deletions(-) diff --git a/docs/github-apps.md b/docs/github-apps.md index 113fc89347..afcad958e3 100644 --- a/docs/github-apps.md +++ b/docs/github-apps.md @@ -5,7 +5,7 @@ GitHub Apps are a new type of integration offering narrow, specific permissions, To learn more, head to the GitHub Apps section under the GitHub Developer [Getting started with Building Apps](https://developer.github.com/apps/getting-started-with-building-apps/#using-github-apps) documentation. -A GitHub App (known in Octokit as a `GitHubApp`) specifies permissions (read, write, none) it will be granted for various scopes. +A GitHub App (known in Octokit as a `GitHubApp`) specifies permissions (read, write, none) it will be granted for various scopes and also registers for various webhook events. A GitHub App is installed in an `Organization` or `User` account (known in Octokit as an `Installation`) where it is further limited to nominated (or all) repositories for that account. @@ -52,7 +52,7 @@ In order to do much more, a GitHubApp needs to create a temporary installation t ``` csharp // Create an Installation token for Insallation Id 123 -var response = appClient.CreateInstallationToken(123); +var response = await appClient.CreateInstallationToken(123); // The token will expire! response.ExpiresAt; @@ -73,18 +73,45 @@ Once authenticated as an `Installation`, a [subset of regular API endpoints](htt var response = await installationClient.Issue.Comment.Create("owner", "repo", 1, "Hello from my GitHubApp Installation!"); ``` -## A Note on Installations -GitHub sends the specific installation id with every event payload. You can access it using, for instance: +## A Note on identifying Installation Id's +GitHub Apps can be registered for webhook events. -``` csharp -var payload = serializer_.Deserialize(json); -long installationId = payload.Installation.Id; +WebHook payloads sent to these registrations now include an extra field to indicate the Id of the GitHub App Installation that is associated with the received webhook. + +Example webhook for an opened Pull Request: +``` json +{ + "action": "opened", + "number": 1, + "pull_request": { + ... + }, + "repository": { + ... + }, + "sender": { + ... + }, + "installation": { + "id": 1234 + } +} ``` -You can then get use the installation id to get an access token using the GitHubClient: +You can retrieve this `installation.id` from your webhook payload, and use it to create the Installation token as above, to further interact with the repository as that Installation of the GitHub App. + +Although Octokit.net doesn't have explicit webhook support, the `ActivityPayload` response classes do generally align with webhook payloads (assuming the octokit.net custom deserializer is used), so we have added the field to these: ``` csharp -var token = await appClient.CreateInstallationToken(installationId); +// json payload from the received webhook +var json = "..."; + +// Deserialize the pull_request event +var serializer = new Octokit.Internal.SimpleJsonSerializer(); +var payload = serializer_.Deserialize(json); + +// Create an Installation token for the associated Insallation Id +var response = await appClient.CreateInstallationToken(payload.Installation.Id); ``` ## A Note on JWT Tokens From 21f9f7fcc1c667c360b2caffab385e61923019ff Mon Sep 17 00:00:00 2001 From: Ryan Gribble Date: Wed, 14 Mar 2018 21:03:03 +1000 Subject: [PATCH 57/84] fix convention test failures --- Octokit/Models/Response/Installation.cs | 2 +- Octokit/Models/Response/InstallationId.cs | 11 ++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/Octokit/Models/Response/Installation.cs b/Octokit/Models/Response/Installation.cs index 5271e455b1..e7a77841b8 100644 --- a/Octokit/Models/Response/Installation.cs +++ b/Octokit/Models/Response/Installation.cs @@ -76,7 +76,7 @@ public Installation(long id, User account, string accessTokenUrl, string reposit internal string DebuggerDisplay { - get { return string.Format(CultureInfo.InvariantCulture, "Installation Id: {0} ; App Id: {1}", Id, AppId); } + get { return string.Format(CultureInfo.InvariantCulture, "Id: {0} AppId: {1}", Id, AppId); } } } diff --git a/Octokit/Models/Response/InstallationId.cs b/Octokit/Models/Response/InstallationId.cs index 1f7f86cd98..ccaf8b75f7 100644 --- a/Octokit/Models/Response/InstallationId.cs +++ b/Octokit/Models/Response/InstallationId.cs @@ -1,5 +1,9 @@ -namespace Octokit +using System.Diagnostics; +using System.Globalization; + +namespace Octokit { + [DebuggerDisplay("{DebuggerDisplay,nq}")] public class InstallationId { public InstallationId() { } @@ -13,5 +17,10 @@ public InstallationId(long id) /// The Installation Id. /// public long Id { get; private set; } + + internal string DebuggerDisplay + { + get { return string.Format(CultureInfo.InvariantCulture, "Id: {0}", Id); } + } } } \ No newline at end of file From 4e19617aa2b292cb1a2432e6163595b79a031521 Mon Sep 17 00:00:00 2001 From: Ryan Gribble Date: Wed, 14 Mar 2018 21:10:18 +1000 Subject: [PATCH 58/84] test projects still had some old runtime parts in them! --- Octokit.Tests.Conventions/Octokit.Tests.Conventions.csproj | 2 -- Octokit.Tests/Octokit.Tests.csproj | 2 -- 2 files changed, 4 deletions(-) diff --git a/Octokit.Tests.Conventions/Octokit.Tests.Conventions.csproj b/Octokit.Tests.Conventions/Octokit.Tests.Conventions.csproj index f563be0e00..9ec5bb01ea 100644 --- a/Octokit.Tests.Conventions/Octokit.Tests.Conventions.csproj +++ b/Octokit.Tests.Conventions/Octokit.Tests.Conventions.csproj @@ -9,8 +9,6 @@ Octokit.Tests.Conventions Octokit.Tests.Conventions true - 1.6.0 - 1.0.4 false false false diff --git a/Octokit.Tests/Octokit.Tests.csproj b/Octokit.Tests/Octokit.Tests.csproj index 6c6ffa63e0..4a89573463 100644 --- a/Octokit.Tests/Octokit.Tests.csproj +++ b/Octokit.Tests/Octokit.Tests.csproj @@ -9,8 +9,6 @@ Octokit.Tests Octokit.Tests true - 1.6.0 - 1.0.4 false false false From 9aa755d5040d7ab5e278f0e1e7ddfc8c32d1dee8 Mon Sep 17 00:00:00 2001 From: Ryan Gribble Date: Wed, 14 Mar 2018 21:33:08 +1000 Subject: [PATCH 59/84] travis osx image needs to be at least 10.12 for .NET Core 2.0 --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 18af34f695..1885792f0a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,7 +7,7 @@ matrix: sudo: required dotnet: 2.0.3 - os: osx - osx_image: xcode8 + osx_image: xcode8.3 dotnet: 2.0.3 before_script: From 095be97175d6d2e7d88730c0a2b6d72e47df9c65 Mon Sep 17 00:00:00 2001 From: Ryan Gribble Date: Wed, 14 Mar 2018 21:41:31 +1000 Subject: [PATCH 60/84] shell script might need the same argument tweak for cake --- build.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.sh b/build.sh index ad542461c5..14a78b37ec 100755 --- a/build.sh +++ b/build.sh @@ -8,4 +8,4 @@ fi cd build dotnet restore -dotnet run -- "$@" \ No newline at end of file +dotnet run "$@" \ No newline at end of file From f5a093e72551d4044030a49ec39f19db0a6e27f3 Mon Sep 17 00:00:00 2001 From: Ryan Gribble Date: Wed, 14 Mar 2018 21:52:46 +1000 Subject: [PATCH 61/84] more doc tweaks --- docs/github-apps.md | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/docs/github-apps.md b/docs/github-apps.md index afcad958e3..c1de6dab8d 100644 --- a/docs/github-apps.md +++ b/docs/github-apps.md @@ -23,18 +23,16 @@ Each GitHub App has a private certificate (PEM file) generated through the GitHu ``` csharp // A time based JWT token, signed by the GitHub App's private certificate -var jwtToken = @"eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOjE1MjA0Mjc3MTQsImV4cCI6MTUyMDQyODMxNCwiaXNzIjo5NzM1fQ.K-d3FKWKddMygFqvPZYWQusqhbF1LYfcIM0VbBq4uJsS9VkjhyXALlHmTJWjdblzx-U55lkZc_KWdJd6GlDxvoRb5w_9nrLcIFRbYVgi9XTYpCc3o5j7Qh3FvKxA1bzEs8XGrxjjE7-WJn_xi85ugFKTy9tlIRPa-PHeIOvNp4fz4ru8SFPoD4epiraeEyLfpU_ke-HYF7Ws7ar19zQkfJKRHSIFm1LxJ5MGKWT8pQBBUSGxGPgEG_tYI83aYw6cVx-DLV290bpr23LRUC684Wv_XabUDzXjPUYynAc01APZF6aN8B0LHdPbG8I6Yd74sQfmN-aHz5moz8ZNWLNm8Q -@"; +var jwtToken = "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOjE1MjA0Mjc3MTQsImV4cCI6MTUyMDQyODMxNCwiaXNzIjo5NzM1fQ.K-d3FKWKddMygFqvPZYWQusqhbF1LYfcIM0VbBq4uJsS9VkjhyXALlHmTJWjdblzx-U55lkZc_KWdJd6GlDxvoRb5w_9nrLcIFRbYVgi9XTYpCc3o5j7Qh3FvKxA1bzEs8XGrxjjE7-WJn_xi85ugFKTy9tlIRPa-PHeIOvNp4fz4ru8SFPoD4epiraeEyLfpU_ke-HYF7Ws7ar19zQkfJKRHSIFm1LxJ5MGKWT8pQBBUSGxGPgEG_tYI83aYw6cVx-DLV290bpr23LRUC684Wv_XabUDzXjPUYynAc01APZF6aN8B0LHdPbG8I6Yd74sQfmN-aHz5moz8ZNWLNm8Q"; +// Use the JWT as a Bearer token var gitHubClient = new GitHubClient(new ProductHeaderValue("MyApp")) { Credentials = new Credentials(jwtToken, AuthenticationType.Bearer) }; - -var appsClient = gitHubClient.GitHubApps; ``` -The authenticated app can query various top level information about itself +The authenticated `GitHubApp` can query various top level information about itself: ``` csharp // Get the current authenticated GitHubApp @@ -48,13 +46,13 @@ var installation = await appClient.GetInstallation(123); ``` -In order to do much more, a GitHubApp needs to create a temporary installation token for a specific Installation Id, and use that as further authentication: +In order to do more than top level calls, a `GitHubApp` needs to authenticate as a specific `Installation` by creating a temporary installation token, and using that for authentication: ``` csharp // Create an Installation token for Insallation Id 123 var response = await appClient.CreateInstallationToken(123); -// The token will expire! +// NOTE - the token will expire! response.ExpiresAt; // Create a new GitHubClient using the installation token as authentication @@ -117,7 +115,7 @@ var response = await appClient.CreateInstallationToken(payload.Installation.Id); ## A Note on JWT Tokens Octokit.net expects that you will pass in the appropriately signed JWT token required to authenticate the `GitHubApp`. -Luckily one of our contributors [@adriangodong](https://github.com/adriangodong) has created a library `GitHubJwt` ([GitHub](https://github.com/adriangodong/githubjwt) [NuGet.org](https://www.nuget.org/packages/githubjwt)) which you can use to help with this (as long as you are targetting `netstandard2.0` or above). +Luckily one of our contributors [@adriangodong](https://github.com/adriangodong) has created a library `GitHubJwt` ( [GitHub](https://github.com/adriangodong/githubjwt) | [NuGet](https://www.nuget.org/packages/githubjwt) ) which you can use to help with this (as long as you are targetting `netstandard2.0` or above). ``` csharp var generator = new GitHubJwt.GitHubJwtFactory( From 95d94851476045642bbc1e69589abab9831a262f Mon Sep 17 00:00:00 2001 From: Ryan Gribble Date: Wed, 14 Mar 2018 21:53:29 +1000 Subject: [PATCH 62/84] Make sure compiler warning output isnt somehow causing Linux and OSX builds to fail --- Octokit.Tests/Octokit.Tests.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Octokit.Tests/Octokit.Tests.csproj b/Octokit.Tests/Octokit.Tests.csproj index 4a89573463..d53e8befbe 100644 --- a/Octokit.Tests/Octokit.Tests.csproj +++ b/Octokit.Tests/Octokit.Tests.csproj @@ -29,7 +29,7 @@ - + From d87d277673c31ec0984737757f35fff562e6cacb Mon Sep 17 00:00:00 2001 From: Ryan Gribble Date: Wed, 14 Mar 2018 21:59:27 +1000 Subject: [PATCH 63/84] moar logging for linux/OSX builds --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 1885792f0a..8a2cdd573c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -16,4 +16,4 @@ before_script: script: - git fetch --unshallow --tags - dotnet --info - - ./build.sh --linksources=true + - ./build.sh --linksources=true --verbosity=diagnostic From f87dc1e6a3a761125b368b19cb79a0bd18a466c6 Mon Sep 17 00:00:00 2001 From: Ryan Gribble Date: Wed, 14 Mar 2018 22:08:19 +1000 Subject: [PATCH 64/84] stop sourcelink on linux/OSX builds to see if that is the problem --- .travis.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 8a2cdd573c..d34c258af0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,5 +15,4 @@ before_script: script: - git fetch --unshallow --tags - - dotnet --info - - ./build.sh --linksources=true --verbosity=diagnostic + - ./build.sh --verbosity=diagnostic From 2c87015720ff17e5006eee94875aed71c0f984d1 Mon Sep 17 00:00:00 2001 From: Ryan Gribble Date: Thu, 15 Mar 2018 21:27:02 +1000 Subject: [PATCH 65/84] set verbosity to detailed for the dotnet build step --- build.ps1 | 4 ++-- build.sh | 3 +++ build/Context.cs | 2 +- build/Tasks/Build.cs | 1 + 4 files changed, 7 insertions(+), 3 deletions(-) diff --git a/build.ps1 b/build.ps1 index 3efb86c2c4..a2e6e94ef6 100644 --- a/build.ps1 +++ b/build.ps1 @@ -106,13 +106,13 @@ $Arguments = @{ # Start Cake Push-Location Set-Location build -Write-Host "Restoring packages..." +Write-Host "Preparing Cake.Frosting build runner..." Invoke-Expression "dotnet restore" if($LASTEXITCODE -ne 0) { Pop-Location; exit $LASTEXITCODE; } -Write-Host "Running build..." +Write-Host "Running Cake.Frosting build runner..." Invoke-Expression "dotnet run $Arguments" if($LASTEXITCODE -ne 0) { Pop-Location; diff --git a/build.sh b/build.sh index 14a78b37ec..af97dec198 100755 --- a/build.sh +++ b/build.sh @@ -7,5 +7,8 @@ if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then fi cd build +echo "Preparing Cake.Frosting build runner..." dotnet restore + +echo "Executing Cake.Frosting build runner..." dotnet run "$@" \ No newline at end of file diff --git a/build/Context.cs b/build/Context.cs index 0fbaedb524..12f6cb437f 100644 --- a/build/Context.cs +++ b/build/Context.cs @@ -36,7 +36,7 @@ public DotNetCoreTestSettings GetTestSettings() if (!this.IsRunningOnWindows()) { - var testFramework = "netcoreapp1.0"; + var testFramework = "netcoreapp2.0"; this.Information($"Running tests against {testFramework} only as we're not on Windows."); settings.Framework = testFramework; diff --git a/build/Tasks/Build.cs b/build/Tasks/Build.cs index 3d679aed00..15d58ce46a 100644 --- a/build/Tasks/Build.cs +++ b/build/Tasks/Build.cs @@ -10,6 +10,7 @@ public override void Run(Context context) { context.DotNetCoreBuild("./Octokit.sln", new DotNetCoreBuildSettings { + Verbosity = DotNetCoreVerbosity.Detailed, Configuration = context.Configuration, ArgumentCustomization = args => args .Append("/p:Version={0}", context.Version.GetSemanticVersion()) From 138c22f4a343649ed189c149702f81b1ad72ecc1 Mon Sep 17 00:00:00 2001 From: Ryan Gribble Date: Thu, 15 Mar 2018 22:09:03 +1000 Subject: [PATCH 66/84] try new sourcelink and list out remotes --- .travis.yml | 3 ++- Octokit.Reactive/Octokit.Reactive.csproj | 2 +- Octokit/Octokit.csproj | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index d34c258af0..5641fb720a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,4 +15,5 @@ before_script: script: - git fetch --unshallow --tags - - ./build.sh --verbosity=diagnostic + - git remote + - ./build.sh --verbosity=verbose diff --git a/Octokit.Reactive/Octokit.Reactive.csproj b/Octokit.Reactive/Octokit.Reactive.csproj index baad918d5d..08e99ec587 100644 --- a/Octokit.Reactive/Octokit.Reactive.csproj +++ b/Octokit.Reactive/Octokit.Reactive.csproj @@ -41,7 +41,7 @@ - + diff --git a/Octokit/Octokit.csproj b/Octokit/Octokit.csproj index d46a35000a..fe8654680a 100644 --- a/Octokit/Octokit.csproj +++ b/Octokit/Octokit.csproj @@ -37,7 +37,7 @@ - + From 99891af738d6132a8fbadc35236e1288b3d197f7 Mon Sep 17 00:00:00 2001 From: Ryan Gribble Date: Thu, 15 Mar 2018 22:20:04 +1000 Subject: [PATCH 67/84] is travis being weird with git clone? --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 5641fb720a..bbbe495200 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,5 +15,5 @@ before_script: script: - git fetch --unshallow --tags - - git remote + - git remote -v show origin - ./build.sh --verbosity=verbose From b24285d381e1d7a054f205a8692d43d1550d2503 Mon Sep 17 00:00:00 2001 From: Ryan Gribble Date: Thu, 15 Mar 2018 22:44:07 +1000 Subject: [PATCH 68/84] SourceLink may be defaulting to true on CI server so explicitly set it as false rather than omitting it --- build/Tasks/Build.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/Tasks/Build.cs b/build/Tasks/Build.cs index 15d58ce46a..684f3b15bf 100644 --- a/build/Tasks/Build.cs +++ b/build/Tasks/Build.cs @@ -14,7 +14,7 @@ public override void Run(Context context) Configuration = context.Configuration, ArgumentCustomization = args => args .Append("/p:Version={0}", context.Version.GetSemanticVersion()) - .AppendIfTrue(context.LinkSources, "/p:SourceLinkCreate=true") + .Append("/p:SourceLinkCreate={0}", context.LinkSources.ToString().ToLower()) }); } } \ No newline at end of file From 697ca2b5a1bc20c9b89bce01854fcf2c59f03e4f Mon Sep 17 00:00:00 2001 From: Ryan Gribble Date: Thu, 15 Mar 2018 22:59:09 +1000 Subject: [PATCH 69/84] detailed is a bit too verbose for travis, try normal --- build/Tasks/Build.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/Tasks/Build.cs b/build/Tasks/Build.cs index 684f3b15bf..f68487c4ac 100644 --- a/build/Tasks/Build.cs +++ b/build/Tasks/Build.cs @@ -10,7 +10,7 @@ public override void Run(Context context) { context.DotNetCoreBuild("./Octokit.sln", new DotNetCoreBuildSettings { - Verbosity = DotNetCoreVerbosity.Detailed, + Verbosity = DotNetCoreVerbosity.Normal, Configuration = context.Configuration, ArgumentCustomization = args => args .Append("/p:Version={0}", context.Version.GetSemanticVersion()) From 3812a761c778ede9a8a1e4db6f31a7cea3f024ca Mon Sep 17 00:00:00 2001 From: Ryan Gribble Date: Thu, 15 Mar 2018 23:11:59 +1000 Subject: [PATCH 70/84] turn sourcelink back on for Linux/OSX --- .travis.yml | 2 +- appveyor.yml | 2 +- build.ps1 | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index bbbe495200..eaf9d97e02 100644 --- a/.travis.yml +++ b/.travis.yml @@ -16,4 +16,4 @@ before_script: script: - git fetch --unshallow --tags - git remote -v show origin - - ./build.sh --verbosity=verbose + - ./build.sh --linksources=true --verbosity=verbose diff --git a/appveyor.yml b/appveyor.yml index f806456db8..afa12b1369 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -5,7 +5,7 @@ init: build_script: - dotnet --info - - ps: .\build.ps1 -LinkSources + - ps: .\build.ps1 -LinkSources -Verbosity Verbose test: off diff --git a/build.ps1 b/build.ps1 index a2e6e94ef6..2cceda4763 100644 --- a/build.ps1 +++ b/build.ps1 @@ -26,7 +26,7 @@ Param( [string]$Configuration = "Release", [switch]$LinkSources, [ValidateSet("Quiet", "Minimal", "Normal", "Verbose", "Diagnostic")] - [string]$Verbosity = "Verbose", + [string]$Verbosity = "Normal", [switch]$WhatIf, [Parameter(Position=0,Mandatory=$false,ValueFromRemainingArguments=$true)] [string[]]$ScriptArgs From 5775520d8b8243ef45ac16e37f29d0ce4ef17e1f Mon Sep 17 00:00:00 2001 From: Ryan Gribble Date: Fri, 16 Mar 2018 21:38:33 +1000 Subject: [PATCH 71/84] fix compiler warning --- Octokit/Models/Response/Installation.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Octokit/Models/Response/Installation.cs b/Octokit/Models/Response/Installation.cs index e7a77841b8..cadf38bc0e 100644 --- a/Octokit/Models/Response/Installation.cs +++ b/Octokit/Models/Response/Installation.cs @@ -74,7 +74,7 @@ public Installation(long id, User account, string accessTokenUrl, string reposit /// public StringEnum RepositorySelection { get; protected set; } - internal string DebuggerDisplay + internal new string DebuggerDisplay { get { return string.Format(CultureInfo.InvariantCulture, "Id: {0} AppId: {1}", Id, AppId); } } From e3b385891205cac07b34207112d201593e6b037a Mon Sep 17 00:00:00 2001 From: Ryan Gribble Date: Fri, 16 Mar 2018 21:39:32 +1000 Subject: [PATCH 72/84] Try SourceLink.Create.CommandLine instead of SourceLink.Create.GitHub --- Octokit.Reactive/Octokit.Reactive.csproj | 9 +++------ Octokit/Octokit.csproj | 2 +- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/Octokit.Reactive/Octokit.Reactive.csproj b/Octokit.Reactive/Octokit.Reactive.csproj index 08e99ec587..0d3c9b2d4f 100644 --- a/Octokit.Reactive/Octokit.Reactive.csproj +++ b/Octokit.Reactive/Octokit.Reactive.csproj @@ -33,6 +33,9 @@ + + + @@ -40,10 +43,4 @@ - - - - - - diff --git a/Octokit/Octokit.csproj b/Octokit/Octokit.csproj index fe8654680a..57f4db5238 100644 --- a/Octokit/Octokit.csproj +++ b/Octokit/Octokit.csproj @@ -37,7 +37,7 @@ - + From bddd276987ca7628573ce81c49796fac59c6ca8c Mon Sep 17 00:00:00 2001 From: Ryan Gribble Date: Fri, 16 Mar 2018 22:15:32 +1000 Subject: [PATCH 73/84] CliToolReferences did not update to latest versions --- Octokit.Reactive/Octokit.Reactive.csproj | 4 ++-- Octokit/Octokit.csproj | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Octokit.Reactive/Octokit.Reactive.csproj b/Octokit.Reactive/Octokit.Reactive.csproj index 0d3c9b2d4f..981d448083 100644 --- a/Octokit.Reactive/Octokit.Reactive.csproj +++ b/Octokit.Reactive/Octokit.Reactive.csproj @@ -34,8 +34,8 @@ - - + + diff --git a/Octokit/Octokit.csproj b/Octokit/Octokit.csproj index 57f4db5238..88f50e45d6 100644 --- a/Octokit/Octokit.csproj +++ b/Octokit/Octokit.csproj @@ -38,8 +38,8 @@ - - + + From 1b6e6d3cf79c0aaba5370ac7db5ef3cfb6a0dd51 Mon Sep 17 00:00:00 2001 From: Ryan Gribble Date: Sat, 17 Mar 2018 21:59:53 +1000 Subject: [PATCH 74/84] remove debug origin info --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index eaf9d97e02..d9f978c4d2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,5 +15,4 @@ before_script: script: - git fetch --unshallow --tags - - git remote -v show origin - ./build.sh --linksources=true --verbosity=verbose From 8ff176b9c5c7bc172aab69277e757d4713cac2f3 Mon Sep 17 00:00:00 2001 From: Ryan Gribble Date: Sat, 17 Mar 2018 22:00:16 +1000 Subject: [PATCH 75/84] turn off msbuild output --- build/Tasks/Build.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/build/Tasks/Build.cs b/build/Tasks/Build.cs index f68487c4ac..68035fc0bd 100644 --- a/build/Tasks/Build.cs +++ b/build/Tasks/Build.cs @@ -10,7 +10,6 @@ public override void Run(Context context) { context.DotNetCoreBuild("./Octokit.sln", new DotNetCoreBuildSettings { - Verbosity = DotNetCoreVerbosity.Normal, Configuration = context.Configuration, ArgumentCustomization = args => args .Append("/p:Version={0}", context.Version.GetSemanticVersion()) From 2f0c914ba3b488f09f208b3b74c6203252704787 Mon Sep 17 00:00:00 2001 From: Ryan Gribble Date: Sat, 17 Mar 2018 22:00:35 +1000 Subject: [PATCH 76/84] go back to SourceLink.Create.GitHub! --- Octokit.Reactive/Octokit.Reactive.csproj | 2 +- Octokit/Octokit.csproj | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Octokit.Reactive/Octokit.Reactive.csproj b/Octokit.Reactive/Octokit.Reactive.csproj index 981d448083..74412737fd 100644 --- a/Octokit.Reactive/Octokit.Reactive.csproj +++ b/Octokit.Reactive/Octokit.Reactive.csproj @@ -33,7 +33,7 @@ - + diff --git a/Octokit/Octokit.csproj b/Octokit/Octokit.csproj index 88f50e45d6..3ea8f869e4 100644 --- a/Octokit/Octokit.csproj +++ b/Octokit/Octokit.csproj @@ -37,7 +37,7 @@ - + From fa98682f0270944dfe2f2fea2bec4e17c5927bc0 Mon Sep 17 00:00:00 2001 From: Ryan Gribble Date: Thu, 22 Mar 2018 08:05:13 +1000 Subject: [PATCH 77/84] time diff between dev PC and API causes issues if specifying a full 600 second token --- Octokit.Tests.Integration/Helper.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Octokit.Tests.Integration/Helper.cs b/Octokit.Tests.Integration/Helper.cs index 0d2c4cdd6b..b987f35b7d 100644 --- a/Octokit.Tests.Integration/Helper.cs +++ b/Octokit.Tests.Integration/Helper.cs @@ -79,7 +79,7 @@ public static class Helper new GitHubJwt.GitHubJwtFactoryOptions { AppIntegrationId = Convert.ToInt32(GitHubAppId), - ExpirationSeconds = 600 + ExpirationSeconds = 590 } ); From a9f83182ed4a6178a535a543d131a18b9633dc33 Mon Sep 17 00:00:00 2001 From: Ryan Gribble Date: Thu, 22 Mar 2018 08:05:33 +1000 Subject: [PATCH 78/84] handle extra date format that Installation end point now returns --- Octokit/SimpleJson.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/Octokit/SimpleJson.cs b/Octokit/SimpleJson.cs index 87653eb92e..4b48db24c7 100644 --- a/Octokit/SimpleJson.cs +++ b/Octokit/SimpleJson.cs @@ -1293,6 +1293,7 @@ class PocoJsonSerializerStrategy : IJsonSerializerStrategy private static readonly string[] Iso8601Format = new string[] { @"yyyy-MM-dd\THH:mm:ss.FFFFFFF\Z", + @"yyyy-MM-dd\THH:mm:ss.FFFFFFFK", @"yyyy-MM-dd\THH:mm:ss\Z", @"yyyy-MM-dd\THH:mm:ssK" }; From 63c11c8dfc32db663128ade2c7295132ead07941 Mon Sep 17 00:00:00 2001 From: Ryan Gribble Date: Thu, 22 Mar 2018 08:05:47 +1000 Subject: [PATCH 79/84] field needs to be protected in order to be deserialized --- Octokit/Models/Response/InstallationId.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Octokit/Models/Response/InstallationId.cs b/Octokit/Models/Response/InstallationId.cs index ccaf8b75f7..973ce84f32 100644 --- a/Octokit/Models/Response/InstallationId.cs +++ b/Octokit/Models/Response/InstallationId.cs @@ -16,7 +16,7 @@ public InstallationId(long id) /// /// The Installation Id. /// - public long Id { get; private set; } + public long Id { get; protected set; } internal string DebuggerDisplay { From dd1f1027ee3df0053e00351b48587a2b5b0b1487 Mon Sep 17 00:00:00 2001 From: Ryan Gribble Date: Wed, 4 Apr 2018 20:44:08 +1000 Subject: [PATCH 80/84] provide even more buffer for client vs server clock drift --- Octokit.Tests.Integration/Helper.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Octokit.Tests.Integration/Helper.cs b/Octokit.Tests.Integration/Helper.cs index b987f35b7d..6f89c1339c 100644 --- a/Octokit.Tests.Integration/Helper.cs +++ b/Octokit.Tests.Integration/Helper.cs @@ -79,7 +79,7 @@ public static class Helper new GitHubJwt.GitHubJwtFactoryOptions { AppIntegrationId = Convert.ToInt32(GitHubAppId), - ExpirationSeconds = 590 + ExpirationSeconds = 500 } ); From ac2b32a9c50d1d5f00bec0892ecf91257d201432 Mon Sep 17 00:00:00 2001 From: Ryan Gribble Date: Wed, 4 Apr 2018 20:44:25 +1000 Subject: [PATCH 81/84] Update to latest GitHubJwt reference --- Octokit.Tests.Integration/Octokit.Tests.Integration.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj b/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj index a73a3c2236..c38f326981 100644 --- a/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj +++ b/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj @@ -47,7 +47,7 @@ - 0.0.1 + 0.0.2 From 89a152a36c0c796a07431836d9bc0b47523a9d54 Mon Sep 17 00:00:00 2001 From: Ryan Gribble Date: Wed, 4 Apr 2018 21:39:32 +1000 Subject: [PATCH 82/84] go back to SDK 1 since SDK 2 is having sporadic travisCI faliures in TestSourceLink build step --- .travis.yml | 4 ++-- .../Octokit.Tests.Conventions.csproj | 2 +- .../Octokit.Tests.Integration.csproj | 6 +++--- Octokit.Tests/Octokit.Tests.csproj | 4 ++-- build.ps1 | 8 ++++---- build/Build.csproj | 2 +- build/Context.cs | 2 +- 7 files changed, 14 insertions(+), 14 deletions(-) diff --git a/.travis.yml b/.travis.yml index d9f978c4d2..016965ce31 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,10 +5,10 @@ matrix: - os: linux dist: trusty sudo: required - dotnet: 2.0.3 + dotnet: 1.0.4 - os: osx osx_image: xcode8.3 - dotnet: 2.0.3 + dotnet: 1.0.4 before_script: - if test "$TRAVIS_OS_NAME" == "osx"; then export FrameworkPathOverride=/Library/Frameworks/Mono.framework/Versions/Current/lib/mono/4.5/; else export FrameworkPathOverride=/usr/lib/mono/4.5/; fi diff --git a/Octokit.Tests.Conventions/Octokit.Tests.Conventions.csproj b/Octokit.Tests.Conventions/Octokit.Tests.Conventions.csproj index 9ec5bb01ea..7b86824986 100644 --- a/Octokit.Tests.Conventions/Octokit.Tests.Conventions.csproj +++ b/Octokit.Tests.Conventions/Octokit.Tests.Conventions.csproj @@ -4,7 +4,7 @@ Convention-based tests for Octokit Octokit.Tests.Conventions GitHub - netcoreapp2.0;net452 + netcoreapp1.0;net452 $(NoWarn);CS4014;CS1998 Octokit.Tests.Conventions Octokit.Tests.Conventions diff --git a/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj b/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj index c38f326981..726470a412 100644 --- a/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj +++ b/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj @@ -4,7 +4,7 @@ Integration tests for Octokit Octokit.Tests.Integration GitHub - netcoreapp2.0;net452 + netcoreapp1.0;net452 $(NoWarn);CS4014;CS1998 Octokit.Tests.Integration Octokit.Tests.Integration @@ -19,7 +19,7 @@ false - + $(DefineConstants);GITHUBJWT_HELPER_AVAILABLE @@ -45,7 +45,7 @@ - + 0.0.2 diff --git a/Octokit.Tests/Octokit.Tests.csproj b/Octokit.Tests/Octokit.Tests.csproj index d53e8befbe..09f702ac02 100644 --- a/Octokit.Tests/Octokit.Tests.csproj +++ b/Octokit.Tests/Octokit.Tests.csproj @@ -4,7 +4,7 @@ Tests for Octokit Octokit.Tests GitHub - netcoreapp2.0;net452 + netcoreapp1.0;net452 $(NoWarn);CS4014;CS1998 Octokit.Tests Octokit.Tests @@ -32,7 +32,7 @@ - + $(DefineConstants);NO_SERIALIZABLE;HAS_TYPEINFO diff --git a/build.ps1 b/build.ps1 index 2cceda4763..850c3be973 100644 --- a/build.ps1 +++ b/build.ps1 @@ -32,9 +32,9 @@ Param( [string[]]$ScriptArgs ) -$DotNetChannel = "2.0"; -$DotNetVersion = "2.0.3"; -$DotNetInstallerUri = "https://dot.net/v1/dotnet-install.ps1"; +$DotNetChannel = "preview"; +$DotNetVersion = "1.0.1"; +$DotNetInstallerUri = "https://raw.githubusercontent.com/dotnet/cli/rel/1.0.1/scripts/obtain/dotnet-install.ps1"; $NugetUrl = "https://dist.nuget.org/win-x86-commandline/latest/nuget.exe" # Make sure tools folder exists @@ -65,7 +65,7 @@ if (Get-Command dotnet -ErrorAction SilentlyContinue) { $FoundDotNetCliVersion = dotnet --version; } -if($FoundDotNetCliVersion -lt $DotNetVersion) { +if($FoundDotNetCliVersion -ne $DotNetVersion) { $InstallPath = Join-Path $PSScriptRoot ".dotnet" if (!(Test-Path $InstallPath)) { mkdir -Force $InstallPath | Out-Null; diff --git a/build/Build.csproj b/build/Build.csproj index 00ec86fa0a..725a902448 100644 --- a/build/Build.csproj +++ b/build/Build.csproj @@ -2,7 +2,7 @@ Exe - netcoreapp2.0 + netcoreapp1.1 diff --git a/build/Context.cs b/build/Context.cs index 12f6cb437f..0fbaedb524 100644 --- a/build/Context.cs +++ b/build/Context.cs @@ -36,7 +36,7 @@ public DotNetCoreTestSettings GetTestSettings() if (!this.IsRunningOnWindows()) { - var testFramework = "netcoreapp2.0"; + var testFramework = "netcoreapp1.0"; this.Information($"Running tests against {testFramework} only as we're not on Windows."); settings.Framework = testFramework; From 08d543987c8f0118ed6236c0e8c902dafea5bc46 Mon Sep 17 00:00:00 2001 From: Ryan Gribble Date: Wed, 4 Apr 2018 22:40:54 +1000 Subject: [PATCH 83/84] get appveyor working --- Octokit.Reactive/Octokit.Reactive.csproj | 9 ++++++--- Octokit/Octokit.csproj | 6 +++--- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/Octokit.Reactive/Octokit.Reactive.csproj b/Octokit.Reactive/Octokit.Reactive.csproj index 74412737fd..baad918d5d 100644 --- a/Octokit.Reactive/Octokit.Reactive.csproj +++ b/Octokit.Reactive/Octokit.Reactive.csproj @@ -33,9 +33,6 @@ - - - @@ -43,4 +40,10 @@ + + + + + + diff --git a/Octokit/Octokit.csproj b/Octokit/Octokit.csproj index 3ea8f869e4..d46a35000a 100644 --- a/Octokit/Octokit.csproj +++ b/Octokit/Octokit.csproj @@ -37,9 +37,9 @@ - - - + + + From b6cc81df70097d8eefbfd4f187350b38ca175984 Mon Sep 17 00:00:00 2001 From: Ryan Gribble Date: Wed, 4 Apr 2018 23:02:24 +1000 Subject: [PATCH 84/84] update sourcelink back to latest, and use SDK 1.04 (runtime 1.0.5) --- Octokit.Reactive/Octokit.Reactive.csproj | 9 +++------ Octokit/Octokit.csproj | 6 +++--- build.ps1 | 2 +- 3 files changed, 7 insertions(+), 10 deletions(-) diff --git a/Octokit.Reactive/Octokit.Reactive.csproj b/Octokit.Reactive/Octokit.Reactive.csproj index baad918d5d..74412737fd 100644 --- a/Octokit.Reactive/Octokit.Reactive.csproj +++ b/Octokit.Reactive/Octokit.Reactive.csproj @@ -33,6 +33,9 @@ + + + @@ -40,10 +43,4 @@ - - - - - - diff --git a/Octokit/Octokit.csproj b/Octokit/Octokit.csproj index d46a35000a..3ea8f869e4 100644 --- a/Octokit/Octokit.csproj +++ b/Octokit/Octokit.csproj @@ -37,9 +37,9 @@ - - - + + + diff --git a/build.ps1 b/build.ps1 index 850c3be973..e4fcc58b21 100644 --- a/build.ps1 +++ b/build.ps1 @@ -33,7 +33,7 @@ Param( ) $DotNetChannel = "preview"; -$DotNetVersion = "1.0.1"; +$DotNetVersion = "1.0.4"; $DotNetInstallerUri = "https://raw.githubusercontent.com/dotnet/cli/rel/1.0.1/scripts/obtain/dotnet-install.ps1"; $NugetUrl = "https://dist.nuget.org/win-x86-commandline/latest/nuget.exe"