mirror of
https://github.com/zoriya/octokit.net.git
synced 2026-06-03 03:01:31 +00:00
Merge remote-tracking branch 'upstream/master' into add-user-permissions
This commit is contained in:
@@ -171,6 +171,20 @@ namespace Octokit.Reactive
|
||||
/// <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>
|
||||
|
||||
@@ -246,6 +246,25 @@ namespace Octokit.Reactive
|
||||
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
|
||||
|
||||
@@ -13,7 +13,7 @@ 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()
|
||||
@@ -21,7 +21,7 @@ public class EnterpriseLdapClientTests : IDisposable
|
||||
_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]
|
||||
|
||||
@@ -433,7 +433,7 @@ public class RepositoriesClientTests
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Helper.DeleteRepo(_repository);
|
||||
Helper.DeleteRepo(Helper.GetAuthenticatedClient().Connection, _repository);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -43,7 +43,7 @@ namespace Octokit.Tests.Integration.Clients
|
||||
// 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();
|
||||
|
||||
@@ -60,7 +60,7 @@ namespace Octokit.Tests.Integration.Clients
|
||||
// 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();
|
||||
|
||||
|
||||
@@ -148,4 +148,34 @@ public class TeamsClientTests
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -79,7 +79,7 @@ namespace Octokit.Tests.Integration.Clients
|
||||
}
|
||||
|
||||
// Remove user if it was already renamed
|
||||
EnterpriseHelper.DeleteUser(renamedUsername);
|
||||
EnterpriseHelper.DeleteUser(_github.Connection, renamedUsername);
|
||||
}
|
||||
|
||||
[GitHubEnterpriseTest]
|
||||
|
||||
@@ -108,50 +108,18 @@ namespace Octokit.Tests.Integration
|
||||
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 { }
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using Octokit.Reactive;
|
||||
|
||||
namespace Octokit.Tests.Integration
|
||||
{
|
||||
@@ -110,34 +111,50 @@ namespace Octokit.Tests.Integration
|
||||
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 (key != null)
|
||||
DeleteKey(key.Id);
|
||||
if (team != null)
|
||||
DeleteTeam(connection, team.Id);
|
||||
}
|
||||
|
||||
public static void DeleteKey(int keyId)
|
||||
public static void DeleteTeam(IConnection connection, int teamId)
|
||||
{
|
||||
var api = GetAuthenticatedClient();
|
||||
try
|
||||
{
|
||||
api.User.Keys.Delete(keyId).Wait(TimeSpan.FromSeconds(15));
|
||||
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(connection, key.Id);
|
||||
}
|
||||
|
||||
public static void DeleteKey(IConnection connection, int keyId)
|
||||
{
|
||||
try
|
||||
{
|
||||
var client = new GitHubClient(connection);
|
||||
client.User.Keys.Delete(keyId).Wait(TimeSpan.FromSeconds(15));
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
|
||||
@@ -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; }
|
||||
@@ -24,7 +26,7 @@ namespace Octokit.Tests.Integration.Helpers
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
EnterpriseHelper.DeleteUser(User);
|
||||
EnterpriseHelper.DeleteUser(_connection, User.Login);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,35 +9,35 @@ namespace Octokit.Tests.Integration.Helpers
|
||||
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)
|
||||
@@ -48,7 +48,7 @@ namespace Octokit.Tests.Integration.Helpers
|
||||
|
||||
var key = await client.User.Keys.Create(new NewPublicKey(keyTitle, keyData));
|
||||
|
||||
return new PublicKeyContext(key);
|
||||
return new PublicKeyContext(client.Connection, key);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -11,35 +11,35 @@ namespace Octokit.Tests.Integration.Helpers
|
||||
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)
|
||||
@@ -50,7 +50,7 @@ namespace Octokit.Tests.Integration.Helpers
|
||||
|
||||
var key = await client.User.Keys.Create(new NewPublicKey(keyTitle, keyData));
|
||||
|
||||
return new PublicKeyContext(key);
|
||||
return new PublicKeyContext(client.Connection, key);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -8,14 +8,16 @@ namespace Octokit.Tests.Integration.Helpers
|
||||
{
|
||||
internal sealed class PublicKeyContext : IDisposable
|
||||
{
|
||||
internal PublicKeyContext(PublicKey key)
|
||||
internal PublicKeyContext(IConnection connection, PublicKey key)
|
||||
{
|
||||
_connection = connection;
|
||||
Key = key;
|
||||
KeyId = key.Id;
|
||||
KeyTitle = key.Title;
|
||||
KeyData = key.Key;
|
||||
}
|
||||
|
||||
private IConnection _connection;
|
||||
internal int KeyId { get; private set; }
|
||||
internal string KeyTitle { get; private set; }
|
||||
internal string KeyData { get; private set; }
|
||||
@@ -24,7 +26,7 @@ namespace Octokit.Tests.Integration.Helpers
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Helper.DeleteKey(Key);
|
||||
Helper.DeleteKey(_connection, Key);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,18 +3,21 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Octokit.Reactive;
|
||||
|
||||
namespace Octokit.Tests.Integration.Helpers
|
||||
{
|
||||
internal sealed class RepositoryContext : IDisposable
|
||||
{
|
||||
internal RepositoryContext(Repository repo)
|
||||
internal RepositoryContext(IConnection connection, Repository repo)
|
||||
{
|
||||
_connection = connection;
|
||||
Repository = repo;
|
||||
RepositoryOwner = repo.Owner.Login;
|
||||
RepositoryName = repo.Name;
|
||||
}
|
||||
|
||||
private IConnection _connection;
|
||||
internal string RepositoryOwner { get; private set; }
|
||||
internal string RepositoryName { get; private set; }
|
||||
|
||||
@@ -22,7 +25,7 @@ namespace Octokit.Tests.Integration.Helpers
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Helper.DeleteRepo(Repository);
|
||||
Helper.DeleteRepo(_connection, Repository);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+5
-3
@@ -6,15 +6,17 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace Octokit.Tests.Integration.Helpers
|
||||
{
|
||||
internal sealed class EnterpriseTeamContext : IDisposable
|
||||
internal sealed class TeamContext : IDisposable
|
||||
{
|
||||
internal EnterpriseTeamContext(Team team)
|
||||
internal TeamContext(IConnection connection, Team team)
|
||||
{
|
||||
_connection = connection;
|
||||
Team = team;
|
||||
TeamId = team.Id;
|
||||
TeamName = team.Name;
|
||||
}
|
||||
|
||||
private IConnection _connection;
|
||||
internal int TeamId { get; private set; }
|
||||
internal string TeamName { get; private set; }
|
||||
|
||||
@@ -22,7 +24,7 @@ namespace Octokit.Tests.Integration.Helpers
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
EnterpriseHelper.DeleteTeam(Team);
|
||||
Helper.DeleteTeam(_connection, Team);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -127,7 +127,7 @@
|
||||
<Compile Include="Helpers\PersonalAccessTokenTestAttribute.cs" />
|
||||
<Compile Include="Helpers\PaidAccountTestAttribute.cs" />
|
||||
<Compile Include="Helpers\ReferenceExtensionsTests.cs" />
|
||||
<Compile Include="Helpers\EnterpriseTeamContext.cs" />
|
||||
<Compile Include="Helpers\TeamContext.cs" />
|
||||
<Compile Include="Helpers\RepositoryContext.cs" />
|
||||
<Compile Include="Helpers\RepositorySetupHelper.cs" />
|
||||
<Compile Include="HttpClientAdapterTests.cs" />
|
||||
|
||||
+1
-1
@@ -15,7 +15,7 @@ namespace Octokit.Tests.Integration
|
||||
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 ObservableEnterpriseLdapClientTests()
|
||||
|
||||
@@ -101,6 +101,6 @@ public class ObservableRespositoryDeployKeysClientTests : IDisposable
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Helper.DeleteRepo(_repository);
|
||||
Helper.DeleteRepo(Helper.GetAuthenticatedClient().Connection, _repository);
|
||||
}
|
||||
}
|
||||
@@ -82,7 +82,7 @@ namespace Octokit.Tests.Integration.Clients
|
||||
}
|
||||
|
||||
// Remove user if it was already renamed
|
||||
EnterpriseHelper.DeleteUser(renamedUsername);
|
||||
EnterpriseHelper.DeleteUser(_github.Connection, renamedUsername);
|
||||
}
|
||||
|
||||
[GitHubEnterpriseTest]
|
||||
|
||||
@@ -3,6 +3,7 @@ using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using NSubstitute;
|
||||
using Xunit;
|
||||
using System.Net;
|
||||
|
||||
namespace Octokit.Tests.Clients
|
||||
{
|
||||
@@ -302,6 +303,18 @@ namespace Octokit.Tests.Clients
|
||||
connection.Connection.Received().Put(Arg.Is<Uri>(u => u.ToString() == "teams/1/repos/org/repo"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AddOrUpdatePermission()
|
||||
{
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new TeamsClient(connection);
|
||||
var newPermission = new RepositoryPermissionRequest(Permission.Admin);
|
||||
|
||||
client.AddRepository(1, "org", "repo", newPermission);
|
||||
|
||||
connection.Connection.Received().Put<HttpStatusCode>(Arg.Is<Uri>(u => u.ToString() == "teams/1/repos/org/repo"), Arg.Any<object>(), "", "application/vnd.github.ironman-preview+json");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void EnsureNonNullOrg()
|
||||
{
|
||||
|
||||
@@ -159,6 +159,17 @@ namespace Octokit
|
||||
/// <returns></returns>
|
||||
Task<bool> AddRepository(int id, string organization, string repoName);
|
||||
|
||||
/// <summary>
|
||||
/// Add a repository to the 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="ApiException">Thrown when a general API error occurs.</exception>
|
||||
/// <returns></returns>
|
||||
Task<bool> AddRepository(int id, string organization, string repoName, RepositoryPermissionRequest permission);
|
||||
|
||||
/// <summary>
|
||||
/// Remove a repository from the team
|
||||
/// </summary>
|
||||
|
||||
@@ -302,6 +302,33 @@ namespace Octokit
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add a repository to the 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="ApiException">Thrown when a general API error occurs.</exception>
|
||||
/// <returns></returns>
|
||||
public async Task<bool> AddRepository(int id, string organization, string repoName, RepositoryPermissionRequest permission)
|
||||
{
|
||||
Ensure.ArgumentNotNullOrEmptyString(organization, "organization");
|
||||
Ensure.ArgumentNotNullOrEmptyString(repoName, "repoName");
|
||||
|
||||
var endpoint = ApiUrls.TeamRepository(id, organization, repoName);
|
||||
|
||||
try
|
||||
{
|
||||
var httpStatusCode = await ApiConnection.Connection.Put<HttpStatusCode>(endpoint, permission, "", AcceptHeaders.OrganizationPermissionsPreview).ConfigureAwait(false);
|
||||
return httpStatusCode.HttpResponse.StatusCode == HttpStatusCode.NoContent;
|
||||
}
|
||||
catch (NotFoundException)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Remove a repository from the team
|
||||
/// </summary>
|
||||
|
||||
@@ -466,7 +466,7 @@ namespace Octokit
|
||||
/// <param name="data">The object to serialize as the body of the request</param>
|
||||
/// <param name="accepts">Specifies accept response media type</param>
|
||||
/// <returns>The returned <seealso cref="HttpStatusCode"/></returns>
|
||||
public async Task<HttpStatusCode> Delete(Uri uri,object data, string accepts)
|
||||
public async Task<HttpStatusCode> Delete(Uri uri, object data, string accepts)
|
||||
{
|
||||
Ensure.ArgumentNotNull(uri, "uri");
|
||||
Ensure.ArgumentNotNull(accepts, "accepts");
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
using Octokit.Internal;
|
||||
using System.Diagnostics;
|
||||
using System.Globalization;
|
||||
|
||||
namespace Octokit
|
||||
{
|
||||
[DebuggerDisplay("{DebuggerDisplay,nq}")]
|
||||
public class RepositoryPermissionRequest
|
||||
{
|
||||
/// <summary>
|
||||
/// Used to add or update a team repository.
|
||||
/// </summary>
|
||||
public RepositoryPermissionRequest(Permission permission)
|
||||
{
|
||||
Permission = permission;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The permission to grant the team on this repository.
|
||||
/// </summary>
|
||||
public Permission Permission { get; private set; }
|
||||
|
||||
internal string DebuggerDisplay
|
||||
{
|
||||
get
|
||||
{
|
||||
return string.Format(CultureInfo.InvariantCulture, "Permission: {0}", Permission);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -466,6 +466,7 @@
|
||||
<Compile Include="Clients\MigrationsClient.cs" />
|
||||
<Compile Include="Models\Request\StartMigrationRequest.cs" />
|
||||
<Compile Include="Models\Response\Migration.cs" />
|
||||
<Compile Include="Models\Request\RepositoryPermissionRequest.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
||||
@@ -477,6 +477,7 @@
|
||||
<Compile Include="Models\Response\Enterprise\Migration.cs" />
|
||||
<Compile Include="Models\Request\StartMigrationRequest.cs" />
|
||||
<Compile Include="Models\Response\Migration.cs" />
|
||||
<Compile Include="Models\Request\RepositoryPermissionRequest.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildExtensionsPath)\Novell\Novell.MonoDroid.CSharp.targets" />
|
||||
</Project>
|
||||
@@ -473,6 +473,7 @@
|
||||
<Compile Include="Models\Response\Enterprise\Migration.cs" />
|
||||
<Compile Include="Models\Request\StartMigrationRequest.cs" />
|
||||
<Compile Include="Models\Response\Migration.cs" />
|
||||
<Compile Include="Models\Request\RepositoryPermissionRequest.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildExtensionsPath)\Xamarin\iOS\Xamarin.MonoTouch.CSharp.targets" />
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
|
||||
@@ -463,6 +463,7 @@
|
||||
<Compile Include="Clients\MigrationsClient.cs" />
|
||||
<Compile Include="Models\Request\StartMigrationRequest.cs" />
|
||||
<Compile Include="Models\Response\Migration.cs" />
|
||||
<Compile Include="Models\Request\RepositoryPermissionRequest.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<CodeAnalysisDictionary Include="..\CustomDictionary.xml">
|
||||
|
||||
@@ -470,6 +470,7 @@
|
||||
<Compile Include="Clients\MigrationsClient.cs" />
|
||||
<Compile Include="Models\Request\StartMigrationRequest.cs" />
|
||||
<Compile Include="Models\Response\Migration.cs" />
|
||||
<Compile Include="Models\Request\RepositoryPermissionRequest.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<CodeAnalysisDictionary Include="..\CustomDictionary.xml">
|
||||
|
||||
@@ -144,6 +144,7 @@
|
||||
<Compile Include="Models\Request\NotificationsRequest.cs" />
|
||||
<Compile Include="Models\Request\CommitRequest.cs" />
|
||||
<Compile Include="Models\Request\StartMigrationRequest.cs" />
|
||||
<Compile Include="Models\Request\RepositoryPermissionRequest.cs" />
|
||||
<Compile Include="Models\Request\UserRename.cs" />
|
||||
<Compile Include="Models\Response\ActivityPayloads\ActivityPayload.cs" />
|
||||
<Compile Include="Models\Response\ActivityPayloads\CommitCommentPayload.cs" />
|
||||
|
||||
Reference in New Issue
Block a user