From e31ac8659a124079a696c84bfb22f67c759bd6d5 Mon Sep 17 00:00:00 2001 From: Ryan Gribble Date: Sat, 1 Oct 2016 23:23:24 +1000 Subject: [PATCH] Add new fields to RepositoryUpdate request and update RepositoriesClient.Edit() method to specify preview accepts header and fix impacted unit tests Also added some checking for RepositoryUpdate.Name being null, as it is a required parameter --- .../Clients/RepositoriesClientTests.cs | 8 ++-- Octokit/Clients/RepositoriesClient.cs | 5 ++- Octokit/Models/Request/RepositoryUpdate.cs | 42 ++++++++++++++++++- 3 files changed, 48 insertions(+), 7 deletions(-) diff --git a/Octokit.Tests/Clients/RepositoriesClientTests.cs b/Octokit.Tests/Clients/RepositoriesClientTests.cs index efa1efe5..d8c6c958 100644 --- a/Octokit.Tests/Clients/RepositoriesClientTests.cs +++ b/Octokit.Tests/Clients/RepositoriesClientTests.cs @@ -1015,12 +1015,12 @@ namespace Octokit.Tests.Clients { var connection = Substitute.For(); var client = new RepositoriesClient(connection); - var update = new RepositoryUpdate(); + var update = new RepositoryUpdate("repo"); client.Edit("owner", "repo", update); connection.Received() - .Patch(Arg.Is(u => u.ToString() == "repos/owner/repo"), Arg.Any()); + .Patch(Arg.Is(u => u.ToString() == "repos/owner/repo"), Arg.Any(), "application/vnd.github.polaris-preview+json"); } [Fact] @@ -1028,12 +1028,12 @@ namespace Octokit.Tests.Clients { var connection = Substitute.For(); var client = new RepositoriesClient(connection); - var update = new RepositoryUpdate(); + var update = new RepositoryUpdate("repo"); client.Edit(1, update); connection.Received() - .Patch(Arg.Is(u => u.ToString() == "repositories/1"), Arg.Any()); + .Patch(Arg.Is(u => u.ToString() == "repositories/1"), Arg.Any(), "application/vnd.github.polaris-preview+json"); } [Fact] diff --git a/Octokit/Clients/RepositoriesClient.cs b/Octokit/Clients/RepositoriesClient.cs index 3717e79a..3e9b8026 100644 --- a/Octokit/Clients/RepositoriesClient.cs +++ b/Octokit/Clients/RepositoriesClient.cs @@ -192,8 +192,9 @@ namespace Octokit Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(name, "name"); Ensure.ArgumentNotNull(update, "update"); + Ensure.ArgumentNotNull(update.Name, "update.Name"); - return ApiConnection.Patch(ApiUrls.Repository(owner, name), update); + return ApiConnection.Patch(ApiUrls.Repository(owner, name), update, AcceptHeaders.SquashCommitPreview); } /// @@ -206,7 +207,7 @@ namespace Octokit { Ensure.ArgumentNotNull(update, "update"); - return ApiConnection.Patch(ApiUrls.Repository(repositoryId), update); + return ApiConnection.Patch(ApiUrls.Repository(repositoryId), update, AcceptHeaders.SquashCommitPreview); } /// diff --git a/Octokit/Models/Request/RepositoryUpdate.cs b/Octokit/Models/Request/RepositoryUpdate.cs index ad413593..dbce3686 100644 --- a/Octokit/Models/Request/RepositoryUpdate.cs +++ b/Octokit/Models/Request/RepositoryUpdate.cs @@ -1,4 +1,5 @@ -using System.Diagnostics; +using System; +using System.Diagnostics; using System.Diagnostics.CodeAnalysis; using System.Globalization; @@ -11,38 +12,77 @@ namespace Octokit [DebuggerDisplay("{DebuggerDisplay,nq}")] public class RepositoryUpdate { + [Obsolete("Please use the ctor RepositoryUpdate(string name) as Name is a required field")] + public RepositoryUpdate() + { + + } + + /// + /// Creates an object that describes an update to a repository on GitHub. + /// + /// The name of the repository. This is the only required parameter. + public RepositoryUpdate(string name) + { + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + + Name = name; + } + /// /// Required. Gets or sets the repository name. /// public string Name { get; set; } + /// /// Optional. Gets or sets the repository description. The default is null (do not update) /// public string Description { get; set; } + /// /// Optional. Gets or sets the repository homepage url. The default is null (do not update). /// public string Homepage { get; set; } + /// /// Gets or sets whether to make the repository private. The default is null (do not update). /// public bool? Private { get; set; } + /// /// Gets or sets whether to enable issues for the repository. The default is null (do not update). /// public bool? HasIssues { get; set; } + /// /// Optional. Gets or sets whether to enable the wiki for the repository. The default is null (do not update). /// public bool? HasWiki { get; set; } + /// /// Optional. Gets or sets whether to enable downloads for the repository. The default is null (do not update). /// public bool? HasDownloads { get; set; } + /// /// Optional. Gets or sets the default branch. The default is null (do not update). /// public string DefaultBranch { get; set; } + + /// + /// Optional. Allows the "Rebase and Merge" method to be used. + /// + public bool? AllowRebaseMerge { get; set; } + + /// + /// Optional. Allows the "Squash Merge" merge method to be used. + /// + public bool? AllowSquashMerge { get; set; } + + /// + /// Optional. Allows the "Create a merge commit" merge method to be used. + /// + public bool? AllowMergeCommit { get; set; } [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] internal string DebuggerDisplay