From a80e226dce8d58c577d9e7f11c1a475308d6dbf0 Mon Sep 17 00:00:00 2001 From: Stanley Goldman Date: Tue, 7 Aug 2018 12:52:32 -0400 Subject: [PATCH] Adding functionality to query installations for user --- .../Clients/GitHubAppsClientTests.cs | 35 +++++++++++++++++++ Octokit/Clients/GitHubAppsClient.cs | 20 +++++++++++ Octokit/Clients/IGitHubAppsClient.cs | 12 +++++++ Octokit/Helpers/ApiUrls.cs | 9 +++++ 4 files changed, 76 insertions(+) diff --git a/Octokit.Tests/Clients/GitHubAppsClientTests.cs b/Octokit.Tests/Clients/GitHubAppsClientTests.cs index 201a32de3d..35e1c01627 100644 --- a/Octokit.Tests/Clients/GitHubAppsClientTests.cs +++ b/Octokit.Tests/Clients/GitHubAppsClientTests.cs @@ -101,5 +101,40 @@ public void PostsToCorrectUrl() connection.Received().Post(Arg.Is(u => u.ToString() == "installations/3141/access_tokens"), string.Empty, "application/vnd.github.machine-man-preview+json"); } } + + public class TheGetAllInstallationsForUserMethod + { + [Fact] + public void GetsFromCorrectUrl() + { + var connection = Substitute.For(); + var client = new GitHubAppsClient(connection); + + client.GetAllInstallationsForUser(); + + connection.Received().GetAll(Arg.Is(u => u.ToString() == "user/installations"), null, "application/vnd.github.machine-man-preview+json"); + } + } + + public class TheGetInstallationsForUserMethod + { + [Fact] + public void GetsFromCorrectUrl() + { + var connection = Substitute.For(); + var client = new GitHubAppsClient(connection); + + var options = new ApiOptions + { + PageSize = 1, + PageCount = 1, + StartPage = 1 + }; + + client.GetInstallationsForUser(options); + + connection.Received().GetAll(Arg.Is(u => u.ToString() == "user/installations"), null, "application/vnd.github.machine-man-preview+json", options); + } + } } } diff --git a/Octokit/Clients/GitHubAppsClient.cs b/Octokit/Clients/GitHubAppsClient.cs index 0a865fb1b7..f365393d15 100644 --- a/Octokit/Clients/GitHubAppsClient.cs +++ b/Octokit/Clients/GitHubAppsClient.cs @@ -78,5 +78,25 @@ public Task CreateInstallationToken(long installationId) { return ApiConnection.Post(ApiUrls.AccessTokens(installationId), string.Empty, AcceptHeaders.GitHubAppsPreview); } + + /// + /// List installations for user + /// + /// https://developer.github.com/v3/apps/#list-installations-for-user + public Task> GetAllInstallationsForUser() + { + return ApiConnection.GetAll(ApiUrls.UserInstallations(), null, AcceptHeaders.GitHubAppsPreview); + } + + /// + /// List installations for user + /// + /// https://developer.github.com/v3/apps/#list-installations-for-user + public Task> GetInstallationsForUser(ApiOptions options) + { + Ensure.ArgumentNotNull(options, nameof(options)); + + return ApiConnection.GetAll(ApiUrls.UserInstallations(), null, AcceptHeaders.GitHubAppsPreview, options); + } } } \ No newline at end of file diff --git a/Octokit/Clients/IGitHubAppsClient.cs b/Octokit/Clients/IGitHubAppsClient.cs index 71802151f7..55a391fb97 100644 --- a/Octokit/Clients/IGitHubAppsClient.cs +++ b/Octokit/Clients/IGitHubAppsClient.cs @@ -54,5 +54,17 @@ public interface IGitHubAppsClient /// /// The Id of the GitHub App Installation Task CreateInstallationToken(long installationId); + + /// + /// List installations for user + /// + /// https://developer.github.com/v3/apps/#list-installations-for-user + Task> GetAllInstallationsForUser(); + + /// + /// List installations for user + /// + /// https://developer.github.com/v3/apps/#list-installations-for-user + Task> GetInstallationsForUser(ApiOptions options); } } \ No newline at end of file diff --git a/Octokit/Helpers/ApiUrls.cs b/Octokit/Helpers/ApiUrls.cs index c7c8d3179b..3d67f95c84 100644 --- a/Octokit/Helpers/ApiUrls.cs +++ b/Octokit/Helpers/ApiUrls.cs @@ -324,6 +324,15 @@ public static Uri Installation(long installationId) return "app/installations/{0}".FormatUri(installationId); } + /// + /// Returns the that returns all the installations in repositories the user has explicit permission to access + /// + /// + public static Uri UserInstallations() + { + return "user/installations".FormatUri(); + } + /// /// Returns the that returns all of the issues across all the authenticated user’s visible /// repositories including owned repositories, member repositories, and organization repositories: