mirror of
https://github.com/zoriya/octokit.net.git
synced 2026-06-08 12:42:32 +00:00
modified XML docs
added new overloads
This commit is contained in:
@@ -4,6 +4,12 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace Octokit
|
||||
{
|
||||
/// <summary>
|
||||
/// A client for GitHub's Pull Requests API.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// See the <a href="http://developer.github.com/v3/activity/notifications/">Pull Requests API documentation</a> for more information.
|
||||
/// </remarks>
|
||||
public class PullRequestsClient : ApiClient, IPullRequestsClient
|
||||
{
|
||||
public PullRequestsClient(IApiConnection apiConnection) : base(apiConnection)
|
||||
@@ -31,6 +37,18 @@ namespace Octokit
|
||||
return ApiConnection.Get<PullRequest>(ApiUrls.PullRequest(owner, name, number));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get a pull request by number.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// http://developer.github.com/v3/pulls/#get-a-single-pull-request
|
||||
/// </remarks>
|
||||
/// <returns>A <see cref="PullRequest"/> result</returns>
|
||||
public Task<PullRequest> Get(int repositoryId, int number)
|
||||
{
|
||||
return ApiConnection.Get<PullRequest>(ApiUrls.PullRequest(repositoryId, number));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get all open pull requests for the repository.
|
||||
/// </summary>
|
||||
@@ -48,6 +66,19 @@ namespace Octokit
|
||||
return GetAllForRepository(owner, name, new PullRequestRequest(), ApiOptions.None);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get all open pull requests for the repository.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// http://developer.github.com/v3/pulls/#list-pull-requests
|
||||
/// </remarks>
|
||||
/// <param name="repositoryId">The ID of the repository</param>
|
||||
/// <returns>A <see cref="IReadOnlyList{PullRequest}"/> of <see cref="PullRequest"/>s which are currently open</returns>
|
||||
public Task<IReadOnlyList<PullRequest>> GetAllForRepository(int repositoryId)
|
||||
{
|
||||
return GetAllForRepository(repositoryId, new PullRequestRequest(), ApiOptions.None);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get all open pull requests for the repository.
|
||||
/// </summary>
|
||||
@@ -67,6 +98,22 @@ namespace Octokit
|
||||
return GetAllForRepository(owner, name, new PullRequestRequest(), options);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get all open pull requests for the repository.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// http://developer.github.com/v3/pulls/#list-pull-requests
|
||||
/// </remarks>
|
||||
/// <param name="repositoryId">The ID of the repository</param>
|
||||
/// <param name="options">Options for changing the API response</param>
|
||||
/// <returns>A <see cref="IReadOnlyList{PullRequest}"/> of <see cref="PullRequest"/>s which are currently open</returns>
|
||||
public Task<IReadOnlyList<PullRequest>> GetAllForRepository(int repositoryId, ApiOptions options)
|
||||
{
|
||||
Ensure.ArgumentNotNull(options, "options");
|
||||
|
||||
return GetAllForRepository(repositoryId, new PullRequestRequest(), options);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Query pull requests for the repository based on criteria
|
||||
/// </summary>
|
||||
@@ -86,6 +133,22 @@ namespace Octokit
|
||||
return GetAllForRepository(owner, name, request, ApiOptions.None);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Query pull requests for the repository based on criteria
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// http://developer.github.com/v3/pulls/#list-pull-requests
|
||||
/// </remarks>
|
||||
/// <param name="repositoryId">The ID of the repository</param>
|
||||
/// <param name="request">Used to filter and sort the list of pull requests returned</param>
|
||||
/// <returns>A <see cref="IReadOnlyList{PullRequest}"/> of <see cref="PullRequest"/>s which match the criteria</returns>
|
||||
public Task<IReadOnlyList<PullRequest>> GetAllForRepository(int repositoryId, PullRequestRequest request)
|
||||
{
|
||||
Ensure.ArgumentNotNull(request, "request");
|
||||
|
||||
return GetAllForRepository(repositoryId, request, ApiOptions.None);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Query pull requests for the repository based on criteria
|
||||
/// </summary>
|
||||
@@ -108,6 +171,25 @@ namespace Octokit
|
||||
request.ToParametersDictionary(), options);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Query pull requests for the repository based on criteria
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// http://developer.github.com/v3/pulls/#list-pull-requests
|
||||
/// </remarks>
|
||||
/// <param name="repositoryId">The ID of the repository</param>
|
||||
/// <param name="request">Used to filter and sort the list of pull requests returned</param>
|
||||
/// <param name="options">Options for changing the API response</param>
|
||||
/// <returns>A <see cref="IReadOnlyList{PullRequest}"/> of <see cref="PullRequest"/>s which match the criteria</returns>
|
||||
public Task<IReadOnlyList<PullRequest>> GetAllForRepository(int repositoryId, PullRequestRequest request, ApiOptions options)
|
||||
{
|
||||
Ensure.ArgumentNotNull(request, "request");
|
||||
Ensure.ArgumentNotNull(options, "options");
|
||||
|
||||
return ApiConnection.GetAll<PullRequest>(ApiUrls.PullRequests(repositoryId),
|
||||
request.ToParametersDictionary(), options);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create a pull request for the specified repository.
|
||||
/// </summary>
|
||||
@@ -125,6 +207,20 @@ namespace Octokit
|
||||
return ApiConnection.Post<PullRequest>(ApiUrls.PullRequests(owner, name), newPullRequest);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create a pull request for the specified repository.
|
||||
/// </summary>
|
||||
/// <remarks>http://developer.github.com/v3/pulls/#create-a-pull-request</remarks>
|
||||
/// <param name="repositoryId">The ID of the repository</param>
|
||||
/// <param name="newPullRequest">A <see cref="NewPullRequest"/> instance describing the new PullRequest to create</param>
|
||||
/// <returns>A <see cref="PullRequest"/> result which was created on the server</returns>
|
||||
public Task<PullRequest> Create(int repositoryId, NewPullRequest newPullRequest)
|
||||
{
|
||||
Ensure.ArgumentNotNull(newPullRequest, "newPullRequest");
|
||||
|
||||
return ApiConnection.Post<PullRequest>(ApiUrls.PullRequests(repositoryId), newPullRequest);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create a pull request for the specified repository.
|
||||
/// </summary>
|
||||
@@ -144,6 +240,22 @@ namespace Octokit
|
||||
return ApiConnection.Patch<PullRequest>(ApiUrls.PullRequest(owner, name, number), pullRequestUpdate);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create a pull request for the specified repository.
|
||||
/// </summary>
|
||||
/// <remarks>http://developer.github.com/v3/pulls/#update-a-pull-request</remarks>
|
||||
/// <param name="repositoryId">The ID of the repository</param>
|
||||
/// <param name="number">The PullRequest number</param>
|
||||
/// <param name="pullRequestUpdate">An <see cref="PullRequestUpdate"/> instance describing the changes to make to the PullRequest
|
||||
/// </param>
|
||||
/// <returns>An updated <see cref="PullRequest"/> result</returns>
|
||||
public Task<PullRequest> Update(int repositoryId, int number, PullRequestUpdate pullRequestUpdate)
|
||||
{
|
||||
Ensure.ArgumentNotNull(pullRequestUpdate, "pullRequestUpdate");
|
||||
|
||||
return ApiConnection.Patch<PullRequest>(ApiUrls.PullRequest(repositoryId, number), pullRequestUpdate);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Merge a pull request.
|
||||
/// </summary>
|
||||
@@ -162,7 +274,41 @@ namespace Octokit
|
||||
try
|
||||
{
|
||||
var endpoint = ApiUrls.MergePullRequest(owner, name, number);
|
||||
return await ApiConnection.Put<PullRequestMerge>(endpoint, mergePullRequest,null,
|
||||
return await ApiConnection.Put<PullRequestMerge>(endpoint, mergePullRequest, null,
|
||||
AcceptHeaders.SquashCommitPreview).ConfigureAwait(false);
|
||||
}
|
||||
catch (ApiException ex)
|
||||
{
|
||||
if (ex.StatusCode == HttpStatusCode.MethodNotAllowed)
|
||||
{
|
||||
throw new PullRequestNotMergeableException(ex.HttpResponse);
|
||||
}
|
||||
|
||||
if (ex.StatusCode == HttpStatusCode.Conflict)
|
||||
{
|
||||
throw new PullRequestMismatchException(ex.HttpResponse);
|
||||
}
|
||||
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Merge a pull request.
|
||||
/// </summary>
|
||||
/// <remarks>http://developer.github.com/v3/pulls/#merge-a-pull-request-merge-buttontrade</remarks>
|
||||
/// <param name="repositoryId">The ID of the repository</param>
|
||||
/// <param name="number">The pull request number</param>
|
||||
/// <param name="mergePullRequest">A <see cref="MergePullRequest"/> instance describing a pull request merge</param>
|
||||
/// <returns>An <see cref="PullRequestMerge"/> result which indicates the merge result</returns>
|
||||
public async Task<PullRequestMerge> Merge(int repositoryId, int number, MergePullRequest mergePullRequest)
|
||||
{
|
||||
Ensure.ArgumentNotNull(mergePullRequest, "mergePullRequest");
|
||||
|
||||
try
|
||||
{
|
||||
var endpoint = ApiUrls.MergePullRequest(repositoryId, number);
|
||||
return await ApiConnection.Put<PullRequestMerge>(endpoint, mergePullRequest, null,
|
||||
AcceptHeaders.SquashCommitPreview).ConfigureAwait(false);
|
||||
}
|
||||
catch (ApiException ex)
|
||||
@@ -206,6 +352,27 @@ namespace Octokit
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the pull request merge status.
|
||||
/// </summary>
|
||||
/// <remarks>http://developer.github.com/v3/pulls/#get-if-a-pull-request-has-been-merged</remarks>
|
||||
/// <param name="repositoryId">The ID of the repository</param>
|
||||
/// <param name="number">The pull request number</param>
|
||||
/// <returns>True if the operation has been merged, false otherwise</returns>
|
||||
public async Task<bool> Merged(int repositoryId, int number)
|
||||
{
|
||||
try
|
||||
{
|
||||
var endpoint = ApiUrls.MergePullRequest(repositoryId, number);
|
||||
var response = await Connection.Get<object>(endpoint, null, null).ConfigureAwait(false);
|
||||
return response.HttpResponse.IsTrue();
|
||||
}
|
||||
catch (NotFoundException)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the list of commits on a pull request.
|
||||
/// </summary>
|
||||
@@ -222,6 +389,18 @@ namespace Octokit
|
||||
return ApiConnection.GetAll<PullRequestCommit>(ApiUrls.PullRequestCommits(owner, name, number));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the list of commits on a pull request.
|
||||
/// </summary>
|
||||
/// <remarks>http://developer.github.com/v3/pulls/#list-commits-on-a-pull-request</remarks>
|
||||
/// <param name="repositoryId">The ID of the repository</param>
|
||||
/// <param name="number">The pull request number</param>
|
||||
/// <returns>A <see cref="IReadOnlyList{PullRequestCommit}"/> of <see cref="Commit"/>s which are part of this pull request</returns>
|
||||
public Task<IReadOnlyList<PullRequestCommit>> Commits(int repositoryId, int number)
|
||||
{
|
||||
return ApiConnection.GetAll<PullRequestCommit>(ApiUrls.PullRequestCommits(repositoryId, number));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the list of files on a pull request.
|
||||
/// </summary>
|
||||
@@ -237,5 +416,17 @@ namespace Octokit
|
||||
|
||||
return ApiConnection.GetAll<PullRequestFile>(ApiUrls.PullRequestFiles(owner, name, 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>
|
||||
/// <returns>A <see cref="IReadOnlyList{PullRequestFile}"/> which are part of this pull request</returns>
|
||||
public Task<IReadOnlyList<PullRequestFile>> Files(int repositoryId, int number)
|
||||
{
|
||||
return ApiConnection.GetAll<PullRequestFile>(ApiUrls.PullRequestFiles(repositoryId, number));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user