From 30e6cb6ae3d7463817cade674797bd2386436aff Mon Sep 17 00:00:00 2001 From: James R Sconfitto Date: Sun, 3 Nov 2013 21:32:48 -0500 Subject: [PATCH 01/37] Add `StarredClient` --- Octokit/Clients/IStarredClient.cs | 22 +++++++++++++++++++++ Octokit/Clients/StarsClient.cs | 33 +++++++++++++++++++++++++++++++ Octokit/Helpers/ApiUrls.cs | 20 +++++++++++++++++++ Octokit/Octokit.csproj | 2 ++ 4 files changed, 77 insertions(+) create mode 100644 Octokit/Clients/IStarredClient.cs create mode 100644 Octokit/Clients/StarsClient.cs diff --git a/Octokit/Clients/IStarredClient.cs b/Octokit/Clients/IStarredClient.cs new file mode 100644 index 00000000..9c20a5d4 --- /dev/null +++ b/Octokit/Clients/IStarredClient.cs @@ -0,0 +1,22 @@ +using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; +using System.Threading.Tasks; + +namespace Octokit.Clients +{ + interface IStarredClient + { + /// + /// Retrieves all of the starred (ies) for the authenticated user. + /// + /// Thrown if the client is not authenticated. + /// A of . + Task> GetAllForCurrent(); + + /// + /// Retrieves all of the (ies) starred by the passed user. + /// + /// A of . + Task> GetAllForUser(string user); + } +} diff --git a/Octokit/Clients/StarsClient.cs b/Octokit/Clients/StarsClient.cs new file mode 100644 index 00000000..30dbac9d --- /dev/null +++ b/Octokit/Clients/StarsClient.cs @@ -0,0 +1,33 @@ +using System; +using System.Collections.Generic; +using System.Threading.Tasks; + +namespace Octokit +{ + public class StarredClient : ApiClient, Octokit.Clients.IStarredClient + { + public StarredClient(IApiConnection apiConnection) : base(apiConnection) + { + } + + /// + /// Retrieves all of the starred (ies) for the current user. + /// + /// Thrown if the client is not authenticated. + /// A of . + public Task> GetAllForCurrent() + { + return ApiConnection.GetAll(ApiUrls.Starred()); + } + + /// + /// Retrieves all of the s for the current user specific to the specified repository. + /// + /// Thrown if the client is not authenticated. + /// A of . + public Task> GetAllForUser(string user) + { + return ApiConnection.GetAll(ApiUrls.Starred(user)); + } + } +} diff --git a/Octokit/Helpers/ApiUrls.cs b/Octokit/Helpers/ApiUrls.cs index ac2ee83f..2ff60318 100644 --- a/Octokit/Helpers/ApiUrls.cs +++ b/Octokit/Helpers/ApiUrls.cs @@ -10,6 +10,7 @@ namespace Octokit static readonly Uri _currentUserRepositoriesUrl = new Uri("user/repos", UriKind.Relative); static readonly Uri _currentUserOrganizationsUrl = new Uri("user/orgs", UriKind.Relative); static readonly Uri _currentUserSshKeys = new Uri("user/keys", UriKind.Relative); + static readonly Uri _currentUserStars = new Uri("user/starred", UriKind.Relative); static readonly Uri _currentUserEmailsEndpoint = new Uri("user/emails", UriKind.Relative); static readonly Uri _currentUserAuthorizationsEndpoint = new Uri("authorizations", UriKind.Relative); static readonly Uri _currentUserNotificationsEndpoint = new Uri("notifications", UriKind.Relative); @@ -246,5 +247,24 @@ namespace Octokit { return "repos/{0}/{1}/statuses/{2}".FormatUri(owner, name, reference); } + + /// + /// Returns the that lists the starred repositories for the specified user. + /// + /// + public static Uri Starred() + { + return _currentUserStars; + } + + /// + /// Returns the that lists the starred repositories for the specified user. + /// + /// The user that has the stars + /// + public static Uri Starred(string user) + { + return "users/{0}/starred".FormatUri(user); + } } } diff --git a/Octokit/Octokit.csproj b/Octokit/Octokit.csproj index 27dcf08c..17e2dbaa 100644 --- a/Octokit/Octokit.csproj +++ b/Octokit/Octokit.csproj @@ -54,7 +54,9 @@ + + From c2a4d887a7c5f5a677c6d8773d9acccf3cee584d Mon Sep 17 00:00:00 2001 From: James R Sconfitto Date: Sun, 3 Nov 2013 21:37:42 -0500 Subject: [PATCH 02/37] Docs cleanup --- Octokit/Helpers/ApiUrls.cs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Octokit/Helpers/ApiUrls.cs b/Octokit/Helpers/ApiUrls.cs index 2ff60318..3ceb3058 100644 --- a/Octokit/Helpers/ApiUrls.cs +++ b/Octokit/Helpers/ApiUrls.cs @@ -249,9 +249,8 @@ namespace Octokit } /// - /// Returns the that lists the starred repositories for the specified user. + /// Returns the that lists the starred repositories for the authenticated user. /// - /// public static Uri Starred() { return _currentUserStars; @@ -261,7 +260,6 @@ namespace Octokit /// Returns the that lists the starred repositories for the specified user. /// /// The user that has the stars - /// public static Uri Starred(string user) { return "users/{0}/starred".FormatUri(user); From 4da44bb16c3ee66ba52e8751f35ecdb9a2be86b2 Mon Sep 17 00:00:00 2001 From: James R Sconfitto Date: Sun, 3 Nov 2013 21:43:21 -0500 Subject: [PATCH 03/37] Don't need that line, do i --- Octokit/Clients/IStarredClient.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/Octokit/Clients/IStarredClient.cs b/Octokit/Clients/IStarredClient.cs index 9c20a5d4..646a2999 100644 --- a/Octokit/Clients/IStarredClient.cs +++ b/Octokit/Clients/IStarredClient.cs @@ -1,5 +1,4 @@ using System.Collections.Generic; -using System.Diagnostics.CodeAnalysis; using System.Threading.Tasks; namespace Octokit.Clients From 13676d57386028f08dc03837f2a53b7e2eac1ddc Mon Sep 17 00:00:00 2001 From: James R Sconfitto Date: Sun, 3 Nov 2013 23:22:08 -0500 Subject: [PATCH 04/37] Add tests for the starred client --- Octokit.Tests/Clients/StarredClientTests.cs | 39 +++++++++++++++++++++ Octokit.Tests/Octokit.Tests.csproj | 1 + 2 files changed, 40 insertions(+) create mode 100644 Octokit.Tests/Clients/StarredClientTests.cs diff --git a/Octokit.Tests/Clients/StarredClientTests.cs b/Octokit.Tests/Clients/StarredClientTests.cs new file mode 100644 index 00000000..650d4852 --- /dev/null +++ b/Octokit.Tests/Clients/StarredClientTests.cs @@ -0,0 +1,39 @@ +using System; +using NSubstitute; +using Xunit; + +namespace Octokit.Tests.Clients +{ + public class StarredClientTests + { + public class TheGetAllForCurrentMethod + { + [Fact] + public void RequestsCorrectUrl() + { + var endpoint = new Uri("user/starred", UriKind.Relative); + var connection = Substitute.For(); + var client = new StarredClient(connection); + + client.GetAllForCurrent(); + + connection.Received().GetAll(endpoint); + } + } + + public class TheGetAllForUserMethod + { + [Fact] + public void RequestsCorrectUrl() + { + var endpoint = new Uri("users/banana/starred", UriKind.Relative); + var connection = Substitute.For(); + var client = new StarredClient(connection); + + client.GetAllForUser("banana"); + + connection.Received().GetAll(endpoint); + } + } + } +} diff --git a/Octokit.Tests/Octokit.Tests.csproj b/Octokit.Tests/Octokit.Tests.csproj index 7434fab8..b49db2e6 100644 --- a/Octokit.Tests/Octokit.Tests.csproj +++ b/Octokit.Tests/Octokit.Tests.csproj @@ -66,6 +66,7 @@ + From 884d43dc6815f21386379f432fe25c9fa1e76601 Mon Sep 17 00:00:00 2001 From: James R Sconfitto Date: Mon, 4 Nov 2013 13:01:47 -0500 Subject: [PATCH 05/37] Adjust namespacing and docs --- Octokit/Clients/IStarredClient.cs | 2 +- Octokit/Clients/StarsClient.cs | 7 +++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/Octokit/Clients/IStarredClient.cs b/Octokit/Clients/IStarredClient.cs index 646a2999..5539ea6e 100644 --- a/Octokit/Clients/IStarredClient.cs +++ b/Octokit/Clients/IStarredClient.cs @@ -1,7 +1,7 @@ using System.Collections.Generic; using System.Threading.Tasks; -namespace Octokit.Clients +namespace Octokit { interface IStarredClient { diff --git a/Octokit/Clients/StarsClient.cs b/Octokit/Clients/StarsClient.cs index 30dbac9d..77727d25 100644 --- a/Octokit/Clients/StarsClient.cs +++ b/Octokit/Clients/StarsClient.cs @@ -4,7 +4,7 @@ using System.Threading.Tasks; namespace Octokit { - public class StarredClient : ApiClient, Octokit.Clients.IStarredClient + public class StarredClient : ApiClient, IStarredClient { public StarredClient(IApiConnection apiConnection) : base(apiConnection) { @@ -21,10 +21,9 @@ namespace Octokit } /// - /// Retrieves all of the s for the current user specific to the specified repository. + /// Retrieves all of the (ies) starred by the specified user. /// - /// Thrown if the client is not authenticated. - /// A of . + /// A starred by the specified user. public Task> GetAllForUser(string user) { return ApiConnection.GetAll(ApiUrls.Starred(user)); From c9e350c1be0248edf6d8e17449dc63991da22432 Mon Sep 17 00:00:00 2001 From: James R Sconfitto Date: Mon, 4 Nov 2013 22:07:05 -0500 Subject: [PATCH 06/37] Ensure not null --- Octokit/Clients/StarsClient.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Octokit/Clients/StarsClient.cs b/Octokit/Clients/StarsClient.cs index 77727d25..f3aa0c0e 100644 --- a/Octokit/Clients/StarsClient.cs +++ b/Octokit/Clients/StarsClient.cs @@ -26,6 +26,8 @@ namespace Octokit /// A starred by the specified user. public Task> GetAllForUser(string user) { + Ensure.ArgumentNotNull(user, "user"); + return ApiConnection.GetAll(ApiUrls.Starred(user)); } } From fc4b122620e1fc3d9e6a813b49cfa758d1895682 Mon Sep 17 00:00:00 2001 From: James R Sconfitto Date: Mon, 4 Nov 2013 22:08:36 -0500 Subject: [PATCH 07/37] Make sure it's not empty too i guess --- Octokit/Clients/StarsClient.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Octokit/Clients/StarsClient.cs b/Octokit/Clients/StarsClient.cs index f3aa0c0e..532f41ef 100644 --- a/Octokit/Clients/StarsClient.cs +++ b/Octokit/Clients/StarsClient.cs @@ -26,7 +26,7 @@ namespace Octokit /// A starred by the specified user. public Task> GetAllForUser(string user) { - Ensure.ArgumentNotNull(user, "user"); + Ensure.ArgumentNotNullOrEmptyString(user, "user"); return ApiConnection.GetAll(ApiUrls.Starred(user)); } From 6ad6d8ba7743b6a6be5fa6daded2fc493620726f Mon Sep 17 00:00:00 2001 From: James R Sconfitto Date: Tue, 5 Nov 2013 13:07:33 -0500 Subject: [PATCH 08/37] Wow, i'm so bad at this --- Octokit/Octokit.csproj | 1 - 1 file changed, 1 deletion(-) diff --git a/Octokit/Octokit.csproj b/Octokit/Octokit.csproj index 0808bc50..3434535c 100644 --- a/Octokit/Octokit.csproj +++ b/Octokit/Octokit.csproj @@ -66,7 +66,6 @@ - From 8e9b2c8b75e5ff0d4533665546f5c786abe415a0 Mon Sep 17 00:00:00 2001 From: James R Sconfitto Date: Tue, 5 Nov 2013 21:59:40 -0500 Subject: [PATCH 09/37] Project and file name fixups --- Octokit/Clients/{StarsClient.cs => StarredClient.cs} | 0 Octokit/Octokit.csproj | 3 +-- 2 files changed, 1 insertion(+), 2 deletions(-) rename Octokit/Clients/{StarsClient.cs => StarredClient.cs} (100%) diff --git a/Octokit/Clients/StarsClient.cs b/Octokit/Clients/StarredClient.cs similarity index 100% rename from Octokit/Clients/StarsClient.cs rename to Octokit/Clients/StarredClient.cs diff --git a/Octokit/Octokit.csproj b/Octokit/Octokit.csproj index 71f658b8..24c58037 100644 --- a/Octokit/Octokit.csproj +++ b/Octokit/Octokit.csproj @@ -63,12 +63,11 @@ - - + From f244ad39584848b44ec0b31831417fb6817f5514 Mon Sep 17 00:00:00 2001 From: James R Sconfitto Date: Wed, 6 Nov 2013 09:10:27 -0500 Subject: [PATCH 10/37] Add request parameters for star sorting --- Octokit/Clients/StarredClient.cs | 15 ++++++++++++++ Octokit/Models/Request/StarredRequest.cs | 25 ++++++++++++++++++++++++ Octokit/Octokit.csproj | 1 + 3 files changed, 41 insertions(+) create mode 100644 Octokit/Models/Request/StarredRequest.cs diff --git a/Octokit/Clients/StarredClient.cs b/Octokit/Clients/StarredClient.cs index 532f41ef..b8460d96 100644 --- a/Octokit/Clients/StarredClient.cs +++ b/Octokit/Clients/StarredClient.cs @@ -20,6 +20,21 @@ namespace Octokit return ApiConnection.GetAll(ApiUrls.Starred()); } + /// + /// Retrieves all of the starred (ies) for the current user. + /// + /// Star-specific request parameters that sort the resulting stars + /// Thrown if the client is not authenticated. + /// A of . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters", + Justification="But i think i do need star-specific request parameters")] + public Task> GetAllForCurrent(StarredRequest request) + { + Ensure.ArgumentNotNull(request, "request"); + + return ApiConnection.GetAll(ApiUrls.Starred(), request.ToParametersDictionary()); + } + /// /// Retrieves all of the (ies) starred by the specified user. /// diff --git a/Octokit/Models/Request/StarredRequest.cs b/Octokit/Models/Request/StarredRequest.cs new file mode 100644 index 00000000..4d71a41a --- /dev/null +++ b/Octokit/Models/Request/StarredRequest.cs @@ -0,0 +1,25 @@ +using Octokit.Internal; + +namespace Octokit +{ + public class StarredRequest : RequestParameters + { + public StarredRequest() + { + SortProperty = StarredSort.Created; + SortDirection = SortDirection.Ascending; + } + + [Parameter(Key = "sort")] + public StarredSort SortProperty { get; set; } + + [Parameter(Key = "direction")] + public SortDirection SortDirection { get; set; } + } + + public enum StarredSort + { + Created, + Updated + } +} diff --git a/Octokit/Octokit.csproj b/Octokit/Octokit.csproj index 24c58037..60433b36 100644 --- a/Octokit/Octokit.csproj +++ b/Octokit/Octokit.csproj @@ -79,6 +79,7 @@ + From 43ba74f26acb24224208cea71c6977f35f9cb16f Mon Sep 17 00:00:00 2001 From: James R Sconfitto Date: Wed, 6 Nov 2013 21:15:35 -0500 Subject: [PATCH 11/37] Take parameters for stars for a specified user --- Octokit/Clients/StarredClient.cs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/Octokit/Clients/StarredClient.cs b/Octokit/Clients/StarredClient.cs index b8460d96..edd18b6c 100644 --- a/Octokit/Clients/StarredClient.cs +++ b/Octokit/Clients/StarredClient.cs @@ -45,5 +45,20 @@ namespace Octokit return ApiConnection.GetAll(ApiUrls.Starred(user)); } + + /// + /// Retrieves all of the (ies) starred by the specified user. + /// + /// A starred by the specified user. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")] + public Task> GetAllForUser(string user, StarredRequest request) + { + Ensure.ArgumentNotNullOrEmptyString(user, "user"); + Ensure.ArgumentNotNull(request, "request"); + + return ApiConnection.GetAll(ApiUrls.Starred(user), request.ToParametersDictionary()); + } + + } } From 52d4a8b5f4db1dda0a2c6a8420dc34e0f8c998c6 Mon Sep 17 00:00:00 2001 From: James R Sconfitto Date: Wed, 6 Nov 2013 21:40:09 -0500 Subject: [PATCH 12/37] Add stargazers for repository --- Octokit.Tests/Clients/StarredClientTests.cs | 15 +++++++++++++++ Octokit/Clients/StarredClient.cs | 12 ++++++++++-- Octokit/Helpers/ApiUrls.cs | 8 ++++++++ 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/Octokit.Tests/Clients/StarredClientTests.cs b/Octokit.Tests/Clients/StarredClientTests.cs index 650d4852..cb2c045c 100644 --- a/Octokit.Tests/Clients/StarredClientTests.cs +++ b/Octokit.Tests/Clients/StarredClientTests.cs @@ -35,5 +35,20 @@ namespace Octokit.Tests.Clients connection.Received().GetAll(endpoint); } } + + public class TheGetAllStargazersForRepoMethod + { + [Fact] + public void RequestsCorrectUrl() + { + var endpoint = new Uri("repos/fight/club/stargazers", UriKind.Relative); + var connection = Substitute.For(); + var client = new StarredClient(connection); + + client.GetAllStargazers("fight", "club"); + + connection.Received().GetAll(endpoint); + } + } } } diff --git a/Octokit/Clients/StarredClient.cs b/Octokit/Clients/StarredClient.cs index edd18b6c..b1d9b3a3 100644 --- a/Octokit/Clients/StarredClient.cs +++ b/Octokit/Clients/StarredClient.cs @@ -10,6 +10,16 @@ namespace Octokit { } + /// + /// Retrieves all of the starred (ies) for the current user. + /// + /// Thrown if the client is not authenticated. + /// A of . + public Task> GetAllStargazers(string owner, string repo) + { + return ApiConnection.GetAll(ApiUrls.Stargazers(owner, repo)); + } + /// /// Retrieves all of the starred (ies) for the current user. /// @@ -58,7 +68,5 @@ namespace Octokit return ApiConnection.GetAll(ApiUrls.Starred(user), request.ToParametersDictionary()); } - - } } diff --git a/Octokit/Helpers/ApiUrls.cs b/Octokit/Helpers/ApiUrls.cs index 25d998e7..e2028422 100644 --- a/Octokit/Helpers/ApiUrls.cs +++ b/Octokit/Helpers/ApiUrls.cs @@ -358,6 +358,14 @@ namespace Octokit return "repos/{0}/{1}/statuses/{2}".FormatUri(owner, name, reference); } + /// + /// Returns the that lists the starred repositories for the authenticated user. + /// + public static Uri Stargazers(string owner, string repo) + { + return "repos/{0}/{1}/stargazers".FormatUri(owner, repo); + } + /// /// Returns the that lists the starred repositories for the authenticated user. /// From e63c19c82fd9bfe0089e20cab0b8ba3b7a911eee Mon Sep 17 00:00:00 2001 From: James R Sconfitto Date: Wed, 6 Nov 2013 21:42:07 -0500 Subject: [PATCH 13/37] Quick pass of stargazer docs --- Octokit/Clients/StarredClient.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Octokit/Clients/StarredClient.cs b/Octokit/Clients/StarredClient.cs index b1d9b3a3..0d2ee2ff 100644 --- a/Octokit/Clients/StarredClient.cs +++ b/Octokit/Clients/StarredClient.cs @@ -11,10 +11,10 @@ namespace Octokit } /// - /// Retrieves all of the starred (ies) for the current user. + /// Retrieves all of the stargazers for the passed repository. /// /// Thrown if the client is not authenticated. - /// A of . + /// A of . public Task> GetAllStargazers(string owner, string repo) { return ApiConnection.GetAll(ApiUrls.Stargazers(owner, repo)); From 7f9518db8d683d344d80f81d1b0abc5d19c13ccb Mon Sep 17 00:00:00 2001 From: James R Sconfitto Date: Wed, 6 Nov 2013 22:33:03 -0500 Subject: [PATCH 14/37] Add `CheckStarred` method --- Octokit.Tests/Clients/StarredClientTests.cs | 28 +++++++++++++++++++- Octokit/Clients/StarredClient.cs | 29 ++++++++++++++++++++- Octokit/Helpers/ApiUrls.cs | 11 ++++++++ 3 files changed, 66 insertions(+), 2 deletions(-) diff --git a/Octokit.Tests/Clients/StarredClientTests.cs b/Octokit.Tests/Clients/StarredClientTests.cs index cb2c045c..086e335f 100644 --- a/Octokit.Tests/Clients/StarredClientTests.cs +++ b/Octokit.Tests/Clients/StarredClientTests.cs @@ -1,6 +1,10 @@ -using System; +using Octokit.Internal; +using System; +using System.Net; +using System.Threading.Tasks; using NSubstitute; using Xunit; +using Xunit.Extensions; namespace Octokit.Tests.Clients { @@ -50,5 +54,27 @@ namespace Octokit.Tests.Clients connection.Received().GetAll(endpoint); } } + + public class TheCheckStarredMethod + { + [Theory] + [InlineData(HttpStatusCode.NoContent, true)] + [InlineData(HttpStatusCode.NotFound, false)] + public async Task RequestsCorrectValueForStatusCode(HttpStatusCode status, bool expected) + { + var response = Task.Factory.StartNew>(() => + new ApiResponse { StatusCode = status }); + var connection = Substitute.For(); + connection.GetAsync(Arg.Is(u => u.ToString() == "user/starred/yes/no"), + null, null).Returns(response); + var apiConnection = Substitute.For(); + apiConnection.Connection.Returns(connection); + var client = new StarredClient(apiConnection); + + var result = await client.CheckStarred("yes", "no"); + + Assert.Equal(expected, result); + } + } } } diff --git a/Octokit/Clients/StarredClient.cs b/Octokit/Clients/StarredClient.cs index 0d2ee2ff..f3b35338 100644 --- a/Octokit/Clients/StarredClient.cs +++ b/Octokit/Clients/StarredClient.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Net; using System.Threading.Tasks; namespace Octokit @@ -37,7 +38,7 @@ namespace Octokit /// Thrown if the client is not authenticated. /// A of . [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters", - Justification="But i think i do need star-specific request parameters")] + Justification = "But i think i do need star-specific request parameters")] public Task> GetAllForCurrent(StarredRequest request) { Ensure.ArgumentNotNull(request, "request"); @@ -68,5 +69,31 @@ namespace Octokit return ApiConnection.GetAll(ApiUrls.Starred(user), request.ToParametersDictionary()); } + + /// + /// Check if a repository is starred by the current authenticated user + /// + /// The owner of the repository + /// The name of the repository + public async Task CheckStarred(string owner, string repo) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNull(repo, "repo"); + + try + { + var response = await Connection.GetAsync(ApiUrls.CheckStarred(owner, repo), null, null) + .ConfigureAwait(false); + if (response.StatusCode != HttpStatusCode.NotFound && response.StatusCode != HttpStatusCode.NoContent) + { + throw new ApiException("Invalid Status Code returned. Expected a 204 or a 404", response.StatusCode); + } + return response.StatusCode == HttpStatusCode.NoContent; + } + catch (NotFoundException) + { + return false; + } + } } } diff --git a/Octokit/Helpers/ApiUrls.cs b/Octokit/Helpers/ApiUrls.cs index e2028422..37f1645d 100644 --- a/Octokit/Helpers/ApiUrls.cs +++ b/Octokit/Helpers/ApiUrls.cs @@ -383,6 +383,17 @@ namespace Octokit return "users/{0}/starred".FormatUri(user); } + /// + /// Returns the that shows whether the repo is starred by the current user. + /// + /// The owner of the repository + /// The name of the repository + /// + public static Uri CheckStarred(string owner, string repo) + { + return "user/starred/{0}/{1}".FormatUri(owner, repo); + } + /// Returns the for the specified tag. /// /// The owner of the repository From 5b804b6ef94905b012706ab5c3c3538ea221a6bb Mon Sep 17 00:00:00 2001 From: James R Sconfitto Date: Thu, 7 Nov 2013 07:58:09 -0500 Subject: [PATCH 15/37] Adjust some Uri names for starring --- Octokit/Clients/StarredClient.cs | 6 +++--- Octokit/Helpers/ApiUrls.cs | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Octokit/Clients/StarredClient.cs b/Octokit/Clients/StarredClient.cs index f3b35338..cd2958dc 100644 --- a/Octokit/Clients/StarredClient.cs +++ b/Octokit/Clients/StarredClient.cs @@ -54,7 +54,7 @@ namespace Octokit { Ensure.ArgumentNotNullOrEmptyString(user, "user"); - return ApiConnection.GetAll(ApiUrls.Starred(user)); + return ApiConnection.GetAll(ApiUrls.StarredByUser(user)); } /// @@ -67,7 +67,7 @@ namespace Octokit Ensure.ArgumentNotNullOrEmptyString(user, "user"); Ensure.ArgumentNotNull(request, "request"); - return ApiConnection.GetAll(ApiUrls.Starred(user), request.ToParametersDictionary()); + return ApiConnection.GetAll(ApiUrls.StarredByUser(user), request.ToParametersDictionary()); } /// @@ -82,7 +82,7 @@ namespace Octokit try { - var response = await Connection.GetAsync(ApiUrls.CheckStarred(owner, repo), null, null) + var response = await Connection.GetAsync(ApiUrls.Starred(owner, repo), null, null) .ConfigureAwait(false); if (response.StatusCode != HttpStatusCode.NotFound && response.StatusCode != HttpStatusCode.NoContent) { diff --git a/Octokit/Helpers/ApiUrls.cs b/Octokit/Helpers/ApiUrls.cs index 37f1645d..cba5b9f2 100644 --- a/Octokit/Helpers/ApiUrls.cs +++ b/Octokit/Helpers/ApiUrls.cs @@ -378,7 +378,7 @@ namespace Octokit /// Returns the that lists the starred repositories for the specified user. /// /// The user that has the stars - public static Uri Starred(string user) + public static Uri StarredByUser(string user) { return "users/{0}/starred".FormatUri(user); } @@ -389,7 +389,7 @@ namespace Octokit /// The owner of the repository /// The name of the repository /// - public static Uri CheckStarred(string owner, string repo) + public static Uri Starred(string owner, string repo) { return "user/starred/{0}/{1}".FormatUri(owner, repo); } From 77cbd28194ffbbdd43a5ae86b95592957de466e8 Mon Sep 17 00:00:00 2001 From: James R Sconfitto Date: Thu, 7 Nov 2013 21:43:58 -0500 Subject: [PATCH 16/37] Add ability to star a repository --- Octokit/Clients/StarredClient.cs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/Octokit/Clients/StarredClient.cs b/Octokit/Clients/StarredClient.cs index cd2958dc..168fcf0f 100644 --- a/Octokit/Clients/StarredClient.cs +++ b/Octokit/Clients/StarredClient.cs @@ -95,5 +95,26 @@ namespace Octokit return false; } } + + public async Task StarRepo(string owner, string repo) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNull(repo, "repo"); + + try + { + var response = await Connection.PutAsync(ApiUrls.Starred(owner, repo), null, null) + .ConfigureAwait(false); + if (response.StatusCode != HttpStatusCode.NotFound && response.StatusCode != HttpStatusCode.NoContent) + { + throw new ApiException("Invalid Status Code returned. Expected a 204 or a 404", response.StatusCode); + } + return response.StatusCode == HttpStatusCode.NoContent; + } + catch (NotFoundException) + { + return false; + } + } } } From ff136ee82472327457f4c5f4ea189b73bc14eb1f Mon Sep 17 00:00:00 2001 From: James R Sconfitto Date: Fri, 8 Nov 2013 07:51:51 -0500 Subject: [PATCH 17/37] Add ability to stop starring a repository Change the `DeleteAsync` method to return `Task>` in order to check the status code --- Octokit/Clients/StarredClient.cs | 22 ++++++++++++++++++++++ Octokit/Http/Connection.cs | 2 +- Octokit/Http/IConnection.cs | 2 +- 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/Octokit/Clients/StarredClient.cs b/Octokit/Clients/StarredClient.cs index 168fcf0f..6e24af1f 100644 --- a/Octokit/Clients/StarredClient.cs +++ b/Octokit/Clients/StarredClient.cs @@ -116,5 +116,27 @@ namespace Octokit return false; } } + + public async Task RemoveStarFromRepo(string owner, string repo) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNull(repo, "repo"); + + try + { + var response = await Connection.DeleteAsync(ApiUrls.Starred(owner, repo)) + .ConfigureAwait(false); + + if (response.StatusCode != HttpStatusCode.NotFound && response.StatusCode != HttpStatusCode.NoContent) + { + throw new ApiException("Invalid Status Code returned. Expected a 204 or a 404", response.StatusCode); + } + return response.StatusCode == HttpStatusCode.NoContent; + } + catch (NotFoundException) + { + return false ; + } + } } } diff --git a/Octokit/Http/Connection.cs b/Octokit/Http/Connection.cs index 36fcb14a..11179137 100644 --- a/Octokit/Http/Connection.cs +++ b/Octokit/Http/Connection.cs @@ -205,7 +205,7 @@ namespace Octokit return Run(request); } - public Task DeleteAsync(Uri uri) + public Task> DeleteAsync(Uri uri) { Ensure.ArgumentNotNull(uri, "uri"); diff --git a/Octokit/Http/IConnection.cs b/Octokit/Http/IConnection.cs index 548da217..dfc0681f 100644 --- a/Octokit/Http/IConnection.cs +++ b/Octokit/Http/IConnection.cs @@ -13,7 +13,7 @@ namespace Octokit Task> PutAsync(Uri uri, object body); Task> PutAsync(Uri uri, object body, string twoFactorAuthenticationCode); - Task DeleteAsync(Uri uri); + Task> DeleteAsync(Uri uri); Uri BaseAddress { get; } From 4082746925a292879831c199823e1eba1fb090f7 Mon Sep 17 00:00:00 2001 From: James R Sconfitto Date: Fri, 8 Nov 2013 08:57:41 -0500 Subject: [PATCH 18/37] Add star-related files to all projects --- Octokit.Tests/OctoKit.Tests-NetCore45.csproj | 1 + Octokit/Octokit-Mono.csproj | 3 +++ Octokit/Octokit-netcore45.csproj | 3 +++ 3 files changed, 7 insertions(+) diff --git a/Octokit.Tests/OctoKit.Tests-NetCore45.csproj b/Octokit.Tests/OctoKit.Tests-NetCore45.csproj index 9604328c..7f71dd98 100644 --- a/Octokit.Tests/OctoKit.Tests-NetCore45.csproj +++ b/Octokit.Tests/OctoKit.Tests-NetCore45.csproj @@ -66,6 +66,7 @@ + diff --git a/Octokit/Octokit-Mono.csproj b/Octokit/Octokit-Mono.csproj index 5db7e288..8e006709 100644 --- a/Octokit/Octokit-Mono.csproj +++ b/Octokit/Octokit-Mono.csproj @@ -55,9 +55,11 @@ + + @@ -70,6 +72,7 @@ + diff --git a/Octokit/Octokit-netcore45.csproj b/Octokit/Octokit-netcore45.csproj index ed5fbb5f..3b645d7e 100644 --- a/Octokit/Octokit-netcore45.csproj +++ b/Octokit/Octokit-netcore45.csproj @@ -75,6 +75,7 @@ + @@ -86,6 +87,7 @@ + @@ -153,6 +155,7 @@ + From ffbe00d4bc3b91c49fb7357f61d554ea70b3e218 Mon Sep 17 00:00:00 2001 From: James R Sconfitto Date: Fri, 8 Nov 2013 12:59:31 -0500 Subject: [PATCH 19/37] Fix projects to include all necessary files --- Octokit/Octokit-MonoAndroid.csproj | 7 +++++-- Octokit/Octokit-Monotouch.csproj | 7 +++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/Octokit/Octokit-MonoAndroid.csproj b/Octokit/Octokit-MonoAndroid.csproj index 0847f4a8..564f27d3 100644 --- a/Octokit/Octokit-MonoAndroid.csproj +++ b/Octokit/Octokit-MonoAndroid.csproj @@ -1,4 +1,4 @@ - + Debug @@ -213,6 +213,9 @@ + + + - + \ No newline at end of file diff --git a/Octokit/Octokit-Monotouch.csproj b/Octokit/Octokit-Monotouch.csproj index 37824954..c643883b 100644 --- a/Octokit/Octokit-Monotouch.csproj +++ b/Octokit/Octokit-Monotouch.csproj @@ -1,4 +1,4 @@ - + Debug @@ -208,6 +208,9 @@ + + + - + \ No newline at end of file From a8e47d323f992a05de50a3c072ffba6f246c71fe Mon Sep 17 00:00:00 2001 From: James R Sconfitto Date: Fri, 8 Nov 2013 18:35:41 -0500 Subject: [PATCH 20/37] Code review fixes * Add all `StarredClient` methods to the interface * Add xml doc comments * Correct parameter names --- Octokit/Clients/IStarredClient.cs | 59 +++++++++++++++++++++++++++++-- Octokit/Clients/StarredClient.cs | 54 ++++++++++++++++++++-------- 2 files changed, 95 insertions(+), 18 deletions(-) diff --git a/Octokit/Clients/IStarredClient.cs b/Octokit/Clients/IStarredClient.cs index 5539ea6e..d2c7c646 100644 --- a/Octokit/Clients/IStarredClient.cs +++ b/Octokit/Clients/IStarredClient.cs @@ -6,16 +6,69 @@ namespace Octokit interface IStarredClient { /// - /// Retrieves all of the starred (ies) for the authenticated user. + /// Retrieves all of the stargazers for the passed repository. + /// + /// The owner of the repository + /// The name of the repository + /// Thrown if the client is not authenticated. + /// A of . + Task> GetAllStargazers(string owner, string name); + + /// + /// Retrieves all of the starred (ies) for the current user. /// /// Thrown if the client is not authenticated. /// A of . Task> GetAllForCurrent(); /// - /// Retrieves all of the (ies) starred by the passed user. + /// Retrieves all of the starred (ies) for the current user. /// - /// A of . + /// Star-specific request parameters that sort the results + /// Thrown if the client is not authenticated. + /// A of . + Task> GetAllForCurrent(StarredRequest request); + + /// + /// Retrieves all of the (ies) starred by the specified user. + /// + /// The login of the user + /// Thrown if the client is not authenticated. + /// A starred by the specified user. Task> GetAllForUser(string user); + + /// + /// Retrieves all of the (ies) starred by the specified user. + /// + /// The login of the user + /// Star-specific request parameters that sort the results + /// Thrown if the client is not authenticated. + /// A starred by the specified user. + Task> GetAllForUser(string user, StarredRequest request); + + /// + /// Check if a repository is starred by the current authenticated user. + /// + /// The owner of the repository + /// The name of the repository + /// Thrown if the client is not authenticated. + /// A bool representing the success of the operation + Task CheckStarred(string owner, string name); + + /// + /// Stars a repository for the authenticated user. + /// + /// The owner of the repository to star + /// The name of the repository to star + /// A bool representing the success of starring + Task StarRepo(string owner, string name); + + /// + /// Unstars a repository for the authenticated user. + /// + /// The owner of the repository to unstar + /// The name of the repository to unstar + /// A bool representing the success of the operation + Task RemoveStarFromRepo(string owner, string name); } } diff --git a/Octokit/Clients/StarredClient.cs b/Octokit/Clients/StarredClient.cs index 6e24af1f..cedb2cc8 100644 --- a/Octokit/Clients/StarredClient.cs +++ b/Octokit/Clients/StarredClient.cs @@ -14,11 +14,16 @@ namespace Octokit /// /// Retrieves all of the stargazers for the passed repository. /// + /// The owner of the repository + /// The name of the repository /// Thrown if the client is not authenticated. /// A of . - public Task> GetAllStargazers(string owner, string repo) + public Task> GetAllStargazers(string owner, string name) { - return ApiConnection.GetAll(ApiUrls.Stargazers(owner, repo)); + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + + return ApiConnection.GetAll(ApiUrls.Stargazers(owner, name)); } /// @@ -34,7 +39,7 @@ namespace Octokit /// /// Retrieves all of the starred (ies) for the current user. /// - /// Star-specific request parameters that sort the resulting stars + /// Star-specific request parameters that sort the results /// Thrown if the client is not authenticated. /// A of . [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters", @@ -49,6 +54,8 @@ namespace Octokit /// /// Retrieves all of the (ies) starred by the specified user. /// + /// The login of the user + /// Thrown if the client is not authenticated. /// A starred by the specified user. public Task> GetAllForUser(string user) { @@ -60,6 +67,9 @@ namespace Octokit /// /// Retrieves all of the (ies) starred by the specified user. /// + /// The login of the user + /// Star-specific request parameters that sort the results + /// Thrown if the client is not authenticated. /// A starred by the specified user. [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")] public Task> GetAllForUser(string user, StarredRequest request) @@ -71,18 +81,20 @@ namespace Octokit } /// - /// Check if a repository is starred by the current authenticated user + /// Check if a repository is starred by the current authenticated user. /// /// The owner of the repository - /// The name of the repository - public async Task CheckStarred(string owner, string repo) + /// The name of the repository + /// Thrown if the client is not authenticated. + /// A bool representing the success of the operation + public async Task CheckStarred(string owner, string name) { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); - Ensure.ArgumentNotNull(repo, "repo"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); try { - var response = await Connection.GetAsync(ApiUrls.Starred(owner, repo), null, null) + var response = await Connection.GetAsync(ApiUrls.Starred(owner, name), null, null) .ConfigureAwait(false); if (response.StatusCode != HttpStatusCode.NotFound && response.StatusCode != HttpStatusCode.NoContent) { @@ -96,14 +108,20 @@ namespace Octokit } } - public async Task StarRepo(string owner, string repo) + /// + /// Stars a repository for the authenticated user. + /// + /// The owner of the repository to star + /// The name of the repository to star + /// A bool representing the success of starring the repository. + public async Task StarRepo(string owner, string name) { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); - Ensure.ArgumentNotNull(repo, "repo"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); try { - var response = await Connection.PutAsync(ApiUrls.Starred(owner, repo), null, null) + var response = await Connection.PutAsync(ApiUrls.Starred(owner, name), null, null) .ConfigureAwait(false); if (response.StatusCode != HttpStatusCode.NotFound && response.StatusCode != HttpStatusCode.NoContent) { @@ -117,14 +135,20 @@ namespace Octokit } } - public async Task RemoveStarFromRepo(string owner, string repo) + /// + /// Unstars a repository for the authenticated user. + /// + /// The owner of the repository to unstar + /// The name of the repository to unstar + /// A bool representing the success of unstarring the repository. + public async Task RemoveStarFromRepo(string owner, string name) { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); - Ensure.ArgumentNotNull(repo, "repo"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); try { - var response = await Connection.DeleteAsync(ApiUrls.Starred(owner, repo)) + var response = await Connection.DeleteAsync(ApiUrls.Starred(owner, name)) .ConfigureAwait(false); if (response.StatusCode != HttpStatusCode.NotFound && response.StatusCode != HttpStatusCode.NoContent) @@ -135,7 +159,7 @@ namespace Octokit } catch (NotFoundException) { - return false ; + return false; } } } From cdad0ad809816d6891333864276753fb9ab75e64 Mon Sep 17 00:00:00 2001 From: James R Sconfitto Date: Sat, 9 Nov 2013 10:46:46 -0500 Subject: [PATCH 21/37] Return a status code from Delete requests --- Octokit.Tests/Http/ApiConnectionTests.cs | 5 +++-- Octokit/Http/Connection.cs | 11 +++++++++-- Octokit/Http/IConnection.cs | 3 ++- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/Octokit.Tests/Http/ApiConnectionTests.cs b/Octokit.Tests/Http/ApiConnectionTests.cs index 9b5df215..d76967f8 100644 --- a/Octokit.Tests/Http/ApiConnectionTests.cs +++ b/Octokit.Tests/Http/ApiConnectionTests.cs @@ -1,4 +1,5 @@ using System; +using System.Net; using System.Collections.Generic; using System.IO; using System.Threading.Tasks; @@ -248,9 +249,9 @@ namespace Octokit.Tests.Http public async Task MakesDeleteRequest() { var deleteUri = new Uri("anything", UriKind.Relative); - IResponse response = new ApiResponse {BodyAsObject = new object()}; + HttpStatusCode statusCode = HttpStatusCode.NoContent; var connection = Substitute.For(); - connection.DeleteAsync(Args.Uri).Returns(Task.FromResult(response)); + connection.DeleteAsync(Args.Uri).Returns(Task.FromResult(statusCode)); var apiConnection = new ApiConnection(connection); await apiConnection.Delete(deleteUri); diff --git a/Octokit/Http/Connection.cs b/Octokit/Http/Connection.cs index 0a967530..edf77ee7 100644 --- a/Octokit/Http/Connection.cs +++ b/Octokit/Http/Connection.cs @@ -205,11 +205,11 @@ namespace Octokit return Run(request); } - public Task> DeleteAsync(Uri uri) + public Task DeleteAsync(Uri uri) { Ensure.ArgumentNotNull(uri, "uri"); - return Run(new Request + return RunForStatus(new Request { Method = HttpMethod.Delete, BaseAddress = BaseAddress, @@ -257,6 +257,13 @@ namespace Octokit return RunRequest(request); } + async Task RunForStatus(IRequest request) + { + _jsonPipeline.SerializeRequest(request); + var response = await RunRequest(request).ConfigureAwait(false); + return response.StatusCode; + } + async Task> Run(IRequest request) { _jsonPipeline.SerializeRequest(request); diff --git a/Octokit/Http/IConnection.cs b/Octokit/Http/IConnection.cs index dfc0681f..6d513ba8 100644 --- a/Octokit/Http/IConnection.cs +++ b/Octokit/Http/IConnection.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Net; using System.Threading.Tasks; namespace Octokit @@ -13,7 +14,7 @@ namespace Octokit Task> PutAsync(Uri uri, object body); Task> PutAsync(Uri uri, object body, string twoFactorAuthenticationCode); - Task> DeleteAsync(Uri uri); + Task DeleteAsync(Uri uri); Uri BaseAddress { get; } From a53a76484b27b3985b66792de84776354ccdd613 Mon Sep 17 00:00:00 2001 From: James R Sconfitto Date: Sat, 9 Nov 2013 10:49:11 -0500 Subject: [PATCH 22/37] Adjust for new delete request signature --- Octokit/Clients/StarredClient.cs | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/Octokit/Clients/StarredClient.cs b/Octokit/Clients/StarredClient.cs index cedb2cc8..06e46c53 100644 --- a/Octokit/Clients/StarredClient.cs +++ b/Octokit/Clients/StarredClient.cs @@ -96,10 +96,7 @@ namespace Octokit { var response = await Connection.GetAsync(ApiUrls.Starred(owner, name), null, null) .ConfigureAwait(false); - if (response.StatusCode != HttpStatusCode.NotFound && response.StatusCode != HttpStatusCode.NoContent) - { - throw new ApiException("Invalid Status Code returned. Expected a 204 or a 404", response.StatusCode); - } + return response.StatusCode == HttpStatusCode.NoContent; } catch (NotFoundException) @@ -123,10 +120,7 @@ namespace Octokit { var response = await Connection.PutAsync(ApiUrls.Starred(owner, name), null, null) .ConfigureAwait(false); - if (response.StatusCode != HttpStatusCode.NotFound && response.StatusCode != HttpStatusCode.NoContent) - { - throw new ApiException("Invalid Status Code returned. Expected a 204 or a 404", response.StatusCode); - } + return response.StatusCode == HttpStatusCode.NoContent; } catch (NotFoundException) @@ -148,14 +142,10 @@ namespace Octokit try { - var response = await Connection.DeleteAsync(ApiUrls.Starred(owner, name)) - .ConfigureAwait(false); + var statusCode = await Connection.DeleteAsync(ApiUrls.Starred(owner, name)) + .ConfigureAwait(false); - if (response.StatusCode != HttpStatusCode.NotFound && response.StatusCode != HttpStatusCode.NoContent) - { - throw new ApiException("Invalid Status Code returned. Expected a 204 or a 404", response.StatusCode); - } - return response.StatusCode == HttpStatusCode.NoContent; + return statusCode == HttpStatusCode.NoContent; } catch (NotFoundException) { From 09e422b0eaf7d11408c3e3fd020085d9f9ce183c Mon Sep 17 00:00:00 2001 From: James R Sconfitto Date: Sat, 9 Nov 2013 12:25:58 -0500 Subject: [PATCH 23/37] Format test code --- Octokit.Tests/Clients/StarredClientTests.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Octokit.Tests/Clients/StarredClientTests.cs b/Octokit.Tests/Clients/StarredClientTests.cs index 086e335f..efb582cd 100644 --- a/Octokit.Tests/Clients/StarredClientTests.cs +++ b/Octokit.Tests/Clients/StarredClientTests.cs @@ -60,17 +60,17 @@ namespace Octokit.Tests.Clients [Theory] [InlineData(HttpStatusCode.NoContent, true)] [InlineData(HttpStatusCode.NotFound, false)] - public async Task RequestsCorrectValueForStatusCode(HttpStatusCode status, bool expected) + public async Task ReturnsCorrectResultBasedOnStatus(HttpStatusCode status, bool expected) { var response = Task.Factory.StartNew>(() => new ApiResponse { StatusCode = status }); var connection = Substitute.For(); - connection.GetAsync(Arg.Is(u => u.ToString() == "user/starred/yes/no"), - null, null).Returns(response); + connection.GetAsync(Arg.Is(u => u.ToString() == "user/starred/yes/no"), null, null) + .Returns(response); var apiConnection = Substitute.For(); apiConnection.Connection.Returns(connection); - var client = new StarredClient(apiConnection); + var client = new StarredClient(apiConnection); var result = await client.CheckStarred("yes", "no"); Assert.Equal(expected, result); From 2acc03172592e61ffa463b2a3ec87ff7748d0ebb Mon Sep 17 00:00:00 2001 From: James R Sconfitto Date: Sat, 9 Nov 2013 12:26:19 -0500 Subject: [PATCH 24/37] Add test for `RemoveStarFromRepo` method --- Octokit.Tests/Clients/StarredClientTests.cs | 24 +++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/Octokit.Tests/Clients/StarredClientTests.cs b/Octokit.Tests/Clients/StarredClientTests.cs index efb582cd..89b46ce3 100644 --- a/Octokit.Tests/Clients/StarredClientTests.cs +++ b/Octokit.Tests/Clients/StarredClientTests.cs @@ -76,5 +76,29 @@ namespace Octokit.Tests.Clients Assert.Equal(expected, result); } } + + public class TheRemoveStarFromRepoMethod + { + [Theory] + [InlineData(HttpStatusCode.NoContent, true)] + [InlineData(HttpStatusCode.NotFound, false)] + [InlineData(HttpStatusCode.OK, false)] + public async Task ReturnsCorrectResultBasedOnStatus(HttpStatusCode status, bool expected) + { + var response = Task.Factory.StartNew(() => status); + + var connection = Substitute.For(); + connection.DeleteAsync(Arg.Is(u => u.ToString() == "user/starred/yes/no")) + .Returns(response); + + var apiConnection = Substitute.For(); + apiConnection.Connection.Returns(connection); + + var client = new StarredClient(apiConnection); + var result = await client.RemoveStarFromRepo("yes", "no"); + + Assert.Equal(expected, result); + } + } } } From ea007ca3d0b7c86869c0a95027ecc436b04718b8 Mon Sep 17 00:00:00 2001 From: James R Sconfitto Date: Sat, 9 Nov 2013 12:54:42 -0500 Subject: [PATCH 25/37] Add test for `StarRepo` --- Octokit.Tests/Clients/StarredClientTests.cs | 24 +++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/Octokit.Tests/Clients/StarredClientTests.cs b/Octokit.Tests/Clients/StarredClientTests.cs index 89b46ce3..6f21e19f 100644 --- a/Octokit.Tests/Clients/StarredClientTests.cs +++ b/Octokit.Tests/Clients/StarredClientTests.cs @@ -77,6 +77,30 @@ namespace Octokit.Tests.Clients } } + public class TheStarRepoMethod + { + [Theory] + [InlineData(HttpStatusCode.NoContent, true)] + [InlineData(HttpStatusCode.NotFound, false)] + public async Task ReturnsCorrectResultBasedOnStatus(HttpStatusCode status, bool expected) + { + var response = Task.Factory.StartNew>(() => + new ApiResponse { StatusCode = status }); + + var connection = Substitute.For(); + connection.PutAsync(Arg.Is(u => u.ToString() == "user/starred/yes/no"), + Args.Object, Args.String).Returns(response); + + var apiConnection = Substitute.For(); + apiConnection.Connection.Returns(connection); + + var client = new StarredClient(apiConnection); + var result = await client.StarRepo("yes", "no"); + + Assert.Equal(expected, result); + } + } + public class TheRemoveStarFromRepoMethod { [Theory] From c1e022a77cba07df438f519dc98dac063deccf42 Mon Sep 17 00:00:00 2001 From: James R Sconfitto Date: Sat, 9 Nov 2013 13:00:29 -0500 Subject: [PATCH 26/37] Add theory case --- Octokit.Tests/Clients/StarredClientTests.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/Octokit.Tests/Clients/StarredClientTests.cs b/Octokit.Tests/Clients/StarredClientTests.cs index 6f21e19f..7203f2fc 100644 --- a/Octokit.Tests/Clients/StarredClientTests.cs +++ b/Octokit.Tests/Clients/StarredClientTests.cs @@ -82,6 +82,7 @@ namespace Octokit.Tests.Clients [Theory] [InlineData(HttpStatusCode.NoContent, true)] [InlineData(HttpStatusCode.NotFound, false)] + [InlineData(HttpStatusCode.OK, false)] public async Task ReturnsCorrectResultBasedOnStatus(HttpStatusCode status, bool expected) { var response = Task.Factory.StartNew>(() => From 2ae91349a8878bc45dbd12baaf84084d801fe46f Mon Sep 17 00:00:00 2001 From: James R Sconfitto Date: Sat, 9 Nov 2013 17:56:58 -0500 Subject: [PATCH 27/37] Add the starred client to the GitHub client --- Octokit/GitHubClient.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Octokit/GitHubClient.cs b/Octokit/GitHubClient.cs index 9bbcd384..1dbbd359 100644 --- a/Octokit/GitHubClient.cs +++ b/Octokit/GitHubClient.cs @@ -89,6 +89,7 @@ namespace Octokit Release = new ReleasesClient(apiConnection); User = new UsersClient(apiConnection); SshKey = new SshKeysClient(apiConnection); + Star = new StarredClient(apiConnection); GitDatabase = new GitDatabaseClient(apiConnection); } @@ -134,6 +135,7 @@ namespace Octokit public IRepositoriesClient Repository { get; private set; } public IReleasesClient Release { get; private set; } public ISshKeysClient SshKey { get; private set; } + public IStarredClient Star { get; private set; } public IUsersClient User { get; private set; } public INotificationsClient Notification { get; private set; } public IGitDatabaseClient GitDatabase { get; private set; } From 4ce2e0e4df2d2a118363617ab6d5851f02f585af Mon Sep 17 00:00:00 2001 From: James R Sconfitto Date: Sat, 9 Nov 2013 18:07:34 -0500 Subject: [PATCH 28/37] Add star into interface --- Octokit/IGitHubClient.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/Octokit/IGitHubClient.cs b/Octokit/IGitHubClient.cs index c8586208..f8e8e49e 100644 --- a/Octokit/IGitHubClient.cs +++ b/Octokit/IGitHubClient.cs @@ -14,6 +14,7 @@ namespace Octokit IRepositoriesClient Repository { get; } IReleasesClient Release { get; } ISshKeysClient SshKey { get; } + IStarredClient Star { get; } IUsersClient User { get; } INotificationsClient Notification { get; } IGitDatabaseClient GitDatabase { get; } From 1c26f5e683aa364a17c5ba7e759f496a7fde7661 Mon Sep 17 00:00:00 2001 From: James R Sconfitto Date: Sat, 9 Nov 2013 18:15:41 -0500 Subject: [PATCH 29/37] Oops! Thanks Code Analysis :thumbsup: --- Octokit/Clients/IStarredClient.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Octokit/Clients/IStarredClient.cs b/Octokit/Clients/IStarredClient.cs index d2c7c646..ffb8695c 100644 --- a/Octokit/Clients/IStarredClient.cs +++ b/Octokit/Clients/IStarredClient.cs @@ -3,7 +3,7 @@ using System.Threading.Tasks; namespace Octokit { - interface IStarredClient + public interface IStarredClient { /// /// Retrieves all of the stargazers for the passed repository. From 55ebcb88b205d0162f2413f26cadffd75b75b78f Mon Sep 17 00:00:00 2001 From: Brendan Forster Date: Sat, 9 Nov 2013 10:38:58 -0600 Subject: [PATCH 30/37] kill the duplication of the setup --- .../ReleasesClientTests.cs | 29 ++++++++++++------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/Octokit.Tests.Integration/ReleasesClientTests.cs b/Octokit.Tests.Integration/ReleasesClientTests.cs index 788b91e0..e78a5df4 100644 --- a/Octokit.Tests.Integration/ReleasesClientTests.cs +++ b/Octokit.Tests.Integration/ReleasesClientTests.cs @@ -1,4 +1,5 @@ -using System.Linq; +using System; +using System.Linq; using System.Net.Http.Headers; using System.Threading.Tasks; using Xunit; @@ -7,17 +8,23 @@ namespace Octokit.Tests.Integration { public class ReleasesClientTests { - public class TheGetReleasesMethod + public class TheGetReleasesMethod : IDisposable { - [IntegrationTest] - public async Task ReturnsReleases() + readonly IReleasesClient _releaseClient; + + public TheGetReleasesMethod() { var github = new GitHubClient(new ProductHeaderValue("OctokitTests")) { Credentials = Helper.Credentials }; + _releaseClient = github.Release; + } - var releases = await github.Release.GetAll("git-tfs", "git-tfs"); + [IntegrationTest] + public async Task ReturnsReleases() + { + var releases = await _releaseClient.GetAll("git-tfs", "git-tfs"); Assert.True(releases.Count > 5); Assert.True(releases.Any(release => release.TagName == "v0.18.0")); @@ -26,16 +33,16 @@ namespace Octokit.Tests.Integration [IntegrationTest] public async Task ReturnsReleasesWithNullPublishDate() { - var github = new GitHubClient(new ProductHeaderValue("OctokitTests")) - { - Credentials = Helper.Credentials - }; - - var releases = await github.Release.GetAll("Particular", "ServiceInsight"); + var releases = await _releaseClient.GetAll("Particular", "ServiceInsight"); Assert.True(releases.Count == 1); Assert.False(releases.First().PublishedAt.HasValue); } + + public void Dispose() + { + + } } } } From c35f773f025f5fb4bbc46e365f100372f7f3c33f Mon Sep 17 00:00:00 2001 From: Brendan Forster Date: Sat, 9 Nov 2013 17:03:06 -0600 Subject: [PATCH 31/37] defined Release integration test and placeholders --- .../ReleasesClientTests.cs | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/Octokit.Tests.Integration/ReleasesClientTests.cs b/Octokit.Tests.Integration/ReleasesClientTests.cs index e78a5df4..b3182593 100644 --- a/Octokit.Tests.Integration/ReleasesClientTests.cs +++ b/Octokit.Tests.Integration/ReleasesClientTests.cs @@ -11,6 +11,9 @@ namespace Octokit.Tests.Integration public class TheGetReleasesMethod : IDisposable { readonly IReleasesClient _releaseClient; + readonly Repository _repository; + readonly string _repositoryOwner; + readonly string _repositoryName; public TheGetReleasesMethod() { @@ -19,6 +22,19 @@ namespace Octokit.Tests.Integration Credentials = Helper.Credentials }; _releaseClient = github.Release; + + var repoName = Helper.MakeNameWithTimestamp("public-repo"); + _repository = github.Repository.Create(new NewRepository { Name = repoName }).Result; + _repositoryOwner = _repository.Owner.Login; + _repositoryName = _repository.Name; + + // TODO: create test blob + // TODO: create test tree + // TODO: create test commit + // TODO: update master reference to latest commit + + var releaseWithNoUpdate = new ReleaseUpdate("0.1"); + var release = github.Release.CreateRelease(_repositoryOwner, _repositoryName, releaseWithNoUpdate).Result; } [IntegrationTest] @@ -33,7 +49,7 @@ namespace Octokit.Tests.Integration [IntegrationTest] public async Task ReturnsReleasesWithNullPublishDate() { - var releases = await _releaseClient.GetAll("Particular", "ServiceInsight"); + var releases = await _releaseClient.GetAll(_repositoryOwner, _repositoryName); Assert.True(releases.Count == 1); Assert.False(releases.First().PublishedAt.HasValue); @@ -41,7 +57,7 @@ namespace Octokit.Tests.Integration public void Dispose() { - + Helper.DeleteRepo(_repository); } } } From d99c3b691f7dd6e2e15c19920609f3bc9895ed02 Mon Sep 17 00:00:00 2001 From: Brendan Forster Date: Sun, 10 Nov 2013 00:18:26 -0600 Subject: [PATCH 32/37] thank you @haacked for showing me the light --- .../ReleasesClientTests.cs | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/Octokit.Tests.Integration/ReleasesClientTests.cs b/Octokit.Tests.Integration/ReleasesClientTests.cs index b3182593..ebe9c8a8 100644 --- a/Octokit.Tests.Integration/ReleasesClientTests.cs +++ b/Octokit.Tests.Integration/ReleasesClientTests.cs @@ -14,27 +14,20 @@ namespace Octokit.Tests.Integration readonly Repository _repository; readonly string _repositoryOwner; readonly string _repositoryName; + readonly GitHubClient _github; public TheGetReleasesMethod() { - var github = new GitHubClient(new ProductHeaderValue("OctokitTests")) + _github = new GitHubClient(new ProductHeaderValue("OctokitTests")) { Credentials = Helper.Credentials }; - _releaseClient = github.Release; + _releaseClient = _github.Release; var repoName = Helper.MakeNameWithTimestamp("public-repo"); - _repository = github.Repository.Create(new NewRepository { Name = repoName }).Result; + _repository = _github.Repository.Create(new NewRepository { Name = repoName, AutoInit = true }).Result; _repositoryOwner = _repository.Owner.Login; _repositoryName = _repository.Name; - - // TODO: create test blob - // TODO: create test tree - // TODO: create test commit - // TODO: update master reference to latest commit - - var releaseWithNoUpdate = new ReleaseUpdate("0.1"); - var release = github.Release.CreateRelease(_repositoryOwner, _repositoryName, releaseWithNoUpdate).Result; } [IntegrationTest] @@ -49,6 +42,10 @@ namespace Octokit.Tests.Integration [IntegrationTest] public async Task ReturnsReleasesWithNullPublishDate() { + // create a release without a publish date + var releaseWithNoUpdate = new ReleaseUpdate("0.1") { Draft = true }; + var release = _releaseClient.CreateRelease(_repositoryOwner, _repositoryName, releaseWithNoUpdate).Result; + var releases = await _releaseClient.GetAll(_repositoryOwner, _repositoryName); Assert.True(releases.Count == 1); From 9365158c33a5843ef5aee49b3913189a8c846574 Mon Sep 17 00:00:00 2001 From: Steffen Forkmann Date: Sun, 10 Nov 2013 16:52:52 +0100 Subject: [PATCH 33/37] Use the new "FixProjectFiles" task which adds missing files to the projects and also removes duplicates. --- build.fsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.fsx b/build.fsx index 28248f33..8d37b39e 100644 --- a/build.fsx +++ b/build.fsx @@ -47,7 +47,7 @@ Target "CheckProjects" (fun _ -> Target "FixProjects" (fun _ -> !! "./Octokit/Octokit*.csproj" - |> Fake.MSBuild.ProjectSystem.FixMissingFiles "./Octokit/Octokit.csproj" + |> Fake.MSBuild.ProjectSystem.FixProjectFiles "./Octokit/Octokit.csproj" ) Target "BuildApp" (fun _ -> From 8c231da69f56d9bfd902790cba61ef19cb1613db Mon Sep 17 00:00:00 2001 From: James R Sconfitto Date: Sun, 10 Nov 2013 13:18:27 -0500 Subject: [PATCH 34/37] Move Starring into Activities It's where it belongs. --- Octokit/Clients/ActivitiesClient.cs | 2 ++ Octokit/Clients/IActivitiesClient.cs | 1 + Octokit/GitHubClient.cs | 2 -- Octokit/IGitHubClient.cs | 1 - 4 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Octokit/Clients/ActivitiesClient.cs b/Octokit/Clients/ActivitiesClient.cs index ade4ac5d..bf07a291 100644 --- a/Octokit/Clients/ActivitiesClient.cs +++ b/Octokit/Clients/ActivitiesClient.cs @@ -6,8 +6,10 @@ : base(apiConnection) { Events = new EventsClient(apiConnection); + Starring = new StarredClient(apiConnection); } public IEventsClient Events { get; private set; } + public IStarredClient Starring { get; private set; } } } diff --git a/Octokit/Clients/IActivitiesClient.cs b/Octokit/Clients/IActivitiesClient.cs index 81c4f294..ad1e4fcc 100644 --- a/Octokit/Clients/IActivitiesClient.cs +++ b/Octokit/Clients/IActivitiesClient.cs @@ -3,5 +3,6 @@ public interface IActivitiesClient { IEventsClient Events { get; } + IStarredClient Starring { get; } } } \ No newline at end of file diff --git a/Octokit/GitHubClient.cs b/Octokit/GitHubClient.cs index 1dbbd359..9bbcd384 100644 --- a/Octokit/GitHubClient.cs +++ b/Octokit/GitHubClient.cs @@ -89,7 +89,6 @@ namespace Octokit Release = new ReleasesClient(apiConnection); User = new UsersClient(apiConnection); SshKey = new SshKeysClient(apiConnection); - Star = new StarredClient(apiConnection); GitDatabase = new GitDatabaseClient(apiConnection); } @@ -135,7 +134,6 @@ namespace Octokit public IRepositoriesClient Repository { get; private set; } public IReleasesClient Release { get; private set; } public ISshKeysClient SshKey { get; private set; } - public IStarredClient Star { get; private set; } public IUsersClient User { get; private set; } public INotificationsClient Notification { get; private set; } public IGitDatabaseClient GitDatabase { get; private set; } diff --git a/Octokit/IGitHubClient.cs b/Octokit/IGitHubClient.cs index f8e8e49e..c8586208 100644 --- a/Octokit/IGitHubClient.cs +++ b/Octokit/IGitHubClient.cs @@ -14,7 +14,6 @@ namespace Octokit IRepositoriesClient Repository { get; } IReleasesClient Release { get; } ISshKeysClient SshKey { get; } - IStarredClient Star { get; } IUsersClient User { get; } INotificationsClient Notification { get; } IGitDatabaseClient GitDatabase { get; } From 9b2b3306e03fc2bce032fd2a3c637bab3c147f65 Mon Sep 17 00:00:00 2001 From: James R Sconfitto Date: Sun, 10 Nov 2013 13:23:36 -0500 Subject: [PATCH 35/37] Remove silly redundant method --- Octokit/Http/Connection.cs | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/Octokit/Http/Connection.cs b/Octokit/Http/Connection.cs index edf77ee7..e41b77e4 100644 --- a/Octokit/Http/Connection.cs +++ b/Octokit/Http/Connection.cs @@ -205,16 +205,17 @@ namespace Octokit return Run(request); } - public Task DeleteAsync(Uri uri) + public async Task DeleteAsync(Uri uri) { Ensure.ArgumentNotNull(uri, "uri"); - return RunForStatus(new Request + var response = await Run(new Request { Method = HttpMethod.Delete, BaseAddress = BaseAddress, Endpoint = uri }); + return response.StatusCode; } public Uri BaseAddress { get; private set; } @@ -257,13 +258,6 @@ namespace Octokit return RunRequest(request); } - async Task RunForStatus(IRequest request) - { - _jsonPipeline.SerializeRequest(request); - var response = await RunRequest(request).ConfigureAwait(false); - return response.StatusCode; - } - async Task> Run(IRequest request) { _jsonPipeline.SerializeRequest(request); From f2af483214b5e3a8e225d1e9f3c0ad221edd922b Mon Sep 17 00:00:00 2001 From: Steffen Forkmann Date: Sun, 10 Nov 2013 20:58:57 +0100 Subject: [PATCH 36/37] Check if we are already on the minimal FAKE version - otherwise patch it. --- build.cmd | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/build.cmd b/build.cmd index 55b1e728..431be99c 100644 --- a/build.cmd +++ b/build.cmd @@ -1,10 +1,20 @@ @echo off +SET MinimalFAKEVersion=639 +SET FAKEVersion=1 +cls + +if exist tools\FAKE.Core\tools\PatchVersion.txt ( + FOR /F "tokens=*" %%i in (tools\FAKE.Core\tools\PatchVersion.txt) DO (SET FAKEVersion=%%i) +) + +if %MinimalFAKEVersion% lss %FAKEVersion% goto Build +if %MinimalFAKEVersion%==%FAKEVersion% goto Build + +"tools\nuget\nuget.exe" "install" "FAKE.Core" "-OutputDirectory" "tools" "-ExcludeVersion" "-Prerelease" + :Build cls -if not exist tools\FAKE.Core\tools\Fake.exe ( - "tools\nuget\nuget.exe" "install" "FAKE.Core" "-OutputDirectory" "tools" "-ExcludeVersion" "-Prerelease" -) SET TARGET="Default" From 9ed5f25aba4e493ce14aa6b9d6d9d0b2ab1e5708 Mon Sep 17 00:00:00 2001 From: Haacked Date: Sun, 10 Nov 2013 22:52:32 -0800 Subject: [PATCH 37/37] Update octokit icon for nuget package Fixes #202 --- Octokit.Reactive.nuspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Octokit.Reactive.nuspec b/Octokit.Reactive.nuspec index 22e4db7e..ba8fdc70 100644 --- a/Octokit.Reactive.nuspec +++ b/Octokit.Reactive.nuspec @@ -8,7 +8,7 @@ @summary@ https://github.com/octokit/octokit.net/blob/master/LICENSE.txt https://github.com/octokit/octokit.net - https://f.cloud.github.com/assets/19977/1441274/160fba8c-41a9-11e3-831d-61d88fa886f4.png + https://f.cloud.github.com/assets/19977/1510987/64af2b26-4a9d-11e3-89fc-96a185171c75.png false @description@ @releaseNotes@