-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #138 from dahlbyk/ObservableMilestones
Reactive Milestone Client
- Loading branch information
Showing
13 changed files
with
947 additions
and
423 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Diagnostics.CodeAnalysis; | ||
using System.Reactive; | ||
|
||
namespace Octokit | ||
{ | ||
public interface IObservableMilestonesClient | ||
{ | ||
/// <summary> | ||
/// Gets a single Milestone by number. | ||
/// </summary> | ||
/// <remarks> | ||
/// http://developer.github.com/v3/issues/milestones/#get-a-single-milestone | ||
/// </remarks> | ||
/// <returns></returns> | ||
[SuppressMessage("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "Get", | ||
Justification = "Method makes a network request")] | ||
IObservable<Milestone> Get(string owner, string name, int number); | ||
|
||
/// <summary> | ||
/// Gets all open milestones for the repository. | ||
/// </summary> | ||
/// <remarks> | ||
/// http://developer.github.com/v3/issues/milestones/#list-milestones-for-a-repository | ||
/// </remarks> | ||
/// <param name="owner">The owner of the repository</param> | ||
/// <param name="name">The name of the repository</param> | ||
/// <returns></returns> | ||
IObservable<Milestone> GetForRepository(string owner, string name); | ||
|
||
/// <summary> | ||
/// Gets all open milestones for the repository. | ||
/// </summary> | ||
/// <remarks> | ||
/// http://developer.github.com/v3/issues/milestones/#list-milestones-for-a-repository | ||
/// </remarks> | ||
/// <param name="owner">The owner of the repository</param> | ||
/// <param name="name">The name of the repository</param> | ||
/// <param name="request">Used to filter and sort the list of Milestones returned</param> | ||
/// <returns></returns> | ||
IObservable<Milestone> GetForRepository(string owner, string name, MilestoneRequest request); | ||
|
||
/// <summary> | ||
/// Creates a milestone for the specified repository. Any user with pull access to a repository can create an | ||
/// Milestone. | ||
/// </summary> | ||
/// <remarks>http://developer.github.com/v3/issues/milestones/#create-a-milestone</remarks> | ||
/// <param name="owner">The owner of the repository</param> | ||
/// <param name="name">The name of the repository</param> | ||
/// <param name="newMilestone">A <see cref="NewMilestone"/> instance describing the new Milestone to create</param> | ||
/// <returns></returns> | ||
IObservable<Milestone> Create(string owner, string name, NewMilestone newMilestone); | ||
|
||
/// <summary> | ||
/// Creates a milestone for the specified repository. Any user with pull access to a repository can create an | ||
/// Milestone. | ||
/// </summary> | ||
/// <remarks>http://developer.github.com/v3/issues/milestones/#update-a-milestone</remarks> | ||
/// <param name="owner">The owner of the repository</param> | ||
/// <param name="name">The name of the repository</param> | ||
/// <param name="number">The Milestone number</param> | ||
/// <param name="milestoneUpdate">An <see cref="MilestoneUpdate"/> instance describing the changes to make to the Milestone | ||
/// </param> | ||
/// <returns></returns> | ||
IObservable<Milestone> Update(string owner, string name, int number, MilestoneUpdate milestoneUpdate); | ||
|
||
/// <summary> | ||
/// Deletes a milestone for the specified repository. Any user with pull access to a repository can create an | ||
/// Milestone. | ||
/// </summary> | ||
/// <remarks>http://developer.github.com/v3/issues/milestones/#delete-a-milestone</remarks> | ||
/// <param name="owner">The owner of the repository</param> | ||
/// <param name="name">The name of the repository</param> | ||
/// <param name="number">The milestone number</param> | ||
/// <returns></returns> | ||
IObservable<Unit> Delete(string owner, string name, int number); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
using System; | ||
using System.Reactive; | ||
using System.Reactive.Threading.Tasks; | ||
using Octokit.Reactive.Internal; | ||
|
||
namespace Octokit.Reactive.Clients | ||
{ | ||
public class ObservableMilestonesClient : IObservableMilestonesClient | ||
{ | ||
readonly IMilestonesClient _client; | ||
readonly IConnection _connection; | ||
|
||
public ObservableMilestonesClient(IGitHubClient client) | ||
{ | ||
Ensure.ArgumentNotNull(client, "client"); | ||
|
||
_client = client.Issue.Milestone; | ||
_connection = client.Connection; | ||
} | ||
|
||
/// <summary> | ||
/// Gets a single Milestone by number. | ||
/// </summary> | ||
/// <remarks> | ||
/// http://developer.github.com/v3/issues/milestones/#get-a-single-milestone | ||
/// </remarks> | ||
/// <returns></returns> | ||
public IObservable<Milestone> Get(string owner, string name, int number) | ||
{ | ||
Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); | ||
Ensure.ArgumentNotNullOrEmptyString(name, "name"); | ||
|
||
return _client.Get(owner, name, number).ToObservable(); | ||
} | ||
|
||
/// <summary> | ||
/// Gets all open milestones for the repository. | ||
/// </summary> | ||
/// <remarks> | ||
/// http://developer.github.com/v3/issues/milestones/#list-milestones-for-a-repository | ||
/// </remarks> | ||
/// <param name="owner">The owner of the repository</param> | ||
/// <param name="name">The name of the repository</param> | ||
/// <returns></returns> | ||
public IObservable<Milestone> GetForRepository(string owner, string name) | ||
{ | ||
return _connection.GetAndFlattenAllPages<Milestone>(ApiUrls.Milestones(owner, name)); | ||
} | ||
|
||
/// <summary> | ||
/// Gets all open milestones for the repository. | ||
/// </summary> | ||
/// <remarks> | ||
/// http://developer.github.com/v3/issues/milestones/#list-milestones-for-a-repository | ||
/// </remarks> | ||
/// <param name="owner">The owner of the repository</param> | ||
/// <param name="name">The name of the repository</param> | ||
/// <param name="request">Used to filter and sort the list of Milestones returned</param> | ||
/// <returns></returns> | ||
public IObservable<Milestone> GetForRepository(string owner, string name, MilestoneRequest request) | ||
{ | ||
Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); | ||
Ensure.ArgumentNotNullOrEmptyString(name, "name"); | ||
Ensure.ArgumentNotNull(request, "request"); | ||
|
||
return _connection.GetAndFlattenAllPages<Milestone>(ApiUrls.Milestones(owner, name), | ||
request.ToParametersDictionary()); | ||
} | ||
|
||
/// <summary> | ||
/// Creates an Milestone for the specified repository. Any user with pull access to a repository can create an | ||
/// Milestone. | ||
/// </summary> | ||
/// <remarks>http://developer.github.com/v3/issues/milestones/#create-a-milestone</remarks> | ||
/// <param name="owner">The owner of the repository</param> | ||
/// <param name="name">The name of the repository</param> | ||
/// <param name="newMilestone">A <see cref="NewMilestone"/> instance describing the new Milestone to create</param> | ||
/// <returns></returns> | ||
public IObservable<Milestone> Create(string owner, string name, NewMilestone newMilestone) | ||
{ | ||
Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); | ||
Ensure.ArgumentNotNullOrEmptyString(name, "name"); | ||
Ensure.ArgumentNotNull(newMilestone, "newMilestone"); | ||
|
||
return _client.Create(owner, name, newMilestone).ToObservable(); | ||
} | ||
|
||
/// <summary> | ||
/// Creates an Milestone for the specified repository. Any user with pull access to a repository can create an | ||
/// Milestone. | ||
/// </summary> | ||
/// <remarks>http://developer.github.com/v3/issues/milestones/#create-a-milestone</remarks> | ||
/// <param name="owner">The owner of the repository</param> | ||
/// <param name="name">The name of the repository</param> | ||
/// <param name="number">The Milestone number</param> | ||
/// <param name="milestoneUpdate">An <see cref="MilestoneUpdate"/> instance describing the changes to make to the Milestone | ||
/// </param> | ||
/// <returns></returns> | ||
public IObservable<Milestone> Update(string owner, string name, int number, MilestoneUpdate milestoneUpdate) | ||
{ | ||
Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); | ||
Ensure.ArgumentNotNullOrEmptyString(name, "name"); | ||
Ensure.ArgumentNotNull(milestoneUpdate, "milestoneUpdate"); | ||
|
||
return _client.Update(owner, name, number, milestoneUpdate).ToObservable(); | ||
} | ||
|
||
/// <summary> | ||
/// Deletes a milestone for the specified repository. Any user with pull access to a repository can create an | ||
/// Milestone. | ||
/// </summary> | ||
/// <remarks>http://developer.github.com/v3/issues/milestones/#delete-a-milestone</remarks> | ||
/// <param name="owner">The owner of the repository</param> | ||
/// <param name="name">The name of the repository</param> | ||
/// <param name="number">The milestone number</param> | ||
/// <returns></returns> | ||
public IObservable<Unit> Delete(string owner, string name, int number) | ||
{ | ||
Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); | ||
Ensure.ArgumentNotNullOrEmptyString(name, "name"); | ||
|
||
return _client.Delete(owner, name, number).ToObservable(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
Octokit.Tests.Integration/Reactive/ObservableMilestonesClientTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
using System.Linq; | ||
using System.Net.Http.Headers; | ||
using System.Reactive.Linq; | ||
using System.Threading.Tasks; | ||
using Octokit.Reactive.Clients; | ||
using Xunit; | ||
|
||
namespace Octokit.Tests.Integration | ||
{ | ||
public class ObservableMilestonesClientTests | ||
{ | ||
public class TheGetMethod | ||
{ | ||
[IntegrationTest] | ||
public async Task ReturnsSpecifiedMilestone() | ||
{ | ||
var github = new GitHubClient(new ProductHeaderValue("OctokitTests")) | ||
{ | ||
Credentials = Helper.Credentials | ||
}; | ||
var client = new ObservableMilestonesClient(github); | ||
var observable = client.Get("libgit2", "libgit2sharp", 1); | ||
var milestone = await observable; | ||
|
||
Assert.Equal(1, milestone.Number); | ||
Assert.Equal("v0.4.0", milestone.Title); | ||
Assert.Equal(7, milestone.ClosedIssues); | ||
} | ||
|
||
[IntegrationTest] | ||
public void ReturnsAllMilestones() | ||
{ | ||
var github = new GitHubClient(new ProductHeaderValue("OctokitTests")) | ||
{ | ||
Credentials = Helper.Credentials | ||
}; | ||
var client = new ObservableMilestonesClient(github); | ||
var milestones = client.GetForRepository("libgit2", "libgit2sharp", new MilestoneRequest { State = ItemState.Closed }).ToList().Wait(); | ||
|
||
Assert.NotEmpty(milestones); | ||
Assert.True(milestones.All(m => m.State == ItemState.Closed)); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.