diff --git a/Octokit.Reactive/Clients/IObservableStarredClient.cs b/Octokit.Reactive/Clients/IObservableStarredClient.cs index 63dd4e35..a1c5c9f6 100644 --- a/Octokit.Reactive/Clients/IObservableStarredClient.cs +++ b/Octokit.Reactive/Clients/IObservableStarredClient.cs @@ -13,6 +13,15 @@ namespace Octokit.Reactive /// A of s starring the passed repository IObservable GetAllStargazers(string owner, string name); + /// + /// Retrieves all of the stargazers for the passed repository with star creation timestamps. + /// + /// The owner of the repository + /// The name of the repository + /// Thrown if the client is not authenticated. + /// A of s starring the passed repository with star creation timestamps. + IObservable GetAllStargazersWithTimestamps(string owner, string name); + /// /// Retrieves all of the starred (ies) for the current user /// @@ -22,6 +31,15 @@ namespace Octokit.Reactive /// IObservable GetAllForCurrent(); + /// + /// Retrieves all of the starred (ies) for the current user with star creation timestamps. + /// + /// Thrown if the client is not authenticated. + /// + /// A of (ies) starred by the current authenticated user with star creation timestamps. + /// + IObservable GetAllForCurrentWithTimestamps(); + /// /// Retrieves all of the starred (ies) for the current user /// @@ -33,6 +51,17 @@ namespace Octokit.Reactive /// IObservable GetAllForCurrent(StarredRequest request); + /// + /// Retrieves all of the starred (ies) for the current user with star creation timestamps. + /// + /// Star-specific request parameters that sort the results + /// Thrown if the client is not authenticated. + /// + /// A of (ies) starred by the current user, + /// sorted according to the passed request parameters and with star creation timestamps. + /// + IObservable GetAllForCurrentWithTimestamps(StarredRequest request); + /// /// Retrieves all of the (ies) starred by the specified user /// @@ -41,6 +70,16 @@ namespace Octokit.Reactive /// A starred by the specified user IObservable GetAllForUser(string user); + /// + /// Retrieves all of the (ies) starred by the specified user with star creation timestamps. + /// + /// The login of the user + /// Thrown if the client is not authenticated. + /// + /// A (ies) starred by the specified user with star creation timestamps. + /// + IObservable GetAllForUserWithTimestamps(string user); + /// /// Retrieves all of the (ies) starred by the specified user /// @@ -50,6 +89,18 @@ namespace Octokit.Reactive /// A starred by the specified user IObservable GetAllForUser(string user, StarredRequest request); + /// + /// Retrieves all of the (ies) starred by the specified user with star creation timestamps. + /// + /// The login of the user + /// Star-specific request parameters that sort the results + /// Thrown if the client is not authenticated. + /// + /// A of (ies) starred by the specified user, + /// sorted according to the passed request parameters and with star creation timestamps. + /// + IObservable GetAllForUserWithTimestamps(string user, StarredRequest request); + /// /// Check if a repository is starred by the current authenticated user /// diff --git a/Octokit.Reactive/Clients/ObservableStarredClient.cs b/Octokit.Reactive/Clients/ObservableStarredClient.cs index d03911e1..9f09031f 100644 --- a/Octokit.Reactive/Clients/ObservableStarredClient.cs +++ b/Octokit.Reactive/Clients/ObservableStarredClient.cs @@ -32,6 +32,21 @@ namespace Octokit.Reactive return _connection.GetAndFlattenAllPages(ApiUrls.Stargazers(owner, name)); } + /// + /// Retrieves all of the stargazers for the passed repository with star creation timestamps. + /// + /// The owner of the repository + /// The name of the repository + /// Thrown if the client is not authenticated. + /// A of s starring the passed repository with star creation timestamps. + public IObservable GetAllStargazersWithTimestamps(string owner, string name) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + + return _connection.GetAndFlattenAllPages(ApiUrls.Stargazers(owner, name), null, AcceptHeaders.StarCreationTimestamps); + } + /// /// Retrieves all of the starred (ies) for the current user /// @@ -44,6 +59,18 @@ namespace Octokit.Reactive return _connection.GetAndFlattenAllPages(ApiUrls.Starred()); } + /// + /// Retrieves all of the starred (ies) for the current user with star creation timestamps. + /// + /// Thrown if the client is not authenticated. + /// + /// A of (ies) starred by the current authenticated user with star creation timestamps. + /// + public IObservable GetAllForCurrentWithTimestamps() + { + return _connection.GetAndFlattenAllPages(ApiUrls.Starred(), null, AcceptHeaders.StarCreationTimestamps); + } + /// /// Retrieves all of the starred (ies) for the current user /// @@ -61,6 +88,23 @@ namespace Octokit.Reactive return _connection.GetAndFlattenAllPages(ApiUrls.Starred(), request.ToParametersDictionary()); } + /// + /// Retrieves all of the starred (ies) for the current user with star creation timestamps. + /// + /// Star-specific request parameters that sort the results + /// Thrown if the client is not authenticated. + /// + /// A of (ies) starred by the current user, + /// sorted according to the passed request parameters and with star creation timestamps. + /// + [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")] + public IObservable GetAllForCurrentWithTimestamps(StarredRequest request) + { + Ensure.ArgumentNotNull(request, "request"); + + return _connection.GetAndFlattenAllPages(ApiUrls.Starred(), request.ToParametersDictionary(), AcceptHeaders.StarCreationTimestamps); + } + /// /// Retrieves all of the (ies) starred by the specified user /// @@ -74,6 +118,21 @@ namespace Octokit.Reactive return _connection.GetAndFlattenAllPages(ApiUrls.StarredByUser(user)); } + /// + /// Retrieves all of the (ies) starred by the specified user with star creation timestamps. + /// + /// The login of the user + /// Thrown if the client is not authenticated. + /// + /// A (ies) starred by the specified user with star creation timestamps. + /// + public IObservable GetAllForUserWithTimestamps(string user) + { + Ensure.ArgumentNotNullOrEmptyString(user, "user"); + + return _connection.GetAndFlattenAllPages(ApiUrls.StarredByUser(user), null, AcceptHeaders.StarCreationTimestamps); + } + /// /// Retrieves all of the (ies) starred by the specified user /// @@ -90,6 +149,25 @@ namespace Octokit.Reactive return _connection.GetAndFlattenAllPages(ApiUrls.StarredByUser(user), request.ToParametersDictionary()); } + /// + /// Retrieves all of the (ies) starred by the specified user with star creation timestamps. + /// + /// The login of the user + /// Star-specific request parameters that sort the results + /// Thrown if the client is not authenticated. + /// + /// A of (ies) starred by the specified user, + /// sorted according to the passed request parameters and with star creation timestamps. + /// + [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")] + public IObservable GetAllForUserWithTimestamps(string user, StarredRequest request) + { + Ensure.ArgumentNotNullOrEmptyString(user, "user"); + Ensure.ArgumentNotNull(request, "request"); + + return _connection.GetAndFlattenAllPages(ApiUrls.StarredByUser(user), request.ToParametersDictionary(), AcceptHeaders.StarCreationTimestamps); + } + /// /// Check if a repository is starred by the current authenticated user /// diff --git a/Octokit.Tests.Integration/Clients/StarredClientTests.cs b/Octokit.Tests.Integration/Clients/StarredClientTests.cs new file mode 100644 index 00000000..e55880e8 --- /dev/null +++ b/Octokit.Tests.Integration/Clients/StarredClientTests.cs @@ -0,0 +1,35 @@ +using System; +using Octokit.Tests.Integration.Helpers; +using System.Linq; +using System.Threading.Tasks; +using Xunit; + +namespace Octokit.Tests.Integration.Clients +{ + public class StarredClientTests + { + private readonly IGitHubClient _client; + private readonly IStarredClient _fixture; + + public StarredClientTests() + { + _client = Helper.GetAuthenticatedClient(); + _fixture = _client.Activity.Starring; + } + + [IntegrationTest] + public async Task CanCreateAndRetrieveStarsWithTimestamps() + { + using (var context = await _client.CreateRepositoryContext("public-repo")) + { + await _fixture.RemoveStarFromRepo(context.RepositoryOwner, context.RepositoryName); + await _fixture.StarRepo(context.RepositoryOwner, context.RepositoryName); + var currentUser = await _client.User.Current(); + var userStars = await _fixture.GetAllStargazersWithTimestamps(context.RepositoryOwner, context.RepositoryName); + var userStar = userStars.SingleOrDefault(x => x.User.Id == currentUser.Id); + Assert.NotNull(userStar); + Assert.True(DateTimeOffset.UtcNow.Subtract(userStar.StarredAt) < TimeSpan.FromMinutes(5)); + } + } + } +} diff --git a/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj b/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj index 0f8192e9..b2cd9b6c 100644 --- a/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj +++ b/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj @@ -96,6 +96,7 @@ + diff --git a/Octokit.Tests/Clients/RepositoryPagesClientTests.cs b/Octokit.Tests/Clients/RepositoryPagesClientTests.cs index b169bd83..e783b48a 100644 --- a/Octokit.Tests/Clients/RepositoryPagesClientTests.cs +++ b/Octokit.Tests/Clients/RepositoryPagesClientTests.cs @@ -39,7 +39,7 @@ namespace Octokit.Tests.Clients var connection = Substitute.For(); var client = new RepositoryPagesClient(connection); - client.GetAllBuilds("fake", "repo"); + client.GetAll("fake", "repo"); connection.Received().GetAll(Arg.Is(u => u.ToString() == "repos/fake/repo/pages/builds")); } @@ -63,7 +63,7 @@ namespace Octokit.Tests.Clients var connection = Substitute.For(); var client = new RepositoryPagesClient(connection); - client.GetLatestBuild("fake", "repo"); + client.GetLatest("fake", "repo"); connection.Received().Get(Arg.Is(u => u.ToString() == "repos/fake/repo/pages/builds/latest"), null); } diff --git a/Octokit/Clients/IRepositoryPagesClient.cs b/Octokit/Clients/IRepositoryPagesClient.cs index b04c538c..579b2633 100644 --- a/Octokit/Clients/IRepositoryPagesClient.cs +++ b/Octokit/Clients/IRepositoryPagesClient.cs @@ -32,7 +32,7 @@ namespace Octokit /// See the API documentation for more information. /// /// - Task> GetAllBuilds(string owner, string repositoryName); + Task> GetAll(string owner, string repositoryName); /// /// Gets the build metadata for the last build for a given repository /// @@ -42,6 +42,6 @@ namespace Octokit /// See the API documentation for more information. /// /// - Task GetLatestBuild(string owner, string repositoryName); + Task GetLatest(string owner, string repositoryName); } } \ No newline at end of file diff --git a/Octokit/Clients/IStarredClient.cs b/Octokit/Clients/IStarredClient.cs index 1110dbb7..d93b632d 100644 --- a/Octokit/Clients/IStarredClient.cs +++ b/Octokit/Clients/IStarredClient.cs @@ -20,6 +20,15 @@ namespace Octokit /// A of s starring the passed repository. Task> GetAllStargazers(string owner, string name); + /// + /// Retrieves all of the stargazers for the passed repository with star creation timestamps. + /// + /// The owner of the repository + /// The name of the repository + /// Thrown if the client is not authenticated. + /// A of s starring the passed repository with star creation timestamps. + Task> GetAllStargazersWithTimestamps(string owner, string name); + /// /// Retrieves all of the starred (ies) for the current user. /// @@ -29,6 +38,15 @@ namespace Octokit /// Task> GetAllForCurrent(); + /// + /// Retrieves all of the starred (ies) for the current user with star creation timestamps. + /// + /// Thrown if the client is not authenticated. + /// + /// A of (ies) starred by the current authenticated user with star creation timestamps. + /// + Task> GetAllForCurrentWithTimestamps(); + /// /// Retrieves all of the starred (ies) for the current user. /// @@ -39,7 +57,18 @@ namespace Octokit /// sorted according to the passed request parameters. /// Task> GetAllForCurrent(StarredRequest request); - + + /// + /// Retrieves all of the starred (ies) for the current user with star creation timestamps. + /// + /// Star-specific request parameters that sort the results + /// Thrown if the client is not authenticated. + /// + /// A of (ies) starred by the current user, + /// sorted according to the passed request parameters and with star creation timestamps. + /// + Task> GetAllForCurrentWithTimestamps(StarredRequest request); + /// /// Retrieves all of the (ies) starred by the specified user. /// @@ -50,6 +79,16 @@ namespace Octokit /// Task> GetAllForUser(string user); + /// + /// Retrieves all of the (ies) starred by the specified user with star creation timestamps. + /// + /// The login of the user + /// Thrown if the client is not authenticated. + /// + /// A (ies) starred by the specified user with star creation timestamps. + /// + Task> GetAllForUserWithTimestamps(string user); + /// /// Retrieves all of the (ies) starred by the specified user. /// @@ -58,6 +97,18 @@ namespace Octokit /// Thrown if the client is not authenticated. /// A starred by the specified user. Task> GetAllForUser(string user, StarredRequest request); + + /// + /// Retrieves all of the (ies) starred by the specified user with star creation timestamps. + /// + /// The login of the user + /// Star-specific request parameters that sort the results + /// Thrown if the client is not authenticated. + /// + /// A of (ies) starred by the specified user, + /// sorted according to the passed request parameters and with star creation timestamps. + /// + Task> GetAllForUserWithTimestamps(string user, StarredRequest request); /// /// Check if a repository is starred by the current authenticated user. diff --git a/Octokit/Clients/RepositoryPagesClient.cs b/Octokit/Clients/RepositoryPagesClient.cs index 549077be..a45cac79 100644 --- a/Octokit/Clients/RepositoryPagesClient.cs +++ b/Octokit/Clients/RepositoryPagesClient.cs @@ -46,7 +46,7 @@ namespace Octokit /// See the API documentation for more information. /// /// - public Task> GetAllBuilds(string owner, string repositoryName) + public Task> GetAll(string owner, string repositoryName) { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(repositoryName, "repositoryName"); @@ -63,7 +63,7 @@ namespace Octokit /// See the API documentation for more information. /// /// - public Task GetLatestBuild(string owner, string repositoryName) + public Task GetLatest(string owner, string repositoryName) { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(repositoryName, "repositoryName"); diff --git a/Octokit/Clients/StarredClient.cs b/Octokit/Clients/StarredClient.cs index 73f42a7a..1ed20dcd 100644 --- a/Octokit/Clients/StarredClient.cs +++ b/Octokit/Clients/StarredClient.cs @@ -35,6 +35,21 @@ namespace Octokit return ApiConnection.GetAll(ApiUrls.Stargazers(owner, name)); } + /// + /// Retrieves all of the stargazers for the passed repository with star creation timestamps. + /// + /// The owner of the repository + /// The name of the repository + /// Thrown if the client is not authenticated. + /// A of s starring the passed repository with star creation timestamps. + public Task> GetAllStargazersWithTimestamps(string owner, string name) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + + return ApiConnection.GetAll(ApiUrls.Stargazers(owner, name), null, AcceptHeaders.StarCreationTimestamps); + } + /// /// Retrieves all of the starred (ies) for the current user. /// @@ -47,6 +62,18 @@ namespace Octokit return ApiConnection.GetAll(ApiUrls.Starred()); } + /// + /// Retrieves all of the starred (ies) for the current user with star creation timestamps. + /// + /// Thrown if the client is not authenticated. + /// + /// A of (ies) starred by the current authenticated user with star creation timestamps. + /// + public Task> GetAllForCurrentWithTimestamps() + { + return ApiConnection.GetAll(ApiUrls.Starred(), null, AcceptHeaders.StarCreationTimestamps); + } + /// /// Retrieves all of the starred (ies) for the current user. /// @@ -65,6 +92,24 @@ namespace Octokit return ApiConnection.GetAll(ApiUrls.Starred(), request.ToParametersDictionary()); } + /// + /// Retrieves all of the starred (ies) for the current user with star creation timestamps. + /// + /// Star-specific request parameters that sort the results + /// Thrown if the client is not authenticated. + /// + /// A of (ies) starred by the current user, + /// sorted according to the passed request parameters and with star creation timestamps. + /// + [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters", + Justification = "But i think i do need star-specific request parameters")] + public Task> GetAllForCurrentWithTimestamps(StarredRequest request) + { + Ensure.ArgumentNotNull(request, "request"); + + return ApiConnection.GetAll(ApiUrls.Starred(), request.ToParametersDictionary(), AcceptHeaders.StarCreationTimestamps); + } + /// /// Retrieves all of the (ies) starred by the specified user. /// @@ -80,6 +125,21 @@ namespace Octokit return ApiConnection.GetAll(ApiUrls.StarredByUser(user)); } + /// + /// Retrieves all of the (ies) starred by the specified user with star creation timestamps. + /// + /// The login of the user + /// Thrown if the client is not authenticated. + /// + /// A (ies) starred by the specified user with star creation timestamps. + /// + public Task> GetAllForUserWithTimestamps(string user) + { + Ensure.ArgumentNotNullOrEmptyString(user, "user"); + + return ApiConnection.GetAll(ApiUrls.StarredByUser(user), null, AcceptHeaders.StarCreationTimestamps); + } + /// /// Retrieves all of the (ies) starred by the specified user. /// @@ -96,6 +156,25 @@ namespace Octokit return ApiConnection.GetAll(ApiUrls.StarredByUser(user), request.ToParametersDictionary()); } + /// + /// Retrieves all of the (ies) starred by the specified user with star creation timestamps. + /// + /// The login of the user + /// Star-specific request parameters that sort the results + /// Thrown if the client is not authenticated. + /// + /// A of (ies) starred by the specified user, + /// sorted according to the passed request parameters and with star creation timestamps. + /// + [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")] + public Task> GetAllForUserWithTimestamps(string user, StarredRequest request) + { + Ensure.ArgumentNotNullOrEmptyString(user, "user"); + Ensure.ArgumentNotNull(request, "request"); + + return ApiConnection.GetAll(ApiUrls.StarredByUser(user), request.ToParametersDictionary(), AcceptHeaders.StarCreationTimestamps); + } + /// /// Check if a repository is starred by the current authenticated user. /// diff --git a/Octokit/Helpers/AcceptHeaders.cs b/Octokit/Helpers/AcceptHeaders.cs index 425782a8..387b5ed5 100644 --- a/Octokit/Helpers/AcceptHeaders.cs +++ b/Octokit/Helpers/AcceptHeaders.cs @@ -11,6 +11,8 @@ public const string LicensesApiPreview = "application/vnd.github.drax-preview+json"; public const string ProtectedBranchesApiPreview = "application/vnd.github.loki-preview+json"; + + public const string StarCreationTimestamps = "application/vnd.github.v3.star+json"; } } \ No newline at end of file diff --git a/Octokit/Models/Response/RepositoryStar.cs b/Octokit/Models/Response/RepositoryStar.cs new file mode 100644 index 00000000..bb5e21b8 --- /dev/null +++ b/Octokit/Models/Response/RepositoryStar.cs @@ -0,0 +1,40 @@ +using System; +using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; +using System.Globalization; + +namespace Octokit +{ + /// + /// Represents additional information about a star (such as creation time) + /// + [DebuggerDisplay("{DebuggerDisplay,nq}")] + public class RepositoryStar + { + public RepositoryStar() { } + + public RepositoryStar(DateTimeOffset starredAt, Repository repo) + { + StarredAt = starredAt; + Repo = repo; + } + + /// + /// The date the star was created. + /// + public DateTimeOffset StarredAt { get; protected set; } + + /// + /// The repository associated with the star. + /// + public Repository Repo { get; protected set; } + + internal string DebuggerDisplay + { + get + { + return string.Format(CultureInfo.InvariantCulture, Repo.DebuggerDisplay); + } + } + } +} \ No newline at end of file diff --git a/Octokit/Models/Response/UserStar.cs b/Octokit/Models/Response/UserStar.cs new file mode 100644 index 00000000..610401ce --- /dev/null +++ b/Octokit/Models/Response/UserStar.cs @@ -0,0 +1,40 @@ +using System; +using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; +using System.Globalization; + +namespace Octokit +{ + /// + /// Represents additional information about a star (such as creation time) + /// + [DebuggerDisplay("{DebuggerDisplay,nq}")] + public class UserStar + { + public UserStar() { } + + public UserStar(DateTimeOffset starredAt, User user) + { + StarredAt = starredAt; + User = user; + } + + /// + /// The date the star was created. + /// + public DateTimeOffset StarredAt { get; protected set; } + + /// + /// The user associated with the star. + /// + public User User { get; protected set; } + + internal string DebuggerDisplay + { + get + { + return string.Format(CultureInfo.InvariantCulture, User.DebuggerDisplay); + } + } + } +} \ No newline at end of file diff --git a/Octokit/Octokit-Mono.csproj b/Octokit/Octokit-Mono.csproj index ff99d832..b76e6323 100644 --- a/Octokit/Octokit-Mono.csproj +++ b/Octokit/Octokit-Mono.csproj @@ -418,6 +418,8 @@ + + \ No newline at end of file diff --git a/Octokit/Octokit-MonoAndroid.csproj b/Octokit/Octokit-MonoAndroid.csproj index d77e6d91..45e80dc0 100644 --- a/Octokit/Octokit-MonoAndroid.csproj +++ b/Octokit/Octokit-MonoAndroid.csproj @@ -425,6 +425,8 @@ + + \ No newline at end of file diff --git a/Octokit/Octokit-Monotouch.csproj b/Octokit/Octokit-Monotouch.csproj index 25462c6b..e66291bf 100644 --- a/Octokit/Octokit-Monotouch.csproj +++ b/Octokit/Octokit-Monotouch.csproj @@ -421,6 +421,8 @@ + + diff --git a/Octokit/Octokit-Portable.csproj b/Octokit/Octokit-Portable.csproj index 5e047bd0..6860a747 100644 --- a/Octokit/Octokit-Portable.csproj +++ b/Octokit/Octokit-Portable.csproj @@ -415,6 +415,8 @@ + + diff --git a/Octokit/Octokit-netcore45.csproj b/Octokit/Octokit-netcore45.csproj index 5a583ea6..e922b06a 100644 --- a/Octokit/Octokit-netcore45.csproj +++ b/Octokit/Octokit-netcore45.csproj @@ -422,6 +422,8 @@ + + diff --git a/Octokit/Octokit.csproj b/Octokit/Octokit.csproj index 73a2f144..38e44875 100644 --- a/Octokit/Octokit.csproj +++ b/Octokit/Octokit.csproj @@ -434,6 +434,8 @@ + +