mirror of
https://github.com/zoriya/octokit.net.git
synced 2025-12-06 07:16:09 +00:00
* add proper accept header to all teams calls * use hardcoded headers in unit tests * dont remove support for preview branch protection, on earlier github enterprise versions
This commit is contained in:
committed by
Ryan Gribble
parent
82b1b2144f
commit
f9bf9b2347
@@ -549,7 +549,7 @@ namespace Octokit.Reactive
|
||||
Ensure.ArgumentNotNullOrEmptyString(name, nameof(name));
|
||||
Ensure.ArgumentNotNull(options, nameof(options));
|
||||
|
||||
return _connection.GetAndFlattenAllPages<Team>(ApiUrls.RepositoryTeams(owner, name), options);
|
||||
return _connection.GetAndFlattenAllPages<Team>(ApiUrls.RepositoryTeams(owner, name), null, AcceptHeaders.NestedTeamsPreview, options);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -565,7 +565,7 @@ namespace Octokit.Reactive
|
||||
{
|
||||
Ensure.ArgumentNotNull(options, nameof(options));
|
||||
|
||||
return _connection.GetAndFlattenAllPages<Team>(ApiUrls.RepositoryTeams(repositoryId), options);
|
||||
return _connection.GetAndFlattenAllPages<Team>(ApiUrls.RepositoryTeams(repositoryId), null, AcceptHeaders.NestedTeamsPreview, options);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -722,6 +722,8 @@ namespace Octokit.Tests.Clients
|
||||
connection.Received()
|
||||
.GetAll<Team>(
|
||||
Arg.Is<Uri>(u => u.ToString() == "repos/owner/name/teams"),
|
||||
null,
|
||||
"application/vnd.github.hellcat-preview+json",
|
||||
Args.ApiOptions);
|
||||
}
|
||||
|
||||
@@ -757,6 +759,8 @@ namespace Octokit.Tests.Clients
|
||||
connection.Received()
|
||||
.GetAll<Team>(
|
||||
Arg.Is<Uri>(u => u.ToString() == "repos/owner/name/teams"),
|
||||
null,
|
||||
"application/vnd.github.hellcat-preview+json",
|
||||
options);
|
||||
}
|
||||
|
||||
|
||||
@@ -1037,12 +1037,14 @@ namespace Octokit.Tests.Clients
|
||||
{
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new RepositoryBranchesClient(connection);
|
||||
const string previewAcceptsHeader = "application/vnd.github.loki-preview+json";
|
||||
|
||||
client.GetAllProtectedBranchTeamRestrictions("owner", "repo", "branch");
|
||||
|
||||
connection.Received()
|
||||
.Get<IReadOnlyList<Team>>(Arg.Is<Uri>(u => u.ToString() == "repos/owner/repo/branches/branch/protection/restrictions/teams"), null, previewAcceptsHeader);
|
||||
.Get<IReadOnlyList<Team>>(
|
||||
Arg.Is<Uri>(u => u.ToString() == "repos/owner/repo/branches/branch/protection/restrictions/teams"),
|
||||
null,
|
||||
"application/vnd.github.loki-preview+json,application/vnd.github.hellcat-preview+json");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -1050,12 +1052,14 @@ namespace Octokit.Tests.Clients
|
||||
{
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new RepositoryBranchesClient(connection);
|
||||
const string previewAcceptsHeader = "application/vnd.github.loki-preview+json";
|
||||
|
||||
client.GetAllProtectedBranchTeamRestrictions(1, "branch");
|
||||
|
||||
connection.Received()
|
||||
.Get<IReadOnlyList<Team>>(Arg.Is<Uri>(u => u.ToString() == "repositories/1/branches/branch/protection/restrictions/teams"), null, previewAcceptsHeader);
|
||||
.Get<IReadOnlyList<Team>>(
|
||||
Arg.Is<Uri>(u => u.ToString() == "repositories/1/branches/branch/protection/restrictions/teams"),
|
||||
null,
|
||||
"application/vnd.github.loki-preview+json,application/vnd.github.hellcat-preview+json");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -1085,12 +1089,15 @@ namespace Octokit.Tests.Clients
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new RepositoryBranchesClient(connection);
|
||||
var newTeams = new BranchProtectionTeamCollection() { "test" };
|
||||
const string previewAcceptsHeader = "application/vnd.github.loki-preview+json";
|
||||
|
||||
client.UpdateProtectedBranchTeamRestrictions("owner", "repo", "branch", newTeams);
|
||||
|
||||
connection.Received()
|
||||
.Put<IReadOnlyList<Team>>(Arg.Is<Uri>(u => u.ToString() == "repos/owner/repo/branches/branch/protection/restrictions/teams"), Arg.Any<IReadOnlyList<string>>(), null, previewAcceptsHeader);
|
||||
.Put<IReadOnlyList<Team>>(
|
||||
Arg.Is<Uri>(u => u.ToString() == "repos/owner/repo/branches/branch/protection/restrictions/teams"),
|
||||
Arg.Any<IReadOnlyList<string>>(),
|
||||
null,
|
||||
"application/vnd.github.loki-preview+json,application/vnd.github.hellcat-preview+json");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -1099,12 +1106,15 @@ namespace Octokit.Tests.Clients
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new RepositoryBranchesClient(connection);
|
||||
var newTeams = new BranchProtectionTeamCollection() { "test" };
|
||||
const string previewAcceptsHeader = "application/vnd.github.loki-preview+json";
|
||||
|
||||
client.UpdateProtectedBranchTeamRestrictions(1, "branch", newTeams);
|
||||
|
||||
connection.Received()
|
||||
.Put<IReadOnlyList<Team>>(Arg.Is<Uri>(u => u.ToString() == "repositories/1/branches/branch/protection/restrictions/teams"), Arg.Any<IReadOnlyList<string>>(), null, previewAcceptsHeader);
|
||||
.Put<IReadOnlyList<Team>>(
|
||||
Arg.Is<Uri>(u => u.ToString() == "repositories/1/branches/branch/protection/restrictions/teams"),
|
||||
Arg.Any<IReadOnlyList<string>>(),
|
||||
null,
|
||||
"application/vnd.github.loki-preview+json,application/vnd.github.hellcat-preview+json");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -1137,12 +1147,14 @@ namespace Octokit.Tests.Clients
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new RepositoryBranchesClient(connection);
|
||||
var newTeams = new BranchProtectionTeamCollection() { "test" };
|
||||
const string previewAcceptsHeader = "application/vnd.github.loki-preview+json";
|
||||
|
||||
client.AddProtectedBranchTeamRestrictions("owner", "repo", "branch", newTeams);
|
||||
|
||||
connection.Received()
|
||||
.Post<IReadOnlyList<Team>>(Arg.Is<Uri>(u => u.ToString() == "repos/owner/repo/branches/branch/protection/restrictions/teams"), Arg.Any<IReadOnlyList<string>>(), previewAcceptsHeader);
|
||||
.Post<IReadOnlyList<Team>>(
|
||||
Arg.Is<Uri>(u => u.ToString() == "repos/owner/repo/branches/branch/protection/restrictions/teams"),
|
||||
Arg.Any<IReadOnlyList<string>>(),
|
||||
"application/vnd.github.loki-preview+json,application/vnd.github.hellcat-preview+json");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -1151,12 +1163,14 @@ namespace Octokit.Tests.Clients
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new RepositoryBranchesClient(connection);
|
||||
var newTeams = new BranchProtectionTeamCollection() { "test" };
|
||||
const string previewAcceptsHeader = "application/vnd.github.loki-preview+json";
|
||||
|
||||
client.AddProtectedBranchTeamRestrictions(1, "branch", newTeams);
|
||||
|
||||
connection.Received()
|
||||
.Post<IReadOnlyList<Team>>(Arg.Is<Uri>(u => u.ToString() == "repositories/1/branches/branch/protection/restrictions/teams"), Arg.Any<IReadOnlyList<string>>(), previewAcceptsHeader);
|
||||
.Post<IReadOnlyList<Team>>(
|
||||
Arg.Is<Uri>(u => u.ToString() == "repositories/1/branches/branch/protection/restrictions/teams"),
|
||||
Arg.Any<IReadOnlyList<string>>(),
|
||||
"application/vnd.github.loki-preview+json,application/vnd.github.hellcat-preview+json");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -1189,12 +1203,14 @@ namespace Octokit.Tests.Clients
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new RepositoryBranchesClient(connection);
|
||||
var teamsToRemove = new BranchProtectionTeamCollection() { "test" };
|
||||
const string previewAcceptsHeader = "application/vnd.github.loki-preview+json";
|
||||
|
||||
client.DeleteProtectedBranchTeamRestrictions("owner", "repo", "branch", teamsToRemove);
|
||||
|
||||
connection.Received()
|
||||
.Delete<IReadOnlyList<Team>>(Arg.Is<Uri>(u => u.ToString() == "repos/owner/repo/branches/branch/protection/restrictions/teams"), Arg.Any<IReadOnlyList<string>>(), previewAcceptsHeader);
|
||||
.Delete<IReadOnlyList<Team>>(
|
||||
Arg.Is<Uri>(u => u.ToString() == "repos/owner/repo/branches/branch/protection/restrictions/teams"),
|
||||
Arg.Any<BranchProtectionTeamCollection>(),
|
||||
"application/vnd.github.loki-preview+json,application/vnd.github.hellcat-preview+json");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -1203,12 +1219,14 @@ namespace Octokit.Tests.Clients
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new RepositoryBranchesClient(connection);
|
||||
var teamsToRemove = new BranchProtectionTeamCollection() { "test" };
|
||||
const string previewAcceptsHeader = "application/vnd.github.loki-preview+json";
|
||||
|
||||
client.DeleteProtectedBranchTeamRestrictions(1, "branch", teamsToRemove);
|
||||
|
||||
connection.Received()
|
||||
.Delete<IReadOnlyList<Team>>(Arg.Is<Uri>(u => u.ToString() == "repositories/1/branches/branch/protection/restrictions/teams"), Arg.Any<IReadOnlyList<string>>(), previewAcceptsHeader);
|
||||
.Delete<IReadOnlyList<Team>>(
|
||||
Arg.Is<Uri>(u => u.ToString() == "repositories/1/branches/branch/protection/restrictions/teams"),
|
||||
Arg.Any<IReadOnlyList<string>>(),
|
||||
"application/vnd.github.loki-preview+json,application/vnd.github.hellcat-preview+json");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
||||
@@ -724,7 +724,7 @@ namespace Octokit
|
||||
Ensure.ArgumentNotNullOrEmptyString(name, nameof(name));
|
||||
Ensure.ArgumentNotNull(options, nameof(options));
|
||||
|
||||
return ApiConnection.GetAll<Team>(ApiUrls.RepositoryTeams(owner, name), options);
|
||||
return ApiConnection.GetAll<Team>(ApiUrls.RepositoryTeams(owner, name), null, AcceptHeaders.NestedTeamsPreview, options);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -848,7 +848,7 @@ namespace Octokit
|
||||
Ensure.ArgumentNotNullOrEmptyString(name, nameof(name));
|
||||
Ensure.ArgumentNotNullOrEmptyString(branch, nameof(branch));
|
||||
|
||||
return ApiConnection.Get<IReadOnlyList<Team>>(ApiUrls.RepoRestrictionsTeams(owner, name, branch), null, AcceptHeaders.ProtectedBranchesApiPreview);
|
||||
return ApiConnection.Get<IReadOnlyList<Team>>(ApiUrls.RepoRestrictionsTeams(owner, name, branch), null, AcceptHeaders.Concat(AcceptHeaders.ProtectedBranchesApiPreview, AcceptHeaders.NestedTeamsPreview));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -863,7 +863,7 @@ namespace Octokit
|
||||
{
|
||||
Ensure.ArgumentNotNullOrEmptyString(branch, nameof(branch));
|
||||
|
||||
return ApiConnection.Get<IReadOnlyList<Team>>(ApiUrls.RepoRestrictionsTeams(repositoryId, branch), null, AcceptHeaders.ProtectedBranchesApiPreview);
|
||||
return ApiConnection.Get<IReadOnlyList<Team>>(ApiUrls.RepoRestrictionsTeams(repositoryId, branch), null, AcceptHeaders.Concat(AcceptHeaders.ProtectedBranchesApiPreview, AcceptHeaders.NestedTeamsPreview));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -883,7 +883,7 @@ namespace Octokit
|
||||
Ensure.ArgumentNotNullOrEmptyString(branch, nameof(branch));
|
||||
Ensure.ArgumentNotNull(teams, nameof(teams));
|
||||
|
||||
return ApiConnection.Put<IReadOnlyList<Team>>(ApiUrls.RepoRestrictionsTeams(owner, name, branch), teams, null, AcceptHeaders.ProtectedBranchesApiPreview);
|
||||
return ApiConnection.Put<IReadOnlyList<Team>>(ApiUrls.RepoRestrictionsTeams(owner, name, branch), teams, null, AcceptHeaders.Concat(AcceptHeaders.ProtectedBranchesApiPreview, AcceptHeaders.NestedTeamsPreview));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -900,7 +900,7 @@ namespace Octokit
|
||||
Ensure.ArgumentNotNullOrEmptyString(branch, nameof(branch));
|
||||
Ensure.ArgumentNotNull(teams, nameof(teams));
|
||||
|
||||
return ApiConnection.Put<IReadOnlyList<Team>>(ApiUrls.RepoRestrictionsTeams(repositoryId, branch), teams, null, AcceptHeaders.ProtectedBranchesApiPreview);
|
||||
return ApiConnection.Put<IReadOnlyList<Team>>(ApiUrls.RepoRestrictionsTeams(repositoryId, branch), teams, null, AcceptHeaders.Concat(AcceptHeaders.ProtectedBranchesApiPreview, AcceptHeaders.NestedTeamsPreview));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -920,7 +920,7 @@ namespace Octokit
|
||||
Ensure.ArgumentNotNullOrEmptyString(branch, nameof(branch));
|
||||
Ensure.ArgumentNotNull(teams, nameof(teams));
|
||||
|
||||
return ApiConnection.Post<IReadOnlyList<Team>>(ApiUrls.RepoRestrictionsTeams(owner, name, branch), teams, AcceptHeaders.ProtectedBranchesApiPreview);
|
||||
return ApiConnection.Post<IReadOnlyList<Team>>(ApiUrls.RepoRestrictionsTeams(owner, name, branch), teams, AcceptHeaders.Concat(AcceptHeaders.ProtectedBranchesApiPreview, AcceptHeaders.NestedTeamsPreview));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -937,7 +937,7 @@ namespace Octokit
|
||||
Ensure.ArgumentNotNullOrEmptyString(branch, nameof(branch));
|
||||
Ensure.ArgumentNotNull(teams, nameof(teams));
|
||||
|
||||
return ApiConnection.Post<IReadOnlyList<Team>>(ApiUrls.RepoRestrictionsTeams(repositoryId, branch), teams, AcceptHeaders.ProtectedBranchesApiPreview);
|
||||
return ApiConnection.Post<IReadOnlyList<Team>>(ApiUrls.RepoRestrictionsTeams(repositoryId, branch), teams, AcceptHeaders.Concat(AcceptHeaders.ProtectedBranchesApiPreview, AcceptHeaders.NestedTeamsPreview));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -957,7 +957,7 @@ namespace Octokit
|
||||
Ensure.ArgumentNotNullOrEmptyString(branch, nameof(branch));
|
||||
Ensure.ArgumentNotNull(teams, nameof(teams));
|
||||
|
||||
return ApiConnection.Delete<IReadOnlyList<Team>>(ApiUrls.RepoRestrictionsTeams(owner, name, branch), teams, AcceptHeaders.ProtectedBranchesApiPreview);
|
||||
return ApiConnection.Delete<IReadOnlyList<Team>>(ApiUrls.RepoRestrictionsTeams(owner, name, branch), teams, AcceptHeaders.Concat(AcceptHeaders.ProtectedBranchesApiPreview, AcceptHeaders.NestedTeamsPreview));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -974,7 +974,7 @@ namespace Octokit
|
||||
Ensure.ArgumentNotNullOrEmptyString(branch, nameof(branch));
|
||||
Ensure.ArgumentNotNull(teams, nameof(teams));
|
||||
|
||||
return ApiConnection.Delete<IReadOnlyList<Team>>(ApiUrls.RepoRestrictionsTeams(repositoryId, branch), teams, AcceptHeaders.ProtectedBranchesApiPreview);
|
||||
return ApiConnection.Delete<IReadOnlyList<Team>>(ApiUrls.RepoRestrictionsTeams(repositoryId, branch), teams, AcceptHeaders.Concat(AcceptHeaders.ProtectedBranchesApiPreview, AcceptHeaders.NestedTeamsPreview));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user