Skip to content

Commit

Permalink
Add pagination support to ReferencesClient. (#1694)
Browse files Browse the repository at this point in the history
* Add pagination support to ReferencesClient.

* Add missing unit tests for ReferencesClient

* Add integration tests for ReferencesClient pagination.

* Refactor assertion.
  • Loading branch information
gdziadkiewicz authored and ryangribble committed Dec 1, 2017
1 parent e9c7e02 commit e1b6434
Show file tree
Hide file tree
Showing 6 changed files with 465 additions and 16 deletions.
48 changes: 48 additions & 0 deletions Octokit.Reactive/Clients/IObservableReferencesClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,18 @@ public interface IObservableReferencesClient
/// <returns></returns>
IObservable<Reference> GetAll(string owner, string name);

/// <summary>
/// Gets all references for a given repository
/// </summary>
/// <remarks>
/// http://developer.github.com/v3/git/refs/#get-all-references
/// </remarks>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <param name="options">Options for changing the API response</param>
/// <returns></returns>
IObservable<Reference> GetAll(string owner, string name, ApiOptions options);

/// <summary>
/// Gets all references for a given repository
/// </summary>
Expand All @@ -60,6 +72,17 @@ public interface IObservableReferencesClient
/// <returns></returns>
IObservable<Reference> GetAll(long repositoryId);

/// <summary>
/// Gets all references for a given repository
/// </summary>
/// <remarks>
/// http://developer.github.com/v3/git/refs/#get-all-references
/// </remarks>
/// <param name="repositoryId">The Id of the repository</param>
/// <param name="options">Options for changing the API response</param>
/// <returns></returns>
IObservable<Reference> GetAll(long repositoryId, ApiOptions options);

/// <summary>
/// Gets references for a given repository by sub-namespace, i.e. "tags" or "heads"
/// </summary>
Expand All @@ -72,6 +95,19 @@ public interface IObservableReferencesClient
/// <returns></returns>
IObservable<Reference> GetAllForSubNamespace(string owner, string name, string subNamespace);

/// <summary>
/// Gets references for a given repository by sub-namespace, i.e. "tags" or "heads"
/// </summary>
/// <remarks>
/// http://developer.github.com/v3/git/refs/#get-all-references
/// </remarks>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <param name="subNamespace">The sub-namespace to get references for</param>
/// <param name="options">Options for changing the API response</param>
/// <returns></returns>
IObservable<Reference> GetAllForSubNamespace(string owner, string name, string subNamespace, ApiOptions options);

/// <summary>
/// Gets references for a given repository by sub-namespace, i.e. "tags" or "heads"
/// </summary>
Expand All @@ -83,6 +119,18 @@ public interface IObservableReferencesClient
/// <returns></returns>
IObservable<Reference> GetAllForSubNamespace(long repositoryId, string subNamespace);

/// <summary>
/// Gets references for a given repository by sub-namespace, i.e. "tags" or "heads"
/// </summary>
/// <remarks>
/// http://developer.github.com/v3/git/refs/#get-all-references
/// </remarks>
/// <param name="repositoryId">The Id of the repository</param>
/// <param name="subNamespace">The sub-namespace to get references for</param>
/// <param name="options">Options for changing the API response</param>
/// <returns></returns>
IObservable<Reference> GetAllForSubNamespace(long repositoryId, string subNamespace, ApiOptions options);

/// <summary>
/// Creates a reference for a given repository
/// </summary>
Expand Down
73 changes: 69 additions & 4 deletions Octokit.Reactive/Clients/ObservableReferencesClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,27 @@ public IObservable<Reference> Get(long repositoryId, string reference)
/// <param name="name">The name of the repository</param>
/// <returns></returns>
public IObservable<Reference> GetAll(string owner, string name)
{
return GetAll(owner, name, ApiOptions.None);
}

/// <summary>
/// Gets all references for a given repository
/// </summary>
/// <remarks>
/// http://developer.github.com/v3/git/refs/#get-all-references
/// </remarks>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <param name="options">Options for changing the API response</param>
/// <returns></returns>
public IObservable<Reference> GetAll(string owner, string name, ApiOptions options)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");
Ensure.ArgumentNotNull(options, "options");

return _connection.GetAndFlattenAllPages<Reference>(ApiUrls.Reference(owner, name));
return _connection.GetAndFlattenAllPages<Reference>(ApiUrls.Reference(owner, name), options);
}

