mirror of
https://github.com/zoriya/octokit.net.git
synced 2026-06-05 11:40:42 +00:00
Implement Enterprise Organization client
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Octokit;
|
||||
using Octokit.Tests.Integration;
|
||||
using Xunit;
|
||||
|
||||
public class EnterpriseOrganizationClientTests
|
||||
{
|
||||
readonly IGitHubClient _github;
|
||||
|
||||
public EnterpriseOrganizationClientTests()
|
||||
{
|
||||
_github = EnterpriseHelper.GetAuthenticatedClient();
|
||||
}
|
||||
|
||||
[GitHubEnterpriseTest]
|
||||
public async Task CanCreateOrganization()
|
||||
{
|
||||
string orgLogin = Helper.MakeNameWithTimestamp("MyOrganization");
|
||||
string orgName = String.Concat(orgLogin, " Display Name");
|
||||
|
||||
var newOrganization = new NewOrganization(orgLogin, EnterpriseHelper.GHEUserName, orgName);
|
||||
var organization = await
|
||||
_github.Enterprise.Organization.Create(newOrganization);
|
||||
|
||||
Assert.NotNull(organization);
|
||||
|
||||
// Get organization and check login/name
|
||||
var checkOrg = await _github.Organization.Get(orgLogin);
|
||||
Assert.Equal(checkOrg.Login, orgLogin);
|
||||
Assert.Equal(checkOrg.Name, orgName);
|
||||
}
|
||||
}
|
||||
@@ -79,6 +79,7 @@
|
||||
<Compile Include="Clients\BranchesClientTests.cs" />
|
||||
<Compile Include="Clients\Enterprise\EnterpriseLicenseClientTests.cs" />
|
||||
<Compile Include="Clients\Enterprise\EnterpriseAdminStatsClientTests.cs" />
|
||||
<Compile Include="Clients\Enterprise\EnterpriseOrganizationClientTests.cs" />
|
||||
<Compile Include="Clients\GitHubClientTests.cs" />
|
||||
<Compile Include="Clients\MergingClientTests.cs" />
|
||||
<Compile Include="Clients\CommitsClientTests.cs" />
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using NSubstitute;
|
||||
using Xunit;
|
||||
|
||||
namespace Octokit.Tests.Clients
|
||||
{
|
||||
public class EnterpriseOrganizationClientTests
|
||||
{
|
||||
public class TheCreateMethod
|
||||
{
|
||||
[Fact]
|
||||
public void RequestsCorrectUrl()
|
||||
{
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new EnterpriseOrganizationClient(connection);
|
||||
|
||||
string expectedUri = "admin/organizations";
|
||||
client.Create(new NewOrganization("org", "admin", "org name"));
|
||||
|
||||
connection.Received().Post<Organization>(Arg.Is<Uri>(u => u.ToString() == expectedUri), Arg.Any<object>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void PassesRequestObject()
|
||||
{
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new EnterpriseOrganizationClient(connection);
|
||||
|
||||
client.Create(new NewOrganization("org", "admin", "org name"));
|
||||
|
||||
connection.Received().Post<Organization>(
|
||||
Arg.Any<Uri>(),
|
||||
Arg.Is<NewOrganization>(a =>
|
||||
a.Login == "org"
|
||||
&& a.Admin == "admin"
|
||||
&& a.ProfileName == "org name"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task EnsuresNonNullArguments()
|
||||
{
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new EnterpriseOrganizationClient(connection);
|
||||
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Create(null));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -86,6 +86,7 @@
|
||||
<ItemGroup>
|
||||
<Compile Include="Authentication\CredentialsTests.cs" />
|
||||
<Compile Include="Clients\Enterprise\EnterpriseAdminStatsClientTests.cs" />
|
||||
<Compile Include="Clients\Enterprise\EnterpriseOrganizationClientTests.cs" />
|
||||
<Compile Include="Clients\Enterprise\EnterpriseLicenseClientTests.cs" />
|
||||
<Compile Include="Clients\MergingClientTests.cs" />
|
||||
<Compile Include="Clients\OauthClientTests.cs" />
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
{
|
||||
AdminStats = new EnterpriseAdminStatsClient(apiConnection);
|
||||
License = new EnterpriseLicenseClient(apiConnection);
|
||||
Organization = new EnterpriseOrganizationClient(apiConnection);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -33,5 +34,13 @@
|
||||
/// See the <a href="https://developer.github.com/v3/enterprise/license/">Enterprise License API documentation</a> for more information.
|
||||
///</remarks>
|
||||
public IEnterpriseLicenseClient License { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// A client for GitHub's Enterprise Organization API
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// See the <a href="https://developer.github.com/v3/enterprise/orgs/">Enterprise Organization API documentation</a> for more information.
|
||||
///</remarks>
|
||||
public IEnterpriseOrganizationClient Organization { get; private set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Octokit
|
||||
{
|
||||
/// <summary>
|
||||
/// A client for GitHub's Enterprise Organization API
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// See the <a href="https://developer.github.com/v3/enterprise/orgs/">Enterprise Organization API documentation</a> for more information.
|
||||
///</remarks>
|
||||
public class EnterpriseOrganizationClient : ApiClient, IEnterpriseOrganizationClient
|
||||
{
|
||||
public EnterpriseOrganizationClient(IApiConnection apiConnection)
|
||||
: base(apiConnection)
|
||||
{ }
|
||||
|
||||
/// <summary>
|
||||
/// Creates an Organization on a GitHub Enterprise appliance (must be Site Admin user).
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// https://developer.github.com/v3/enterprise/orgs/#create-an-organization
|
||||
/// </remarks>
|
||||
/// <param name="newOrganization">A <see cref="NewOrganization"/> instance describing the organization to be created</param>
|
||||
/// <returns>The <see cref="Organization"/> created.</returns>
|
||||
public async Task<Organization> Create(NewOrganization newOrganization)
|
||||
{
|
||||
Ensure.ArgumentNotNull(newOrganization, "newOrganization");
|
||||
|
||||
var endpoint = ApiUrls.EnterpriseOrganization();
|
||||
|
||||
return await ApiConnection.Post<Organization>(endpoint, newOrganization);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -23,5 +23,13 @@
|
||||
/// See the <a href="https://developer.github.com/v3/enterprise/license/">Enterprise License API documentation</a> for more information.
|
||||
///</remarks>
|
||||
IEnterpriseLicenseClient License { get; }
|
||||
|
||||
/// <summary>
|
||||
/// A client for GitHub's Enterprise Organization API
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// See the <a href="https://developer.github.com/v3/enterprise/orgs/">Enterprise Organization API documentation</a> for more information.
|
||||
///</remarks>
|
||||
IEnterpriseOrganizationClient Organization { get; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Octokit
|
||||
{
|
||||
/// <summary>
|
||||
/// A client for GitHub's Enterprise Organization API
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// See the <a href="https://developer.github.com/v3/enterprise/orgs/">Enterprise Organization API documentation</a> for more information.
|
||||
///</remarks>
|
||||
public interface IEnterpriseOrganizationClient
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates an Organization on a GitHub Enterprise appliance (must be Site Admin user).
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// https://developer.github.com/v3/enterprise/orgs/#create-an-organization
|
||||
/// </remarks>
|
||||
/// <param name="newOrganization">A <see cref="NewOrganization"/> instance describing the organization to be created</param>
|
||||
/// <returns>The <see cref="Organization"/> created.</returns>
|
||||
Task<Organization> Create(NewOrganization newOrganization);
|
||||
}
|
||||
}
|
||||
@@ -1657,5 +1657,10 @@ namespace Octokit
|
||||
{
|
||||
return "enterprise/settings/license".FormatUri();
|
||||
}
|
||||
|
||||
public static Uri EnterpriseOrganization()
|
||||
{
|
||||
return "admin/organizations".FormatUri();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
using System;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Diagnostics;
|
||||
using System.Globalization;
|
||||
|
||||
namespace Octokit
|
||||
{
|
||||
/// <summary>
|
||||
/// Describes a new organization to create via the <see cref="IEnterpriseOrganizationClient.Create(NewOrganization)" /> method.
|
||||
/// </summary>
|
||||
[DebuggerDisplay("{DebuggerDisplay,nq}")]
|
||||
public class NewOrganization
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="NewOrganization"/> class.
|
||||
/// </summary>
|
||||
/// <param name="login">The organization's username</param>
|
||||
/// <param name="admin">The login of the user who will manage this organization</param>
|
||||
public NewOrganization(string login, string admin) : this(login, admin, null)
|
||||
{ }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="NewOrganization"/> class.
|
||||
/// </summary>
|
||||
/// <param name="login">The organization's username</param>
|
||||
/// <param name="admin">The login of the user who will manage this organization</param>
|
||||
/// <param name="profileName">The organization's display name</param>
|
||||
public NewOrganization(string login, string admin, string profileName)
|
||||
{
|
||||
Login = login;
|
||||
Admin = admin;
|
||||
ProfileName = profileName;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The organization's username (required)
|
||||
/// </summary>
|
||||
public string Login { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// The login of the user who will manage this organization (required)
|
||||
/// </summary>
|
||||
public string Admin { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// The organization's display name
|
||||
/// </summary>
|
||||
public string ProfileName { get; private set; }
|
||||
|
||||
internal string DebuggerDisplay
|
||||
{
|
||||
get
|
||||
{
|
||||
return string.Format(CultureInfo.InvariantCulture, "Login: {0} Admin: {1} ProfileName: {2}", Login, Admin, ProfileName ?? "");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -59,8 +59,10 @@
|
||||
</Compile>
|
||||
<Compile Include="Clients\ActivitiesClient.cs" />
|
||||
<Compile Include="Clients\Enterprise\EnterpriseAdminStatsClient.cs" />
|
||||
<Compile Include="Clients\Enterprise\EnterpriseOrganizationClient.cs" />
|
||||
<Compile Include="Clients\Enterprise\EnterpriseLicenseClient.cs" />
|
||||
<Compile Include="Clients\Enterprise\EnterpriseClient.cs" />
|
||||
<Compile Include="Clients\Enterprise\IEnterpriseOrganizationClient.cs" />
|
||||
<Compile Include="Clients\Enterprise\IEnterpriseLicenseClient.cs" />
|
||||
<Compile Include="Clients\Enterprise\IEnterpriseAdminStatsClient.cs" />
|
||||
<Compile Include="Clients\Enterprise\IEnterpriseClient.cs" />
|
||||
@@ -106,6 +108,7 @@
|
||||
<Compile Include="Models\Request\BranchUpdate.cs" />
|
||||
<Compile Include="Models\Request\GistFileUpdate.cs" />
|
||||
<Compile Include="Models\Request\NewArbitraryMarkDown.cs" />
|
||||
<Compile Include="Models\Request\NewOrganization.cs" />
|
||||
<Compile Include="Models\Request\NewMerge.cs" />
|
||||
<Compile Include="Models\Request\NewRepositoryWebHook.cs" />
|
||||
<Compile Include="Models\Request\PublicRepositoryRequest.cs" />
|
||||
|
||||
Reference in New Issue
Block a user