From 0b5f3e9611db01e8d8f808eed688a885c5c63d5b Mon Sep 17 00:00:00 2001 From: William Barbosa Date: Fri, 2 Oct 2015 19:25:46 -0300 Subject: [PATCH 1/4] Adds InvalidGitIgnoreTemplateException --- .../InvalidGitignoreTemplateException.cs | 58 +++++++++++++++++++ Octokit/Octokit-Mono.csproj | 3 +- Octokit/Octokit-MonoAndroid.csproj | 1 + Octokit/Octokit-Monotouch.csproj | 3 +- Octokit/Octokit-Portable.csproj | 3 +- Octokit/Octokit-netcore45.csproj | 1 + Octokit/Octokit.csproj | 3 +- 7 files changed, 68 insertions(+), 4 deletions(-) create mode 100644 Octokit/Exceptions/InvalidGitignoreTemplateException.cs diff --git a/Octokit/Exceptions/InvalidGitignoreTemplateException.cs b/Octokit/Exceptions/InvalidGitignoreTemplateException.cs new file mode 100644 index 00000000..fead0915 --- /dev/null +++ b/Octokit/Exceptions/InvalidGitignoreTemplateException.cs @@ -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.Exceptions +{ + /// + /// Represents a HTTP 403 - Forbidden response returned from the API. + /// +#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 : ApiException + { + /// + /// Constructs an instance of ApiValidationException + /// + public InvalidGitIgnoreTemplateException() + : base() { } + + /// + /// Constructs an instance of ApiValidationException + /// + /// The HTTP payload from the server + public InvalidGitIgnoreTemplateException(string message) + : this(message, null) { } + + /// + /// Constructs an instance of InvalidGitignoreTemplateException + /// + /// Error message returned from the server + /// The inner exception + public InvalidGitIgnoreTemplateException(string message, Exception innerException) + : base(message, innerException) { } + +#if !NETFX_CORE + /// + /// Constructs an instance of InvalidGitignoreTemplateException + /// + /// + /// The that holds the + /// serialized object data about the exception being thrown. + /// + /// + /// The that contains + /// contextual information about the source or destination. + /// + protected InvalidGitIgnoreTemplateException(SerializationInfo info, StreamingContext context) + : base(info, context) { } +#endif + } +} \ No newline at end of file diff --git a/Octokit/Octokit-Mono.csproj b/Octokit/Octokit-Mono.csproj index 3d6206fc..1f1f92ec 100644 --- a/Octokit/Octokit-Mono.csproj +++ b/Octokit/Octokit-Mono.csproj @@ -403,6 +403,7 @@ + - + \ No newline at end of file diff --git a/Octokit/Octokit-MonoAndroid.csproj b/Octokit/Octokit-MonoAndroid.csproj index ea68c7d3..bb05fb4f 100644 --- a/Octokit/Octokit-MonoAndroid.csproj +++ b/Octokit/Octokit-MonoAndroid.csproj @@ -411,6 +411,7 @@ + \ No newline at end of file diff --git a/Octokit/Octokit-Monotouch.csproj b/Octokit/Octokit-Monotouch.csproj index 7b228d6d..7144cfd4 100644 --- a/Octokit/Octokit-Monotouch.csproj +++ b/Octokit/Octokit-Monotouch.csproj @@ -407,7 +407,8 @@ + - + \ No newline at end of file diff --git a/Octokit/Octokit-Portable.csproj b/Octokit/Octokit-Portable.csproj index 28280e54..f2e8c351 100644 --- a/Octokit/Octokit-Portable.csproj +++ b/Octokit/Octokit-Portable.csproj @@ -400,6 +400,7 @@ + @@ -430,4 +431,4 @@ --> - + \ No newline at end of file diff --git a/Octokit/Octokit-netcore45.csproj b/Octokit/Octokit-netcore45.csproj index 6f98071f..f4b7d2ff 100644 --- a/Octokit/Octokit-netcore45.csproj +++ b/Octokit/Octokit-netcore45.csproj @@ -404,6 +404,7 @@ + diff --git a/Octokit/Octokit.csproj b/Octokit/Octokit.csproj index 3708c95b..3f6ae1b2 100644 --- a/Octokit/Octokit.csproj +++ b/Octokit/Octokit.csproj @@ -71,6 +71,7 @@ + @@ -441,4 +442,4 @@ --> - + \ No newline at end of file From 7dee540afdf40a8a0756ffcf48f47fdac3203c1e Mon Sep 17 00:00:00 2001 From: William Barbosa Date: Sun, 4 Oct 2015 10:12:34 -0300 Subject: [PATCH 2/4] Throwing proper exception on RepositoresClient --- Octokit/Clients/RepositoriesClient.cs | 9 +++++++ .../InvalidGitignoreTemplateException.cs | 24 +++++++++---------- 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/Octokit/Clients/RepositoriesClient.cs b/Octokit/Clients/RepositoriesClient.cs index 996e5b08..b6bb1ccd 100644 --- a/Octokit/Clients/RepositoriesClient.cs +++ b/Octokit/Clients/RepositoriesClient.cs @@ -116,6 +116,15 @@ namespace Octokit { throw new PrivateRepositoryQuotaExceededException(e); } + + if (String.Equals( + "gitignore_template is an unknown gitignore template.", + errorMessage, + StringComparison.OrdinalIgnoreCase)) + { + throw new InvalidGitIgnoreTemplateException(e); + } + throw; } } diff --git a/Octokit/Exceptions/InvalidGitignoreTemplateException.cs b/Octokit/Exceptions/InvalidGitignoreTemplateException.cs index fead0915..6d26621d 100644 --- a/Octokit/Exceptions/InvalidGitignoreTemplateException.cs +++ b/Octokit/Exceptions/InvalidGitignoreTemplateException.cs @@ -6,7 +6,7 @@ using System.Runtime.Serialization; using System.Text; using System.Threading.Tasks; -namespace Octokit.Exceptions +namespace Octokit { /// /// Represents a HTTP 403 - Forbidden response returned from the API. @@ -16,7 +16,7 @@ namespace Octokit.Exceptions #endif [SuppressMessage("Microsoft.Design", "CA1032:ImplementStandardExceptionConstructors", Justification = "These exceptions are specific to the GitHub API and not general purpose exceptions")] - public class InvalidGitIgnoreTemplateException : ApiException + public class InvalidGitIgnoreTemplateException : ApiValidationException { /// /// Constructs an instance of ApiValidationException @@ -27,17 +27,17 @@ namespace Octokit.Exceptions /// /// Constructs an instance of ApiValidationException /// - /// The HTTP payload from the server - public InvalidGitIgnoreTemplateException(string message) - : this(message, null) { } + /// The inner validation exception. + public InvalidGitIgnoreTemplateException(ApiValidationException innerException) + : base(innerException) { } - /// - /// Constructs an instance of InvalidGitignoreTemplateException - /// - /// Error message returned from the server - /// The inner exception - public InvalidGitIgnoreTemplateException(string message, Exception innerException) - : base(message, innerException) { } + public override string Message + { + get + { + return "The Gitignore template provided is not valid."; + } + } #if !NETFX_CORE /// From 64326519ee12449a4de2921c2c2b819d2a446f7f Mon Sep 17 00:00:00 2001 From: William Barbosa Date: Thu, 8 Oct 2015 20:38:18 -0300 Subject: [PATCH 3/4] Changes the way the exception is verified --- .../Clients/RepositoriesClientTests.cs | 19 +++++++++++++++++++ Octokit/Clients/RepositoriesClient.cs | 5 +---- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/Octokit.Tests.Integration/Clients/RepositoriesClientTests.cs b/Octokit.Tests.Integration/Clients/RepositoriesClientTests.cs index 31273268..dba163e8 100644 --- a/Octokit.Tests.Integration/Clients/RepositoriesClientTests.cs +++ b/Octokit.Tests.Integration/Clients/RepositoriesClientTests.cs @@ -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( + () => github.CreateRepositoryContext(newRepository)); + + Assert.NotNull(thrown); + } + [IntegrationTest] public async Task ThrowsRepositoryExistsExceptionForExistingRepository() { diff --git a/Octokit/Clients/RepositoriesClient.cs b/Octokit/Clients/RepositoriesClient.cs index b6bb1ccd..246876ad 100644 --- a/Octokit/Clients/RepositoriesClient.cs +++ b/Octokit/Clients/RepositoriesClient.cs @@ -117,10 +117,7 @@ namespace Octokit throw new PrivateRepositoryQuotaExceededException(e); } - if (String.Equals( - "gitignore_template is an unknown gitignore template.", - errorMessage, - StringComparison.OrdinalIgnoreCase)) + if (errorMessage.EndsWith("is an unknown gitignore template.", StringComparison.OrdinalIgnoreCase)) { throw new InvalidGitIgnoreTemplateException(e); } From 76ff9d85ae60950c641948ad2295055ddf4614da Mon Sep 17 00:00:00 2001 From: William Barbosa Date: Sat, 10 Oct 2015 07:40:27 -0300 Subject: [PATCH 4/4] :poop: brainfart --- Octokit/Clients/RepositoriesClient.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Octokit/Clients/RepositoriesClient.cs b/Octokit/Clients/RepositoriesClient.cs index 246876ad..fbc4e76c 100644 --- a/Octokit/Clients/RepositoriesClient.cs +++ b/Octokit/Clients/RepositoriesClient.cs @@ -117,7 +117,7 @@ namespace Octokit throw new PrivateRepositoryQuotaExceededException(e); } - if (errorMessage.EndsWith("is an unknown gitignore template.", StringComparison.OrdinalIgnoreCase)) + if (errorMessage != null && errorMessage.EndsWith("is an unknown gitignore template.", StringComparison.OrdinalIgnoreCase)) { throw new InvalidGitIgnoreTemplateException(e); }