Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add proper accept header to all team calls (Fixes #1794) #1795

Merged
merged 3 commits into from
Apr 25, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Octokit.Reactive/Clients/ObservableRepositoriesClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ public IObservable<Team> GetAllTeams(string owner, string name, ApiOptions optio
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>
Expand All @@ -565,7 +565,7 @@ public IObservable<Team> GetAllTeams(long repositoryId, ApiOptions options)
{
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>
Expand Down
4 changes: 4 additions & 0 deletions Octokit.Tests/Clients/RepositoriesClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -722,6 +722,8 @@ public async Task RequestsTheCorrectUrl()
connection.Received()
.GetAll<Team>(
Arg.Is<Uri>(u => u.ToString() == "repos/owner/name/teams"),
null,
"application/vnd.github.hellcat-preview+json",
Args.ApiOptions);
}

Expand Down Expand Up @@ -757,6 +759,8 @@ public async Task RequestsTheCorrectUrlWithApiOptions()
connection.Received()
.GetAll<Team>(
Arg.Is<Uri>(u => u.ToString() == "repos/owner/name/teams"),
null,
"application/vnd.github.hellcat-preview+json",
options);
}

Expand Down
50 changes: 34 additions & 16 deletions Octokit.Tests/Clients/RepositoryBranchesClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1037,25 +1037,29 @@ public void RequestsTheCorrectUrl()
{
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]
public void RequestsTheCorrectUrlWithRepositoryId()
{
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]
Expand Down Expand Up @@ -1085,12 +1089,15 @@ public void RequestsTheCorrectUrl()
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]
Expand All @@ -1099,12 +1106,15 @@ public void RequestsTheCorrectUrlWithRepositoryId()
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]
Expand Down Expand Up @@ -1137,12 +1147,14 @@ public void RequestsTheCorrectUrl()
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]
Expand All @@ -1151,12 +1163,14 @@ public void RequestsTheCorrectUrlWithRepositoryId()
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]
Expand Down Expand Up @@ -1189,12 +1203,14 @@ public void RequestsTheCorrectUrl()
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]
Expand All @@ -1203,12 +1219,14 @@ public void RequestsTheCorrectUrlWithRepositoryId()
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]
Expand Down
2 changes: 1 addition & 1 deletion Octokit/Clients/RepositoriesClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -724,7 +724,7 @@ public Task<IReadOnlyList<Team>> GetAllTeams(string owner, string name, ApiOptio
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>
Expand Down
16 changes: 8 additions & 8 deletions Octokit/Clients/RepositoryBranchesClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -906,7 +906,7 @@ public Task<IReadOnlyList<Team>> GetAllProtectedBranchTeamRestrictions(string ow
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>
Expand All @@ -921,7 +921,7 @@ public Task<IReadOnlyList<Team>> GetAllProtectedBranchTeamRestrictions(long repo
{
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>
Expand All @@ -941,7 +941,7 @@ public Task<IReadOnlyList<Team>> UpdateProtectedBranchTeamRestrictions(string ow
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>
Expand All @@ -958,7 +958,7 @@ public Task<IReadOnlyList<Team>> UpdateProtectedBranchTeamRestrictions(long repo
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>
Expand All @@ -978,7 +978,7 @@ public Task<IReadOnlyList<Team>> AddProtectedBranchTeamRestrictions(string owner
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>
Expand All @@ -995,7 +995,7 @@ public Task<IReadOnlyList<Team>> AddProtectedBranchTeamRestrictions(long reposit
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>
Expand All @@ -1015,7 +1015,7 @@ public Task<IReadOnlyList<Team>> DeleteProtectedBranchTeamRestrictions(string ow
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>
Expand All @@ -1032,7 +1032,7 @@ public Task<IReadOnlyList<Team>> DeleteProtectedBranchTeamRestrictions(long repo
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>
Expand Down