Add actual "GetAllForRepository" Activity Feed (#1288)

This commit is contained in:
Tim Miller
2016-05-04 21:57:31 -04:00
committed by Brendan Forster
parent 7bb751c594
commit 7b372253ca
8 changed files with 283 additions and 6 deletions
@@ -47,6 +47,29 @@ namespace Octokit.Reactive
/// <returns>All the <see cref="Activity"/>s for the particular repository.</returns>
IObservable<Activity> GetAllForRepository(string owner, string name, ApiOptions options);
/// <summary>
/// Gets all the issue events for a given repository
/// </summary>
/// <remarks>
/// http://developer.github.com/v3/activity/events/#list-issue-events-for-a-repository
/// </remarks>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <returns>All the <see cref="Activity"/>s for the particular repository.</returns>
IObservable<Activity> GetAllIssuesForRepository(string owner, string name);
/// <summary>
/// Gets all the issue events for a given repository
/// </summary>
/// <remarks>
/// http://developer.github.com/v3/activity/events/#list-issue-events-for-a-repository
/// </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>All the <see cref="Activity"/>s for the particular repository.</returns>
IObservable<Activity> GetAllIssuesForRepository(string owner, string name, ApiOptions options);
/// <summary>
/// Gets all the events for a given repository network
/// </summary>
@@ -74,6 +74,42 @@ namespace Octokit.Reactive
Ensure.ArgumentNotNullOrEmptyString(name, "name");
Ensure.ArgumentNotNull(options, "options");
return _connection.GetAndFlattenAllPages<Activity>(ApiUrls.Events(owner, name), options);
}
/// <summary>
/// Gets all the events for a given repository
/// </summary>
/// <remarks>
/// http://developer.github.com/v3/activity/events/#list-issue-events-for-a-repository
/// </remarks>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <returns>All the <see cref="Activity"/>s for the particular repository.</returns>
public IObservable<Activity> GetAllIssuesForRepository(string owner, string name)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");
return GetAllIssuesForRepository(owner, name, ApiOptions.None);
}
/// <summary>
/// Gets all the events for a given repository
/// </summary>
/// <remarks>
/// http://developer.github.com/v3/activity/events/#list-issue-events-for-a-repository
/// </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>All the <see cref="Activity"/>s for the particular repository.</returns>
public IObservable<Activity> GetAllIssuesForRepository(string owner, string name, ApiOptions options)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");
Ensure.ArgumentNotNull(options, "options");
return _connection.GetAndFlattenAllPages<Activity>(ApiUrls.IssuesEvents(owner, name), options);
}
@@ -159,6 +159,82 @@ namespace Octokit.Tests.Integration.Reactive
}
public class TheGetAllIssuesForRepositoryMethod
{
readonly ObservableEventsClient _eventsClient;
const string owner = "octokit";
const string name = "octokit.net";
public TheGetAllIssuesForRepositoryMethod()
{
_eventsClient = new ObservableEventsClient(Helper.GetAuthenticatedClient());
}
[IntegrationTest]
public async Task ReturnsRepositoryEvents()
{
var repositoryEvents = await _eventsClient.GetAllIssuesForRepository(owner, name).ToList();
Assert.NotEmpty(repositoryEvents);
}
[IntegrationTest]
public async Task ReturnsCorrectCountOfRepositoryEventsWithoutStart()
{
var options = new ApiOptions
{
PageSize = 5,
PageCount = 1
};
var repositoryEvents = await _eventsClient.GetAllIssuesForRepository(owner, name, options).ToList();
Assert.Equal(5, repositoryEvents.Count);
}
[IntegrationTest]
public async Task ReturnsCorrectCountOfRepositoryEventsWithStart()
{
var options = new ApiOptions
{
PageSize = 5,
PageCount = 1,
StartPage = 2
};
var repositoryEvents = await _eventsClient.GetAllIssuesForRepository(owner, name, options).ToList();
Assert.Equal(5, repositoryEvents.Count);
}
[IntegrationTest]
public async Task ReturnsDistinctRepositoryEventsBasedOnStartPage()
{
var startOptions = new ApiOptions
{
PageSize = 5,
PageCount = 1
};
var firstRepositoryEventsPage = await _eventsClient.GetAllIssuesForRepository(owner, name, startOptions).ToList();
var skipStartOptions = new ApiOptions
{
PageSize = 5,
PageCount = 1,
StartPage = 2
};
var secondRepositoryEventsPage = await _eventsClient.GetAllIssuesForRepository(owner, name, skipStartOptions).ToList();
Assert.NotEqual(firstRepositoryEventsPage[0].Id, secondRepositoryEventsPage[0].Id);
Assert.NotEqual(firstRepositoryEventsPage[1].Id, secondRepositoryEventsPage[1].Id);
Assert.NotEqual(firstRepositoryEventsPage[2].Id, secondRepositoryEventsPage[2].Id);
Assert.NotEqual(firstRepositoryEventsPage[3].Id, secondRepositoryEventsPage[3].Id);
Assert.NotEqual(firstRepositoryEventsPage[4].Id, secondRepositoryEventsPage[4].Id);
}
}
public class TheGetAllForRepositoryNetworkMethod
{
readonly ObservableEventsClient _eventsClient;
+49 -2
View File
@@ -72,7 +72,7 @@ namespace Octokit.Tests.Clients
client.GetAllForRepository("fake", "repo");
connection.Received().GetAll<Activity>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/issues/events"), Args.ApiOptions);
connection.Received().GetAll<Activity>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/events"), Args.ApiOptions);
}
[Fact]
public void RequestsCorrectUrlWithApiOptions()
@@ -90,7 +90,7 @@ namespace Octokit.Tests.Clients
client.GetAllForRepository("fake", "repo", options);
connection.Received().GetAll<Activity>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/issues/events"), options);
connection.Received().GetAll<Activity>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/events"), options);
}
[Fact]
@@ -109,6 +109,53 @@ namespace Octokit.Tests.Clients
}
}
public class TheGetAllIssuesForRepositoryMethod
{
[Fact]
public void RequestsCorrectUrl()
{
var connection = Substitute.For<IApiConnection>();
var client = new EventsClient(connection);
client.GetAllIssuesForRepository("fake", "repo");
connection.Received().GetAll<Activity>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/issues/events"), Args.ApiOptions);
}
[Fact]
public void RequestsCorrectUrlWithApiOptions()
{
var connection = Substitute.For<IApiConnection>();
var client = new EventsClient(connection);
var options = new ApiOptions
{
PageSize = 1,
PageCount = 1,
StartPage = 1
};
client.GetAllIssuesForRepository("fake", "repo", options);
connection.Received().GetAll<Activity>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/issues/events"), options);
}
[Fact]
public async Task EnsuresArgumentsNotNull()
{
var connection = Substitute.For<IApiConnection>();
var client = new EventsClient(connection);
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllIssuesForRepository(null, "name"));
await Assert.ThrowsAsync<ArgumentException>(() => client.GetAllIssuesForRepository("", "name"));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllIssuesForRepository("owner", null));
await Assert.ThrowsAsync<ArgumentException>(() => client.GetAllIssuesForRepository("owner", ""));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllIssuesForRepository("owner", "name", null));
await Assert.ThrowsAsync<ArgumentException>(() => client.GetAllIssuesForRepository("owner", "", ApiOptions.None));
await Assert.ThrowsAsync<ArgumentException>(() => client.GetAllIssuesForRepository("", "name", ApiOptions.None));
}
}
public class TheGetAllForRepositoryNetworkMethod
{
[Fact]
@@ -44,7 +44,7 @@ namespace Octokit.Tests.Reactive
client.GetAllForRepository("fake", "repo");
gitHubClient.Connection.Received(1).Get<List<Activity>>(new Uri("repos/fake/repo/issues/events", UriKind.Relative), Args.EmptyDictionary, null);
gitHubClient.Connection.Received(1).Get<List<Activity>>(new Uri("repos/fake/repo/events", UriKind.Relative), Args.EmptyDictionary, null);
}
[Fact]
@@ -60,6 +60,32 @@ namespace Octokit.Tests.Reactive
}
}
public class TheGetAllIssuesForRepositoryMethod
{
[Fact]
public void RequestsCorrectUrl()
{
var gitHubClient = Substitute.For<IGitHubClient>();
var client = new ObservableEventsClient(gitHubClient);
client.GetAllIssuesForRepository("fake", "repo");
gitHubClient.Connection.Received(1).Get<List<Activity>>(new Uri("repos/fake/repo/issues/events", UriKind.Relative), Args.EmptyDictionary, null);
}
[Fact]
public async Task EnsuresArgumentsNotNull()
{
var gitHubClient = Substitute.For<IGitHubClient>();
var client = new ObservableEventsClient(gitHubClient);
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllIssuesForRepository(null, "name").ToTask());
await Assert.ThrowsAsync<ArgumentException>(() => client.GetAllIssuesForRepository("", "name").ToTask());
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllIssuesForRepository("owner", null).ToTask());
await Assert.ThrowsAsync<ArgumentException>(() => client.GetAllIssuesForRepository("owner", "").ToTask());
}
}
public class TheGetAllForRepositoryNetworkMethod
{
[Fact]
+40 -3
View File
@@ -51,7 +51,7 @@ namespace Octokit
/// Gets all the events for a given repository
/// </summary>
/// <remarks>
/// http://developer.github.com/v3/activity/events/#list-issue-events-for-a-repository
/// https://developer.github.com/v3/activity/events/#list-repository-events
/// </remarks>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
@@ -68,7 +68,7 @@ namespace Octokit
/// Gets all the events for a given repository
/// </summary>
/// <remarks>
/// http://developer.github.com/v3/activity/events/#list-issue-events-for-a-repository
/// https://developer.github.com/v3/activity/events/#list-repository-events
/// </remarks>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
@@ -80,7 +80,44 @@ namespace Octokit
Ensure.ArgumentNotNullOrEmptyString(name, "name");
Ensure.ArgumentNotNull(options, "options");
return ApiConnection.GetAll<Activity>(ApiUrls.IssuesEvents(owner, name),options);
return ApiConnection.GetAll<Activity>(ApiUrls.Events(owner, name), options);
}
/// <summary>
/// Gets all the event issues for a given repository
/// </summary>
/// <remarks>
/// http://developer.github.com/v3/activity/events/#list-issue-events-for-a-repository
/// </remarks>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <returns>All the <see cref="Activity"/>s for the particular repository.</returns>
public Task<IReadOnlyList<Activity>> GetAllIssuesForRepository(string owner, string name)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");
return GetAllIssuesForRepository(owner, name, ApiOptions.None);
}
/// <summary>
/// Gets all the event issues for a given repository
/// </summary>
/// <remarks>
/// http://developer.github.com/v3/activity/events/#list-issue-events-for-a-repository
/// </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>All the <see cref="Activity"/>s for the particular repository.</returns>
public Task<IReadOnlyList<Activity>> GetAllIssuesForRepository(string owner, string name, ApiOptions options)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");
Ensure.ArgumentNotNull(options, "options");
return ApiConnection.GetAll<Activity>(ApiUrls.IssuesEvents(owner, name), options);
}
/// <summary>
+21
View File
@@ -54,7 +54,28 @@ namespace Octokit
/// <returns>All the <see cref="Activity"/>s for the particular repository.</returns>
Task<IReadOnlyList<Activity>> GetAllForRepository(string owner, string name, ApiOptions options);
/// <summary>
/// Gets all the issue events for a given repository
/// </summary>
/// <remarks>
/// http://developer.github.com/v3/activity/events/#list-issue-events-for-a-repository
/// </remarks>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <returns>All the <see cref="Activity"/>s for the particular repository.</returns>
Task<IReadOnlyList<Activity>> GetAllIssuesForRepository(string owner, string name);
/// <summary>
/// Gets all the issue events for a given repository
/// </summary>
/// <remarks>
/// http://developer.github.com/v3/activity/events/#list-issue-events-for-a-repository
/// </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>All the <see cref="Activity"/>s for the particular repository.</returns>
Task<IReadOnlyList<Activity>> GetAllIssuesForRepository(string owner, string name, ApiOptions options);
/// <summary>
/// Gets all the events for a given repository network
+11
View File
@@ -494,6 +494,17 @@ namespace Octokit
return "orgs/{0}/public_members/{1}".FormatUri(org, name);
}
/// <summary>
/// Returns the <see cref="Uri"/> that returns the issue/pull request event and issue info for the specified repository.
/// </summary>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <returns></returns>
public static Uri Events(string owner, string name)
{
return "repos/{0}/{1}/events".FormatUri(owner, name);
}
/// <summary>
/// Returns the <see cref="Uri"/> that returns the issue/pull request event info for the specified issue.
/// </summary>