Skip to content

Commit

Permalink
Add actual "GetAllForRepository" Activity Feed (#1288)
Browse files Browse the repository at this point in the history
  • Loading branch information
drasticactions authored and shiftkey committed May 5, 2016
1 parent 7bb751c commit 7b37225
Show file tree
Hide file tree
Showing 8 changed files with 283 additions and 6 deletions.
23 changes: 23 additions & 0 deletions Octokit.Reactive/Clients/IObservableEventsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,29 @@ public interface IObservableEventsClient
/// <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>
Expand Down
36 changes: 36 additions & 0 deletions Octokit.Reactive/Clients/ObservableEventsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,42 @@ public IObservable<Activity> GetAllForRepository(string owner, string name, ApiO
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);
}

Expand Down
76 changes: 76 additions & 0 deletions Octokit.Tests.Integration/Reactive/ObservableEventsClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,82 @@ public async Task ReturnsDistinctRepositoryEventsBasedOnStartPage()

}

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;
Expand Down
51 changes: 49 additions & 2 deletions Octokit.Tests/Clients/EventsClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public void RequestsCorrectUrl()

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()
Expand All @@ -90,7 +90,7 @@ public void RequestsCorrectUrlWithApiOptions()

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]
Expand All @@ -109,6 +109,53 @@ public async Task EnsuresArgumentsNotNull()
}
}

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]
Expand Down
28 changes: 27 additions & 1 deletion Octokit.Tests/Reactive/ObservableEventsClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public void RequestsCorrectUrl()

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]
Expand All @@ -60,6 +60,32 @@ public async Task EnsuresArgumentsNotNull()
}
}

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]
Expand Down
43 changes: 40 additions & 3 deletions Octokit/Clients/EventsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public Task<IReadOnlyList<Activity>> GetAll(ApiOptions options)
/// 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>
Expand All @@ -68,7 +68,7 @@ public Task<IReadOnlyList<Activity>> GetAllForRepository(string owner, string na
/// 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>
Expand All @@ -80,7 +80,44 @@ public Task<IReadOnlyList<Activity>> GetAllForRepository(string owner, string na
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>
Expand Down
21 changes: 21 additions & 0 deletions Octokit/Clients/IEventsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,28 @@ public interface IEventsClient
/// <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
Expand Down
11 changes: 11 additions & 0 deletions Octokit/Helpers/ApiUrls.cs
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,17 @@ public static Uri OrganizationMembership(string org, string name)
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>
Expand Down

0 comments on commit 7b37225

Please sign in to comment.