using System.Linq; using System.Threading.Tasks; namespace Octokit { /// /// A client for GitHub Applications Installations API. /// /// /// See the GitHub Apps Installations API documentation for more information. /// public class GitHubAppInstallationsClient : ApiClient, IGitHubAppInstallationsClient { public GitHubAppInstallationsClient(IApiConnection apiConnection) : base(apiConnection) { } /// /// List repositories of the authenticated GitHub App Installation (requires GitHubApp Installation-Token auth). /// /// https://developer.github.com/v3/apps/installations/#list-repositories [ManualRoute("GET", "/installation/repositories")] public Task GetAllRepositoriesForCurrent() { return GetAllRepositoriesForCurrent(ApiOptions.None); } /// /// List repositories of the authenticated GitHub App Installation (requires GitHubApp Installation-Token auth). /// /// Options for changing the API response /// https://developer.github.com/v3/apps/installations/#list-repositories [Preview("machine-man")] [ManualRoute("GET", "/installation/repositories")] public async Task GetAllRepositoriesForCurrent(ApiOptions options) { Ensure.ArgumentNotNull(options, nameof(options)); var results = await ApiConnection.GetAll(ApiUrls.InstallationRepositories(), null, AcceptHeaders.GitHubAppsPreview, options).ConfigureAwait(false); return new RepositoriesResponse( results.Count > 0 ? results.Max(x => x.TotalCount) : 0, results.SelectMany(x => x.Repositories).ToList()); } /// /// List repositories accessible to the user for an installation (requires GitHubApp User-To-Server Auth). /// /// The Id of the installation /// https://developer.github.com/v3/apps/installations/#list-repositories-accessible-to-the-user-for-an-installation [ManualRoute("GET", "/user/installation/{id}/repositories")] public Task GetAllRepositoriesForCurrentUser(long installationId) { return GetAllRepositoriesForCurrentUser(installationId, ApiOptions.None); } /// /// List repositories accessible to the user for an installation (requires GitHubApp User-To-Server Auth). /// /// The Id of the installation /// Options for changing the API response /// https://developer.github.com/v3/apps/installations/#list-repositories-accessible-to-the-user-for-an-installation [Preview("machine-man")] [ManualRoute("GET", "/user/installation/{id}/repositories")] public async Task GetAllRepositoriesForCurrentUser(long installationId, ApiOptions options) { Ensure.ArgumentNotNull(options, nameof(options)); var results = await ApiConnection.GetAll(ApiUrls.UserInstallationRepositories(installationId), null, AcceptHeaders.GitHubAppsPreview, options).ConfigureAwait(false); return new RepositoriesResponse( results.Count > 0 ? results.Max(x => x.TotalCount) : 0, results.SelectMany(x => x.Repositories).ToList()); } } }