/// <summary>
Expand All @@ -86,7 +102,23 @@ public IObservable<Reference> GetAll(string owner, string name)
/// <returns></returns>
public IObservable<Reference> GetAll(long repositoryId)
{
return _connection.GetAndFlattenAllPages<Reference>(ApiUrls.Reference(repositoryId));
return GetAll(repositoryId, ApiOptions.None);
}

/// <summary>
/// Gets all references for a given repository
/// </summary>
/// <remarks>
/// http://developer.github.com/v3/git/refs/#get-all-references
/// </remarks>
/// <param name="repositoryId">The Id of the repository</param>
/// <param name="options">Options for changing the API response</param>
/// <returns></returns>
public IObservable<Reference> GetAll(long repositoryId, ApiOptions options)
{
Ensure.ArgumentNotNull(options, "options");

return _connection.GetAndFlattenAllPages<Reference>(ApiUrls.Reference(repositoryId), options);
}

/// <summary>
Expand All @@ -100,12 +132,29 @@ public IObservable<Reference> GetAll(long repositoryId)
/// <param name="subNamespace">The sub-namespace to get references for</param>
/// <returns></returns>
public IObservable<Reference> GetAllForSubNamespace(string owner, string name, string subNamespace)
{
return GetAllForSubNamespace(owner, name, subNamespace, ApiOptions.None);
}

/// <summary>
/// Gets references for a given repository by sub-namespace, i.e. "tags" or "heads"
/// </summary>
/// <remarks>
/// http://developer.github.com/v3/git/refs/#get-all-references
/// </remarks>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <param name="subNamespace">The sub-namespace to get references for</param>
/// <param name="options">Options for changing the API response</param>
/// <returns></returns>
public IObservable<Reference> GetAllForSubNamespace(string owner, string name, string subNamespace, ApiOptions options)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");
Ensure.ArgumentNotNullOrEmptyString(subNamespace, "subNamespace");
Ensure.ArgumentNotNull(options, "options");

return _connection.GetAndFlattenAllPages<Reference>(ApiUrls.Reference(owner, name, subNamespace));
return _connection.GetAndFlattenAllPages<Reference>(ApiUrls.Reference(owner, name, subNamespace), options);
}

/// <summary>
Expand All @@ -118,10 +167,26 @@ public IObservable<Reference> GetAllForSubNamespace(string owner, string name, s
/// <param name="subNamespace">The sub-namespace to get references for</param>
/// <returns></returns>
public IObservable<Reference> GetAllForSubNamespace(long repositoryId, string subNamespace)
{
return GetAllForSubNamespace(repositoryId, subNamespace, ApiOptions.None);
}

/// <summary>
/// Gets references for a given repository by sub-namespace, i.e. "tags" or "heads"
/// </summary>
/// <remarks>
/// http://developer.github.com/v3/git/refs/#get-all-references
/// </remarks>
/// <param name="repositoryId">The Id of the repository</param>
/// <param name="subNamespace">The sub-namespace to get references for</param>
/// <param name="options">Options for changing the API response</param>
/// <returns></returns>
public IObservable<Reference> GetAllForSubNamespace(long repositoryId, string subNamespace, ApiOptions options)
{
Ensure.ArgumentNotNullOrEmptyString(subNamespace, "subNamespace");
Ensure.ArgumentNotNull(options, "options");

return _connection.GetAndFlattenAllPages<Reference>(ApiUrls.Reference(repositoryId, subNamespace));
return _connection.GetAndFlattenAllPages<Reference>(ApiUrls.Reference(repositoryId, subNamespace), options);
}

/// <summary>
Expand Down
Loading

0 comments on commit e1b6434

Please sign in to comment.