Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to pass ApiOptions to PullRequestsClient.Files #2553

Merged
merged 2 commits into from
Aug 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions Octokit.Reactive/Clients/IObservablePullRequestsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,16 @@ public interface IObservablePullRequestsClient
/// <param name="number">The pull request number</param>
IObservable<PullRequestCommit> Commits(long repositoryId, int number);

/// <summary>
/// Get the list of files on a pull request.
/// </summary>
/// <remarks>https://developer.github.com/v3/pulls/#list-pull-requests-files</remarks>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <param name="number">The pull request number</param>
/// <param name="options">Options for changing the API response</param>
IObservable<PullRequestFile> Files(string owner, string name, int number, ApiOptions options);

/// <summary>
/// Get the list of files on a pull request.
/// </summary>
Expand All @@ -240,6 +250,15 @@ public interface IObservablePullRequestsClient
/// <param name="number">The pull request number</param>
IObservable<PullRequestFile> Files(string owner, string name, int number);

/// <summary>
/// Get the list of files on a pull request.
/// </summary>
/// <remarks>https://developer.github.com/v3/pulls/#list-pull-requests-files</remarks>
/// <param name="repositoryId">The Id of the repository</param>
/// <param name="number">The pull request number</param>
/// <param name="options">Options for changing the API response</param>
IObservable<PullRequestFile> Files(long repositoryId, int number, ApiOptions options);

/// <summary>
/// Get the list of files on a pull request.
/// </summary>
Expand Down
31 changes: 28 additions & 3 deletions Octokit.Reactive/Clients/ObservablePullRequestsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -359,12 +359,37 @@ public IObservable<PullRequestCommit> Commits(long repositoryId, int number)
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <param name="number">The pull request number</param>
public IObservable<PullRequestFile> Files(string owner, string name, int number)
/// <param name="options">Options for changing the API response</param>
public IObservable<PullRequestFile> Files(string owner, string name, int number, ApiOptions options)
{
Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner));
Ensure.ArgumentNotNullOrEmptyString(name, nameof(name));

return _connection.GetAndFlattenAllPages<PullRequestFile>(ApiUrls.PullRequestFiles(owner, name, number));
return _connection.GetAndFlattenAllPages<PullRequestFile>(ApiUrls.PullRequestFiles(owner, name, number), options);
}

/// <summary>
/// Get the list of files on a pull request.
/// </summary>
/// <remarks>https://developer.github.com/v3/pulls/#list-pull-requests-files</remarks>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <param name="number">The pull request number</param>
public IObservable<PullRequestFile> Files(string owner, string name, int number)
{
return Files(owner, name, number, ApiOptions.None);
}

/// <summary>
/// Get the list of files on a pull request.
/// </summary>
/// <remarks>https://developer.github.com/v3/pulls/#list-pull-requests-files</remarks>
/// <param name="repositoryId">The Id of the repository</param>
/// <param name="number">The pull request number</param>
/// <param name="options">Options for changing the API response</param>
public IObservable<PullRequestFile> Files(long repositoryId, int number, ApiOptions options)
{
return _connection.GetAndFlattenAllPages<PullRequestFile>(ApiUrls.PullRequestFiles(repositoryId, number), options);
}

/// <summary>
Expand All @@ -375,7 +400,7 @@ public IObservable<PullRequestFile> Files(string owner, string name, int number)
/// <param name="number">The pull request number</param>
public IObservable<PullRequestFile> Files(long repositoryId, int number)
{
return _connection.GetAndFlattenAllPages<PullRequestFile>(ApiUrls.PullRequestFiles(repositoryId, number));
return Files(repositoryId, number, ApiOptions.None);
}
}
}
4 changes: 2 additions & 2 deletions Octokit.Tests/Clients/PullRequestsClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ public async Task RequestsCorrectUrl()
await client.Files("fake", "repo", 42);

connection.Received()
.GetAll<PullRequestFile>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/pulls/42/files"));
.GetAll<PullRequestFile>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/pulls/42/files"), Args.ApiOptions);
}

[Fact]
Expand All @@ -473,7 +473,7 @@ public async Task RequestsCorrectUrlWithRepositoryId()
await client.Files(1, 42);

connection.Received()
.GetAll<PullRequestFile>(Arg.Is<Uri>(u => u.ToString() == "repositories/1/pulls/42/files"));
.GetAll<PullRequestFile>(Arg.Is<Uri>(u => u.ToString() == "repositories/1/pulls/42/files"), Args.ApiOptions);
}

[Fact]
Expand Down
8 changes: 4 additions & 4 deletions Octokit.Tests/Reactive/ObservablePullRequestsClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -704,7 +704,7 @@ public async Task FetchesAllFilesForPullRequest()
CreateResponse(HttpStatusCode.OK),
new List<PullRequestFile> { file }
);
connection.Get<List<PullRequestFile>>(Args.Uri, null)
connection.Get<List<PullRequestFile>>(Args.Uri, Arg.Any<IDictionary<string, string>>())
.Returns(Task.FromResult(response));
gitHubClient.Connection.Returns(connection);
var client = new ObservablePullRequestsClient(gitHubClient);
Expand All @@ -713,7 +713,7 @@ public async Task FetchesAllFilesForPullRequest()

