mirror of
https://github.com/zoriya/octokit.net.git
synced 2025-12-05 23:06:10 +00:00
Begin implementation of Enterprise ManagementConsole API, redux (#2010)
* Initial implementation of ManagementConsole - maintenance mode * Add environment var support for management console password for integration tests * Add reactive client and unit tests * Update some xmlDoc * I think this is a better way to setup the underlying baseUri on IConneciton, to achieve managemet console access rather than requiring a specific GitHubClient that cant call normal API's Instead, the management client methods can check the base Url and if it contains /api/v3/ they can set their relative endpoint Uri to include a leading "/" which will cause the /api/v3/ to be removed. * Update EnterpriseClient.cs Fix xml comments * Update IEnterpriseClient.cs Fix xml comments * Still trying to get the xmDoc perfect, thanks app veyor :) * XmlDoc'ing my way to success * Add specific test attribute for management console tests * check chronic string empty/null * Use helper's password field in test * Tidy up maintenance mode tests by using a context/destructor to manage the initial/end state of maintenance mode * make internal and tidy up URL concatenation * move GHE endpoint fixup inside ApiUrls methods * Rework request object to be the correct structure so SimpleJsonSerializer can be used to serialize it. Remove MaintenanceDate class and just pass in the Date/string for when Still need to use UrlFormEncoding rather than json in the POST body though... * Create abstract base class for FormUrlEncoded parameters (similar to existing RequetParameters) and inherit from it in UpdateMaintenanceRequest * Fix maintenance context logic - destructor should always turn maintenance OFF regardless of initial requested state * Fix xml comment * Fix Xml comment * Those pesky xml comments! * Fine, I give up! * Fix string.Format * fix bad rebase * fix failing convention tests * restore missing whitespace * writing some docs * some edits * edit
This commit is contained in:
@@ -13,7 +13,7 @@
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// See the <a href="http://developer.github.com/v3/enterprise/admin_stats/">Enterprise Admin Stats API documentation</a> for more information.
|
||||
///</remarks>
|
||||
/// </remarks>
|
||||
IObservableEnterpriseAdminStatsClient AdminStats { get; }
|
||||
|
||||
/// <summary>
|
||||
@@ -21,7 +21,7 @@
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// See the <a href="https://developer.github.com/v3/enterprise/ldap/">Enterprise LDAP API documentation</a> for more information.
|
||||
///</remarks>
|
||||
/// </remarks>
|
||||
IObservableEnterpriseLdapClient Ldap { get; }
|
||||
|
||||
/// <summary>
|
||||
@@ -29,15 +29,23 @@
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// See the <a href="https://developer.github.com/v3/enterprise/license/">Enterprise License API documentation</a> for more information.
|
||||
///</remarks>
|
||||
/// </remarks>
|
||||
IObservableEnterpriseLicenseClient License { get; }
|
||||
|
||||
/// <summary>
|
||||
/// A client for GitHub's Enterprise Management Console API
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// See the <a href="https://developer.github.com/v3/enterprise/management_console/">Enterprise Management Console API documentation</a> for more information.
|
||||
/// </remarks>
|
||||
IObservableEnterpriseManagementConsoleClient ManagementConsole { 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>
|
||||
/// </remarks>
|
||||
IObservableEnterpriseOrganizationClient Organization { get; }
|
||||
|
||||
/// <summary>
|
||||
@@ -45,7 +53,7 @@
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// See the <a href="https://developer.github.com/v3/enterprise/search_indexing/">Enterprise Search Indexing API documentation</a> for more information.
|
||||
///</remarks>
|
||||
/// </remarks>
|
||||
IObservableEnterpriseSearchIndexingClient SearchIndexing { get; }
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
|
||||
namespace Octokit.Reactive
|
||||
{
|
||||
/// <summary>
|
||||
/// A client for GitHub's Enterprise Management Console API
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// See the <a href="https://developer.github.com/v3/enterprise/management_console/">Enterprise Management Console API documentation</a> for more information.
|
||||
/// </remarks>
|
||||
public interface IObservableEnterpriseManagementConsoleClient
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets GitHub Enterprise Maintenance Mode Status
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// https://developer.github.com/v3/enterprise/management_console/#check-maintenance-status
|
||||
/// </remarks>
|
||||
/// <returns>The <see cref="MaintenanceModeResponse"/>.</returns>
|
||||
[SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate")]
|
||||
IObservable<MaintenanceModeResponse> GetMaintenanceMode(string managementConsolePassword);
|
||||
|
||||
/// <summary>
|
||||
/// Sets GitHub Enterprise Maintenance Mode
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// https://developer.github.com/v3/enterprise/management_console/#check-maintenance-status
|
||||
/// </remarks>
|
||||
/// <returns>The <see cref="MaintenanceModeResponse"/>.</returns>
|
||||
IObservable<MaintenanceModeResponse> EditMaintenanceMode(UpdateMaintenanceRequest maintenance, string managementConsolePassword);
|
||||
}
|
||||
}
|
||||
@@ -15,6 +15,7 @@
|
||||
AdminStats = new ObservableEnterpriseAdminStatsClient(client);
|
||||
Ldap = new ObservableEnterpriseLdapClient(client);
|
||||
License = new ObservableEnterpriseLicenseClient(client);
|
||||
ManagementConsole = new ObservableEnterpriseManagementConsoleClient(client);
|
||||
Organization = new ObservableEnterpriseOrganizationClient(client);
|
||||
SearchIndexing = new ObservableEnterpriseSearchIndexingClient(client);
|
||||
PreReceiveEnvironment = new ObservableEnterprisePreReceiveEnvironmentsClient(client);
|
||||
@@ -25,7 +26,7 @@
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// See the <a href="http://developer.github.com/v3/enterprise/admin_stats/">Enterprise Admin Stats API documentation</a> for more information.
|
||||
///</remarks>
|
||||
/// </remarks>
|
||||
public IObservableEnterpriseAdminStatsClient AdminStats { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
@@ -33,7 +34,7 @@
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// See the <a href="https://developer.github.com/v3/enterprise/ldap/">Enterprise LDAP API documentation</a> for more information.
|
||||
///</remarks>
|
||||
/// </remarks>
|
||||
public IObservableEnterpriseLdapClient Ldap { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
@@ -41,15 +42,23 @@
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// See the <a href="https://developer.github.com/v3/enterprise/license/">Enterprise License API documentation</a> for more information.
|
||||
///</remarks>
|
||||
/// </remarks>
|
||||
public IObservableEnterpriseLicenseClient License { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// A client for GitHub's Enterprise Management Console API
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// See the <a href="https://developer.github.com/v3/enterprise/management_console/">Enterprise Management Console API documentation</a> for more information.
|
||||
/// </remarks>
|
||||
public IObservableEnterpriseManagementConsoleClient ManagementConsole { 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>
|
||||
/// </remarks>
|
||||
public IObservableEnterpriseOrganizationClient Organization { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
@@ -57,7 +66,7 @@
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// See the <a href="https://developer.github.com/v3/enterprise/search_indexing/">Enterprise Search Indexing API documentation</a> for more information.
|
||||
///</remarks>
|
||||
/// </remarks>
|
||||
public IObservableEnterpriseSearchIndexingClient SearchIndexing { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
using System;
|
||||
using System.Reactive.Threading.Tasks;
|
||||
|
||||
namespace Octokit.Reactive
|
||||
{
|
||||
/// <summary>
|
||||
/// A client for GitHub's Enterprise Management Console API
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// See the <a href="https://developer.github.com/v3/enterprise/management_console/">Enterprise Management Console API documentation</a> for more information.
|
||||
/// </remarks>
|
||||
public class ObservableEnterpriseManagementConsoleClient : IObservableEnterpriseManagementConsoleClient
|
||||
{
|
||||
readonly IEnterpriseManagementConsoleClient _client;
|
||||
|
||||
public ObservableEnterpriseManagementConsoleClient(IGitHubClient client)
|
||||
{
|
||||
Ensure.ArgumentNotNull(client, "client");
|
||||
|
||||
_client = client.Enterprise.ManagementConsole;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets GitHub Enterprise Maintenance Mode Status
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// https://developer.github.com/v3/enterprise/management_console/#check-maintenance-status
|
||||
/// </remarks>
|
||||
/// <returns>The <see cref="MaintenanceModeResponse"/>.</returns>
|
||||
public IObservable<MaintenanceModeResponse> GetMaintenanceMode(string managementConsolePassword)
|
||||
{
|
||||
Ensure.ArgumentNotNullOrEmptyString(managementConsolePassword, "managementConsolePassword");
|
||||
|
||||
return _client.GetMaintenanceMode(managementConsolePassword).ToObservable();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets GitHub Enterprise Maintenance Mode
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// https://developer.github.com/v3/enterprise/management_console/#check-maintenance-status
|
||||
/// </remarks>
|
||||
/// <returns>The <see cref="MaintenanceModeResponse"/>.</returns>
|
||||
public IObservable<MaintenanceModeResponse> EditMaintenanceMode(UpdateMaintenanceRequest maintenance, string managementConsolePassword)
|
||||
{
|
||||
Ensure.ArgumentNotNull(maintenance, "maintenance");
|
||||
Ensure.ArgumentNotNullOrEmptyString(managementConsolePassword, "managementConsolePassword");
|
||||
|
||||
return _client.EditMaintenanceMode(maintenance, managementConsolePassword).ToObservable();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Octokit;
|
||||
using Octokit.Tests.Integration;
|
||||
using Octokit.Tests.Integration.Helpers;
|
||||
using Xunit;
|
||||
|
||||
public class EnterpriseManagementConsoleClientTests
|
||||
{
|
||||
readonly IGitHubClient _github;
|
||||
|
||||
public EnterpriseManagementConsoleClientTests()
|
||||
{
|
||||
_github = EnterpriseHelper.GetAuthenticatedClient();
|
||||
}
|
||||
|
||||
[GitHubEnterpriseManagementConsoleTest]
|
||||
public async Task CanGetMaintenanceMode()
|
||||
{
|
||||
var maintenance = await _github.Enterprise.ManagementConsole.GetMaintenanceMode(EnterpriseHelper.ManagementConsolePassword);
|
||||
|
||||
Assert.NotNull(maintenance);
|
||||
}
|
||||
|
||||
[GitHubEnterpriseManagementConsoleTest]
|
||||
public async Task CanSetMaintenanceModeOff()
|
||||
{
|
||||
using (_github.CreateMaintenanceModeContext(true))
|
||||
{
|
||||
// Set maintenance mode OFF now
|
||||
var maintenance = await
|
||||
_github.Enterprise.ManagementConsole.EditMaintenanceMode(
|
||||
new UpdateMaintenanceRequest(),
|
||||
EnterpriseHelper.ManagementConsolePassword);
|
||||
|
||||
Assert.Equal(maintenance.Status, MaintenanceModeStatus.Off);
|
||||
}
|
||||
}
|
||||
|
||||
[GitHubEnterpriseManagementConsoleTest]
|
||||
public async Task CanSetMaintenanceModeOnNow()
|
||||
{
|
||||
using (_github.CreateMaintenanceModeContext(false))
|
||||
{
|
||||
// Set maintenance mode ON now
|
||||
var maintenance = await
|
||||
_github.Enterprise.ManagementConsole.EditMaintenanceMode(
|
||||
new UpdateMaintenanceRequest(
|
||||
new UpdateMaintenanceRequestDetails(true)),
|
||||
EnterpriseHelper.ManagementConsolePassword);
|
||||
|
||||
Assert.Equal(maintenance.Status, MaintenanceModeStatus.On);
|
||||
}
|
||||
}
|
||||
|
||||
[GitHubEnterpriseManagementConsoleTest]
|
||||
public async Task CanScheduleMaintenanceModeOnWithDateTime()
|
||||
{
|
||||
using (_github.CreateMaintenanceModeContext(false))
|
||||
{
|
||||
// Schedule maintenance mode ON in 5 minutes
|
||||
var scheduledTime = DateTimeOffset.Now.AddMinutes(5);
|
||||
var maintenance = await
|
||||
_github.Enterprise.ManagementConsole.EditMaintenanceMode(
|
||||
new UpdateMaintenanceRequest(
|
||||
new UpdateMaintenanceRequestDetails(true, scheduledTime)),
|
||||
EnterpriseHelper.ManagementConsolePassword);
|
||||
|
||||
Assert.Equal(maintenance.Status, MaintenanceModeStatus.Scheduled);
|
||||
}
|
||||
}
|
||||
|
||||
[GitHubEnterpriseManagementConsoleTest]
|
||||
public async Task CanScheduleMaintenanceModeOnWithPhrase()
|
||||
{
|
||||
using (_github.CreateMaintenanceModeContext(false))
|
||||
{
|
||||
// Schedule maintenance mode ON with phrase
|
||||
var maintenance = await
|
||||
_github.Enterprise.ManagementConsole.EditMaintenanceMode(
|
||||
new UpdateMaintenanceRequest(
|
||||
new UpdateMaintenanceRequestDetails(true, "tomorrow at 5pm")),
|
||||
EnterpriseHelper.ManagementConsolePassword);
|
||||
|
||||
Assert.Equal(maintenance.Status, MaintenanceModeStatus.Scheduled);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -69,7 +69,7 @@ namespace Octokit.Tests.Integration
|
||||
static EnterpriseHelper()
|
||||
{
|
||||
// Force reading of environment variables.
|
||||
// This wasn't happening if UserName/Organization were
|
||||
// This wasn't happening if UserName/Organization were
|
||||
// retrieved before Credentials.
|
||||
Debug.WriteIf(Credentials == null, "No credentials specified.");
|
||||
}
|
||||
@@ -108,10 +108,9 @@ namespace Octokit.Tests.Integration
|
||||
get { return Environment.GetEnvironmentVariable("OCTOKIT_GHE_CLIENTSECRET"); }
|
||||
}
|
||||
|
||||
public static void DeleteUser(IConnection connection, User user)
|
||||
public static string ManagementConsolePassword
|
||||
{
|
||||
if (user != null)
|
||||
DeleteUser(connection, user.Login);
|
||||
get { return Environment.GetEnvironmentVariable("OCTOKIT_GHE_CONSOLEPASSWORD"); }
|
||||
}
|
||||
|
||||
public static void DeleteUser(IConnection connection, string username)
|
||||
@@ -162,6 +161,19 @@ namespace Octokit.Tests.Integration
|
||||
}
|
||||
}
|
||||
|
||||
public static void SetMaintenanceMode(IConnection connection, bool enabled)
|
||||
{
|
||||
try
|
||||
{
|
||||
var client = new GitHubClient(connection);
|
||||
client.Enterprise.ManagementConsole.EditMaintenanceMode(
|
||||
new UpdateMaintenanceRequest(new UpdateMaintenanceRequestDetails(enabled)),
|
||||
EnterpriseHelper.ManagementConsolePassword)
|
||||
.Wait(TimeSpan.FromSeconds(15));
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
|
||||
public static IGitHubClient GetAuthenticatedClient()
|
||||
{
|
||||
return new GitHubClient(new ProductHeaderValue("OctokitEnterpriseTests"), GitHubEnterpriseUrl)
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Xunit;
|
||||
using Xunit.Abstractions;
|
||||
using Xunit.Sdk;
|
||||
|
||||
namespace Octokit.Tests.Integration
|
||||
{
|
||||
public class GitHubEnterpriseManagementConsoleTestDiscoverer : IXunitTestCaseDiscoverer
|
||||
{
|
||||
readonly IMessageSink diagnosticMessageSink;
|
||||
|
||||
public GitHubEnterpriseManagementConsoleTestDiscoverer(IMessageSink diagnosticMessageSink)
|
||||
{
|
||||
this.diagnosticMessageSink = diagnosticMessageSink;
|
||||
}
|
||||
|
||||
public IEnumerable<IXunitTestCase> Discover(ITestFrameworkDiscoveryOptions discoveryOptions, ITestMethod testMethod, IAttributeInfo factAttribute)
|
||||
{
|
||||
if (Helper.Credentials == null)
|
||||
return Enumerable.Empty<IXunitTestCase>();
|
||||
|
||||
if (!EnterpriseHelper.IsGitHubEnterpriseEnabled)
|
||||
return Enumerable.Empty<IXunitTestCase>();
|
||||
|
||||
if (String.IsNullOrEmpty(EnterpriseHelper.ManagementConsolePassword))
|
||||
return Enumerable.Empty<IXunitTestCase>();
|
||||
|
||||
return new[] { new XunitTestCase(diagnosticMessageSink, discoveryOptions.MethodDisplayOrDefault(), testMethod) };
|
||||
}
|
||||
}
|
||||
|
||||
[XunitTestCaseDiscoverer("Octokit.Tests.Integration.GitHubEnterpriseManagementConsoleTestDiscoverer", "Octokit.Tests.Integration")]
|
||||
public class GitHubEnterpriseManagementConsoleTestAttribute : FactAttribute
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -79,5 +79,10 @@ VO/+BCBsaoT4g1FFOmJhbBAD3G72yslBnUJmqKP/39pi
|
||||
|
||||
return new GpgKeyContext(client.Connection, key);
|
||||
}
|
||||
|
||||
internal static MaintenanceModeContext CreateMaintenanceModeContext(this IGitHubClient client, bool enabled)
|
||||
{
|
||||
return new MaintenanceModeContext(client.Connection, enabled);
|
||||
}
|
||||
}
|
||||
}
|
||||
28
Octokit.Tests.Integration/Helpers/MaintenanceModeContext.cs
Normal file
28
Octokit.Tests.Integration/Helpers/MaintenanceModeContext.cs
Normal file
@@ -0,0 +1,28 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Octokit.Reactive;
|
||||
|
||||
namespace Octokit.Tests.Integration.Helpers
|
||||
{
|
||||
internal sealed class MaintenanceModeContext : IDisposable
|
||||
{
|
||||
internal MaintenanceModeContext(IConnection connection, bool enabled)
|
||||
{
|
||||
_connection = connection;
|
||||
|
||||
// Ensure maintenance mode is in the desired initial state
|
||||
EnterpriseHelper.SetMaintenanceMode(_connection, enabled);
|
||||
}
|
||||
|
||||
private IConnection _connection;
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
// Ensure maintenance mode is OFF
|
||||
EnterpriseHelper.SetMaintenanceMode(_connection, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using NSubstitute;
|
||||
using Xunit;
|
||||
|
||||
namespace Octokit.Tests.Clients
|
||||
{
|
||||
public class EnterpriseManagementConsoleClientTests
|
||||
{
|
||||
public class TheGetMaintenanceModeMethod
|
||||
{
|
||||
[Fact]
|
||||
public void RequestsCorrectUrl()
|
||||
{
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new EnterpriseManagementConsoleClient(connection);
|
||||
|
||||
string expectedUri = "setup/api/maintenance?api_key=Password01";
|
||||
client.GetMaintenanceMode("Password01");
|
||||
|
||||
connection.Received().Get<MaintenanceModeResponse>(Arg.Is<Uri>(u => u.ToString() == expectedUri));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task EnsuresNonNullArguments()
|
||||
{
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new EnterpriseManagementConsoleClient(connection);
|
||||
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetMaintenanceMode(null));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task EnsuresNonEmptyArguments()
|
||||
{
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new EnterpriseManagementConsoleClient(connection);
|
||||
|
||||
await Assert.ThrowsAsync<ArgumentException>(() => client.GetMaintenanceMode(""));
|
||||
}
|
||||
}
|
||||
|
||||
public class TheEditMaintenanceModeMethod
|
||||
{
|
||||
[Fact]
|
||||
public void RequestsCorrectUrl()
|
||||
{
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new EnterpriseManagementConsoleClient(connection);
|
||||
|
||||
string expectedUri = "setup/api/maintenance?api_key=Password01";
|
||||
client.EditMaintenanceMode(new UpdateMaintenanceRequest(), "Password01");
|
||||
|
||||
connection.Received().Post<MaintenanceModeResponse>(
|
||||
Arg.Is<Uri>(u => u.ToString() == expectedUri),
|
||||
Arg.Any<string>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void PassesRequestObject()
|
||||
{
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new EnterpriseManagementConsoleClient(connection);
|
||||
|
||||
client.EditMaintenanceMode(new UpdateMaintenanceRequest(new UpdateMaintenanceRequestDetails(true)), "Password01");
|
||||
|
||||
connection.Received().Post<MaintenanceModeResponse>(
|
||||
Arg.Any<Uri>(),
|
||||
Arg.Is<string>(a =>
|
||||
a == "maintenance={\"enabled\":true,\"when\":\"now\"}"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task EnsuresNonNullArguments()
|
||||
{
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new EnterpriseManagementConsoleClient(connection);
|
||||
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.EditMaintenanceMode(null, "Password01"));
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.EditMaintenanceMode(new UpdateMaintenanceRequest(), null));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task EnsuresNonEmptyArguments()
|
||||
{
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new EnterpriseManagementConsoleClient(connection);
|
||||
|
||||
await Assert.ThrowsAsync<ArgumentException>(() => client.EditMaintenanceMode(new UpdateMaintenanceRequest(), ""));
|
||||
}
|
||||
}
|
||||
|
||||
public class TheCtor
|
||||
{
|
||||
[Fact]
|
||||
public void EnsuresNonNullArguments()
|
||||
{
|
||||
Assert.Throws<ArgumentNullException>(() => new EnterpriseManagementConsoleClient(null));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
using System;
|
||||
using NSubstitute;
|
||||
using Octokit.Reactive;
|
||||
using Xunit;
|
||||
|
||||
namespace Octokit.Tests
|
||||
{
|
||||
public class ObservableEnterpriseManagementConsoleClientTests
|
||||
{
|
||||
public class TheGetMaintenanceModeMethod
|
||||
{
|
||||
[Fact]
|
||||
public void CallsIntoClient()
|
||||
{
|
||||
var github = Substitute.For<IGitHubClient>();
|
||||
var client = new ObservableEnterpriseManagementConsoleClient(github);
|
||||
|
||||
client.GetMaintenanceMode("Password01");
|
||||
|
||||
github.Enterprise.ManagementConsole.Received(1).
|
||||
GetMaintenanceMode(Arg.Is("Password01"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void EnsuresNonNullArguments()
|
||||
{
|
||||
var github = Substitute.For<IGitHubClient>();
|
||||
var client = new ObservableEnterpriseManagementConsoleClient(github);
|
||||
|
||||
Assert.Throws<ArgumentNullException>(() => client.GetMaintenanceMode(null));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void EnsuresNonEmptyArguments()
|
||||
{
|
||||
var github = Substitute.For<IGitHubClient>();
|
||||
var client = new ObservableEnterpriseManagementConsoleClient(github);
|
||||
|
||||
Assert.Throws<ArgumentException>(() => client.GetMaintenanceMode(""));
|
||||
}
|
||||
}
|
||||
|
||||
public class TheEditMaintenanceModeMethod
|
||||
{
|
||||
[Fact]
|
||||
public void CallsIntoClient()
|
||||
{
|
||||
var github = Substitute.For<IGitHubClient>();
|
||||
var client = new ObservableEnterpriseManagementConsoleClient(github);
|
||||
|
||||
client.EditMaintenanceMode(
|
||||
new UpdateMaintenanceRequest(new UpdateMaintenanceRequestDetails(true)),
|
||||
"Password01");
|
||||
|
||||
github.Enterprise.ManagementConsole.Received(1).
|
||||
EditMaintenanceMode(
|
||||
Arg.Is<UpdateMaintenanceRequest>(a =>
|
||||
a.Maintenance.Enabled == true &&
|
||||
a.Maintenance.When == "now"),
|
||||
Arg.Is("Password01"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void EnsuresNonNullArguments()
|
||||
{
|
||||
var github = Substitute.For<IGitHubClient>();
|
||||
var client = new ObservableEnterpriseManagementConsoleClient(github);
|
||||
|
||||
Assert.Throws<ArgumentNullException>(() => client.EditMaintenanceMode(null, "Password01"));
|
||||
Assert.Throws<ArgumentNullException>(() => client.EditMaintenanceMode(new UpdateMaintenanceRequest(), null));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void EnsuresNonEmptyArguments()
|
||||
{
|
||||
var github = Substitute.For<IGitHubClient>();
|
||||
var client = new ObservableEnterpriseManagementConsoleClient(github);
|
||||
|
||||
Assert.Throws<ArgumentException>(() => client.EditMaintenanceMode(new UpdateMaintenanceRequest(), ""));
|
||||
}
|
||||
}
|
||||
|
||||
public class TheCtor
|
||||
{
|
||||
[Fact]
|
||||
public void EnsuresNonNullArguments()
|
||||
{
|
||||
Assert.Throws<ArgumentNullException>(() => new ObservableEnterpriseManagementConsoleClient(null));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -17,6 +17,7 @@
|
||||
AdminStats = new EnterpriseAdminStatsClient(apiConnection);
|
||||
Ldap = new EnterpriseLdapClient(apiConnection);
|
||||
License = new EnterpriseLicenseClient(apiConnection);
|
||||
ManagementConsole = new EnterpriseManagementConsoleClient(apiConnection);
|
||||
Organization = new EnterpriseOrganizationClient(apiConnection);
|
||||
SearchIndexing = new EnterpriseSearchIndexingClient(apiConnection);
|
||||
PreReceiveEnvironment = new EnterprisePreReceiveEnvironmentsClient(apiConnection);
|
||||
@@ -27,7 +28,7 @@
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// See the <a href="http://developer.github.com/v3/enterprise/admin_stats/">Enterprise Admin Stats API documentation</a> for more information.
|
||||
///</remarks>
|
||||
/// </remarks>
|
||||
public IEnterpriseAdminStatsClient AdminStats { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
@@ -35,7 +36,7 @@
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// See the <a href="https://developer.github.com/v3/enterprise/ldap/">Enterprise LDAP API documentation</a> for more information.
|
||||
///</remarks>
|
||||
/// </remarks>
|
||||
public IEnterpriseLdapClient Ldap { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
@@ -43,15 +44,23 @@
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// See the <a href="https://developer.github.com/v3/enterprise/license/">Enterprise License API documentation</a> for more information.
|
||||
///</remarks>
|
||||
/// </remarks>
|
||||
public IEnterpriseLicenseClient License { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// A client for GitHub's Enterprise Management Console API
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// See the <a href="https://developer.github.com/v3/enterprise/management_console/">Enterprise Management Console API documentation</a> for more information.
|
||||
/// </remarks>
|
||||
public IEnterpriseManagementConsoleClient ManagementConsole { 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>
|
||||
/// </remarks>
|
||||
public IEnterpriseOrganizationClient Organization { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
@@ -59,7 +68,7 @@
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// See the <a href="https://developer.github.com/v3/enterprise/search_indexing/">Enterprise Search Indexing API documentation</a> for more information.
|
||||
///</remarks>
|
||||
/// </remarks>
|
||||
public IEnterpriseSearchIndexingClient SearchIndexing { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Octokit
|
||||
{
|
||||
/// <summary>
|
||||
/// A client for GitHub's Enterprise Management Console API
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// See the <a href="https://developer.github.com/v3/enterprise/management_console/">Enterprise Management Console API documentation</a> for more information.
|
||||
///</remarks>
|
||||
public class EnterpriseManagementConsoleClient : ApiClient, IEnterpriseManagementConsoleClient
|
||||
{
|
||||
public EnterpriseManagementConsoleClient(IApiConnection apiConnection)
|
||||
: base(apiConnection)
|
||||
{ }
|
||||
|
||||
/// <summary>
|
||||
/// Gets GitHub Enterprise Maintenance Mode Status
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// https://developer.github.com/v3/enterprise/management_console/#check-maintenance-status
|
||||
/// </remarks>
|
||||
/// <returns>The <see cref="MaintenanceModeResponse"/>.</returns>
|
||||
public Task<MaintenanceModeResponse> GetMaintenanceMode(string managementConsolePassword)
|
||||
{
|
||||
Ensure.ArgumentNotNullOrEmptyString(managementConsolePassword, "managementConsolePassword");
|
||||
|
||||
var endpoint = ApiUrls.EnterpriseManagementConsoleMaintenance(managementConsolePassword, ApiConnection.Connection.BaseAddress);
|
||||
|
||||
return ApiConnection.Get<MaintenanceModeResponse>(endpoint);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets GitHub Enterprise Maintenance Mode
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// https://developer.github.com/v3/enterprise/management_console/#check-maintenance-status
|
||||
/// </remarks>
|
||||
/// <returns>The <see cref="MaintenanceModeResponse"/>.</returns>
|
||||
public Task<MaintenanceModeResponse> EditMaintenanceMode(UpdateMaintenanceRequest maintenance, string managementConsolePassword)
|
||||
{
|
||||
Ensure.ArgumentNotNull(maintenance, "maintenance");
|
||||
Ensure.ArgumentNotNullOrEmptyString(managementConsolePassword, "managementConsolePassword");
|
||||
|
||||
var endpoint = ApiUrls.EnterpriseManagementConsoleMaintenance(managementConsolePassword, ApiConnection.Connection.BaseAddress);
|
||||
|
||||
return ApiConnection.Post<MaintenanceModeResponse>(endpoint, maintenance.ToFormUrlEncodedParameterString());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -13,7 +13,7 @@
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// See the <a href="http://developer.github.com/v3/enterprise/admin_stats/">Enterprise Admin Stats API documentation</a> for more information.
|
||||
///</remarks>
|
||||
/// </remarks>
|
||||
IEnterpriseAdminStatsClient AdminStats { get; }
|
||||
|
||||
/// <summary>
|
||||
@@ -21,7 +21,7 @@
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// See the <a href="https://developer.github.com/v3/enterprise/ldap/">Enterprise LDAP API documentation</a> for more information.
|
||||
///</remarks>
|
||||
/// </remarks>
|
||||
IEnterpriseLdapClient Ldap { get; }
|
||||
|
||||
/// <summary>
|
||||
@@ -29,15 +29,23 @@
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// See the <a href="https://developer.github.com/v3/enterprise/license/">Enterprise License API documentation</a> for more information.
|
||||
///</remarks>
|
||||
/// </remarks>
|
||||
IEnterpriseLicenseClient License { get; }
|
||||
|
||||
/// <summary>
|
||||
/// A client for GitHub's Enterprise Management Console API
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// See the <a href="https://developer.github.com/v3/enterprise/management_console/">Enterprise Management Console API documentation</a> for more information.
|
||||
/// </remarks>
|
||||
IEnterpriseManagementConsoleClient ManagementConsole { 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>
|
||||
/// </remarks>
|
||||
IEnterpriseOrganizationClient Organization { get; }
|
||||
|
||||
/// <summary>
|
||||
@@ -45,7 +53,7 @@
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// See the <a href="https://developer.github.com/v3/enterprise/search_indexing/">Enterprise Search Indexing API documentation</a> for more information.
|
||||
///</remarks>
|
||||
/// </remarks>
|
||||
IEnterpriseSearchIndexingClient SearchIndexing { get; }
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Octokit
|
||||
{
|
||||
/// <summary>
|
||||
/// A client for GitHub's Enterprise Management Console API
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// See the <a href="https://developer.github.com/v3/enterprise/management_console/">Enterprise Management Console API documentation</a> for more information.
|
||||
///</remarks>
|
||||
public interface IEnterpriseManagementConsoleClient
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets GitHub Enterprise Maintenance Mode Status
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// https://developer.github.com/v3/enterprise/management_console/#check-maintenance-status
|
||||
/// </remarks>
|
||||
/// <returns>The <see cref="MaintenanceModeResponse"/>.</returns>
|
||||
Task<MaintenanceModeResponse> GetMaintenanceMode(string managementConsolePassword);
|
||||
|
||||
/// <summary>
|
||||
/// Sets GitHub Enterprise Maintenance Mode
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// https://developer.github.com/v3/enterprise/management_console/#check-maintenance-status
|
||||
/// </remarks>
|
||||
/// <returns>The <see cref="MaintenanceModeResponse"/>.</returns>
|
||||
Task<MaintenanceModeResponse> EditMaintenanceMode(UpdateMaintenanceRequest maintenance, string managementConsolePassword);
|
||||
}
|
||||
}
|
||||
@@ -2548,6 +2548,18 @@ namespace Octokit
|
||||
return "orgs/{0}/migrations/{1}/repos/{2}/lock".FormatUri(org, id, repo);
|
||||
}
|
||||
|
||||
public static Uri EnterpriseManagementConsoleMaintenance(string managementConsolePassword, Uri baseAddress)
|
||||
{
|
||||
if (baseAddress != null
|
||||
&& baseAddress.ToString().EndsWith("/api/v3/", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
// note: leading slash here means the /api/v3/ prefix inherited from baseAddress is ignored
|
||||
return "/setup/api/maintenance?api_key={0}".FormatUri(managementConsolePassword);
|
||||
}
|
||||
|
||||
return "setup/api/maintenance?api_key={0}".FormatUri(managementConsolePassword);
|
||||
}
|
||||
|
||||
public static Uri EnterpriseOrganization()
|
||||
{
|
||||
return "admin/organizations".FormatUri();
|
||||
|
||||
@@ -26,7 +26,7 @@ namespace Octokit.Helpers
|
||||
|
||||
if (branchName.StartsWith("refs/heads"))
|
||||
{
|
||||
throw new ArgumentException(String.Format(CultureInfo.InvariantCulture, "The specified branch name '{0}' appears to be a ref name and not a branch name because it starts with the string 'refs/heads'. Either specify just the branch name or use the Create method if you need to specify the full ref name", branchName), "branchName");
|
||||
throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, "The specified branch name '{0}' appears to be a ref name and not a branch name because it starts with the string 'refs/heads'. Either specify just the branch name or use the Create method if you need to specify the full ref name", branchName), "branchName");
|
||||
}
|
||||
|
||||
var newReference = new NewReference("refs/heads/" + branchName, baseReference.Object.Sha);
|
||||
@@ -48,7 +48,7 @@ namespace Octokit.Helpers
|
||||
|
||||
if (branchName.StartsWith("refs/heads"))
|
||||
{
|
||||
throw new ArgumentException(String.Format(CultureInfo.InvariantCulture, "The specified branch name '{0}' appears to be a ref name and not a branch name because it starts with the string 'refs/heads'. Either specify just the branch name or use the Create method if you need to specify the full ref name", branchName), "branchName");
|
||||
throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, "The specified branch name '{0}' appears to be a ref name and not a branch name because it starts with the string 'refs/heads'. Either specify just the branch name or use the Create method if you need to specify the full ref name", branchName), "branchName");
|
||||
}
|
||||
|
||||
var baseBranch = await referencesClient.Get(owner, name, "heads/master").ConfigureAwait(false);
|
||||
|
||||
107
Octokit/Models/Request/Enterprise/UpdateMaintenanceRequest.cs
Normal file
107
Octokit/Models/Request/Enterprise/UpdateMaintenanceRequest.cs
Normal file
@@ -0,0 +1,107 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Globalization;
|
||||
|
||||
namespace Octokit
|
||||
{
|
||||
[DebuggerDisplay("{DebuggerDisplay,nq}")]
|
||||
public class UpdateMaintenanceRequest : FormUrlEncodedParameters
|
||||
{
|
||||
/// <summary>
|
||||
/// Maintenance request with default details (results in Maintenance mode being turned off immediately)
|
||||
/// </summary>
|
||||
public UpdateMaintenanceRequest()
|
||||
{
|
||||
Maintenance = new UpdateMaintenanceRequestDetails();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Maintenance request with specific details
|
||||
/// </summary>
|
||||
public UpdateMaintenanceRequest(UpdateMaintenanceRequestDetails maintenance)
|
||||
{
|
||||
Ensure.ArgumentNotNull(maintenance, "maintenance");
|
||||
|
||||
Maintenance = maintenance;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Details for the maintenance request
|
||||
/// </summary>
|
||||
public UpdateMaintenanceRequestDetails Maintenance { get; protected set; }
|
||||
|
||||
internal string DebuggerDisplay
|
||||
{
|
||||
get
|
||||
{
|
||||
return string.Format(CultureInfo.InvariantCulture, "Maintenance: {0}", this.Maintenance.DebuggerDisplay);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[DebuggerDisplay("{DebuggerDisplay,nq}")]
|
||||
public class UpdateMaintenanceRequestDetails
|
||||
{
|
||||
/// <summary>
|
||||
/// Maintenance request details with default values (results in Maintenance mode being turned off immediately)
|
||||
/// </summary>
|
||||
public UpdateMaintenanceRequestDetails()
|
||||
{ }
|
||||
|
||||
/// <summary>
|
||||
/// Maintenance request details to enable/disable maintenance mode immediately
|
||||
/// </summary>
|
||||
/// <param name="enabled">true to enable, false to disable</param>
|
||||
public UpdateMaintenanceRequestDetails(bool enabled)
|
||||
{
|
||||
Enabled = enabled;
|
||||
When = "now";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Maintenance request details to enable/disable maintenance at a specified time (only applicable when enabling maintenance)
|
||||
/// </summary>
|
||||
/// <param name="enabled">true to enable, false to disable</param>
|
||||
/// <param name="when">A phrase specifying when maintenance mode will be enabled. Phrase uses humanised forms supported by the <a href="https://github.com/mojombo/chronic">mojombo/chronic library</a> used by the GitHub API</param>
|
||||
/// such as "this friday at 5pm" or "5 minutes before midday tomorrow"
|
||||
/// <remarks>If enabled is false, the when parameter is ignored and maintenance is turned off immediately</remarks>
|
||||
public UpdateMaintenanceRequestDetails(bool enabled, string when)
|
||||
{
|
||||
Ensure.ArgumentNotNullOrEmptyString(when, "when");
|
||||
|
||||
Enabled = enabled;
|
||||
When = when;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Maintenance request details to enable/disable maintenance at a specified time (only applicable when enabling maintenance)
|
||||
/// </summary>
|
||||
/// <param name="enabled">true to enable, false to disable</param>
|
||||
/// <param name="when">A <see cref="DateTimeOffset"/> specifying when maintenance mode will be enabled.</param>
|
||||
/// <remarks>If enabled is false, the when parameter is ignored and maintenance is turned off immediately</remarks>
|
||||
public UpdateMaintenanceRequestDetails(bool enabled, DateTimeOffset when)
|
||||
{
|
||||
Enabled = enabled;
|
||||
When = when.ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ssZ",
|
||||
CultureInfo.InvariantCulture);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Whether maintenance mode is enabled or disabled
|
||||
/// </summary>
|
||||
public bool Enabled { get; protected set; }
|
||||
|
||||
/// <summary>
|
||||
/// When maintenance mode will take effect (only applicable when enabling maintenance)
|
||||
/// </summary>
|
||||
public string When { get; protected set; }
|
||||
|
||||
internal string DebuggerDisplay
|
||||
{
|
||||
get
|
||||
{
|
||||
return string.Format(CultureInfo.InvariantCulture, "Enabled: {0} When: {1}", this.Enabled, this.When);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
71
Octokit/Models/Request/FormUrlEncodedParameters.cs
Normal file
71
Octokit/Models/Request/FormUrlEncodedParameters.cs
Normal file
@@ -0,0 +1,71 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using Octokit.Internal;
|
||||
|
||||
namespace Octokit
|
||||
{
|
||||
/// <summary>
|
||||
/// Base class for classes which represent UrlFormEncoded parameters to certain API endpoints.
|
||||
/// </summary>
|
||||
public abstract class FormUrlEncodedParameters
|
||||
{
|
||||
/// <summary>
|
||||
/// Converts the derived object into a UrlFormEncoded parameter string containing named parameters and their json serialized values
|
||||
/// This format is required for particular API calls (eg the GitHub Enterprise Management Console API) that take a parameter formatted as json but not in the request body
|
||||
/// </summary>
|
||||
[SuppressMessage("Microsoft.Design", "CA1055:UriReturnValuesShouldNotBeStrings")]
|
||||
public string ToFormUrlEncodedParameterString()
|
||||
{
|
||||
var parameters = new List<string>();
|
||||
foreach (var prop in GetPropertyParametersForType(this.GetType()))
|
||||
{
|
||||
parameters.Add(string.Format(CultureInfo.InvariantCulture, "{0}={1}", prop.Key, prop.GetValue(this)));
|
||||
}
|
||||
|
||||
return string.Join("&", parameters);
|
||||
}
|
||||
|
||||
static List<JsonParameter> GetPropertyParametersForType(Type type)
|
||||
{
|
||||
return type.GetAllProperties()
|
||||
.Where(p => p.Name != "DebuggerDisplay")
|
||||
.Select(p => new JsonParameter(p))
|
||||
.ToList();
|
||||
}
|
||||
|
||||
class JsonParameter
|
||||
{
|
||||
readonly PropertyInfo _property;
|
||||
public JsonParameter(PropertyInfo property)
|
||||
{
|
||||
_property = property;
|
||||
Key = GetParameterKeyFromProperty(property);
|
||||
}
|
||||
|
||||
public string Key { get; private set; }
|
||||
|
||||
public string GetValue(object instance)
|
||||
{
|
||||
var value = _property.GetValue(instance, null);
|
||||
return value != null ? new SimpleJsonSerializer().Serialize(value) : null;
|
||||
}
|
||||
|
||||
[SuppressMessage("Microsoft.Globalization", "CA1308:NormalizeStringsToUppercase",
|
||||
Justification = "GitHub API depends on lower case strings")]
|
||||
static string GetParameterKeyFromProperty(PropertyInfo property)
|
||||
{
|
||||
var attribute = property.GetCustomAttributes(typeof(ParameterAttribute), false)
|
||||
.Cast<ParameterAttribute>()
|
||||
.FirstOrDefault(attr => attr.Key != null);
|
||||
|
||||
return attribute == null
|
||||
? property.Name.ToLowerInvariant()
|
||||
: attribute.Key;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -100,7 +100,7 @@ namespace Octokit
|
||||
Comments != null ? "Comments," : ""
|
||||
).Trim(',');
|
||||
|
||||
return String.Format(CultureInfo.InvariantCulture, "Statistics: {0}", fieldsPresent);
|
||||
return string.Format(CultureInfo.InvariantCulture, "Statistics: {0}", fieldsPresent);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ namespace Octokit
|
||||
{
|
||||
get
|
||||
{
|
||||
return String.Format(CultureInfo.InvariantCulture, "TotalCommitComments: {0} TotalGistComments: {1} TotalIssueComments: {2} TotalPullRequestComments: {3}", TotalCommitComments, TotalGistComments, TotalIssueComments, TotalPullRequestComments);
|
||||
return string.Format(CultureInfo.InvariantCulture, "TotalCommitComments: {0} TotalGistComments: {1} TotalIssueComments: {2} TotalPullRequestComments: {3}", TotalCommitComments, TotalGistComments, TotalIssueComments, TotalPullRequestComments);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ namespace Octokit
|
||||
{
|
||||
get
|
||||
{
|
||||
return String.Format(CultureInfo.InvariantCulture, "TotalGists: {0} PrivateGists: {1} PublicGists: {2}", TotalGists, PrivateGists, PublicGists);
|
||||
return string.Format(CultureInfo.InvariantCulture, "TotalGists: {0} PrivateGists: {1} PublicGists: {2}", TotalGists, PrivateGists, PublicGists);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ namespace Octokit
|
||||
{
|
||||
get
|
||||
{
|
||||
return String.Format(CultureInfo.InvariantCulture, "TotalHooks: {0} ActiveHooks: {1} InactiveHooks: {2}", TotalHooks, ActiveHooks, InactiveHooks);
|
||||
return string.Format(CultureInfo.InvariantCulture, "TotalHooks: {0} ActiveHooks: {1} InactiveHooks: {2}", TotalHooks, ActiveHooks, InactiveHooks);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ namespace Octokit
|
||||
{
|
||||
get
|
||||
{
|
||||
return String.Format(CultureInfo.InvariantCulture, "TotalIssues: {0} OpenIssues: {1} ClosedIssues: {2}", TotalIssues, OpenIssues, ClosedIssues);
|
||||
return string.Format(CultureInfo.InvariantCulture, "TotalIssues: {0} OpenIssues: {1} ClosedIssues: {2}", TotalIssues, OpenIssues, ClosedIssues);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ namespace Octokit
|
||||
{
|
||||
get
|
||||
{
|
||||
return String.Format(CultureInfo.InvariantCulture, "TotalMilestones: {0} OpenMilestones: {1} ClosedMilestones: {2}", TotalMilestones, OpenMilestones, ClosedMilestones);
|
||||
return string.Format(CultureInfo.InvariantCulture, "TotalMilestones: {0} OpenMilestones: {1} ClosedMilestones: {2}", TotalMilestones, OpenMilestones, ClosedMilestones);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ namespace Octokit
|
||||
{
|
||||
get
|
||||
{
|
||||
return String.Format(CultureInfo.InvariantCulture, "TotalOrgs: {0} DisabledOrgs: {1} TotalTeams: {2} TotalTeamMembers: {3}", TotalOrgs, DisabledOrgs, TotalTeams, TotalTeamMembers);
|
||||
return string.Format(CultureInfo.InvariantCulture, "TotalOrgs: {0} DisabledOrgs: {1} TotalTeams: {2} TotalTeamMembers: {3}", TotalOrgs, DisabledOrgs, TotalTeams, TotalTeamMembers);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ namespace Octokit
|
||||
{
|
||||
get
|
||||
{
|
||||
return String.Format(CultureInfo.InvariantCulture, "TotalPages: {0}", TotalPages);
|
||||
return string.Format(CultureInfo.InvariantCulture, "TotalPages: {0}", TotalPages);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ namespace Octokit
|
||||
{
|
||||
get
|
||||
{
|
||||
return String.Format(CultureInfo.InvariantCulture, "TotalPulls: {0} MergedPulls: {1} MergeablePulls: {2} UnmergeablePulls: {3}", TotalPulls, MergedPulls, MergeablePulls, UnmergeablePulls);
|
||||
return string.Format(CultureInfo.InvariantCulture, "TotalPulls: {0} MergedPulls: {1} MergeablePulls: {2} UnmergeablePulls: {3}", TotalPulls, MergedPulls, MergeablePulls, UnmergeablePulls);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,7 +59,7 @@ namespace Octokit
|
||||
{
|
||||
get
|
||||
{
|
||||
return String.Format(CultureInfo.InvariantCulture, "TotalRepos: {0} RootRepos: {1} ForkRepos: {2} OrgRepos: {3} TotalPushes: {4} TotalWikis: {5}", TotalRepos, RootRepos, ForkRepos, OrgRepos, TotalPushes, TotalWikis);
|
||||
return string.Format(CultureInfo.InvariantCulture, "TotalRepos: {0} RootRepos: {1} ForkRepos: {2} OrgRepos: {3} TotalPushes: {4} TotalWikis: {5}", TotalRepos, RootRepos, ForkRepos, OrgRepos, TotalPushes, TotalWikis);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ namespace Octokit
|
||||
{
|
||||
get
|
||||
{
|
||||
return String.Format(CultureInfo.InvariantCulture, "TotalUsers: {0} AdminUsers: {1} SuspendedUsers: {2}", TotalUsers, AdminUsers, SuspendedUsers);
|
||||
return string.Format(CultureInfo.InvariantCulture, "TotalUsers: {0} AdminUsers: {1} SuspendedUsers: {2}", TotalUsers, AdminUsers, SuspendedUsers);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ namespace Octokit
|
||||
{
|
||||
get
|
||||
{
|
||||
return String.Format(CultureInfo.InvariantCulture, "Status: {0}", Status);
|
||||
return string.Format(CultureInfo.InvariantCulture, "Status: {0}", Status);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,7 +59,7 @@ namespace Octokit
|
||||
{
|
||||
get
|
||||
{
|
||||
return String.Format(CultureInfo.InvariantCulture, "Seats: {0} SeatsUsed: {1} DaysUntilExpiration: {2}", Seats, SeatsUsed, DaysUntilExpiration);
|
||||
return string.Format(CultureInfo.InvariantCulture, "Seats: {0} SeatsUsed: {1} DaysUntilExpiration: {2}", Seats, SeatsUsed, DaysUntilExpiration);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
using System.Diagnostics;
|
||||
using System.Globalization;
|
||||
|
||||
namespace Octokit
|
||||
{
|
||||
[DebuggerDisplay("{DebuggerDisplay,nq}")]
|
||||
public class MaintenanceModeActiveProcesses
|
||||
{
|
||||
public MaintenanceModeActiveProcesses() { }
|
||||
|
||||
public MaintenanceModeActiveProcesses(string name, int number)
|
||||
{
|
||||
Name = name;
|
||||
Number = number;
|
||||
}
|
||||
|
||||
public string Name { get; protected set; }
|
||||
|
||||
public int Number { get; protected set; }
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return string.Format(CultureInfo.InvariantCulture, "{0} ({1})", Name, Number);
|
||||
}
|
||||
|
||||
internal string DebuggerDisplay
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Globalization;
|
||||
using Octokit.Internal;
|
||||
|
||||
namespace Octokit
|
||||
{
|
||||
[DebuggerDisplay("{DebuggerDisplay,nq}")]
|
||||
public class MaintenanceModeResponse
|
||||
{
|
||||
public MaintenanceModeResponse() { }
|
||||
|
||||
public MaintenanceModeResponse(MaintenanceModeStatus status, string scheduledTime, IReadOnlyList<MaintenanceModeActiveProcesses> activeProcesses)
|
||||
{
|
||||
Status = status;
|
||||
ScheduledTime = scheduledTime;
|
||||
ActiveProcesses = activeProcesses;
|
||||
}
|
||||
|
||||
public StringEnum<MaintenanceModeStatus> Status
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
public string ScheduledTime
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
[Parameter(Key = "connection_services")]
|
||||
public IReadOnlyList<MaintenanceModeActiveProcesses> ActiveProcesses
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
internal string DebuggerDisplay
|
||||
{
|
||||
get
|
||||
{
|
||||
return string.Format(CultureInfo.InvariantCulture,
|
||||
"Status: {0} ScheduledTime: {1} Connections: {2}",
|
||||
Status,
|
||||
ScheduledTime ?? "",
|
||||
string.Join(", ", ActiveProcesses));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public enum MaintenanceModeStatus
|
||||
{
|
||||
[Parameter(Value = "off")]
|
||||
Off,
|
||||
[Parameter(Value = "on")]
|
||||
On,
|
||||
[Parameter(Value = "scheduled")]
|
||||
Scheduled
|
||||
}
|
||||
}
|
||||
@@ -25,7 +25,7 @@ namespace Octokit
|
||||
{
|
||||
get
|
||||
{
|
||||
return String.Format(CultureInfo.InvariantCulture, "Message: {0}", string.Join("\r\n", Message));
|
||||
return string.Format(CultureInfo.InvariantCulture, "Message: {0}", string.Join("\r\n", Message));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
73
docs/enterprise-administration.md
Normal file
73
docs/enterprise-administration.md
Normal file
@@ -0,0 +1,73 @@
|
||||
# GitHub Enterprise Administration
|
||||
|
||||
Octokit also ships with support for the administration APIs that GitHub
|
||||
Enterprise includes to script tasks for administrators.
|
||||
|
||||
```c#
|
||||
var enterprise = new Uri("https://github.myenterprise.com/");
|
||||
var github = new GitHubClient("some app name", enterprise);
|
||||
github.Credentials = new Credentials("some-token-here");
|
||||
|
||||
var stats = await github.Enterprise.AdminStats.GetStatisticsUsers();
|
||||
Console.WriteLine($"Found {stats.AdminUsers} admins, {stats.TotalUsers} total users and {stats.SuspendedUsers} suspended users");
|
||||
```
|
||||
|
||||
Some caveats on using these APIs that you should be aware of:
|
||||
|
||||
- only administrators of the GitHub Enterprise instance are able to access
|
||||
these APIs
|
||||
- administrators creating OAuth tokens to use this endpoint must ensure the
|
||||
`site_admin` scope is set
|
||||
- the [Management Console API](https://developer.github.com/enterprise/2.18/v3/enterprise/management_console/)
|
||||
also require providing the password created during setup of the GitHub
|
||||
Enterprise installation to confirm the action
|
||||
|
||||
You can read more about this support [on the GitHub website](https://developer.github.com/enterprise/2.18/v3/enterprise-admin/).
|
||||
|
||||
|
||||
## Management console
|
||||
|
||||
To view the maintenance mode status of a GitHub Enteprise installation:
|
||||
|
||||
```C#
|
||||
var maintenance = await github.Enterprise.ManagementConsole.GetMaintenanceMode("management-console-password");
|
||||
```
|
||||
|
||||
To put the GitHub Enterprise installation into maintenance mode immediately:
|
||||
|
||||
```C#
|
||||
var request = new UpdateMaintenanceRequest(new UpdateMaintenanceRequestDetails(true));
|
||||
var maintenance = await github.Enterprise.ManagementConsole.EditMaintenanceMode(
|
||||
request,
|
||||
"management-console-password");
|
||||
```
|
||||
|
||||
You can also provide a human-friendly phrase based on the rules in
|
||||
[`mojombo/chronic`](https://github.com/mojombo/chronic):
|
||||
|
||||
```C#
|
||||
var request = new UpdateMaintenanceRequest(new UpdateMaintenanceRequestDetails(true, "tomorrow at 5pm"));
|
||||
var maintenance = await github.Enterprise.ManagementConsole.EditMaintenanceMode(
|
||||
request,
|
||||
"management-console-password");
|
||||
```
|
||||
|
||||
To put the GitHub Enterprise installation into maintenance mode after a period
|
||||
of time:
|
||||
|
||||
```C#
|
||||
var scheduledTime = DateTimeOffset.Now.AddMinutes(10);
|
||||
var request = new UpdateMaintenanceRequest(new UpdateMaintenanceRequestDetails(true, scheduledTime));
|
||||
var maintenance = await github.Enterprise.ManagementConsole.EditMaintenanceMode(
|
||||
request,
|
||||
"management-console-password");
|
||||
```
|
||||
|
||||
To disable maintenance mode, simple pass in `false` or leave the `request`
|
||||
constructor empty:
|
||||
|
||||
```c#
|
||||
var maintenance = await github.Enterprise.ManagementConsole.EditMaintenanceMode(
|
||||
new UpdateMaintenanceRequest(), // off by default if nothing specified
|
||||
"management-console-password");
|
||||
```
|
||||
@@ -109,6 +109,7 @@ if (AskYesNoQuestion "Do you wish to enable GitHub Enterprise (GHE) Integration
|
||||
{
|
||||
VerifyEnvironmentVariable "GitHub Enterprise account name" "OCTOKIT_GHE_USERNAME"
|
||||
VerifyEnvironmentVariable "GitHub Enterprise account password" "OCTOKIT_GHE_PASSWORD" $true
|
||||
VerifyEnvironmentVariable "GitHub Enterprise Management Console password" "OCTOKIT_GHE_CONSOLEPASSWORD" $true
|
||||
VerifyEnvironmentVariable "GitHub Enterprise OAuth token" "OCTOKIT_GHE_OAUTHTOKEN"
|
||||
|
||||
VerifyEnvironmentVariable "GitHub Enterprise organization name" "OCTOKIT_GHE_ORGANIZATION" $true
|
||||
|
||||
Reference in New Issue
Block a user