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

Missing permission parameter #1347

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
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
14 changes: 14 additions & 0 deletions Octokit.Reactive/Clients/IObservableTeamsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,20 @@ public interface IObservableTeamsClient
/// <returns><see langword="true"/> if the repository was added to the team; <see langword="false"/> otherwise.</returns>
IObservable<bool> AddRepository(int id, string organization, string repoName);

/// <summary>
/// Adds a <see cref="Repository"/> to a <see cref="Team"/>.
/// </summary>
/// <param name="id">The team identifier.</param>
/// <param name="organization">Org to associate the repo with.</param>
/// <param name="repoName">Name of the repo.</param>
/// <param name="permission">The permission to grant the team on this repository.</param>
/// <exception cref="ApiValidationException">Thrown if you attempt to add a repository to a team that is not owned by the organization.</exception>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/orgs/teams/#add-team-repo">API documentation</a> for more information.
/// </remarks>
/// <returns><see langword="true"/> if the repository was added to the team; <see langword="false"/> otherwise.</returns>
IObservable<bool> AddRepository(int id, string organization, string repoName, RepositoryPermissionRequest permission);

/// <summary>
/// Gets whether or not the given repository is managed by the given team.
/// </summary>
Expand Down
19 changes: 19 additions & 0 deletions Octokit.Reactive/Clients/ObservableTeamsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,25 @@ public IObservable<bool> AddRepository(int id, string organization, string repoN
return _client.AddRepository(id, organization, repoName).ToObservable();
}

/// <summary>
/// Adds a <see cref="Repository"/> to a <see cref="Team"/>.
/// </summary>
/// <param name="id">The team identifier.</param>
/// <param name="organization">Org to associate the repo with.</param>
/// <param name="repoName">Name of the repo.</param>
/// <param name="permission">The permission to grant the team on this repository.</param>
/// <exception cref="ApiValidationException">Thrown if you attempt to add a repository to a team that is not owned by the organization.</exception>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/orgs/teams/#add-team-repo">API documentation</a> for more information.
/// </remarks>
/// <returns><see langword="true"/> if the repository was added to the team; <see langword="false"/> otherwise.</returns>
public IObservable<bool> AddRepository(int id, string organization, string repoName, RepositoryPermissionRequest permission)
{
Ensure.ArgumentNotNullOrEmptyString(organization, "organization");
Ensure.ArgumentNotNullOrEmptyString(repoName, "repoName");

return _client.AddRepository(id, organization, repoName, permission).ToObservable();
}

/// <summary>
/// Remove a repository from the team
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ public class EnterpriseLdapClientTests : IDisposable
readonly string _testUser = "test-user";
readonly string _distinguishedNameUser = "uid=test-user,ou=users,dc=company,dc=com";

readonly EnterpriseTeamContext _context;
readonly TeamContext _context;
readonly string _distinguishedNameTeam = "cn=test-team,ou=groups,dc=company,dc=com";

public EnterpriseLdapClientTests()
{
_github = EnterpriseHelper.GetAuthenticatedClient();

NewTeam newTeam = new NewTeam(Helper.MakeNameWithTimestamp("test-team")) { Description = "Test Team" };
_context = _github.CreateEnterpriseTeamContext(EnterpriseHelper.Organization, newTeam).Result;
_context = _github.CreateTeamContext(EnterpriseHelper.Organization, newTeam).Result;
}

[GitHubEnterpriseTest]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ public async Task UpdatesHasWiki()

public void Dispose()
{
Helper.DeleteRepo(_repository);
Helper.DeleteRepo(Helper.GetAuthenticatedClient().Connection, _repository);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public async Task ForkCreatedForUserLoggedIn()
// The fork is created asynchronously by github and therefore it cannot
// be certain that the repo exists when the test ends. It is therefore deleted
// before the test starts instead of after.
Helper.DeleteRepo(Helper.Credentials.Login, "octokit.net");
Helper.DeleteRepo(Helper.GetAuthenticatedClient().Connection, Helper.Credentials.Login, "octokit.net");

var github = Helper.GetAuthenticatedClient();

Expand All @@ -60,7 +60,7 @@ public async Task ForkCreatedForOrganization()
// The fork is created asynchronously by github and therefore it cannot
// be certain that the repo exists when the test ends. It is therefore deleted
// before the test starts.
Helper.DeleteRepo(Helper.Organization, "octokit.net");
Helper.DeleteRepo(Helper.GetAuthenticatedClient().Connection, Helper.Organization, "octokit.net");

var github = Helper.GetAuthenticatedClient();

Expand Down
31 changes: 31 additions & 0 deletions Octokit.Tests.Integration/Clients/TeamsClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Threading.Tasks;
using Octokit;
using Octokit.Tests.Integration;
using Octokit.Tests.Integration.Helpers;
using Xunit;

public class TeamsClientTests
Expand Down Expand Up @@ -119,4 +120,34 @@ public async Task GetsAllMembersWhenAuthenticated()
Assert.Contains(Helper.UserName, members.Select(u => u.Login));
}
}

