mirror of
https://github.com/zoriya/octokit.net.git
synced 2026-06-04 03:16:11 +00:00
Permissions attribute was already present on Repository
Ensure Teams.GetAllRepositories() calls pass the preview header and add integration tests to assert the permissions property is populated
This commit is contained in:
@@ -224,7 +224,7 @@ namespace Octokit.Reactive
|
||||
{
|
||||
Ensure.ArgumentNotNull(options, "options");
|
||||
|
||||
return _connection.GetAndFlattenAllPages<Repository>(ApiUrls.TeamRepositories(id), options);
|
||||
return _connection.GetAndFlattenAllPages<Repository>(ApiUrls.TeamRepositories(id), null, AcceptHeaders.OrganizationPermissionsPreview, options);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -37,6 +37,15 @@ namespace Octokit.Reactive.Internal
|
||||
return GetPages(url, parameters, (pageUrl, pageParams) => connection.Get<List<T>>(pageUrl, pageParams, accepts).ToObservable());
|
||||
}
|
||||
|
||||
public static IObservable<T> GetAndFlattenAllPages<T>(this IConnection connection, Uri url, IDictionary<string, string> parameters, string accepts, ApiOptions options)
|
||||
{
|
||||
return GetPagesWithOptions(url, parameters, options, (pageUrl, pageParams, o) =>
|
||||
{
|
||||
var passingParameters = Pagination.Setup(parameters, options);
|
||||
return connection.Get<List<T>>(pageUrl, passingParameters, accepts).ToObservable();
|
||||
});
|
||||
}
|
||||
|
||||
static IObservable<T> GetPages<T>(Uri uri, IDictionary<string, string> parameters,
|
||||
Func<Uri, IDictionary<string, string>, IObservable<IApiResponse<List<T>>>> getPageFunc)
|
||||
{
|
||||
|
||||
@@ -4,6 +4,7 @@ using System.Net;
|
||||
using System.Threading.Tasks;
|
||||
using Octokit;
|
||||
using Octokit.Tests.Integration;
|
||||
using Octokit.Tests.Integration.Helpers;
|
||||
using Xunit;
|
||||
|
||||
public class TeamsClientTests
|
||||
@@ -98,11 +99,11 @@ public class TeamsClientTests
|
||||
}
|
||||
}
|
||||
|
||||
public class TheGetMembersMethod
|
||||
public class TheGetAllMembersMethod
|
||||
{
|
||||
readonly Team team;
|
||||
|
||||
public TheGetMembersMethod()
|
||||
public TheGetAllMembersMethod()
|
||||
{
|
||||
var github = Helper.GetAuthenticatedClient();
|
||||
|
||||
@@ -119,4 +120,32 @@ public class TeamsClientTests
|
||||
Assert.Contains(Helper.UserName, members.Select(u => u.Login));
|
||||
}
|
||||
}
|
||||
|
||||
public class TheGetAllRepositoriesMethod
|
||||
{
|
||||
readonly Team _team;
|
||||
|
||||
public TheGetAllRepositoriesMethod()
|
||||
{
|
||||
var github = Helper.GetAuthenticatedClient();
|
||||
|
||||
_team = github.Organization.Team.GetAll(Helper.Organization).Result.First();
|
||||
}
|
||||
|
||||
[OrganizationTest]
|
||||
public async Task GetsAllRepositories()
|
||||
{
|
||||
var github = Helper.GetAuthenticatedClient();
|
||||
|
||||
using (var repositoryContext = await github.CreateRepositoryContext(Helper.Organization, new NewRepository(Helper.MakeNameWithTimestamp("teamrepo"))))
|
||||
{
|
||||
github.Organization.Team.AddRepository(_team.Id, Helper.Organization, repositoryContext.RepositoryName);
|
||||
|
||||
var repos = await github.Organization.Team.GetAllRepositories(_team.Id);
|
||||
|
||||
Assert.True(repos.Count > 0);
|
||||
Assert.NotNull(repos[0].Permissions);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,15 +4,16 @@ using System.Threading.Tasks;
|
||||
using Octokit;
|
||||
using Octokit.Reactive;
|
||||
using Octokit.Tests.Integration;
|
||||
using Octokit.Tests.Integration.Helpers;
|
||||
using Xunit;
|
||||
|
||||
public class ObservableTeamsClientTests
|
||||
{
|
||||
public class TheGetMembersMethod
|
||||
public class TheGetAllMembersMethod
|
||||
{
|
||||
readonly Team _team;
|
||||
|
||||
public TheGetMembersMethod()
|
||||
public TheGetAllMembersMethod()
|
||||
{
|
||||
var github = Helper.GetAuthenticatedClient();
|
||||
|
||||
@@ -23,12 +24,43 @@ public class ObservableTeamsClientTests
|
||||
public async Task GetsAllMembersWhenAuthenticated()
|
||||
{
|
||||
var github = Helper.GetAuthenticatedClient();
|
||||
|
||||
var client = new ObservableTeamsClient(github);
|
||||
|
||||
var member = await client.GetAllMembers(_team.Id, ApiOptions.None);
|
||||
var observable = client.GetAllMembers(_team.Id, ApiOptions.None);
|
||||
var members = await observable.ToList();
|
||||
|
||||
Assert.Equal(Helper.UserName, member.Login);
|
||||
Assert.True(members.Count > 0);
|
||||
Assert.True(members.Any(x => x.Login == Helper.UserName));
|
||||
}
|
||||
}
|
||||
|
||||
public class TheGetAllRepositoriesMethod
|
||||
{
|
||||
readonly Team _team;
|
||||
|
||||
public TheGetAllRepositoriesMethod()
|
||||
{
|
||||
var github = Helper.GetAuthenticatedClient();
|
||||
|
||||
_team = github.Organization.Team.GetAll(Helper.Organization).Result.First();
|
||||
}
|
||||
|
||||
[OrganizationTest]
|
||||
public async Task GetsAllRepositories()
|
||||
{
|
||||
var github = Helper.GetAuthenticatedClient();
|
||||
var client = new ObservableTeamsClient(github);
|
||||
|
||||
using (var repositoryContext = await github.CreateRepositoryContext(Helper.Organization, new NewRepository(Helper.MakeNameWithTimestamp("teamrepo"))))
|
||||
{
|
||||
client.AddRepository(_team.Id, Helper.Organization, repositoryContext.RepositoryName);
|
||||
|
||||
var observable = client.GetAllRepositories(_team.Id, ApiOptions.None);
|
||||
var repos = await observable.ToList();
|
||||
|
||||
Assert.True(repos.Count() > 0);
|
||||
Assert.NotNull(repos[0].Permissions);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -220,7 +220,7 @@ namespace Octokit.Tests.Clients
|
||||
}
|
||||
}
|
||||
|
||||
public class TheRRemoveMembershipMethod
|
||||
public class TheRemoveMembershipMethod
|
||||
{
|
||||
[Fact]
|
||||
public void RequestsTheCorrectUrl()
|
||||
@@ -255,6 +255,8 @@ namespace Octokit.Tests.Clients
|
||||
|
||||
connection.Received().GetAll<Repository>(
|
||||
Arg.Is<Uri>(u => u.ToString() == "teams/1/repos"),
|
||||
null,
|
||||
"application/vnd.github.ironman-preview+json",
|
||||
Args.ApiOptions);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -276,22 +276,7 @@ namespace Octokit
|
||||
|
||||
var endpoint = ApiUrls.TeamRepositories(id);
|
||||
|
||||
return ApiConnection.GetAll<Repository>(endpoint, options);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns all <see cref="Repository"/>(ies) associated with the given team.
|
||||
/// </summary>
|
||||
/// <param name="id">The team identifier</param>
|
||||
/// <remarks>
|
||||
/// See the <a href="https://developer.github.com/v3/orgs/teams/#list-team-repos">API documentation</a> for more information.
|
||||
/// </remarks>
|
||||
/// <returns>A list of the team's <see cref="Repository"/>(ies).</returns>
|
||||
public Task<IReadOnlyList<Repository>> GetRepositories(int id)
|
||||
{
|
||||
var endpoint = ApiUrls.TeamRepositories(id);
|
||||
|
||||
return ApiConnection.GetAll<Repository>(endpoint);
|
||||
return ApiConnection.GetAll<Repository>(endpoint, null, AcceptHeaders.OrganizationPermissionsPreview, options);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user