mirror of
https://github.com/zoriya/octokit.net.git
synced 2026-06-09 21:09:51 +00:00
Added 'sort' parameter to the list forks api implementation.
This commit is contained in:
@@ -10,7 +10,7 @@ namespace Octokit.Tests.Integration.Clients
|
||||
public class TheGetMethod
|
||||
{
|
||||
[IntegrationTest]
|
||||
public async Task ReturnsForksForProject()
|
||||
public async Task ReturnsForksForRepository()
|
||||
{
|
||||
var github = Helper.GetAuthenticatedClient();
|
||||
|
||||
@@ -20,6 +20,20 @@ namespace Octokit.Tests.Integration.Clients
|
||||
Assert.NotNull(masterFork);
|
||||
Assert.Equal("TeamBinary", masterFork.Owner.Login);
|
||||
}
|
||||
|
||||
[IntegrationTest]
|
||||
public async Task ReturnsForksForRepositorySortingTheResultWithOldestFirst()
|
||||
{
|
||||
var github = Helper.GetAuthenticatedClient();
|
||||
|
||||
var actualForks = (await github.Repository.Forks.Get("octokit", "octokit.net", new RepositoryForksListRequest { Sort = Sort.Oldest })).ToArray();
|
||||
var sortedForks = actualForks.OrderBy(fork => fork.CreatedAt).ToArray();
|
||||
|
||||
for (var index = 0; index < actualForks.Length; index++)
|
||||
{
|
||||
Assert.Equal(sortedForks[index].FullName, actualForks[index].FullName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class TheCreateMethod
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using NSubstitute;
|
||||
using NSubstitute;
|
||||
using Octokit.Tests.Helpers;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Xunit;
|
||||
|
||||
namespace Octokit.Tests.Clients
|
||||
@@ -21,6 +22,19 @@ namespace Octokit.Tests.Clients
|
||||
connection.Received().GetAll<Repository>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/forks"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RequestsCorrectUrlWithRequestParameters()
|
||||
{
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new RepositoriesClient(connection);
|
||||
|
||||
client.Forks.Get("fake", "repo", new RepositoryForksListRequest{Sort = Sort.Stargazers});
|
||||
|
||||
connection.Received().GetAll<Repository>(
|
||||
Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/forks"),
|
||||
Arg.Is<Dictionary<string, string>>(d => d["sort"] == "stargazers"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task EnsuresNonNullArguments()
|
||||
{
|
||||
|
||||
@@ -14,6 +14,14 @@ namespace Octokit
|
||||
[SuppressMessage("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "Get", Justification = "This is ok; we're matching HTTP verbs not keyworks")]
|
||||
Task<IReadOnlyList<Repository>> Get(string owner, string repositoryName);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the list of forks defined for a repository
|
||||
/// </summary>
|
||||
/// <remarks>See <a href="http://developer.github.com/v3/repos/forks/#list-forks">API documentation</a> for more information.</remarks>
|
||||
/// <returns></returns>
|
||||
[SuppressMessage("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "Get", Justification = "This is ok; we're matching HTTP verbs not keyworks")]
|
||||
Task<IReadOnlyList<Repository>> Get(string owner, string repositoryName, RepositoryForksListRequest request);
|
||||
|
||||
/// <summary>
|
||||
/// Creates a fork for a repository. Specify organization in the fork parameter to create for an organization.
|
||||
/// </summary>
|
||||
|
||||
@@ -9,7 +9,8 @@ namespace Octokit
|
||||
/// Initializes a new GitHub Repos Fork API client.
|
||||
/// </summary>
|
||||
/// <param name="apiConnection">An API connection.</param>
|
||||
public RepositoryForksClient(IApiConnection apiConnection) : base(apiConnection)
|
||||
public RepositoryForksClient(IApiConnection apiConnection)
|
||||
: base(apiConnection)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -19,11 +20,24 @@ namespace Octokit
|
||||
/// <remarks>See <a href="http://developer.github.com/v3/repos/forks/#list-forks">API documentation</a> for more information.</remarks>
|
||||
/// <returns></returns>
|
||||
public Task<IReadOnlyList<Repository>> Get(string owner, string repositoryName)
|
||||
{
|
||||
return Get(owner, repositoryName, null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the list of forks defined for a repository
|
||||
/// </summary>
|
||||
/// <remarks>See <a href="http://developer.github.com/v3/repos/forks/#list-forks">API documentation</a> for more information.</remarks>
|
||||
/// <returns></returns>
|
||||
public Task<IReadOnlyList<Repository>> Get(string owner, string repositoryName, RepositoryForksListRequest request)
|
||||
{
|
||||
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
|
||||
Ensure.ArgumentNotNullOrEmptyString(repositoryName, "repositoryName");
|
||||
|
||||
return ApiConnection.GetAll<Repository>(ApiUrls.RepositoryForks(owner, repositoryName));
|
||||
if (request == null)
|
||||
return ApiConnection.GetAll<Repository>(ApiUrls.RepositoryForks(owner, repositoryName));
|
||||
else
|
||||
return ApiConnection.GetAll<Repository>(ApiUrls.RepositoryForks(owner, repositoryName), request.ToParametersDictionary());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
using Octokit.Internal;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Globalization;
|
||||
|
||||
namespace Octokit
|
||||
{
|
||||
[DebuggerDisplay("{DebuggerDisplay,nq}")]
|
||||
public class RepositoryForksListRequest : RequestParameters
|
||||
{
|
||||
public RepositoryForksListRequest()
|
||||
{
|
||||
Sort = Sort.Newest; // Default in accordance with the documentation
|
||||
}
|
||||
|
||||
[Parameter(Key = "sort")]
|
||||
public Sort Sort { get; set; }
|
||||
|
||||
internal string DebuggerDisplay
|
||||
{
|
||||
get
|
||||
{
|
||||
return String.Format(CultureInfo.InvariantCulture, "Sort: {0}", Sort);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public enum Sort
|
||||
{
|
||||
[Parameter(Value = "newest")]
|
||||
Newest,
|
||||
|
||||
[Parameter(Value = "oldest")]
|
||||
Oldest,
|
||||
|
||||
[Parameter(Value = "stargazers")]
|
||||
Stargazers
|
||||
}
|
||||
}
|
||||
@@ -388,6 +388,7 @@
|
||||
<Compile Include="Models\Request\ReleaseAssetUpload.cs" />
|
||||
<Compile Include="Models\Request\RepositoryRequest.cs" />
|
||||
<Compile Include="Models\Response\RepositoryHookConfiguration.cs" />
|
||||
<Compile Include="Models\Request\RepositoryForksListRequest.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
||||
@@ -400,6 +400,7 @@
|
||||
<Compile Include="Models\Request\ReleaseAssetUpload.cs" />
|
||||
<Compile Include="Models\Request\RepositoryRequest.cs" />
|
||||
<Compile Include="Models\Response\RepositoryHookConfiguration.cs" />
|
||||
<Compile Include="Models\Request\RepositoryForksListRequest.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildExtensionsPath)\Novell\Novell.MonoDroid.CSharp.targets" />
|
||||
</Project>
|
||||
@@ -393,6 +393,7 @@
|
||||
<Compile Include="Models\Request\ReleaseAssetUpload.cs" />
|
||||
<Compile Include="Models\Request\RepositoryRequest.cs" />
|
||||
<Compile Include="Models\Response\RepositoryHookConfiguration.cs" />
|
||||
<Compile Include="Models\Request\RepositoryForksListRequest.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildExtensionsPath)\Xamarin\iOS\Xamarin.MonoTouch.CSharp.targets" />
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
|
||||
@@ -386,6 +386,7 @@
|
||||
<Compile Include="Models\Request\ReleaseAssetUpload.cs" />
|
||||
<Compile Include="Models\Request\RepositoryRequest.cs" />
|
||||
<Compile Include="Models\Response\RepositoryHookConfiguration.cs" />
|
||||
<Compile Include="Models\Request\RepositoryForksListRequest.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<CodeAnalysisDictionary Include="..\CustomDictionary.xml">
|
||||
|
||||
@@ -390,6 +390,7 @@
|
||||
<Compile Include="Models\Request\GistFileUpdate.cs" />
|
||||
<Compile Include="Models\Request\ReleaseAssetUpload.cs" />
|
||||
<Compile Include="Models\Request\RepositoryRequest.cs" />
|
||||
<Compile Include="Models\Request\RepositoryForksListRequest.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<CodeAnalysisDictionary Include="..\CustomDictionary.xml">
|
||||
|
||||
@@ -84,6 +84,7 @@
|
||||
<Compile Include="Models\Request\GistFileUpdate.cs" />
|
||||
<Compile Include="Models\Request\NewMerge.cs" />
|
||||
<Compile Include="Models\Request\ReleaseAssetUpload.cs" />
|
||||
<Compile Include="Models\Request\RepositoryForksListRequest.cs" />
|
||||
<Compile Include="Models\Request\RepositoryRequest.cs" />
|
||||
<Compile Include="Models\Request\Signature.cs" />
|
||||
<Compile Include="Models\Request\CreateFileRequest.cs" />
|
||||
|
||||
Reference in New Issue
Block a user