public class TheAddOrUpdateTeamRepositoryMethod
{
private readonly IGitHubClient _github;

public TheAddOrUpdateTeamRepositoryMethod()
{
_github = Helper.GetAuthenticatedClient();
}

[OrganizationTest]
public async Task CanAddRepository()
{
using (var teamContext = await _github.CreateTeamContext(Helper.Organization, new NewTeam(Helper.MakeNameWithTimestamp("team"))))
using (var repoContext = await _github.CreateRepositoryContext(Helper.Organization, new NewRepository(Helper.MakeNameWithTimestamp("team-repository"))))
{
var team = teamContext.Team;
var repo = repoContext.Repository;

var addRepo = await _github.Organization.Team.AddRepository(team.Id, team.Organization.Login, repo.Name, new RepositoryPermissionRequest(Permission.Admin));

Assert.True(addRepo);

var addedRepo = await _github.Organization.Team.GetAllRepositories(team.Id);

//Check if permission was correctly applied
Assert.True(addedRepo.First(x => x.Id == repo.Id).Permissions.Admin == true);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public async Task CanRename()
}

// Remove user if it was already renamed
EnterpriseHelper.DeleteUser(renamedUsername);
EnterpriseHelper.DeleteUser(_github.Connection, renamedUsername);
}

[GitHubEnterpriseTest]
Expand Down
42 changes: 5 additions & 37 deletions Octokit.Tests.Integration/EnterpriseHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,50 +108,18 @@ public static string ClientSecret
get { return Environment.GetEnvironmentVariable("OCTOKIT_GHE_CLIENTSECRET"); }
}

public static void DeleteRepo(Repository repository)
{
if (repository != null)
DeleteRepo(repository.Owner.Login, repository.Name);
}

public static void DeleteRepo(string owner, string name)
{
var api = GetAuthenticatedClient();
try
{
api.Repository.Delete(owner, name).Wait(TimeSpan.FromSeconds(15));
}
catch { }
}

public static void DeleteTeam(Team team)
{
if (team != null)
DeleteTeam(team.Id);
}

public static void DeleteTeam(int teamId)
{
var api = GetAuthenticatedClient();
try
{
api.Organization.Team.Delete(teamId).Wait(TimeSpan.FromSeconds(15));
}
catch { }
}

public static void DeleteUser(User user)
public static void DeleteUser(IConnection connection, User user)
{
if (user != null)
DeleteUser(user.Login);
DeleteUser(connection, user.Login);
}

public static void DeleteUser(string username)
public static void DeleteUser(IConnection connection, string username)
{
var api = GetAuthenticatedClient();
try
{
api.User.Administration.Delete(username).Wait(TimeSpan.FromSeconds(15));
var client = new GitHubClient(connection);
client.User.Administration.Delete(username).Wait(TimeSpan.FromSeconds(15));
}
catch { }
}
Expand Down
37 changes: 27 additions & 10 deletions Octokit.Tests.Integration/Helper.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Diagnostics;
using System.IO;
using Octokit.Reactive;

namespace Octokit.Tests.Integration
{
Expand Down Expand Up @@ -110,34 +111,50 @@ public static string ClientSecret
get { return Environment.GetEnvironmentVariable("OCTOKIT_CLIENTSECRET"); }
}

public static void DeleteRepo(Repository repository)
public static void DeleteRepo(IConnection connection, Repository repository)
{
if (repository != null)
DeleteRepo(repository.Owner.Login, repository.Name);
DeleteRepo(connection, repository.Owner.Login, repository.Name);
}

public static void DeleteRepo(string owner, string name)
public static void DeleteRepo(IConnection connection, string owner, string name)
{
var api = GetAuthenticatedClient();
try
{
api.Repository.Delete(owner, name).Wait(TimeSpan.FromSeconds(15));
var client = new GitHubClient(connection);
client.Repository.Delete(owner, name).Wait(TimeSpan.FromSeconds(15));
}
catch { }
}

public static void DeleteKey(PublicKey key)
public static void DeleteTeam(IConnection connection, Team team)
{
if (team != null)
DeleteTeam(connection, team.Id);
}

public static void DeleteTeam(IConnection connection, int teamId)
{
try
{
var client = new GitHubClient(connection);
client.Organization.Team.Delete(teamId).Wait(TimeSpan.FromSeconds(15));
}
catch { }
}

public static void DeleteKey(IConnection connection, PublicKey key)
{
if (key != null)
DeleteKey(key.Id);
DeleteKey(connection, key.Id);
}

