From e3bf6ed0c93b85f4bf8dad8abd890252b42f3b3f Mon Sep 17 00:00:00 2001 From: Josh Sullivan Date: Tue, 5 Nov 2013 03:08:05 -0500 Subject: [PATCH] Stubbed out the API for pull requests. Still missing pull request files, commit lists and merge checks. --- Octokit/Clients/IPullRequestsClient.cs | 65 +++++++++++++ Octokit/Clients/IRepositoriesClient.cs | 5 + Octokit/Clients/PullRequestsClient.cs | 99 ++++++++++++++++++++ Octokit/Clients/RepositoriesClient.cs | 6 ++ Octokit/Helpers/ApiUrls.cs | 23 +++++ Octokit/Models/Request/NewPullRequest.cs | 30 ++++++ Octokit/Models/Request/PullRequestRequest.cs | 20 ++++ Octokit/Models/Request/PullRequestUpdate.cs | 37 ++++++++ Octokit/Models/Response/PullRequest.cs | 10 ++ Octokit/Octokit-Mono.csproj | 5 + Octokit/Octokit-MonoAndroid.csproj | 5 + Octokit/Octokit-Monotouch.csproj | 5 + Octokit/Octokit-netcore45.csproj | 5 + Octokit/Octokit.csproj | 5 + 14 files changed, 320 insertions(+) create mode 100644 Octokit/Clients/IPullRequestsClient.cs create mode 100644 Octokit/Clients/PullRequestsClient.cs create mode 100644 Octokit/Models/Request/NewPullRequest.cs create mode 100644 Octokit/Models/Request/PullRequestRequest.cs create mode 100644 Octokit/Models/Request/PullRequestUpdate.cs diff --git a/Octokit/Clients/IPullRequestsClient.cs b/Octokit/Clients/IPullRequestsClient.cs new file mode 100644 index 00000000..5bebb732 --- /dev/null +++ b/Octokit/Clients/IPullRequestsClient.cs @@ -0,0 +1,65 @@ +using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; +using System.Threading.Tasks; + +namespace Octokit +{ + public interface IPullRequestsClient + { + /// + /// Gets a single Pull Request by number. + /// + /// + /// http://developer.github.com/v3/pulls/#get-a-single-pull-request + /// + /// + [SuppressMessage("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "Get", + Justification = "Method makes a network request")] + Task Get(string owner, string name, int number); + + /// + /// Gets all open pull requests for the repository. + /// + /// + /// http://developer.github.com/v3/pulls/#list-pull-requests + /// + /// The owner of the repository + /// The name of the repository + /// + Task> GetForRepository(string owner, string name); + + /// + /// Gets all open pull requests for the repository. + /// + /// + /// http://developer.github.com/v3/pulls/#list-pull-requests + /// + /// The owner of the repository + /// The name of the repository + /// Used to filter and sort the list of pull requests returned + /// + Task> GetForRepository(string owner, string name, PullRequestRequest request); + + /// + /// Creates a pull request for the specified repository. + /// + /// http://developer.github.com/v3/pulls/#create-a-pull-request + /// The owner of the repository + /// The name of the repository + /// A instance describing the new PullRequest to create + /// + Task Create(string owner, string name, NewPullRequest newPullRequest); + + /// + /// Creates a pull request for the specified repository. + /// + /// http://developer.github.com/v3/pulls/#update-a-pull-request + /// The owner of the repository + /// The name of the repository + /// The PullRequest number + /// An instance describing the changes to make to the PullRequest + /// + /// + Task Update(string owner, string name, int number, PullRequestUpdate pullRequestUpdate); + } +} diff --git a/Octokit/Clients/IRepositoriesClient.cs b/Octokit/Clients/IRepositoriesClient.cs index 883f9781..b9fb1413 100644 --- a/Octokit/Clients/IRepositoriesClient.cs +++ b/Octokit/Clients/IRepositoriesClient.cs @@ -14,6 +14,11 @@ namespace Octokit /// public interface IRepositoriesClient { + /// + /// Client for managing pull requests. + /// + IPullRequestsClient PullRequest { get; } + /// /// Creates a new repository for the current user. /// diff --git a/Octokit/Clients/PullRequestsClient.cs b/Octokit/Clients/PullRequestsClient.cs new file mode 100644 index 00000000..5bf55e59 --- /dev/null +++ b/Octokit/Clients/PullRequestsClient.cs @@ -0,0 +1,99 @@ +using System; +using System.Collections.Generic; +using System.Threading.Tasks; + +namespace Octokit +{ + public class PullRequestsClient : ApiClient, IPullRequestsClient + { + public PullRequestsClient(IApiConnection apiConnection) + : base(apiConnection) + { + } + + /// + /// Gets a single Pull Request by number. + /// + /// + /// http://developer.github.com/v3/pulls/#get-a-single-pull-request + /// + /// + public Task Get(string owner, string name, int number) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + + return ApiConnection.Get(ApiUrls.PullRequest(owner, name, number)); + } + + /// + /// Gets all open pull requests for the repository. + /// + /// + /// http://developer.github.com/v3/pulls/#list-pull-requests + /// + /// The owner of the repository + /// The name of the repository + /// + public Task> GetForRepository(string owner, string name) + { + return GetForRepository(owner, name, new PullRequestRequest()); + } + + /// + /// Gets all open pull requests for the repository. + /// + /// + /// http://developer.github.com/v3/pulls/#list-pull-requests + /// + /// The owner of the repository + /// The name of the repository + /// Used to filter and sort the list of pull requests returned + /// + public Task> GetForRepository(string owner, string name, PullRequestRequest request) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + Ensure.ArgumentNotNull(request, "request"); + + return ApiConnection.GetAll(ApiUrls.PullRequests(owner, name), + request.ToParametersDictionary()); + } + + /// + /// Creates a pull request for the specified repository. + /// + /// http://developer.github.com/v3/pulls/#create-a-pull-request + /// The owner of the repository + /// The name of the repository + /// A instance describing the new PullRequest to create + /// + public Task Create(string owner, string name, NewPullRequest newPullRequest) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + Ensure.ArgumentNotNull(newPullRequest, "newPullRequest"); + + return ApiConnection.Post(ApiUrls.PullRequests(owner, name), newPullRequest); + } + + /// + /// Creates a pull request for the specified repository. + /// + /// http://developer.github.com/v3/pulls/#update-a-pull-request + /// The owner of the repository + /// The name of the repository + /// The PullRequest number + /// An instance describing the changes to make to the PullRequest + /// + /// + public Task Update(string owner, string name, int number, PullRequestUpdate pullRequestUpdate) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + Ensure.ArgumentNotNull(pullRequestUpdate, "pullRequestUpdate"); + + return ApiConnection.Patch(ApiUrls.PullRequest(owner, name, number), pullRequestUpdate); + } + } +} diff --git a/Octokit/Clients/RepositoriesClient.cs b/Octokit/Clients/RepositoriesClient.cs index 7ec5e31d..d031c040 100644 --- a/Octokit/Clients/RepositoriesClient.cs +++ b/Octokit/Clients/RepositoriesClient.cs @@ -22,8 +22,14 @@ namespace Octokit { CommitStatus = new CommitStatusClient(apiConnection); RepoCollaborators = new RepoCollaboratorsClient(apiConnection); + PullRequest = new PullRequestsClient(apiConnection); } + /// + /// Client for managing pull requests. + /// + public IPullRequestsClient PullRequest { get; private set; } + /// /// Creates a new repository for the current user. /// diff --git a/Octokit/Helpers/ApiUrls.cs b/Octokit/Helpers/ApiUrls.cs index be4379eb..0fbc9321 100644 --- a/Octokit/Helpers/ApiUrls.cs +++ b/Octokit/Helpers/ApiUrls.cs @@ -895,5 +895,28 @@ namespace Octokit { return "users/{0}/following/{1}".FormatUri(login, following); } + + /// + /// Returns the that lists the pull requests for a repository. + /// + /// The owner of the repository + /// The name of the repository + /// + public static Uri PullRequests(string owner, string name) + { + return "repos/{0}/{1}/pulls".FormatUri(owner, name); + } + + /// + /// Returns the that returns the specified pull request. + /// + /// The owner of the repository + /// The name of the repository + /// /// The pull request number + /// + public static Uri PullRequest(string owner, string name, int number) + { + return "repos/{0}/{1}/pulls/{2}".FormatUri(owner, name, number); + } } } diff --git a/Octokit/Models/Request/NewPullRequest.cs b/Octokit/Models/Request/NewPullRequest.cs new file mode 100644 index 00000000..7584bacb --- /dev/null +++ b/Octokit/Models/Request/NewPullRequest.cs @@ -0,0 +1,30 @@ +using System; + +namespace Octokit +{ + /// + /// Describes a new pull request to create via the method. + /// + public class NewPullRequest + { + public NewPullRequest(string title) + { + Ensure.ArgumentNotNull(title, "title"); + + Title = title; + State = ItemState.Open; + } + + /// + /// Title of the pull request (required) + /// + public string Title { get; private set; } + + /// + /// Whether the pull request is open or closed. The default is . + /// + public ItemState State { get; set; } + + + } +} diff --git a/Octokit/Models/Request/PullRequestRequest.cs b/Octokit/Models/Request/PullRequestRequest.cs new file mode 100644 index 00000000..b2cd893c --- /dev/null +++ b/Octokit/Models/Request/PullRequestRequest.cs @@ -0,0 +1,20 @@ +using Octokit.Internal; + +namespace Octokit +{ + public class PullRequestRequest : RequestParameters + { + public PullRequestRequest() + { + State = ItemState.Open; + } + + public ItemState State { get; set; } + + [Parameter(Key = "head")] + public string Head { get; set; } + + [Parameter(Key = "base")] + public string Base { get; set; } + } +} diff --git a/Octokit/Models/Request/PullRequestUpdate.cs b/Octokit/Models/Request/PullRequestUpdate.cs new file mode 100644 index 00000000..941d23a0 --- /dev/null +++ b/Octokit/Models/Request/PullRequestUpdate.cs @@ -0,0 +1,37 @@ +namespace Octokit +{ + public class PullRequestUpdate + { + /// + /// The pull request number. + /// + public int Number { get; set; } + + /// + /// Title of the pull request (required) + /// + public string Title { get; set; } + + /// + /// Whether the pull request is open or closed. The default is . + /// + public ItemState State { get; set; } + + /// + /// The branch (or git ref) you want your changes pulled into. This should be an existing + /// branch on the current repository. You cannot submit a pull request to one repo that + /// requests a merge to a base of another repo. + /// + public string Base { get; set; } + + /// + /// The branch (or git ref) where your changes are implemented. + /// + public string Head { get; set; } + + /// + /// The body for the pull request. Supports GFM. + /// + public string Body { get; set; } + } +} diff --git a/Octokit/Models/Response/PullRequest.cs b/Octokit/Models/Response/PullRequest.cs index 95eb6161..ed977d41 100644 --- a/Octokit/Models/Response/PullRequest.cs +++ b/Octokit/Models/Response/PullRequest.cs @@ -4,6 +4,16 @@ namespace Octokit { public class PullRequest { + /// + /// The URL for this pull request. + /// + public Uri Url { get; set; } + + /// + /// The pull request number. + /// + public int Number { get; set; } + public Uri HtmlUrl { get; set; } public Uri DiffUrl { get; set; } public Uri PatchUrl { get; set; } diff --git a/Octokit/Octokit-Mono.csproj b/Octokit/Octokit-Mono.csproj index cc349c25..dccb201c 100644 --- a/Octokit/Octokit-Mono.csproj +++ b/Octokit/Octokit-Mono.csproj @@ -255,6 +255,11 @@ + + + + + \ No newline at end of file diff --git a/Octokit/Octokit-MonoAndroid.csproj b/Octokit/Octokit-MonoAndroid.csproj index f196e297..c5cdf837 100644 --- a/Octokit/Octokit-MonoAndroid.csproj +++ b/Octokit/Octokit-MonoAndroid.csproj @@ -265,6 +265,11 @@ + + + + + \ No newline at end of file diff --git a/Octokit/Octokit-Monotouch.csproj b/Octokit/Octokit-Monotouch.csproj index 1908e4b1..5b1ba98e 100644 --- a/Octokit/Octokit-Monotouch.csproj +++ b/Octokit/Octokit-Monotouch.csproj @@ -260,6 +260,11 @@ + + + + + \ No newline at end of file diff --git a/Octokit/Octokit-netcore45.csproj b/Octokit/Octokit-netcore45.csproj index c855b507..68d7309f 100644 --- a/Octokit/Octokit-netcore45.csproj +++ b/Octokit/Octokit-netcore45.csproj @@ -253,6 +253,11 @@ + + + + + diff --git a/Octokit/Octokit.csproj b/Octokit/Octokit.csproj index 6402442c..bcc1af8d 100644 --- a/Octokit/Octokit.csproj +++ b/Octokit/Octokit.csproj @@ -117,6 +117,7 @@ + @@ -125,6 +126,7 @@ + @@ -138,6 +140,9 @@ + + +