diff --git a/Octokit.Tests.Integration/Clients/RepositoriesClientTests.cs b/Octokit.Tests.Integration/Clients/RepositoriesClientTests.cs index 18b75783..00938852 100644 --- a/Octokit.Tests.Integration/Clients/RepositoriesClientTests.cs +++ b/Octokit.Tests.Integration/Clients/RepositoriesClientTests.cs @@ -506,216 +506,314 @@ public class RepositoriesClientTests // TODO: Add a test for the team_id param once an overload that takes an organization is added } - public class TheEditMethod : IDisposable + public class TheEditMethod : GitHubClientTestBase { - Repository _repository; + [IntegrationTest] + public async Task UpdatesNothing() + { + using (var repoContext = await _github.CreateRepositoryContext()) + { + var update = new RepositoryUpdate(); + + var updatedRepository = await _github.Repository.Edit(repoContext.RepositoryOwner, repoContext.RepositoryName, update); + + Assert.Equal(repoContext.Repository.Name, updatedRepository.Name); + Assert.Equal(repoContext.Repository.Description, updatedRepository.Description); + Assert.Equal(repoContext.Repository.Homepage, updatedRepository.Homepage); + Assert.Equal(repoContext.Repository.Private, updatedRepository.Private); + Assert.Equal(repoContext.Repository.Visibility, updatedRepository.Visibility); + Assert.Equal(repoContext.Repository.HasIssues, updatedRepository.HasIssues); + //Assert.Equal(_repository.HasProjects, updatedRepository.HasProjects); - not on response! + Assert.Equal(repoContext.Repository.HasWiki, updatedRepository.HasWiki); + Assert.Equal(repoContext.Repository.HasDownloads, updatedRepository.HasDownloads); + Assert.Equal(repoContext.Repository.IsTemplate, updatedRepository.IsTemplate); + Assert.Equal(repoContext.Repository.DefaultBranch, updatedRepository.DefaultBranch); + Assert.Equal(repoContext.Repository.AllowSquashMerge, updatedRepository.AllowSquashMerge); + Assert.Equal(repoContext.Repository.AllowMergeCommit, updatedRepository.AllowMergeCommit); + Assert.Equal(repoContext.Repository.AllowRebaseMerge, updatedRepository.AllowRebaseMerge); + Assert.Equal(repoContext.Repository.AllowAutoMerge, updatedRepository.AllowAutoMerge); + Assert.Equal(repoContext.Repository.DeleteBranchOnMerge, updatedRepository.DeleteBranchOnMerge); + // Assert.Equal(_repository.UseSquashPrTitleAsDefault, updatedRepository.UseSquashPrTitleAsDefault); - not on response! + Assert.Equal(repoContext.Repository.Archived, updatedRepository.Archived); + //Assert.Equal(_repository.AllowForking, updatedRepository.AllowForking); - not on response! + } + } [IntegrationTest] public async Task UpdatesName() { - var github = Helper.GetAuthenticatedClient(); - var repoName = Helper.MakeNameWithTimestamp("public-repo"); - _repository = await github.Repository.Create(new NewRepository(repoName) { AutoInit = true }); - var updatedName = Helper.MakeNameWithTimestamp("updated-repo"); - var update = new RepositoryUpdate(updatedName); + using (var repoContext = await _github.CreateRepositoryContext()) + { + var updatedName = Helper.MakeNameWithTimestamp("updated-repo"); + var update = new RepositoryUpdate() { Name = updatedName }; - _repository = await github.Repository.Edit(Helper.UserName, repoName, update); + var updatedRepository = await _github.Repository.Edit(repoContext.RepositoryOwner, repoContext.RepositoryName, update); - Assert.Equal(update.Name, _repository.Name); + Assert.Equal(update.Name, updatedRepository.Name); + } } [IntegrationTest] public async Task UpdatesNameWithRepositoryId() { - var github = Helper.GetAuthenticatedClient(); - var repoName = Helper.MakeNameWithTimestamp("public-repo"); - _repository = await github.Repository.Create(new NewRepository(repoName) { AutoInit = true }); - var updatedName = Helper.MakeNameWithTimestamp("updated-repo"); - var update = new RepositoryUpdate(updatedName); + using (var repoContext = await _github.CreateRepositoryContext()) + { + var updatedName = Helper.MakeNameWithTimestamp("updated-repo"); + var update = new RepositoryUpdate() { Name = updatedName }; - _repository = await github.Repository.Edit(_repository.Id, update); + var updatedRepository = await _github.Repository.Edit(repoContext.RepositoryId, update); - Assert.Equal(update.Name, _repository.Name); + Assert.Equal(update.Name, updatedRepository.Name); + } + } + + [IntegrationTest] + public async Task UpdatesNameObsolete() + { + using (var repoContext = await _github.CreateRepositoryContext()) + { + var updatedName = Helper.MakeNameWithTimestamp("updated-repo"); + var update = new RepositoryUpdate(updatedName); + + var updatedRepository = await _github.Repository.Edit(repoContext.RepositoryOwner, repoContext.RepositoryName, update); + + Assert.Equal(update.Name, updatedRepository.Name); + } + } + + [IntegrationTest] + public async Task UpdatesNameWithRepositoryIdObsolete() + { + using (var repoContext = await _github.CreateRepositoryContext()) + { + var updatedName = Helper.MakeNameWithTimestamp("updated-repo"); + var update = new RepositoryUpdate(updatedName); + + var updatedRepository = await _github.Repository.Edit(repoContext.RepositoryId, update); + + Assert.Equal(update.Name, updatedRepository.Name); + } } [IntegrationTest] public async Task UpdatesDescription() { - var github = Helper.GetAuthenticatedClient(); - var repoName = Helper.MakeNameWithTimestamp("public-repo"); - _repository = await github.Repository.Create(new NewRepository(repoName) { AutoInit = true }); - var update = new RepositoryUpdate(repoName) { Description = "Updated description" }; + using (var repoContext = await _github.CreateRepositoryContext()) + { + var update = new RepositoryUpdate() { Description = "Updated description" }; - _repository = await github.Repository.Edit(Helper.UserName, repoName, update); + var updatedRepository = await _github.Repository.Edit(repoContext.RepositoryOwner, repoContext.RepositoryName, update); - Assert.Equal("Updated description", _repository.Description); + Assert.Equal(update.Description, updatedRepository.Description); + } } [IntegrationTest] public async Task UpdatesDescriptionWithRepositoryId() { - var github = Helper.GetAuthenticatedClient(); - var repoName = Helper.MakeNameWithTimestamp("public-repo"); - _repository = await github.Repository.Create(new NewRepository(repoName) { AutoInit = true }); - var update = new RepositoryUpdate(repoName) { Description = "Updated description" }; + using (var repoContext = await _github.CreateRepositoryContext()) + { + var update = new RepositoryUpdate() { Description = "Updated description" }; - _repository = await github.Repository.Edit(_repository.Id, update); + var updatedRepository = await _github.Repository.Edit(repoContext.RepositoryId, update); - Assert.Equal("Updated description", _repository.Description); + Assert.Equal(update.Description, updatedRepository.Description); + } } [IntegrationTest] public async Task UpdatesHomepage() { - var github = Helper.GetAuthenticatedClient(); - var repoName = Helper.MakeNameWithTimestamp("public-repo"); - _repository = await github.Repository.Create(new NewRepository(repoName) { AutoInit = true }); - var update = new RepositoryUpdate(repoName) { Homepage = "http://aUrl.to/nowhere" }; + using (var repoContext = await _github.CreateRepositoryContext()) + { + var update = new RepositoryUpdate() { Homepage = "http://aUrl.to/nowhere" }; - _repository = await github.Repository.Edit(Helper.UserName, repoName, update); + var updatedRepository = await _github.Repository.Edit(repoContext.RepositoryOwner, repoContext.RepositoryName, update); - Assert.Equal("http://aUrl.to/nowhere", _repository.Homepage); + Assert.Equal(update.Homepage, updatedRepository.Homepage); + } } [IntegrationTest] public async Task UpdatesHomepageWithRepositoryId() { - var github = Helper.GetAuthenticatedClient(); - var repoName = Helper.MakeNameWithTimestamp("public-repo"); - _repository = await github.Repository.Create(new NewRepository(repoName) { AutoInit = true }); - var update = new RepositoryUpdate(repoName) { Homepage = "http://aUrl.to/nowhere" }; + using (var repoContext = await _github.CreateRepositoryContext()) + { + var update = new RepositoryUpdate() { Homepage = "http://aUrl.to/nowhere" }; - _repository = await github.Repository.Edit(_repository.Id, update); + var updatedRepository = await _github.Repository.Edit(repoContext.RepositoryId, update); - Assert.Equal("http://aUrl.to/nowhere", _repository.Homepage); + Assert.Equal(update.Homepage, updatedRepository.Homepage); + } } [PaidAccountTest] public async Task UpdatesPrivate() { - var github = Helper.GetAuthenticatedClient(); - - var userDetails = await github.User.Current(); - if (userDetails.Plan.PrivateRepos == 0) + using (var repoContext = await _github.CreateRepositoryContext()) { - throw new Exception("Test cannot complete, account is on free plan"); + var update = new RepositoryUpdate() { Private = true }; + + var updatedRepository = await _github.Repository.Edit(repoContext.RepositoryOwner, repoContext.RepositoryName, update); + + Assert.True(updatedRepository.Private); } - - var repoName = Helper.MakeNameWithTimestamp("public-repo"); - _repository = await github.Repository.Create(new NewRepository(repoName) { AutoInit = true }); - var update = new RepositoryUpdate(repoName) { Private = true }; - - _repository = await github.Repository.Edit(Helper.UserName, repoName, update); - - Assert.True(_repository.Private); } [PaidAccountTest] public async Task UpdatesPrivateWithRepositoryId() { - var github = Helper.GetAuthenticatedClient(); - - var userDetails = await github.User.Current(); - if (userDetails.Plan.PrivateRepos == 0) + using (var repoContext = await _github.CreateRepositoryContext()) { - throw new Exception("Test cannot complete, account is on free plan"); + var update = new RepositoryUpdate() { Private = true }; + + var updatedRepository = await _github.Repository.Edit(repoContext.RepositoryId, update); + + Assert.True(updatedRepository.Private); } - - var repoName = Helper.MakeNameWithTimestamp("public-repo"); - _repository = await github.Repository.Create(new NewRepository(repoName) { AutoInit = true }); - var update = new RepositoryUpdate(repoName) { Private = true }; - - _repository = await github.Repository.Edit(_repository.Id, update); - - Assert.True(_repository.Private); - } - - [IntegrationTest] - public async Task UpdatesHasDownloads() - { - var github = Helper.GetAuthenticatedClient(); - var repoName = Helper.MakeNameWithTimestamp("public-repo"); - _repository = await github.Repository.Create(new NewRepository(repoName) { AutoInit = true }); - var update = new RepositoryUpdate(repoName) { HasDownloads = false }; - - _repository = await github.Repository.Edit(Helper.UserName, repoName, update); - - Assert.False(_repository.HasDownloads); - } - - [IntegrationTest] - public async Task UpdatesHasDownloadsWithRepositoryId() - { - var github = Helper.GetAuthenticatedClient(); - var repoName = Helper.MakeNameWithTimestamp("public-repo"); - _repository = await github.Repository.Create(new NewRepository(repoName) { AutoInit = true }); - var update = new RepositoryUpdate(repoName) { HasDownloads = false }; - - _repository = await github.Repository.Edit(_repository.Id, update); - - Assert.False(_repository.HasDownloads); } [IntegrationTest] public async Task UpdatesHasIssues() { - var github = Helper.GetAuthenticatedClient(); - var repoName = Helper.MakeNameWithTimestamp("public-repo"); - _repository = await github.Repository.Create(new NewRepository(repoName) { AutoInit = true }); - var update = new RepositoryUpdate(repoName) { HasIssues = false }; + using (var repoContext = await _github.CreateRepositoryContext()) + { + var update = new RepositoryUpdate() { HasIssues = false }; - _repository = await github.Repository.Edit(Helper.UserName, repoName, update); + var updatedRepository = await _github.Repository.Edit(repoContext.RepositoryOwner, repoContext.RepositoryName, update); - Assert.False(_repository.HasIssues); + Assert.False(updatedRepository.HasIssues); + } } [IntegrationTest] public async Task UpdatesHasIssuesWithRepositoryId() { - var github = Helper.GetAuthenticatedClient(); - var repoName = Helper.MakeNameWithTimestamp("public-repo"); - _repository = await github.Repository.Create(new NewRepository(repoName) { AutoInit = true }); - var update = new RepositoryUpdate(repoName) { HasIssues = false }; + using (var repoContext = await _github.CreateRepositoryContext()) + { + var update = new RepositoryUpdate() { HasIssues = false }; - _repository = await github.Repository.Edit(_repository.Id, update); + var updatedRepository = await _github.Repository.Edit(repoContext.RepositoryId, update); - Assert.False(_repository.HasIssues); + Assert.False(updatedRepository.HasIssues); + } } [IntegrationTest] public async Task UpdatesHasWiki() { - var github = Helper.GetAuthenticatedClient(); - var repoName = Helper.MakeNameWithTimestamp("public-repo"); - _repository = await github.Repository.Create(new NewRepository(repoName) { AutoInit = true }); - var update = new RepositoryUpdate(repoName) { HasWiki = false }; + using (var repoContext = await _github.CreateRepositoryContext()) + { + var update = new RepositoryUpdate() { HasWiki = false }; - _repository = await github.Repository.Edit(Helper.UserName, repoName, update); + var updatedRepository = await _github.Repository.Edit(repoContext.RepositoryOwner, repoContext.RepositoryName, update); - Assert.False(_repository.HasWiki); + Assert.False(updatedRepository.HasWiki); + } } [IntegrationTest] public async Task UpdatesHasWikiWithRepositoryId() { - var github = Helper.GetAuthenticatedClient(); - var repoName = Helper.MakeNameWithTimestamp("public-repo"); - _repository = await github.Repository.Create(new NewRepository(repoName) { AutoInit = true }); - var update = new RepositoryUpdate(repoName) { HasWiki = false }; + using (var repoContext = await _github.CreateRepositoryContext()) + { + var update = new RepositoryUpdate() { HasWiki = false }; - _repository = await github.Repository.Edit(_repository.Id, update); + var updatedRepository = await _github.Repository.Edit(repoContext.RepositoryId, update); - Assert.False(_repository.HasWiki); + Assert.False(updatedRepository.HasWiki); + } + } + + [IntegrationTest] + public async Task UpdatesHasDownloads() + { + using (var repoContext = await _github.CreateRepositoryContext()) + { + var update = new RepositoryUpdate() { HasDownloads = false }; + + var updatedRepository = await _github.Repository.Edit(repoContext.RepositoryOwner, repoContext.RepositoryName, update); + + Assert.False(updatedRepository.HasDownloads); + } + } + + [IntegrationTest] + public async Task UpdatesHasDownloadsWithRepositoryId() + { + using (var repoContext = await _github.CreateRepositoryContext()) + { + var update = new RepositoryUpdate() { HasDownloads = false }; + + var updatedRepository = await _github.Repository.Edit(repoContext.RepositoryId, update); + + Assert.False(updatedRepository.HasDownloads); + } + } + + [IntegrationTest] + public async Task UpdatesIsTemplate() + { + using (var repoContext = await _github.CreateRepositoryContext()) + { + var update = new RepositoryUpdate() { IsTemplate = true }; + + var updatedRepository = await _github.Repository.Edit(repoContext.RepositoryOwner, repoContext.RepositoryName, update); + + Assert.True(updatedRepository.IsTemplate); + } + } + + [IntegrationTest] + public async Task UpdatesIsTemplateWithRepositoryId() + { + using (var repoContext = await _github.CreateRepositoryContext()) + { + var update = new RepositoryUpdate() { IsTemplate = true }; + + var updatedRepository = await _github.Repository.Edit(repoContext.RepositoryId, update); + + Assert.True(updatedRepository.IsTemplate); + } + } + + [IntegrationTest] + public async Task UpdatesDefaultBranch() + { + using (var repoContext = await _github.CreateRepositoryContext()) + { + var reference = _github.Git.Reference.GetAll(repoContext.RepositoryOwner, repoContext.RepositoryName).Result.First(); + _github.Git.Reference.Create(repoContext.RepositoryId, new NewReference("refs/heads/primary", reference.Object.Sha)).Wait(); + var update = new RepositoryUpdate() { DefaultBranch = "primary" }; + + var updatedRepository = await _github.Repository.Edit(repoContext.RepositoryOwner, repoContext.RepositoryName, update); + + Assert.Equal(update.DefaultBranch, updatedRepository.DefaultBranch); + } + } + + [IntegrationTest] + public async Task UpdatesDefaultBranchWithRepositoryId() + { + using (var repoContext = await _github.CreateRepositoryContext()) + { + var reference = _github.Git.Reference.GetAll(repoContext.RepositoryOwner, repoContext.RepositoryName).Result.First(); + _github.Git.Reference.Create(repoContext.RepositoryId, new NewReference("refs/heads/primary", reference.Object.Sha)).Wait(); + var update = new RepositoryUpdate() { DefaultBranch = "primary" }; + + var updatedRepository = await _github.Repository.Edit(repoContext.RepositoryId, update); + + Assert.Equal(update.DefaultBranch, updatedRepository.DefaultBranch); + } } [IntegrationTest] public async Task UpdatesMergeMethod() { - var github = Helper.GetAuthenticatedClient(); - - using (var context = await github.CreateRepositoryContext("public-repo")) + using (var repoContext = await _github.CreateRepositoryContext()) { - var updateRepository = new RepositoryUpdate(context.RepositoryName) + + var updateRepository = new RepositoryUpdate() { AllowMergeCommit = false, AllowSquashMerge = false, @@ -723,28 +821,20 @@ public class RepositoriesClientTests AllowAutoMerge = true }; - var editedRepository = await github.Repository.Edit(context.RepositoryOwner, context.RepositoryName, updateRepository); + var editedRepository = await _github.Repository.Edit(repoContext.RepositoryOwner, repoContext.RepositoryName, updateRepository); Assert.False(editedRepository.AllowMergeCommit); Assert.False(editedRepository.AllowSquashMerge); Assert.True(editedRepository.AllowRebaseMerge); Assert.True(editedRepository.AllowAutoMerge); - - var repository = await github.Repository.Get(context.RepositoryOwner, context.RepositoryName); - Assert.False(repository.AllowMergeCommit); - Assert.False(repository.AllowSquashMerge); - Assert.True(repository.AllowRebaseMerge); - Assert.True(repository.AllowAutoMerge); } } [IntegrationTest] public async Task UpdatesMergeMethodWithRepositoryId() { - var github = Helper.GetAuthenticatedClient(); - - using (var context = await github.CreateRepositoryContext("public-repo")) + using (var repoContext = await _github.CreateRepositoryContext()) { - var updateRepository = new RepositoryUpdate(context.RepositoryName) + var updateRepository = new RepositoryUpdate() { AllowMergeCommit = true, AllowSquashMerge = true, @@ -752,63 +842,62 @@ public class RepositoriesClientTests AllowAutoMerge = true }; - var editedRepository = await github.Repository.Edit(context.RepositoryId, updateRepository); + var editedRepository = await _github.Repository.Edit(repoContext.RepositoryId, updateRepository); Assert.True(editedRepository.AllowMergeCommit); Assert.True(editedRepository.AllowSquashMerge); Assert.False(editedRepository.AllowRebaseMerge); Assert.True(editedRepository.AllowAutoMerge); - - var repository = await github.Repository.Get(context.RepositoryId); - Assert.True(repository.AllowMergeCommit); - Assert.True(repository.AllowSquashMerge); - Assert.False(repository.AllowRebaseMerge); - Assert.True(editedRepository.AllowAutoMerge); } } - + [IntegrationTest] public async Task UpdatesDeleteBranchOnMergeMethod() { - var github = Helper.GetAuthenticatedClient(); - - using (var context = await github.CreateRepositoryContext("public-repo")) + using (var repoContext = await _github.CreateRepositoryContext()) { - var updateRepository = new RepositoryUpdate(context.RepositoryName) - { - DeleteBranchOnMerge = true - }; + var updateRepository = new RepositoryUpdate() { DeleteBranchOnMerge = true }; - var editedRepository = await github.Repository.Edit(context.RepositoryOwner, context.RepositoryName, updateRepository); + var editedRepository = await _github.Repository.Edit(repoContext.RepositoryOwner, repoContext.RepositoryName, updateRepository); Assert.True(editedRepository.DeleteBranchOnMerge); - - var repository = await github.Repository.Get(context.RepositoryOwner, context.RepositoryName); - Assert.True(repository.DeleteBranchOnMerge); } } - + [IntegrationTest] public async Task UpdatesDeleteBranchOnMergeMethodWithRepositoryId() { - var github = Helper.GetAuthenticatedClient(); - - using (var context = await github.CreateRepositoryContext("public-repo")) + using (var repoContext = await _github.CreateRepositoryContext()) { - var updateRepository = new RepositoryUpdate(context.RepositoryName) - { - DeleteBranchOnMerge = true - }; + var updateRepository = new RepositoryUpdate() { DeleteBranchOnMerge = true }; - var editedRepository = await github.Repository.Edit(context.RepositoryId, updateRepository); + var editedRepository = await _github.Repository.Edit(repoContext.RepositoryId, updateRepository); Assert.True(editedRepository.DeleteBranchOnMerge); - - var repository = await github.Repository.Get(context.RepositoryId); - Assert.True(repository.DeleteBranchOnMerge); } } - public void Dispose() + [IntegrationTest] + public async Task UpdatesArchive() { - Helper.DeleteRepo(Helper.GetAuthenticatedClient().Connection, _repository); + using (var repoContext = await _github.CreateRepositoryContext()) + { + var update = new RepositoryUpdate() { Archived = true }; + + var updatedRepository = await _github.Repository.Edit(repoContext.RepositoryOwner, repoContext.RepositoryName, update); + + Assert.Equal(update.Archived, updatedRepository.Archived); + } + } + + [IntegrationTest] + public async Task UpdatesArchiveWithRepositoryId() + { + using (var repoContext = await _github.CreateRepositoryContext()) + { + var update = new RepositoryUpdate() { Archived = true }; + + var updatedRepository = await _github.Repository.Edit(repoContext.RepositoryId, update); + + Assert.Equal(update.Archived, updatedRepository.Archived); + } } } @@ -985,7 +1074,7 @@ public class RepositoriesClientTests Assert.Equal("mit", repository.License.Key); Assert.Equal("MIT License", repository.License.Name); } - + [IntegrationTest] public async Task ReturnsRepositoryDeleteBranchOnMergeOptions() { @@ -2161,4 +2250,49 @@ public class RepositoriesClientTests Assert.True(enabled); } } + + public class RepositoryTestBaseClass : IDisposable + { + protected IGitHubClient _github; + + private readonly List _repositories; + + protected RepositoryTestBaseClass() + { + _github = Helper.GetAuthenticatedClient(); + _repositories = new List(); + } + + public void Dispose() + { + foreach (var repository in _repositories) + { + repository.Dispose(); + } + } + + /// + /// Returns a RepositoryContext, which will be disposed at the end of the test. + /// + /// Your value or uses default of Helper.MakeNameWithTimestamp("public-repo"); + /// + internal RepositoryContext CreateRepository(string name = null) + { + var newContext = _github.CreateRepositoryContext(new NewRepository(Helper.MakeNameWithTimestamp(name ?? Helper.MakeNameWithTimestamp("public-repo"))) { AutoInit = true }).Result; + _repositories.Add(newContext); + return newContext; + } + + /// + /// Returns a RepositoryContext, which will be disposed at the end of the test. + /// + /// Your value or uses default of Helper.MakeNameWithTimestamp("public-repo"); + /// + internal async Task CreateRepositoryAsync(string name = null) + { + var newContext = await _github.CreateRepositoryContext(new NewRepository(Helper.MakeNameWithTimestamp(name ?? Helper.MakeNameWithTimestamp("public-repo"))) { AutoInit = true }); + _repositories.Add(newContext); + return newContext; + } + } } diff --git a/Octokit.Tests.Integration/GitHubClientTestBase.cs b/Octokit.Tests.Integration/GitHubClientTestBase.cs new file mode 100644 index 00000000..269aec6a --- /dev/null +++ b/Octokit.Tests.Integration/GitHubClientTestBase.cs @@ -0,0 +1,12 @@ +namespace Octokit.Tests.Integration +{ + public class GitHubClientTestBase + { + protected readonly IGitHubClient _github; + + public GitHubClientTestBase() + { + _github = Helper.GetAuthenticatedClient(); + } + } +} diff --git a/Octokit.Tests.Integration/SelfTests.cs b/Octokit.Tests.Integration/SelfTests.cs index 23b286e9..418b512d 100644 --- a/Octokit.Tests.Integration/SelfTests.cs +++ b/Octokit.Tests.Integration/SelfTests.cs @@ -15,14 +15,4 @@ namespace Octokit.Tests.Integration Assert.Equal("", errors); } } - - public class GitHubClientTestBase - { - protected readonly IGitHubClient _github; - - public GitHubClientTestBase() - { - _github = Helper.GetAuthenticatedClient(); - } - } } diff --git a/Octokit.Tests/Models/RepositoryUpdateTests.cs b/Octokit.Tests/Models/RepositoryUpdateTests.cs index a1b91b49..b5bfb93a 100644 --- a/Octokit.Tests/Models/RepositoryUpdateTests.cs +++ b/Octokit.Tests/Models/RepositoryUpdateTests.cs @@ -21,8 +21,9 @@ namespace Octokit.Tests.Models "\"has_wiki\":true," + "\"has_downloads\":true}"; - var update = new RepositoryUpdate("Hello-World") + var update = new RepositoryUpdate() { + Name = "Hello-World", Description = "This is your first repository", Homepage = "https://github.com", Private = true, diff --git a/Octokit/Clients/RepositoriesClient.cs b/Octokit/Clients/RepositoriesClient.cs index 612de5d1..4d4bfe3b 100644 --- a/Octokit/Clients/RepositoriesClient.cs +++ b/Octokit/Clients/RepositoriesClient.cs @@ -270,7 +270,6 @@ namespace Octokit Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); Ensure.ArgumentNotNull(update, nameof(update)); - Ensure.ArgumentNotNull(update.Name, nameof(update.Name)); return ApiConnection.Patch(ApiUrls.Repository(owner, name), update, AcceptHeaders.Concat(AcceptHeaders.VisibilityPreview, AcceptHeaders.TemplatePreview)); } diff --git a/Octokit/Models/Request/RepositoryUpdate.cs b/Octokit/Models/Request/RepositoryUpdate.cs index 4a876f05..7e8e3438 100644 --- a/Octokit/Models/Request/RepositoryUpdate.cs +++ b/Octokit/Models/Request/RepositoryUpdate.cs @@ -1,7 +1,6 @@ -using System; +using Octokit.Internal; +using System; using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; -using System.Globalization; namespace Octokit { @@ -12,14 +11,19 @@ namespace Octokit [DebuggerDisplay("{DebuggerDisplay,nq}")] public class RepositoryUpdate { + /// + /// Creates an object that describes an update to a repository on GitHub. + /// + 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. + [Obsolete("Use the constructor with no parameters as name is no longer a required field")] public RepositoryUpdate(string name) { Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); - Name = name; } @@ -44,62 +48,83 @@ namespace Octokit public bool? Private { get; set; } /// - /// Gets or sets whether to enable issues for the repository. The default is null (do not update). + /// Optional. Gets or sets whether the new repository is public, private, or internal. A value provided here overrides any value set in the existing private field. + /// + public RepositoryVisibility? Visibility { get; set; } + + // Yet to be implemented + //public object SecurityAndAnalysis { get; set; } + + /// + /// Gets or sets whether to enable issues for the repository. The default is null (do not update). The default when created is true. /// public bool? HasIssues { get; set; } /// - /// Optional. Gets or sets whether to enable the wiki for the repository. The default is null (do not update). + /// Gets or sets whether to enable projects for the repository. The default is null (do not update). The default when created is true. + /// + public bool? HasProjects { get; set; } + + /// + /// Optional. Gets or sets whether to enable the wiki for the repository. The default is null (do not update). The default when created is true. /// public bool? HasWiki { get; set; } /// - /// Optional. Gets or sets whether to enable downloads for the repository. The default is null (do not update). + /// Optional. Gets or sets whether to enable downloads for the repository. The default is null (do not update). No longer appears on the documentation but still works. /// public bool? HasDownloads { get; set; } + /// + /// Optional. Gets or sets whether the repository is a template. The default is null (do not update). The default when created is false. + /// + public bool? IsTemplate { 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. + /// Optional. Allows the "Squash Merge" merge method to be used. The default is null (do not update). The default when created is true. /// public bool? AllowSquashMerge { get; set; } /// - /// Optional. Allows the "Create a merge commit" merge method to be used. + /// Optional. Allows the "Create a merge commit" merge method to be used. The default is null (do not update). The default when created is true. /// public bool? AllowMergeCommit { get; set; } - + /// + /// Optional. Allows the "Rebase and Merge" method to be used. The default is null (do not update). The default when created is true. + /// + public bool? AllowRebaseMerge { get; set; } + + /// + /// Optional. Allows the auto merge feature to be used. The default is null (do not update). The default when created is false. + /// + public bool? AllowAutoMerge { get; set; } + + /// + /// Optional. Automatically delete branches on PR merge. The default is null (do not update). The default when created is false. + /// public bool? DeleteBranchOnMerge { get; set; } /// - /// Optional. True to archive this repository. Note: you cannot unarchive repositories through the API. + /// Optional. Automatically set the title of squashed commits to be the PR title. The default is null (do not update). The default when created is false. + /// + public bool? UseSquashPrTitleAsDefault { get; set; } + + /// + /// Optional. True to archive this repository. Note: you cannot unarchive repositories through the API. The default is null (do not update). The default when created is false. /// public bool? Archived { get; set; } /// - /// Optional. Gets or sets whether the new repository is public, private, or internal. A value provided here overrides any value set in the existing private field. + /// Optional. Get or set whether to allow this repository to be forked or not. The default is null (do not update). The default when created is false. /// - public RepositoryVisibility? Visibility { get; set; } + public bool? AllowForking { get; set; } - /// - /// Options. Allows the "Auto Merge" method to be used. - /// - public bool? AllowAutoMerge { get; set; } - - [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] - internal string DebuggerDisplay - { - get { return string.Format(CultureInfo.CurrentCulture, "RepositoryUpdate: Name: {0}", Name); } - } + internal string DebuggerDisplay => new SimpleJsonSerializer().Serialize(this); } }