public static void DeleteKey(int keyId)
public static void DeleteKey(IConnection connection, int keyId)
{
var api = GetAuthenticatedClient();
try
{
api.User.Keys.Delete(keyId).Wait(TimeSpan.FromSeconds(15));
var client = new GitHubClient(connection);
client.User.Keys.Delete(keyId).Wait(TimeSpan.FromSeconds(15));
}
catch { }
}
Expand Down
6 changes: 4 additions & 2 deletions Octokit.Tests.Integration/Helpers/EnterpriseUserContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,16 @@ namespace Octokit.Tests.Integration.Helpers
{
internal sealed class EnterpriseUserContext : IDisposable
{
internal EnterpriseUserContext(User user)
internal EnterpriseUserContext(IConnection connection, User user)
{
_connection = connection;
User = user;
UserId = user.Id;
UserLogin = user.Login;
UserEmail = user.Email;
}

private IConnection _connection;
internal int UserId { get; private set; }
internal string UserLogin { get; private set; }
internal string UserEmail { get; private set; }
Expand All @@ -24,7 +26,7 @@ internal EnterpriseUserContext(User user)

public void Dispose()
{
EnterpriseHelper.DeleteUser(User);
EnterpriseHelper.DeleteUser(_connection, User.Login);
}
}
}
14 changes: 7 additions & 7 deletions Octokit.Tests.Integration/Helpers/GithubClientExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,35 +9,35 @@ internal static async Task<RepositoryContext> CreateRepositoryContext(this IGitH
var repoName = Helper.MakeNameWithTimestamp(repositoryName);
var repo = await client.Repository.Create(new NewRepository(repoName) { AutoInit = true });

return new RepositoryContext(repo);
return new RepositoryContext(client.Connection, repo);
}

internal static async Task<RepositoryContext> CreateRepositoryContext(this IGitHubClient client, string organizationLogin, NewRepository newRepository)
{
var repo = await client.Repository.Create(organizationLogin, newRepository);

return new RepositoryContext(repo);
return new RepositoryContext(client.Connection, repo);
}

internal static async Task<RepositoryContext> CreateRepositoryContext(this IGitHubClient client, NewRepository newRepository)
{
var repo = await client.Repository.Create(newRepository);

return new RepositoryContext(repo);
return new RepositoryContext(client.Connection, repo);
}

internal static async Task<EnterpriseTeamContext> CreateEnterpriseTeamContext(this IGitHubClient client, string organization, NewTeam newTeam)
internal static async Task<TeamContext> CreateTeamContext(this IGitHubClient client, string organization, NewTeam newTeam)
{
var team = await client.Organization.Team.Create(organization, newTeam);

return new EnterpriseTeamContext(team);
return new TeamContext(client.Connection, team);
}

internal static async Task<EnterpriseUserContext> CreateEnterpriseUserContext(this IGitHubClient client, NewUser newUser)
{
var user = await client.User.Administration.Create(newUser);

return new EnterpriseUserContext(user);
return new EnterpriseUserContext(client.Connection, user);
}

internal static async Task<PublicKeyContext> CreatePublicKeyContext(this IGitHubClient client)
Expand All @@ -48,7 +48,7 @@ internal static async Task<PublicKeyContext> CreatePublicKeyContext(this IGitHub

var key = await client.User.Keys.Create(new NewPublicKey(keyTitle, keyData));

return new PublicKeyContext(key);
return new PublicKeyContext(client.Connection, key);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,35 +11,35 @@ internal static async Task<RepositoryContext> CreateRepositoryContext(this IObse
var repoName = Helper.MakeNameWithTimestamp(repositoryName);
var repo = await client.Repository.Create(new NewRepository(repoName) { AutoInit = true });

return new RepositoryContext(repo);
return new RepositoryContext(client.Connection, repo);
}

internal static async Task<RepositoryContext> CreateRepositoryContext(this IObservableGitHubClient client, string organizationLogin, NewRepository newRepository)
{
var repo = await client.Repository.Create(organizationLogin, newRepository);

return new RepositoryContext(repo);
return new RepositoryContext(client.Connection, repo);
}

internal static async Task<RepositoryContext> CreateRepositoryContext(this IObservableGitHubClient client, NewRepository newRepository)
{
var repo = await client.Repository.Create(newRepository);

return new RepositoryContext(repo);
return new RepositoryContext(client.Connection, repo);
}

internal static async Task<EnterpriseTeamContext> CreateEnterpriseTeamContext(this IObservableGitHubClient client, string organization, NewTeam newTeam)
internal static async Task<TeamContext> CreateEnterpriseTeamContext(this IObservableGitHubClient client, string organization, NewTeam newTeam)
{
var team = await client.Organization.Team.Create(organization, newTeam);

return new EnterpriseTeamContext(team);
return new TeamContext(client.Connection, team);
}

internal static async Task<EnterpriseUserContext> CreateEnterpriseUserContext(this IObservableGitHubClient client, NewUser newUser)
{
var user = await client.User.Administration.Create(newUser);

return new EnterpriseUserContext(user);
return new EnterpriseUserContext(client.Connection, user);
}

internal static async Task<PublicKeyContext> CreatePublicKeyContext(this IObservableGitHubClient client)
Expand All @@ -50,7 +50,7 @@ internal static async Task<PublicKeyContext> CreatePublicKeyContext(this IObserv

var key = await client.User.Keys.Create(new NewPublicKey(keyTitle, keyData));

return new PublicKeyContext(key);
return new PublicKeyContext(client.Connection, key);
}
}
}
Loading