Merge branch 'gitignore-exception'

This commit is contained in:
Brendan Forster
2015-11-04 09:16:33 -08:00
9 changed files with 91 additions and 2 deletions

View File

@@ -188,6 +188,25 @@ public class RepositoriesClientTests
}
}
[IntegrationTest]
public async Task ThrowsInvalidGitIgnoreExceptionForInvalidTemplateNames()
{
var github = Helper.GetAuthenticatedClient();
var repoName = Helper.MakeNameWithTimestamp("repo-with-gitignore");
var newRepository = new NewRepository(repoName)
{
AutoInit = true,
GitignoreTemplate = "visualstudio"
};
var thrown = await Assert.ThrowsAsync<InvalidGitIgnoreTemplateException>(
() => github.CreateRepositoryContext(newRepository));
Assert.NotNull(thrown);
}
[IntegrationTest]
public async Task ThrowsRepositoryExistsExceptionForExistingRepository()
{

View File

@@ -116,6 +116,12 @@ namespace Octokit
{
throw new PrivateRepositoryQuotaExceededException(e);
}
if (errorMessage != null && errorMessage.EndsWith("is an unknown gitignore template.", StringComparison.OrdinalIgnoreCase))
{
throw new InvalidGitIgnoreTemplateException(e);
}
throw;
}
}

View File

@@ -0,0 +1,58 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;
namespace Octokit
{
/// <summary>
/// Represents a HTTP 403 - Forbidden response returned from the API.
/// </summary>
#if !NETFX_CORE
[Serializable]
#endif
[SuppressMessage("Microsoft.Design", "CA1032:ImplementStandardExceptionConstructors",
Justification = "These exceptions are specific to the GitHub API and not general purpose exceptions")]
public class InvalidGitIgnoreTemplateException : ApiValidationException
{
/// <summary>
/// Constructs an instance of ApiValidationException
/// </summary>
public InvalidGitIgnoreTemplateException()
: base() { }
/// <summary>
/// Constructs an instance of ApiValidationException
/// </summary>
/// <param name="innerException">The inner validation exception.</param>
public InvalidGitIgnoreTemplateException(ApiValidationException innerException)
: base(innerException) { }
public override string Message
{
get
{
return "The Gitignore template provided is not valid.";
}
}
#if !NETFX_CORE
/// <summary>
/// Constructs an instance of InvalidGitignoreTemplateException
/// </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 InvalidGitIgnoreTemplateException(SerializationInfo info, StreamingContext context)
: base(info, context) { }
#endif
}
}

View File

@@ -404,6 +404,7 @@
<Compile Include="Http\IApiInfoProvider.cs" />
<Compile Include="Models\Response\Meta.cs" />
<Compile Include="Models\Common\Committer.cs" />
<Compile Include="Exceptions\InvalidGitIgnoreTemplateException.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
</Project>

View File

@@ -412,6 +412,7 @@
<Compile Include="Models\Response\Meta.cs" />
<Compile Include="Models\Common\Committer.cs" />
<Compile Include="Models\Request\NewArbitraryMarkDown.cs" />
<Compile Include="Exceptions\InvalidGitIgnoreTemplateException.cs" />
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Novell\Novell.MonoDroid.CSharp.targets" />
</Project>
</Project>

View File

@@ -408,7 +408,8 @@
<Compile Include="Models\Response\Meta.cs" />
<Compile Include="Models\Common\Committer.cs" />
<Compile Include="Models\Request\NewArbitraryMarkDown.cs" />
<Compile Include="Exceptions\InvalidGitIgnoreTemplateException.cs" />
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Xamarin\iOS\Xamarin.MonoTouch.CSharp.targets" />
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
</Project>
</Project>

View File

@@ -401,6 +401,7 @@
<Compile Include="Http\IApiInfoProvider.cs" />
<Compile Include="Models\Response\Meta.cs" />
<Compile Include="Models\Common\Committer.cs" />
<Compile Include="Exceptions\InvalidGitIgnoreTemplateException.cs" />
</ItemGroup>
<ItemGroup>
<CodeAnalysisDictionary Include="..\CustomDictionary.xml">

View File

@@ -405,6 +405,7 @@
<Compile Include="Models\Response\Meta.cs" />
<Compile Include="Models\Common\Committer.cs" />
<Compile Include="Models\Request\NewArbitraryMarkDown.cs" />
<Compile Include="Exceptions\InvalidGitIgnoreTemplateException.cs" />
</ItemGroup>
<ItemGroup>
<CodeAnalysisDictionary Include="..\CustomDictionary.xml">

View File

@@ -71,6 +71,7 @@
<Compile Include="Clients\RepositoryDeployKeysClient.cs" />
<Compile Include="Clients\UserKeysClient.cs" />
<Compile Include="Clients\RepositoryContentsClient.cs" />
<Compile Include="Exceptions\InvalidGitIgnoreTemplateException.cs" />
<Compile Include="Exceptions\PrivateRepositoryQuotaExceededException.cs" />
<Compile Include="Exceptions\RepositoryExistsException.cs" />
<Compile Include="Exceptions\RepositoryFormatException.cs" />