mirror of
https://github.com/zoriya/octokit.net.git
synced 2026-06-08 12:42:32 +00:00
maint: Removes private repositories limit exception (#2514)
This commit is contained in:
@@ -408,44 +408,6 @@ public class RepositoriesClientTests
|
||||
Assert.False(thrown.OwnerIsOrganization);
|
||||
}
|
||||
}
|
||||
|
||||
[PaidAccountTest(Skip = "Paid plans now have unlimited repositories. We shouldn't test this now.")]
|
||||
public async Task ThrowsPrivateRepositoryQuotaExceededExceptionWhenOverQuota()
|
||||
{
|
||||
var github = Helper.GetAuthenticatedClient();
|
||||
|
||||
var userDetails = await github.User.Current();
|
||||
var freePrivateSlots = userDetails.Plan.PrivateRepos - userDetails.OwnedPrivateRepos;
|
||||
|
||||
if (userDetails.Plan.PrivateRepos == 0)
|
||||
{
|
||||
throw new Exception("Test cannot complete, account is on free plan");
|
||||
}
|
||||
|
||||
var createRepoTasks =
|
||||
Enumerable.Range(0, (int)freePrivateSlots)
|
||||
.Select(x =>
|
||||
{
|
||||
var repoName = Helper.MakeNameWithTimestamp("private-repo-" + x);
|
||||
var repository = new NewRepository(repoName) { Private = true };
|
||||
return github.Repository.Create(repository);
|
||||
});
|
||||
|
||||
var createdRepositories = await Task.WhenAll(createRepoTasks);
|
||||
|
||||
try
|
||||
{
|
||||
await Assert.ThrowsAsync<PrivateRepositoryQuotaExceededException>(
|
||||
() => github.Repository.Create(new NewRepository("x-private") { Private = true }));
|
||||
}
|
||||
finally
|
||||
{
|
||||
var deleteRepos = createdRepositories
|
||||
.Select(repo => github.Repository.Delete(repo.Owner.Login, repo.Name));
|
||||
|
||||
Task.WhenAll(deleteRepos).Wait();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class TheCreateMethodForOrganization
|
||||
|
||||
@@ -85,30 +85,6 @@ namespace Octokit.Tests.Clients
|
||||
Assert.Equal("aName", exception.RepositoryName);
|
||||
Assert.Null(exception.ExistingRepositoryWebUrl);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ThrowsExceptionWhenPrivateRepositoryQuotaExceeded()
|
||||
{
|
||||
var newRepository = new NewRepository("aName") { Private = true };
|
||||
var response = Substitute.For<IResponse>();
|
||||
response.StatusCode.Returns((HttpStatusCode)422);
|
||||
response.Body.Returns(@"{""message"":""Validation Failed"",""documentation_url"":"
|
||||
+ @"""http://developer.github.com/v3/repos/#create"",""errors"":[{""resource"":""Repository"","
|
||||
+ @"""code"":""custom"",""field"":""name"",""message"":"
|
||||
+ @"""name can't be private. You are over your quota.""}]}");
|
||||
var credentials = new Credentials("haacked", "pwd");
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
connection.Connection.BaseAddress.Returns(GitHubClient.GitHubApiUrl);
|
||||
connection.Connection.Credentials.Returns(credentials);
|
||||
connection.Post<Repository>(Args.Uri, newRepository, "application/vnd.github.nebula-preview+json,application/vnd.github.baptiste-preview+json")
|
||||
.Returns<Task<Repository>>(_ => { throw new ApiValidationException(response); });
|
||||
var client = new RepositoriesClient(connection);
|
||||
|
||||
var exception = await Assert.ThrowsAsync<PrivateRepositoryQuotaExceededException>(
|
||||
() => client.Create(newRepository));
|
||||
|
||||
Assert.NotNull(exception);
|
||||
}
|
||||
}
|
||||
|
||||
public class TheCreateMethodForOrganization
|
||||
|
||||
@@ -131,22 +131,6 @@ namespace Octokit
|
||||
baseAddress, e);
|
||||
}
|
||||
|
||||
if (string.Equals(
|
||||
"please upgrade your plan to create a new private repository.",
|
||||
errorMessage,
|
||||
StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
throw new PrivateRepositoryQuotaExceededException(e);
|
||||
}
|
||||
|
||||
if (string.Equals(
|
||||
"name can't be private. You are over your quota.",
|
||||
errorMessage,
|
||||
StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
throw new PrivateRepositoryQuotaExceededException(e);
|
||||
}
|
||||
|
||||
if (errorMessage != null && errorMessage.EndsWith("is an unknown gitignore template.", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
throw new InvalidGitIgnoreTemplateException(e);
|
||||
|
||||
@@ -1,58 +0,0 @@
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#if !NO_SERIALIZABLE
|
||||
using System.Runtime.Serialization;
|
||||
#endif
|
||||
|
||||
namespace Octokit
|
||||
{
|
||||
/// <summary>
|
||||
/// Exception thrown when creating a private repository, but the user's private quota is or would be exceeded
|
||||
/// by creating it.
|
||||
/// </summary>
|
||||
#if !NO_SERIALIZABLE
|
||||
[Serializable]
|
||||
#endif
|
||||
[SuppressMessage("Microsoft.Design", "CA1032:ImplementStandardExceptionConstructors",
|
||||
Justification = "These exceptions are specific to the GitHub API and not general purpose exceptions")]
|
||||
public class PrivateRepositoryQuotaExceededException : ApiValidationException
|
||||
{
|
||||
/// <summary>
|
||||
/// Constructs an instance of PrivateRepositoryQuotaExceededException.
|
||||
/// </summary>
|
||||
/// <param name="innerException">The inner validation exception.</param>
|
||||
public PrivateRepositoryQuotaExceededException(ApiValidationException innerException)
|
||||
: base(innerException)
|
||||
{
|
||||
}
|
||||
|
||||
public override string Message
|
||||
{
|
||||
get
|
||||
{
|
||||
// TODO: Would be nice to show the actual numbers, but that requires another request.
|
||||
return "You are currently at your limit of private repositories. Either delete a private repository you no "
|
||||
+ "longer use (https://help.github.com/articles/deleting-a-repository/) or upgrade your account to a plan "
|
||||
+ "that allows for more private repositories (https://help.github.com/articles/what-plan-should-i-choose/).";
|
||||
}
|
||||
}
|
||||
|
||||
#if !NO_SERIALIZABLE
|
||||
/// <summary>
|
||||
/// Constructs an instance of PrivateRepositoryQuotaExceededException
|
||||
/// </summary>
|
||||
/// <param name="info">
|
||||
/// The <see cref="SerializationInfo"/> that holds the
|
||||
/// serialized object data about the exception being thrown.
|
||||
/// </param>
|
||||
/// <param name="context">
|
||||
/// The <see cref="StreamingContext"/> that contains
|
||||
/// contextual information about the source or destination.
|
||||
/// </param>
|
||||
protected PrivateRepositoryQuotaExceededException(SerializationInfo info, StreamingContext context)
|
||||
: base(info, context)
|
||||
{
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user