feat: Add missing properties to RepositoryUpdate (#2492)

This commit is contained in:
Chris Simpson
2022-07-22 20:49:08 +01:00
committed by GitHub
parent 251c3a26fc
commit 9af552eeaa
6 changed files with 366 additions and 205 deletions

View File

@@ -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 // 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] [IntegrationTest]
public async Task UpdatesName() public async Task UpdatesName()
{ {
var github = Helper.GetAuthenticatedClient(); using (var repoContext = await _github.CreateRepositoryContext())
var repoName = Helper.MakeNameWithTimestamp("public-repo"); {
_repository = await github.Repository.Create(new NewRepository(repoName) { AutoInit = true }); var updatedName = Helper.MakeNameWithTimestamp("updated-repo");
var updatedName = Helper.MakeNameWithTimestamp("updated-repo"); var update = new RepositoryUpdate() { Name = updatedName };
var update = new RepositoryUpdate(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] [IntegrationTest]
public async Task UpdatesNameWithRepositoryId() public async Task UpdatesNameWithRepositoryId()
{ {
var github = Helper.GetAuthenticatedClient(); using (var repoContext = await _github.CreateRepositoryContext())
var repoName = Helper.MakeNameWithTimestamp("public-repo"); {
_repository = await github.Repository.Create(new NewRepository(repoName) { AutoInit = true }); var updatedName = Helper.MakeNameWithTimestamp("updated-repo");
var updatedName = Helper.MakeNameWithTimestamp("updated-repo"); var update = new RepositoryUpdate() { Name = updatedName };
var update = new RepositoryUpdate(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] [IntegrationTest]
public async Task UpdatesDescription() public async Task UpdatesDescription()
{ {
var github = Helper.GetAuthenticatedClient(); using (var repoContext = await _github.CreateRepositoryContext())
var repoName = Helper.MakeNameWithTimestamp("public-repo"); {
_repository = await github.Repository.Create(new NewRepository(repoName) { AutoInit = true }); var update = new RepositoryUpdate() { Description = "Updated description" };
var update = new RepositoryUpdate(repoName) { 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] [IntegrationTest]
public async Task UpdatesDescriptionWithRepositoryId() public async Task UpdatesDescriptionWithRepositoryId()
{ {
var github = Helper.GetAuthenticatedClient(); using (var repoContext = await _github.CreateRepositoryContext())
var repoName = Helper.MakeNameWithTimestamp("public-repo"); {
_repository = await github.Repository.Create(new NewRepository(repoName) { AutoInit = true }); var update = new RepositoryUpdate() { Description = "Updated description" };
var update = new RepositoryUpdate(repoName) { 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] [IntegrationTest]
public async Task UpdatesHomepage() public async Task UpdatesHomepage()
{ {
var github = Helper.GetAuthenticatedClient(); using (var repoContext = await _github.CreateRepositoryContext())
var repoName = Helper.MakeNameWithTimestamp("public-repo"); {
_repository = await github.Repository.Create(new NewRepository(repoName) { AutoInit = true }); var update = new RepositoryUpdate() { Homepage = "http://aUrl.to/nowhere" };
var update = new RepositoryUpdate(repoName) { 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] [IntegrationTest]
public async Task UpdatesHomepageWithRepositoryId() public async Task UpdatesHomepageWithRepositoryId()
{ {
var github = Helper.GetAuthenticatedClient(); using (var repoContext = await _github.CreateRepositoryContext())
var repoName = Helper.MakeNameWithTimestamp("public-repo"); {
_repository = await github.Repository.Create(new NewRepository(repoName) { AutoInit = true }); var update = new RepositoryUpdate() { Homepage = "http://aUrl.to/nowhere" };
var update = new RepositoryUpdate(repoName) { 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] [PaidAccountTest]
public async Task UpdatesPrivate() public async Task UpdatesPrivate()
{ {
var github = Helper.GetAuthenticatedClient(); using (var repoContext = await _github.CreateRepositoryContext())
var userDetails = await github.User.Current();
if (userDetails.Plan.PrivateRepos == 0)
{ {
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] [PaidAccountTest]
public async Task UpdatesPrivateWithRepositoryId() public async Task UpdatesPrivateWithRepositoryId()
{ {
var github = Helper.GetAuthenticatedClient(); using (var repoContext = await _github.CreateRepositoryContext())
var userDetails = await github.User.Current();
if (userDetails.Plan.PrivateRepos == 0)
{ {
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] [IntegrationTest]
public async Task UpdatesHasIssues() public async Task UpdatesHasIssues()
{ {
var github = Helper.GetAuthenticatedClient(); using (var repoContext = await _github.CreateRepositoryContext())
var repoName = Helper.MakeNameWithTimestamp("public-repo"); {
_repository = await github.Repository.Create(new NewRepository(repoName) { AutoInit = true }); var update = new RepositoryUpdate() { HasIssues = false };
var update = new RepositoryUpdate(repoName) { 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] [IntegrationTest]
public async Task UpdatesHasIssuesWithRepositoryId() public async Task UpdatesHasIssuesWithRepositoryId()
{ {
var github = Helper.GetAuthenticatedClient(); using (var repoContext = await _github.CreateRepositoryContext())
var repoName = Helper.MakeNameWithTimestamp("public-repo"); {
_repository = await github.Repository.Create(new NewRepository(repoName) { AutoInit = true }); var update = new RepositoryUpdate() { HasIssues = false };
var update = new RepositoryUpdate(repoName) { 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] [IntegrationTest]
public async Task UpdatesHasWiki() public async Task UpdatesHasWiki()
{ {
var github = Helper.GetAuthenticatedClient(); using (var repoContext = await _github.CreateRepositoryContext())
var repoName = Helper.MakeNameWithTimestamp("public-repo"); {
_repository = await github.Repository.Create(new NewRepository(repoName) { AutoInit = true }); var update = new RepositoryUpdate() { HasWiki = false };
var update = new RepositoryUpdate(repoName) { 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] [IntegrationTest]
public async Task UpdatesHasWikiWithRepositoryId() public async Task UpdatesHasWikiWithRepositoryId()
{ {
var github = Helper.GetAuthenticatedClient(); using (var repoContext = await _github.CreateRepositoryContext())
var repoName = Helper.MakeNameWithTimestamp("public-repo"); {
_repository = await github.Repository.Create(new NewRepository(repoName) { AutoInit = true }); var update = new RepositoryUpdate() { HasWiki = false };
var update = new RepositoryUpdate(repoName) { 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] [IntegrationTest]
public async Task UpdatesMergeMethod() public async Task UpdatesMergeMethod()
{ {
var github = Helper.GetAuthenticatedClient(); using (var repoContext = await _github.CreateRepositoryContext())
using (var context = await github.CreateRepositoryContext("public-repo"))
{ {
var updateRepository = new RepositoryUpdate(context.RepositoryName)
var updateRepository = new RepositoryUpdate()
{ {
AllowMergeCommit = false, AllowMergeCommit = false,
AllowSquashMerge = false, AllowSquashMerge = false,
@@ -723,28 +821,20 @@ public class RepositoriesClientTests
AllowAutoMerge = true 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.AllowMergeCommit);
Assert.False(editedRepository.AllowSquashMerge); Assert.False(editedRepository.AllowSquashMerge);
Assert.True(editedRepository.AllowRebaseMerge); Assert.True(editedRepository.AllowRebaseMerge);
Assert.True(editedRepository.AllowAutoMerge); 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] [IntegrationTest]
public async Task UpdatesMergeMethodWithRepositoryId() public async Task UpdatesMergeMethodWithRepositoryId()
{ {
var github = Helper.GetAuthenticatedClient(); using (var repoContext = await _github.CreateRepositoryContext())
using (var context = await github.CreateRepositoryContext("public-repo"))
{ {
var updateRepository = new RepositoryUpdate(context.RepositoryName) var updateRepository = new RepositoryUpdate()
{ {
AllowMergeCommit = true, AllowMergeCommit = true,
AllowSquashMerge = true, AllowSquashMerge = true,
@@ -752,63 +842,62 @@ public class RepositoriesClientTests
AllowAutoMerge = true 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.AllowMergeCommit);
Assert.True(editedRepository.AllowSquashMerge); Assert.True(editedRepository.AllowSquashMerge);
Assert.False(editedRepository.AllowRebaseMerge); Assert.False(editedRepository.AllowRebaseMerge);
Assert.True(editedRepository.AllowAutoMerge); 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] [IntegrationTest]
public async Task UpdatesDeleteBranchOnMergeMethod() public async Task UpdatesDeleteBranchOnMergeMethod()
{ {
var github = Helper.GetAuthenticatedClient(); using (var repoContext = await _github.CreateRepositoryContext())
using (var context = await github.CreateRepositoryContext("public-repo"))
{ {
var updateRepository = new RepositoryUpdate(context.RepositoryName) var updateRepository = new RepositoryUpdate() { DeleteBranchOnMerge = true };
{
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); Assert.True(editedRepository.DeleteBranchOnMerge);
var repository = await github.Repository.Get(context.RepositoryOwner, context.RepositoryName);
Assert.True(repository.DeleteBranchOnMerge);
} }
} }
[IntegrationTest] [IntegrationTest]
public async Task UpdatesDeleteBranchOnMergeMethodWithRepositoryId() public async Task UpdatesDeleteBranchOnMergeMethodWithRepositoryId()
{ {
var github = Helper.GetAuthenticatedClient(); using (var repoContext = await _github.CreateRepositoryContext())
using (var context = await github.CreateRepositoryContext("public-repo"))
{ {
var updateRepository = new RepositoryUpdate(context.RepositoryName) var updateRepository = new RepositoryUpdate() { DeleteBranchOnMerge = true };
{
DeleteBranchOnMerge = true
};
var editedRepository = await github.Repository.Edit(context.RepositoryId, updateRepository); var editedRepository = await _github.Repository.Edit(repoContext.RepositoryId, updateRepository);
Assert.True(editedRepository.DeleteBranchOnMerge); 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", repository.License.Key);
Assert.Equal("MIT License", repository.License.Name); Assert.Equal("MIT License", repository.License.Name);
} }
[IntegrationTest] [IntegrationTest]
public async Task ReturnsRepositoryDeleteBranchOnMergeOptions() public async Task ReturnsRepositoryDeleteBranchOnMergeOptions()
{ {
@@ -2161,4 +2250,49 @@ public class RepositoriesClientTests
Assert.True(enabled); Assert.True(enabled);
} }
} }
public class RepositoryTestBaseClass : IDisposable
{
protected IGitHubClient _github;
private readonly List<RepositoryContext> _repositories;
protected RepositoryTestBaseClass()
{
_github = Helper.GetAuthenticatedClient();
_repositories = new List<RepositoryContext>();
}
public void Dispose()
{
foreach (var repository in _repositories)
{
repository.Dispose();
}
}
/// <summary>
/// Returns a RepositoryContext, which will be disposed at the end of the test.
/// </summary>
/// <param name="name">Your value or uses default of Helper.MakeNameWithTimestamp("public-repo");</param>
/// <returns></returns>
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;
}
/// <summary>
/// Returns a RepositoryContext, which will be disposed at the end of the test.
/// </summary>
/// <param name="name">Your value or uses default of Helper.MakeNameWithTimestamp("public-repo");</param>
/// <returns></returns>
internal async Task<RepositoryContext> 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;
}
}
} }

View File

@@ -0,0 +1,12 @@
namespace Octokit.Tests.Integration
{
public class GitHubClientTestBase
{
protected readonly IGitHubClient _github;
public GitHubClientTestBase()
{
_github = Helper.GetAuthenticatedClient();
}
}
}

View File

@@ -15,14 +15,4 @@ namespace Octokit.Tests.Integration
Assert.Equal("", errors); Assert.Equal("", errors);
} }
} }
public class GitHubClientTestBase
{
protected readonly IGitHubClient _github;
public GitHubClientTestBase()
{
_github = Helper.GetAuthenticatedClient();
}
}
} }

View File

@@ -21,8 +21,9 @@ namespace Octokit.Tests.Models
"\"has_wiki\":true," + "\"has_wiki\":true," +
"\"has_downloads\":true}"; "\"has_downloads\":true}";
var update = new RepositoryUpdate("Hello-World") var update = new RepositoryUpdate()
{ {
Name = "Hello-World",
Description = "This is your first repository", Description = "This is your first repository",
Homepage = "https://github.com", Homepage = "https://github.com",
Private = true, Private = true,

View File

@@ -270,7 +270,6 @@ namespace Octokit
Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner));
Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); Ensure.ArgumentNotNullOrEmptyString(name, nameof(name));
Ensure.ArgumentNotNull(update, nameof(update)); Ensure.ArgumentNotNull(update, nameof(update));
Ensure.ArgumentNotNull(update.Name, nameof(update.Name));
return ApiConnection.Patch<Repository>(ApiUrls.Repository(owner, name), update, AcceptHeaders.Concat(AcceptHeaders.VisibilityPreview, AcceptHeaders.TemplatePreview)); return ApiConnection.Patch<Repository>(ApiUrls.Repository(owner, name), update, AcceptHeaders.Concat(AcceptHeaders.VisibilityPreview, AcceptHeaders.TemplatePreview));
} }

View File

@@ -1,7 +1,6 @@
using System; using Octokit.Internal;
using System;
using System.Diagnostics; using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
namespace Octokit namespace Octokit
{ {
@@ -12,14 +11,19 @@ namespace Octokit
[DebuggerDisplay("{DebuggerDisplay,nq}")] [DebuggerDisplay("{DebuggerDisplay,nq}")]
public class RepositoryUpdate public class RepositoryUpdate
{ {
/// <summary>
/// Creates an object that describes an update to a repository on GitHub.
/// </summary>
public RepositoryUpdate() { }
/// <summary> /// <summary>
/// Creates an object that describes an update to a repository on GitHub. /// Creates an object that describes an update to a repository on GitHub.
/// </summary> /// </summary>
/// <param name="name">The name of the repository. This is the only required parameter.</param> /// <param name="name">The name of the repository. This is the only required parameter.</param>
[Obsolete("Use the constructor with no parameters as name is no longer a required field")]
public RepositoryUpdate(string name) public RepositoryUpdate(string name)
{ {
Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); Ensure.ArgumentNotNullOrEmptyString(name, nameof(name));
Name = name; Name = name;
} }
@@ -44,62 +48,83 @@ namespace Octokit
public bool? Private { get; set; } public bool? Private { get; set; }
/// <summary> /// <summary>
/// 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.
/// </summary>
public RepositoryVisibility? Visibility { get; set; }
// Yet to be implemented
//public object SecurityAndAnalysis { get; set; }
/// <summary>
/// Gets or sets whether to enable issues for the repository. The default is null (do not update). The default when created is true.
/// </summary> /// </summary>
public bool? HasIssues { get; set; } public bool? HasIssues { get; set; }
/// <summary> /// <summary>
/// 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.
/// </summary>
public bool? HasProjects { get; set; }
/// <summary>
/// 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.
/// </summary> /// </summary>
public bool? HasWiki { get; set; } public bool? HasWiki { get; set; }
/// <summary> /// <summary>
/// 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.
/// </summary> /// </summary>
public bool? HasDownloads { get; set; } public bool? HasDownloads { get; set; }
/// <summary>
/// Optional. Gets or sets whether the repository is a template. The default is null (do not update). The default when created is false.
/// </summary>
public bool? IsTemplate { get; set; }
/// <summary> /// <summary>
/// Optional. Gets or sets the default branch. The default is null (do not update). /// Optional. Gets or sets the default branch. The default is null (do not update).
/// </summary> /// </summary>
public string DefaultBranch { get; set; } public string DefaultBranch { get; set; }
/// <summary> /// <summary>
/// Optional. Allows the "Rebase and 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.
/// </summary>
public bool? AllowRebaseMerge { get; set; }
/// <summary>
/// Optional. Allows the "Squash Merge" merge method to be used.
/// </summary> /// </summary>
public bool? AllowSquashMerge { get; set; } public bool? AllowSquashMerge { get; set; }
/// <summary> /// <summary>
/// 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.
/// </summary> /// </summary>
public bool? AllowMergeCommit { get; set; } public bool? AllowMergeCommit { get; set; }
/// <summary>
/// Optional. Allows the "Rebase and Merge" method to be used. The default is null (do not update). The default when created is true.
/// </summary>
public bool? AllowRebaseMerge { get; set; }
/// <summary>
/// Optional. Allows the auto merge feature to be used. The default is null (do not update). The default when created is false.
/// </summary>
public bool? AllowAutoMerge { get; set; }
/// <summary>
/// Optional. Automatically delete branches on PR merge. The default is null (do not update). The default when created is false.
/// </summary>
public bool? DeleteBranchOnMerge { get; set; } public bool? DeleteBranchOnMerge { get; set; }
/// <summary> /// <summary>
/// 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.
/// </summary>
public bool? UseSquashPrTitleAsDefault { get; set; }
/// <summary>
/// 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.
/// </summary> /// </summary>
public bool? Archived { get; set; } public bool? Archived { get; set; }
/// <summary> /// <summary>
/// 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.
/// </summary> /// </summary>
public RepositoryVisibility? Visibility { get; set; } public bool? AllowForking { get; set; }
/// <summary> internal string DebuggerDisplay => new SimpleJsonSerializer().Serialize(this);
/// Options. Allows the "Auto Merge" method to be used.
/// </summary>
public bool? AllowAutoMerge { get; set; }
[SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal string DebuggerDisplay
{
get { return string.Format(CultureInfo.CurrentCulture, "RepositoryUpdate: Name: {0}", Name); }
}
} }
} }