From 312904022d48e593af9f0e261f90fd9aa4078be0 Mon Sep 17 00:00:00 2001 From: Chris Simpson Date: Wed, 13 Jul 2022 18:42:07 +0100 Subject: [PATCH] [feat] Add AutoMerge and add MergeOptions to NewRepository object (#2476) --- .../Clients/RepositoriesClientTests.cs | 99 ++++++++++++++++++- Octokit/Models/Request/NewRepository.cs | 20 ++++ Octokit/Models/Request/RepositoryUpdate.cs | 6 ++ Octokit/Models/Response/Repository.cs | 5 +- 4 files changed, 127 insertions(+), 3 deletions(-) diff --git a/Octokit.Tests.Integration/Clients/RepositoriesClientTests.cs b/Octokit.Tests.Integration/Clients/RepositoriesClientTests.cs index cd0c7eb64e..161c21a085 100644 --- a/Octokit.Tests.Integration/Clients/RepositoriesClientTests.cs +++ b/Octokit.Tests.Integration/Clients/RepositoriesClientTests.cs @@ -36,6 +36,10 @@ public async Task CreatesANewPublicRepository() Assert.Null(repository.Homepage); Assert.NotNull(repository.DefaultBranch); Assert.Null(repository.License); + Assert.False(repository.AllowAutoMerge); + Assert.True(repository.AllowMergeCommit); + Assert.True(repository.AllowRebaseMerge); + Assert.True(repository.AllowSquashMerge); } } @@ -62,6 +66,89 @@ public async Task CreatesANewPrivateRepository() } } + [IntegrationTest] + public async Task CreatesARepositoryWithAllowAutoMergeSet() + { + var github = Helper.GetAuthenticatedClient(); + + var repoName = Helper.MakeNameWithTimestamp("repo-auto-merge"); + + var newRepository = new NewRepository(repoName) { AllowAutoMerge = true }; + + using (var context = await github.CreateRepositoryContext(newRepository)) + { + var createdRepository = context.Repository; + + // Default is false if unset, so check for true to ensure change + Assert.True(createdRepository.AllowAutoMerge); + var repository = await github.Repository.Get(Helper.UserName, repoName); + Assert.True(repository.AllowAutoMerge); + + } + } + + [IntegrationTest] + public async Task CreatesARepositoryWithAllowMergeCommitSet() + { + var github = Helper.GetAuthenticatedClient(); + + var repoName = Helper.MakeNameWithTimestamp("repo-merge-commit"); + + var newRepository = new NewRepository(repoName) { AllowMergeCommit = false }; + + using (var context = await github.CreateRepositoryContext(newRepository)) + { + var createdRepository = context.Repository; + + // Default is true if unset, so check for false to ensure change + Assert.False(createdRepository.AllowMergeCommit); + var repository = await github.Repository.Get(Helper.UserName, repoName); + Assert.False(repository.AllowMergeCommit); + } + } + + [IntegrationTest] + public async Task CreatesARepositoryWithAllowRebaseMergeSet() + { + var github = Helper.GetAuthenticatedClient(); + + var repoName = Helper.MakeNameWithTimestamp("repo-rebase-merge"); + + var newRepository = new NewRepository(repoName) { AllowRebaseMerge = false }; + + using (var context = await github.CreateRepositoryContext(newRepository)) + { + var createdRepository = context.Repository; + + // Default is true if unset, so check for false to ensure change + Assert.False(createdRepository.AllowRebaseMerge); + var repository = await github.Repository.Get(Helper.UserName, repoName); + Assert.False(repository.AllowRebaseMerge); + + } + } + + [IntegrationTest] + public async Task CreatesARepositoryWithAllowSquashMergeSet() + { + var github = Helper.GetAuthenticatedClient(); + + var repoName = Helper.MakeNameWithTimestamp("repo-squash-merge"); + + var newRepository = new NewRepository(repoName) { AllowSquashMerge = false }; + + using (var context = await github.CreateRepositoryContext(newRepository)) + { + var createdRepository = context.Repository; + + // Default is true if unset, so check for false to ensure change + Assert.False(createdRepository.AllowSquashMerge); + var repository = await github.Repository.Get(Helper.UserName, repoName); + Assert.False(repository.AllowSquashMerge); + + } + } + [IntegrationTest] public async Task CreatesARepositoryWithoutDownloads() { @@ -632,18 +719,21 @@ public async Task UpdatesMergeMethod() { AllowMergeCommit = false, AllowSquashMerge = false, - AllowRebaseMerge = true + AllowRebaseMerge = true, // this is the default, but the value is tested in UpdatesMergeMethodWithRepositoryId test + AllowAutoMerge = true }; var editedRepository = await github.Repository.Edit(context.RepositoryOwner, context.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); } } @@ -658,18 +748,21 @@ public async Task UpdatesMergeMethodWithRepositoryId() { AllowMergeCommit = true, AllowSquashMerge = true, - AllowRebaseMerge = false + AllowRebaseMerge = false, + AllowAutoMerge = true }; var editedRepository = await github.Repository.Edit(context.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); } } @@ -861,6 +954,7 @@ public async Task ReturnsRepositoryMergeOptions() Assert.NotNull(repository.AllowRebaseMerge); Assert.NotNull(repository.AllowSquashMerge); Assert.NotNull(repository.AllowMergeCommit); + Assert.NotNull(repository.AllowAutoMerge); } } @@ -876,6 +970,7 @@ public async Task ReturnsRepositoryMergeOptionsWithRepositoryId() Assert.NotNull(repository.AllowRebaseMerge); Assert.NotNull(repository.AllowSquashMerge); Assert.NotNull(repository.AllowMergeCommit); + Assert.NotNull(repository.AllowAutoMerge); } } diff --git a/Octokit/Models/Request/NewRepository.cs b/Octokit/Models/Request/NewRepository.cs index aa5152e618..5b8a9feca7 100644 --- a/Octokit/Models/Request/NewRepository.cs +++ b/Octokit/Models/Request/NewRepository.cs @@ -95,6 +95,26 @@ public NewRepository(string name) /// public RepositoryVisibility? Visibility { get; set; } + /// + /// Optional. Gets or sets whether the new repository allows rebase merges. + /// + public bool? AllowRebaseMerge { get; set; } + + /// + /// Optional. Gets or sets whether the new repository allows squash merges. + /// + public bool? AllowSquashMerge { get; set; } + + /// + /// Optional. Gets or sets whether the new repository allows merge commits. + /// + public bool? AllowMergeCommit { get; set; } + + /// + /// Optional. Gets or sets whether the new repository allows auto merge. + /// + public bool? AllowAutoMerge { get; set; } + internal string DebuggerDisplay { get diff --git a/Octokit/Models/Request/RepositoryUpdate.cs b/Octokit/Models/Request/RepositoryUpdate.cs index 8801787950..4a876f05d3 100644 --- a/Octokit/Models/Request/RepositoryUpdate.cs +++ b/Octokit/Models/Request/RepositoryUpdate.cs @@ -77,6 +77,7 @@ public RepositoryUpdate(string name) /// Optional. Allows the "Create a merge commit" merge method to be used. /// public bool? AllowMergeCommit { get; set; } + public bool? DeleteBranchOnMerge { get; set; } @@ -90,6 +91,11 @@ public RepositoryUpdate(string name) /// public RepositoryVisibility? Visibility { get; set; } + /// + /// Options. Allows the "Auto Merge" method to be used. + /// + public bool? AllowAutoMerge { get; set; } + [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] internal string DebuggerDisplay { diff --git a/Octokit/Models/Response/Repository.cs b/Octokit/Models/Response/Repository.cs index 504d98b330..9a078ece9c 100644 --- a/Octokit/Models/Response/Repository.cs +++ b/Octokit/Models/Response/Repository.cs @@ -17,7 +17,7 @@ public Repository(long id) Id = id; } - public Repository(string url, string htmlUrl, string cloneUrl, string gitUrl, string sshUrl, string svnUrl, string mirrorUrl, long id, string nodeId, User owner, string name, string fullName, bool isTemplate, string description, string homepage, string language, bool @private, bool fork, int forksCount, int stargazersCount, string defaultBranch, int openIssuesCount, DateTimeOffset? pushedAt, DateTimeOffset createdAt, DateTimeOffset updatedAt, RepositoryPermissions permissions, Repository parent, Repository source, LicenseMetadata license, bool hasIssues, bool hasWiki, bool hasDownloads, bool hasPages, int subscribersCount, long size, bool? allowRebaseMerge, bool? allowSquashMerge, bool? allowMergeCommit, bool archived, int watchersCount, bool? deleteBranchOnMerge, RepositoryVisibility visibility, IEnumerable topics) + public Repository(string url, string htmlUrl, string cloneUrl, string gitUrl, string sshUrl, string svnUrl, string mirrorUrl, long id, string nodeId, User owner, string name, string fullName, bool isTemplate, string description, string homepage, string language, bool @private, bool fork, int forksCount, int stargazersCount, string defaultBranch, int openIssuesCount, DateTimeOffset? pushedAt, DateTimeOffset createdAt, DateTimeOffset updatedAt, RepositoryPermissions permissions, Repository parent, Repository source, LicenseMetadata license, bool hasIssues, bool hasWiki, bool hasDownloads, bool hasPages, int subscribersCount, long size, bool? allowRebaseMerge, bool? allowSquashMerge, bool? allowMergeCommit, bool archived, int watchersCount, bool? deleteBranchOnMerge, RepositoryVisibility visibility, IEnumerable topics, bool? allowAutoMerge) { Url = url; HtmlUrl = htmlUrl; @@ -62,6 +62,7 @@ public Repository(string url, string htmlUrl, string cloneUrl, string gitUrl, st Topics = topics.ToList(); DeleteBranchOnMerge = deleteBranchOnMerge; Visibility = visibility; + AllowAutoMerge = allowAutoMerge; } public string Url { get; protected set; } @@ -154,6 +155,8 @@ public Repository(string url, string htmlUrl, string cloneUrl, string gitUrl, st public RepositoryVisibility? Visibility { get; protected set; } + public bool? AllowAutoMerge { get; protected set; } + internal string DebuggerDisplay { get