From f73084671315522de6f171e902ac9a432cce9486 Mon Sep 17 00:00:00 2001 From: Henrik Andersson Date: Mon, 16 Mar 2015 17:53:50 +1000 Subject: [PATCH] Add method for getting all files for a PR --- .../Clients/IObservablePullRequestsClient.cs | 11 +++++ .../Clients/ObservablePullRequestsClient.cs | 16 +++++++ Octokit/Clients/IPullRequestsClient.cs | 10 ++++ Octokit/Clients/PullRequestsClient.cs | 16 +++++++ Octokit/Helpers/ApiUrls.cs | 5 ++ Octokit/Models/Response/PullRequestFile.cs | 46 +++++++++++++++++++ Octokit/Octokit-Mono.csproj | 1 + Octokit/Octokit-MonoAndroid.csproj | 1 + Octokit/Octokit-Monotouch.csproj | 1 + Octokit/Octokit-Portable.csproj | 1 + Octokit/Octokit-netcore45.csproj | 1 + Octokit/Octokit.csproj | 1 + 12 files changed, 110 insertions(+) create mode 100644 Octokit/Models/Response/PullRequestFile.cs diff --git a/Octokit.Reactive/Clients/IObservablePullRequestsClient.cs b/Octokit.Reactive/Clients/IObservablePullRequestsClient.cs index 7fd79c95..1ada7bec 100644 --- a/Octokit.Reactive/Clients/IObservablePullRequestsClient.cs +++ b/Octokit.Reactive/Clients/IObservablePullRequestsClient.cs @@ -96,5 +96,16 @@ namespace Octokit.Reactive /// The pull request number /// A collection of results IObservable Commits(string owner, string name, int number); + + /// + /// Get the list of files on a pull request. + /// + /// https://developer.github.com/v3/pulls/#list-pull-requests-files + /// The owner of the repository + /// The name of the repository + /// The pull request number + /// A collection of results + IObservable Files(string owner, string name, int number); + } } diff --git a/Octokit.Reactive/Clients/ObservablePullRequestsClient.cs b/Octokit.Reactive/Clients/ObservablePullRequestsClient.cs index ca8cd05d..ef57fdd3 100644 --- a/Octokit.Reactive/Clients/ObservablePullRequestsClient.cs +++ b/Octokit.Reactive/Clients/ObservablePullRequestsClient.cs @@ -157,5 +157,21 @@ namespace Octokit.Reactive return _connection.GetAndFlattenAllPages(ApiUrls.PullRequestCommits(owner, name, number)); } + + /// + /// Get the list of files on a pull request. + /// + /// https://developer.github.com/v3/pulls/#list-pull-requests-files + /// The owner of the repository + /// The name of the repository + /// The pull request number + /// A collection of results + public IObservable Files(string owner, string name, int number) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + + return _connection.GetAndFlattenAllPages(ApiUrls.PullRequestFiles(owner, name, number)); + } } } \ No newline at end of file diff --git a/Octokit/Clients/IPullRequestsClient.cs b/Octokit/Clients/IPullRequestsClient.cs index f9a3073b..e612850b 100644 --- a/Octokit/Clients/IPullRequestsClient.cs +++ b/Octokit/Clients/IPullRequestsClient.cs @@ -97,5 +97,15 @@ namespace Octokit /// The pull request number /// A of s which are part of this pull request Task> Commits(string owner, string name, int number); + + /// + /// Get the list of files on a pull request. + /// + /// https://developer.github.com/v3/pulls/#list-pull-requests-files + /// The owner of the repository + /// The name of the repository + /// The pull request number + /// A which are part of this pull request + Task> Files(string owner, string name, int number); } } diff --git a/Octokit/Clients/PullRequestsClient.cs b/Octokit/Clients/PullRequestsClient.cs index 8e8ba16e..0c3ea179 100644 --- a/Octokit/Clients/PullRequestsClient.cs +++ b/Octokit/Clients/PullRequestsClient.cs @@ -159,5 +159,21 @@ namespace Octokit return ApiConnection.GetAll(ApiUrls.PullRequestCommits(owner, name, number)); } + + /// + /// Get the list of files on a pull request. + /// + /// https://developer.github.com/v3/pulls/#list-pull-requests-files + /// The owner of the repository + /// The name of the repository + /// The pull request number + /// A of s which are part of this pull request + public Task> Files(string owner, string name, int number) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + + return ApiConnection.GetAll(ApiUrls.PullRequestFiles(owner, name, number)); + } } } diff --git a/Octokit/Helpers/ApiUrls.cs b/Octokit/Helpers/ApiUrls.cs index 192fe138..6700d3a9 100644 --- a/Octokit/Helpers/ApiUrls.cs +++ b/Octokit/Helpers/ApiUrls.cs @@ -811,6 +811,11 @@ namespace Octokit return "repos/{0}/{1}/pulls/{2}/commits".FormatUri(owner, name, number); } + public static Uri PullRequestFiles(string owner, string name, int number) + { + return "/repos/{0}/{1}/pulls/{2}/files".FormatUri(owner, name, number); + } + /// /// Returns the for a spesific comment for the specified commit. /// diff --git a/Octokit/Models/Response/PullRequestFile.cs b/Octokit/Models/Response/PullRequestFile.cs new file mode 100644 index 00000000..dbf9b336 --- /dev/null +++ b/Octokit/Models/Response/PullRequestFile.cs @@ -0,0 +1,46 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Globalization; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Octokit +{ + [DebuggerDisplay("{DebuggerDisplay,nq}")] + public class PullRequestFile + { + public PullRequestFile() { } + + public PullRequestFile(string sha, string fileName, string status, int additions, int deletions, int changes, Uri blobUri, Uri rawUri, Uri contentsUri, string patch) + { + Sha = sha; + FileName = fileName; + Status = status; + Additions = additions; + Deletions = deletions; + Changes = changes; + BlobUri = blobUri; + RawUri = rawUri; + ContentsUri = contentsUri; + Patch = patch; + } + + public string Sha { get; set; } + public string FileName { get; set; } + public string Status { get; set; } + public int Additions { get; set; } + public int Deletions { get; set; } + public int Changes { get; set; } + public Uri BlobUri { get; set; } + public Uri RawUri { get; set; } + public Uri ContentsUri { get; set; } + public string Patch { get; set; } + + internal string DebuggerDisplay + { + get { return String.Format(CultureInfo.InvariantCulture, "Sha: {0} Filename: {1} Additions: {2} Deletions: {3} Changes: {4}", Sha, FileName, Additions, Deletions, Changes); } + } + } +} diff --git a/Octokit/Octokit-Mono.csproj b/Octokit/Octokit-Mono.csproj index be0415f6..08b522f4 100644 --- a/Octokit/Octokit-Mono.csproj +++ b/Octokit/Octokit-Mono.csproj @@ -381,6 +381,7 @@ + \ No newline at end of file diff --git a/Octokit/Octokit-MonoAndroid.csproj b/Octokit/Octokit-MonoAndroid.csproj index 2680ecd3..03023e21 100644 --- a/Octokit/Octokit-MonoAndroid.csproj +++ b/Octokit/Octokit-MonoAndroid.csproj @@ -393,6 +393,7 @@ + \ No newline at end of file diff --git a/Octokit/Octokit-Monotouch.csproj b/Octokit/Octokit-Monotouch.csproj index 1582335c..29d7faa3 100644 --- a/Octokit/Octokit-Monotouch.csproj +++ b/Octokit/Octokit-Monotouch.csproj @@ -386,6 +386,7 @@ + diff --git a/Octokit/Octokit-Portable.csproj b/Octokit/Octokit-Portable.csproj index ef12a34b..377001e6 100644 --- a/Octokit/Octokit-Portable.csproj +++ b/Octokit/Octokit-Portable.csproj @@ -379,6 +379,7 @@ + diff --git a/Octokit/Octokit-netcore45.csproj b/Octokit/Octokit-netcore45.csproj index f5debdf3..53942c26 100644 --- a/Octokit/Octokit-netcore45.csproj +++ b/Octokit/Octokit-netcore45.csproj @@ -383,6 +383,7 @@ + diff --git a/Octokit/Octokit.csproj b/Octokit/Octokit.csproj index d75e762c..98eb49c4 100644 --- a/Octokit/Octokit.csproj +++ b/Octokit/Octokit.csproj @@ -112,6 +112,7 @@ +