diff --git a/Octokit.Reactive/Clients/ObservableTeamsClient.cs b/Octokit.Reactive/Clients/ObservableTeamsClient.cs index 12f81b9e..bd49e541 100644 --- a/Octokit.Reactive/Clients/ObservableTeamsClient.cs +++ b/Octokit.Reactive/Clients/ObservableTeamsClient.cs @@ -143,5 +143,51 @@ namespace Octokit.Reactive { return _connection.GetAndFlattenAllPages(ApiUrls.TeamRepositories(id)); } + + /// + /// Adds a to a . + /// + /// The team identifier. + /// Org to associate the repo with. + /// Name of the repo. + /// Thrown if you attempt to add a repository to a team that is not owned by the organization. + /// + /// See the API documentation for more information. + /// + /// if the repository was added to the team; otherwise. + public IObservable AddRepository(int id, string org, string repo) + { + return _client.AddRepository(id, org, repo).ToObservable(); + } + + /// + /// Removes a from a . + /// + /// The team identifier. + /// Owner of the org the team is associated with. + /// Name of the repo. + /// + /// See the API documentation for more information. + /// + /// if the repository was removed from the team; otherwise. + public IObservable RemoveRepository(int id, string owner, string repo) + { + return _client.RemoveRepository(id, owner, repo).ToObservable(); + } + + /// + /// Gets whether or not the given repository is managed by the given team. + /// + /// The team identifier + /// Owner of the org the team is associated with. + /// Name of the repo. + /// + /// See the API documentation for more information. + /// + /// if the repository is managed by the given team; otherwise. + public IObservable IsRepositoryManagedByTeam(int id, string owner, string repo) + { + return _client.IsRepositoryManagedByTeam(id, owner, repo).ToObservable(); + } } } diff --git a/Octokit/Clients/TeamsClient.cs b/Octokit/Clients/TeamsClient.cs index 393cfa4c..de149530 100644 --- a/Octokit/Clients/TeamsClient.cs +++ b/Octokit/Clients/TeamsClient.cs @@ -195,5 +195,92 @@ namespace Octokit return ApiConnection.GetAll(endpoint); } + + /// + /// Adds a to a . + /// + /// The team identifier. + /// Org to associate the repo with. + /// Name of the repo. + /// Thrown if you attempt to add a repository to a team that is not owned by the organization. + /// + /// See the API documentation for more information. + /// + /// if the repository was added to the team; otherwise. + public async Task AddRepository(int id, string org, string repo) + { + Ensure.ArgumentNotNullOrEmptyString(org, "org"); + Ensure.ArgumentNotNullOrEmptyString(repo, "repo"); + + var endpoint = ApiUrls.TeamRepository(id, org, repo); + + try + { + var httpStatusCode = await ApiConnection.Connection.Put(endpoint); + + return httpStatusCode == System.Net.HttpStatusCode.NoContent; + } + catch (NotFoundException) + { + return false; + } + } + + /// + /// Removes a from a . + /// + /// The team identifier. + /// Owner of the org the team is associated with. + /// Name of the repo. + /// + /// See the API documentation for more information. + /// + /// if the repository was removed from the team; otherwise. + public async Task RemoveRepository(int id, string owner, string repo) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(repo, "repo"); + + var endpoint = ApiUrls.TeamRepository(id, owner, repo); + + try + { + var httpStatusCode = await ApiConnection.Connection.Delete(endpoint); + + return httpStatusCode == System.Net.HttpStatusCode.NoContent; + } + catch (NotFoundException) + { + return false; + } + } + + /// + /// Gets whether or not the given repository is managed by the given team. + /// + /// The team identifier + /// Owner of the org the team is associated with. + /// Name of the repo. + /// + /// See the API documentation for more information. + /// + /// if the repository is managed by the given team; otherwise. + public async Task IsRepositoryManagedByTeam(int id, string owner, string repo) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(repo, "repo"); + + var endpoint = ApiUrls.TeamRepository(id, owner, repo); + + try + { + var response = await ApiConnection.Connection.GetResponse(endpoint); + return response.StatusCode == System.Net.HttpStatusCode.NoContent; + } + catch (NotFoundException) + { + return false; + } + } } }