Skip to content

Commit

Permalink
Adding functionality to query installations for user
Browse files Browse the repository at this point in the history
  • Loading branch information
StanleyGoldman committed Aug 7, 2018
1 parent 90b0a7c commit a80e226
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 0 deletions.
35 changes: 35 additions & 0 deletions Octokit.Tests/Clients/GitHubAppsClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,5 +101,40 @@ public void PostsToCorrectUrl()
connection.Received().Post<AccessToken>(Arg.Is<Uri>(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<IApiConnection>();
var client = new GitHubAppsClient(connection);

client.GetAllInstallationsForUser();

connection.Received().GetAll<Installation>(Arg.Is<Uri>(u => u.ToString() == "user/installations"), null, "application/vnd.github.machine-man-preview+json");
}
}

public class TheGetInstallationsForUserMethod
{
[Fact]
public void GetsFromCorrectUrl()
{
var connection = Substitute.For<IApiConnection>();
var client = new GitHubAppsClient(connection);

var options = new ApiOptions
{
PageSize = 1,
PageCount = 1,
StartPage = 1
};

client.GetInstallationsForUser(options);

connection.Received().GetAll<Installation>(Arg.Is<Uri>(u => u.ToString() == "user/installations"), null, "application/vnd.github.machine-man-preview+json", options);
}
}
}
}
20 changes: 20 additions & 0 deletions Octokit/Clients/GitHubAppsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,5 +78,25 @@ public Task<AccessToken> CreateInstallationToken(long installationId)
{
return ApiConnection.Post<AccessToken>(ApiUrls.AccessTokens(installationId), string.Empty, AcceptHeaders.GitHubAppsPreview);
}

/// <summary>
/// List installations for user
/// </summary>
/// <remarks>https://developer.github.com/v3/apps/#list-installations-for-user</remarks>
public Task<IReadOnlyList<Installation>> GetAllInstallationsForUser()
{
return ApiConnection.GetAll<Installation>(ApiUrls.UserInstallations(), null, AcceptHeaders.GitHubAppsPreview);
}

/// <summary>
/// List installations for user
/// </summary>
/// <remarks>https://developer.github.com/v3/apps/#list-installations-for-user</remarks>
public Task<IReadOnlyList<Installation>> GetInstallationsForUser(ApiOptions options)
{
Ensure.ArgumentNotNull(options, nameof(options));

return ApiConnection.GetAll<Installation>(ApiUrls.UserInstallations(), null, AcceptHeaders.GitHubAppsPreview, options);
}
}
}
12 changes: 12 additions & 0 deletions Octokit/Clients/IGitHubAppsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,17 @@ public interface IGitHubAppsClient
/// </remarks>
/// <param name="installationId">The Id of the GitHub App Installation</param>
Task<AccessToken> CreateInstallationToken(long installationId);

/// <summary>
/// List installations for user
/// </summary>
/// <remarks>https://developer.github.com/v3/apps/#list-installations-for-user</remarks>
Task<IReadOnlyList<Installation>> GetAllInstallationsForUser();

/// <summary>
/// List installations for user
/// </summary>
/// <remarks>https://developer.github.com/v3/apps/#list-installations-for-user</remarks>
Task<IReadOnlyList<Installation>> GetInstallationsForUser(ApiOptions options);
}
}
9 changes: 9 additions & 0 deletions Octokit/Helpers/ApiUrls.cs
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,15 @@ public static Uri Installation(long installationId)
return "app/installations/{0}".FormatUri(installationId);
}

/// <summary>
/// Returns the <see cref="Uri"/> that returns all the installations in repositories the user has explicit permission to access
/// </summary>
/// <returns></returns>
public static Uri UserInstallations()
{
return "user/installations".FormatUri();
}

/// <summary>
/// Returns the <see cref="Uri"/> that returns all of the issues across all the authenticated user’s visible
/// repositories including owned repositories, member repositories, and organization repositories:
Expand Down

0 comments on commit a80e226

Please sign in to comment.