Assert.Equal(1, files.Count);
Assert.Same(file, files[0]);
connection.Received().Get<List<PullRequestFile>>(new Uri(expectedUrl, UriKind.Relative), null);
connection.Received().Get<List<PullRequestFile>>(new Uri(expectedUrl, UriKind.Relative), Arg.Any<IDictionary<string, string>>());
}

[Fact]
Expand All @@ -728,7 +728,7 @@ public async Task FetchesAllFilesForPullRequestWithRepositoryId()
CreateResponse(HttpStatusCode.OK),
new List<PullRequestFile> { file }
);
connection.Get<List<PullRequestFile>>(Args.Uri, null)
connection.Get<List<PullRequestFile>>(Args.Uri, Arg.Any<IDictionary<string, string>>())
.Returns(Task.FromResult(response));
gitHubClient.Connection.Returns(connection);
var client = new ObservablePullRequestsClient(gitHubClient);
Expand All @@ -737,7 +737,7 @@ public async Task FetchesAllFilesForPullRequestWithRepositoryId()

Assert.Equal(1, files.Count);
Assert.Same(file, files[0]);
connection.Received().Get<List<PullRequestFile>>(new Uri(expectedUrl, UriKind.Relative), null);
connection.Received().Get<List<PullRequestFile>>(new Uri(expectedUrl, UriKind.Relative), Arg.Any<IDictionary<string, string>>());
}

[Fact]
Expand Down
19 changes: 19 additions & 0 deletions Octokit/Clients/IPullRequestsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,16 @@ public interface IPullRequestsClient
/// <param name="number">The pull request number</param>
Task<IReadOnlyList<PullRequestCommit>> Commits(long repositoryId, int number);

/// <summary>
/// Get the list of files on a pull request.
/// </summary>
/// <remarks>https://developer.github.com/v3/pulls/#list-pull-requests-files</remarks>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <param name="number">The pull request number</param>
/// <param name="options">Options for changing the API response</param>
Task<IReadOnlyList<PullRequestFile>> Files(string owner, string name, int number, ApiOptions options);

/// <summary>
/// Get the list of files on a pull request.
/// </summary>
Expand All @@ -237,6 +247,15 @@ public interface IPullRequestsClient
/// <param name="number">The pull request number</param>
Task<IReadOnlyList<PullRequestFile>> Files(string owner, string name, int number);

/// <summary>
/// Get the list of files on a pull request.
/// </summary>
/// <remarks>https://developer.github.com/v3/pulls/#list-pull-requests-files</remarks>
/// <param name="repositoryId">The Id of the repository</param>
/// <param name="number">The pull request number</param>
/// <param name="options">Options for changing the API response</param>
Task<IReadOnlyList<PullRequestFile>> Files(long repositoryId, int number, ApiOptions options);

/// <summary>
/// Get the list of files on a pull request.
/// </summary>
Expand Down
31 changes: 29 additions & 2 deletions Octokit/Clients/PullRequestsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -425,11 +425,25 @@ public Task<IReadOnlyList<PullRequestCommit>> Commits(long repositoryId, int num
/// <param name="number">The pull request number</param>
[ManualRoute("GET", "/repos/{owner}/{repo}/pulls/{pull_number}/files")]
public Task<IReadOnlyList<PullRequestFile>> Files(string owner, string name, int number)
{
return Files(owner, name, number, ApiOptions.None);
}

/// <summary>
/// Get the list of files on a pull request.
/// </summary>
/// <remarks>https://developer.github.com/v3/pulls/#list-pull-requests-files</remarks>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <param name="number">The pull request number</param>
/// <param name="options">Options for changing the API response</param>
[ManualRoute("GET", "/repos/{owner}/{repo}/pulls/{pull_number}/files")]
public Task<IReadOnlyList<PullRequestFile>> Files(string owner, string name, int number, ApiOptions options)
{
Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner));
Ensure.ArgumentNotNullOrEmptyString(name, nameof(name));

return ApiConnection.GetAll<PullRequestFile>(ApiUrls.PullRequestFiles(owner, name, number));
return ApiConnection.GetAll<PullRequestFile>(ApiUrls.PullRequestFiles(owner, name, number), options);
}

/// <summary>
Expand All @@ -441,7 +455,20 @@ public Task<IReadOnlyList<PullRequestFile>> Files(string owner, string name, int
[ManualRoute("GET", "/repositories/{id}/pulls/{number}/files")]
public Task<IReadOnlyList<PullRequestFile>> Files(long repositoryId, int number)
{
return ApiConnection.GetAll<PullRequestFile>(ApiUrls.PullRequestFiles(repositoryId, number));
return Files(repositoryId, number, ApiOptions.None);
}

/// <summary>
/// Get the list of files on a pull request.
/// </summary>
/// <remarks>https://developer.github.com/v3/pulls/#list-pull-requests-files</remarks>
/// <param name="repositoryId">The Id of the repository</param>
/// <param name="number">The pull request number</param>
/// <param name="options">Options for changing the API response</param>
[ManualRoute("GET", "/repositories/{id}/pulls/{number}/files")]
public Task<IReadOnlyList<PullRequestFile>> Files(long repositoryId, int number, ApiOptions options)
{
return ApiConnection.GetAll<PullRequestFile>(ApiUrls.PullRequestFiles(repositoryId, number), options);
}
}
}