Skip to content

Commit

Permalink
[feat] Add AutoMerge and add MergeOptions to NewRepository object (#2476
Browse files Browse the repository at this point in the history
)
  • Loading branch information
JonruAlveus authored Jul 13, 2022
1 parent 7ab6dc3 commit 3129040
Show file tree
Hide file tree
Showing 4 changed files with 127 additions and 3 deletions.
99 changes: 97 additions & 2 deletions Octokit.Tests.Integration/Clients/RepositoriesClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand All @@ -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()
{
Expand Down Expand Up @@ -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);
}
}

Expand All @@ -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);
}
}

Expand Down Expand Up @@ -861,6 +954,7 @@ public async Task ReturnsRepositoryMergeOptions()
Assert.NotNull(repository.AllowRebaseMerge);
Assert.NotNull(repository.AllowSquashMerge);
Assert.NotNull(repository.AllowMergeCommit);
Assert.NotNull(repository.AllowAutoMerge);
}
}

Expand All @@ -876,6 +970,7 @@ public async Task ReturnsRepositoryMergeOptionsWithRepositoryId()
Assert.NotNull(repository.AllowRebaseMerge);
Assert.NotNull(repository.AllowSquashMerge);
Assert.NotNull(repository.AllowMergeCommit);
Assert.NotNull(repository.AllowAutoMerge);
}
}

Expand Down
20 changes: 20 additions & 0 deletions Octokit/Models/Request/NewRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,26 @@ public NewRepository(string name)
/// </summary>
public RepositoryVisibility? Visibility { get; set; }

/// <summary>
/// Optional. Gets or sets whether the new repository allows rebase merges.
/// </summary>
public bool? AllowRebaseMerge { get; set; }

/// <summary>
/// Optional. Gets or sets whether the new repository allows squash merges.
/// </summary>
public bool? AllowSquashMerge { get; set; }

/// <summary>
/// Optional. Gets or sets whether the new repository allows merge commits.
/// </summary>
public bool? AllowMergeCommit { get; set; }

/// <summary>
/// Optional. Gets or sets whether the new repository allows auto merge.
/// </summary>
public bool? AllowAutoMerge { get; set; }

internal string DebuggerDisplay
{
get
Expand Down
6 changes: 6 additions & 0 deletions Octokit/Models/Request/RepositoryUpdate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ public RepositoryUpdate(string name)
/// Optional. Allows the "Create a merge commit" merge method to be used.
/// </summary>
public bool? AllowMergeCommit { get; set; }


public bool? DeleteBranchOnMerge { get; set; }

Expand All @@ -90,6 +91,11 @@ public RepositoryUpdate(string name)
/// </summary>
public RepositoryVisibility? Visibility { get; set; }

/// <summary>
/// Options. Allows the "Auto Merge" method to be used.
/// </summary>
public bool? AllowAutoMerge { get; set; }

[SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal string DebuggerDisplay
{
Expand Down
5 changes: 4 additions & 1 deletion Octokit/Models/Response/Repository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> 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<string> topics, bool? allowAutoMerge)
{
Url = url;
HtmlUrl = htmlUrl;
Expand Down Expand Up @@ -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; }
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 3129040

Please sign in to comment.