mirror of
https://github.com/zoriya/octokit.net.git
synced 2026-06-03 19:11:30 +00:00
adjusting exception message to not rely on credentials
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
using Xunit;
|
||||
|
||||
namespace Octokit.Tests.Exceptions
|
||||
{
|
||||
public class RepositoryExistsExceptionTests
|
||||
{
|
||||
public class TheMessageProperty
|
||||
{
|
||||
[Fact]
|
||||
public void WhenOwnerIsNullDoNotMentionInMessage()
|
||||
{
|
||||
var exception = new RepositoryExistsException(
|
||||
null,
|
||||
"some-repo",
|
||||
false,
|
||||
GitHubClient.GitHubDotComUrl,
|
||||
new ApiValidationException());
|
||||
|
||||
Assert.Equal("There is already a repository named 'some-repo' for the current account.", exception.Message);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WhenOwnerIsNotNullMentionInMessage()
|
||||
{
|
||||
var exception = new RepositoryExistsException(
|
||||
"some-org",
|
||||
"some-repo",
|
||||
true,
|
||||
GitHubClient.GitHubDotComUrl,
|
||||
new ApiValidationException());
|
||||
|
||||
Assert.Equal("There is already a repository named 'some-repo' in the organization 'some-org'.", exception.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -98,6 +98,7 @@
|
||||
<Compile Include="Clients\FollowersClientTests.cs" />
|
||||
<Compile Include="Exceptions\ApiExceptionTests.cs" />
|
||||
<Compile Include="Exceptions\ApiValidationExceptionTests.cs" />
|
||||
<Compile Include="Exceptions\RepositoryExistsExceptionTests.cs" />
|
||||
<Compile Include="Exceptions\TwoFactorChallengeFailedException.cs" />
|
||||
<Compile Include="Exceptions\ForbiddenExceptionTests.cs" />
|
||||
<Compile Include="Exceptions\LoginAttemptsExceededExceptionTests.cs" />
|
||||
|
||||
@@ -84,13 +84,11 @@ namespace Octokit
|
||||
errorMessage,
|
||||
StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
string owner = organizationLogin ?? Connection.Credentials.Login;
|
||||
|
||||
var baseAddress = Connection.BaseAddress.Host != GitHubClient.GitHubApiUrl.Host
|
||||
? Connection.BaseAddress
|
||||
: new Uri("https://github.com/");
|
||||
throw new RepositoryExistsException(
|
||||
owner,
|
||||
organizationLogin,
|
||||
newRepository.Name,
|
||||
organizationLogin != null,
|
||||
baseAddress, e);
|
||||
|
||||
@@ -37,11 +37,10 @@ namespace Octokit
|
||||
ApiValidationException innerException)
|
||||
: base(innerException)
|
||||
{
|
||||
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
|
||||
Ensure.ArgumentNotNullOrEmptyString(name, "repositoryName");
|
||||
Ensure.ArgumentNotNull(baseAddress, "baseAddress");
|
||||
|
||||
Owner = owner;
|
||||
Owner = owner ?? ""; // TODO: this is a total hack
|
||||
RepositoryName = name;
|
||||
OwnerIsOrganization = ownerIsOrganization;
|
||||
var webBaseAddress = baseAddress.Host != GitHubClient.GitHubApiUrl.Host
|
||||
@@ -49,8 +48,8 @@ namespace Octokit
|
||||
: GitHubClient.GitHubDotComUrl;
|
||||
ExistingRepositoryWebUrl = new Uri(webBaseAddress, new Uri(owner + "/" + name, UriKind.Relative));
|
||||
string messageFormat = ownerIsOrganization
|
||||
? "There is already a repository named '{0}' in the organization '{1}'"
|
||||
: "There is already a repository named '{0}' for the owner '{1}'.";
|
||||
? "There is already a repository named '{0}' in the organization '{1}'."
|
||||
: "There is already a repository named '{0}' for the current account.";
|
||||
|
||||
_message = String.Format(CultureInfo.InvariantCulture, messageFormat, name, owner);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user