From e292a05c884b5b51666c911bf8b72c3388645eb5 Mon Sep 17 00:00:00 2001 From: Chris Heckathorne Date: Fri, 27 Feb 2015 15:45:32 -0500 Subject: [PATCH 1/5] added support for ref value in get contents api --- Octokit/Clients/IRepositoryContentsClient.cs | 17 ++++++++++++ Octokit/Clients/RepositoryContentsClient.cs | 27 ++++++++++++++++++++ Octokit/Helpers/ApiUrls.cs | 13 ++++++++++ 3 files changed, 57 insertions(+) diff --git a/Octokit/Clients/IRepositoryContentsClient.cs b/Octokit/Clients/IRepositoryContentsClient.cs index 45a217b0da..b18689bc5b 100644 --- a/Octokit/Clients/IRepositoryContentsClient.cs +++ b/Octokit/Clients/IRepositoryContentsClient.cs @@ -14,6 +14,7 @@ public interface IRepositoryContentsClient /// /// /// If given a path to a single file, this method returns a collection containing only that file. + /// See the API documentation for more information. /// /// The owner of the repository /// The name of the repository @@ -23,6 +24,22 @@ public interface IRepositoryContentsClient /// Task> GetAllContents(string owner, string name, string path); + /// + /// Returns the contents of a file or directory in a repository. + /// + /// + /// If given a path to a single file, this method returns a collection containing only that file. + /// See the API documentation for more information. + /// + /// The owner of the repository + /// The name of the repository + /// The content path + /// The name of the commit/branch/tag. Default: the repository�s default branch (usually master) + /// + /// A collection of representing the content at the specified path + /// + Task> GetContents(string owner, string name, string path, string reference); + /// /// Gets the preferred README for the specified repository. /// diff --git a/Octokit/Clients/RepositoryContentsClient.cs b/Octokit/Clients/RepositoryContentsClient.cs index 7b867f0198..199ef96b18 100644 --- a/Octokit/Clients/RepositoryContentsClient.cs +++ b/Octokit/Clients/RepositoryContentsClient.cs @@ -17,6 +17,7 @@ public RepositoryContentsClient(IApiConnection apiConnection) : base(apiConnecti /// /// /// If given a path to a single file, this method returns a collection containing only that file. + /// See the API documentation for more information. /// /// The owner of the repository /// The name of the repository @@ -35,6 +36,32 @@ public async Task> GetAllContents(string owner, return await ApiConnection.GetAll(url); } + /// + /// Returns the contents of a file or directory in a repository. + /// + /// + /// If given a path to a single file, this method returns a collection containing only that file. + /// See the API documentation for more information. + /// + /// The owner of the repository + /// The name of the repository + /// The content path + /// The name of the commit/branch/tag. Default: the repository�s default branch (usually master) + /// + /// A collection of representing the content at the specified path + /// + public async Task> GetContents(string owner, string name, string path, string reference) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + Ensure.ArgumentNotNullOrEmptyString(path, "path"); + Ensure.ArgumentNotNullOrEmptyString(reference, "reference"); + + var url = ApiUrls.RepositoryContent(owner, name, path, reference); + + return await ApiConnection.GetAll(url); + } + /// /// Gets the preferred README for the specified repository. /// diff --git a/Octokit/Helpers/ApiUrls.cs b/Octokit/Helpers/ApiUrls.cs index 357b66c31b..ad59aeaeea 100644 --- a/Octokit/Helpers/ApiUrls.cs +++ b/Octokit/Helpers/ApiUrls.cs @@ -1472,5 +1472,18 @@ public static Uri RepositoryArchiveLink(string owner, string name, ArchiveFormat { return "repos/{0}/{1}/{2}/{3}".FormatUri(owner, name, archiveFormat.ToParameter(), reference); } + + /// + /// Creates the relative for getting the contents of the specified repository and path + /// + /// The owner of the repository + /// The name of the repository + /// The path of the contents to get + /// The name of the commit/branch/tag. Default: the repository’s default branch (usually master) + /// The for getting the contents of the specified repository and path + public static Uri RepositoryContent(string owner, string name, string path, string reference) + { + return "repos/{0}/{1}/contents/{2}?ref={3}".FormatUri(owner, name, path, reference); + } } } From 19d00f60a06e9b323e7f4c50b2ab64ef8a1b24d2 Mon Sep 17 00:00:00 2001 From: Chris Heckathorne Date: Fri, 8 May 2015 15:16:09 -0400 Subject: [PATCH 2/5] added getcontents to observable client --- .../IObservableRepositoryContentsClient.cs | 17 +++++++++++++ .../ObservableRepositoryContentsClient.cs | 25 +++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/Octokit.Reactive/Clients/IObservableRepositoryContentsClient.cs b/Octokit.Reactive/Clients/IObservableRepositoryContentsClient.cs index 4b56ed1b4f..ed40d26e66 100644 --- a/Octokit.Reactive/Clients/IObservableRepositoryContentsClient.cs +++ b/Octokit.Reactive/Clients/IObservableRepositoryContentsClient.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Reactive; namespace Octokit.Reactive @@ -77,6 +78,22 @@ public interface IObservableRepositoryContentsClient /// IObservable GetAllContents(string owner, string name, string path); + /// + /// Returns the contents of a file or directory in a repository. + /// + /// + /// If given a path to a single file, this method returns a collection containing only that file. + /// See the API documentation for more information. + /// + /// The owner of the repository + /// The name of the repository + /// The content path + /// The name of the commit/branch/tag. Default: the repository’s default branch (usually master) + /// + /// A collection of representing the content at the specified path + /// + IObservable> GetContents(string owner, string name, string path, string reference); + /// /// Creates a commit that creates a new file in a repository. /// diff --git a/Octokit.Reactive/Clients/ObservableRepositoryContentsClient.cs b/Octokit.Reactive/Clients/ObservableRepositoryContentsClient.cs index ca2889e478..7001cd4a39 100644 --- a/Octokit.Reactive/Clients/ObservableRepositoryContentsClient.cs +++ b/Octokit.Reactive/Clients/ObservableRepositoryContentsClient.cs @@ -1,6 +1,7 @@ using System; using System.Reactive.Threading.Tasks; using Octokit.Reactive.Internal; +using System.Collections.Generic; namespace Octokit.Reactive { @@ -123,6 +124,30 @@ public IObservable GetAllContents(string owner, string name, .GetAndFlattenAllPages(ApiUrls.RepositoryContent(owner, name, path)); } + /// + /// Returns the contents of a file or directory in a repository. + /// + /// + /// If given a path to a single file, this method returns a collection containing only that file. + /// See the API documentation for more information. + /// + /// The owner of the repository + /// The name of the repository + /// The content path + /// The name of the commit/branch/tag. Default: the repository’s default branch (usually master) + /// + /// A collection of representing the content at the specified path + /// + public IObservable> GetContents(string owner, string name, string path, string reference) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + Ensure.ArgumentNotNullOrEmptyString(path, "path"); + Ensure.ArgumentNotNullOrEmptyString(reference, "reference"); + + return _client.Repository.Content.GetContents(owner, name, path, reference).ToObservable(); + } + /// /// Creates a commit that creates a new file in a repository. /// From 21b35d1f68fc549a20c4c2067b9d0be11df70608 Mon Sep 17 00:00:00 2001 From: Chris Heckathorne Date: Fri, 8 May 2015 15:43:25 -0400 Subject: [PATCH 3/5] fixed up return types --- .../Clients/IObservableRepositoryContentsClient.cs | 2 +- .../Clients/ObservableRepositoryContentsClient.cs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Octokit.Reactive/Clients/IObservableRepositoryContentsClient.cs b/Octokit.Reactive/Clients/IObservableRepositoryContentsClient.cs index ed40d26e66..9c0c5a7de9 100644 --- a/Octokit.Reactive/Clients/IObservableRepositoryContentsClient.cs +++ b/Octokit.Reactive/Clients/IObservableRepositoryContentsClient.cs @@ -92,7 +92,7 @@ public interface IObservableRepositoryContentsClient /// /// A collection of representing the content at the specified path /// - IObservable> GetContents(string owner, string name, string path, string reference); + IObservable GetContents(string owner, string name, string path, string reference); /// /// Creates a commit that creates a new file in a repository. diff --git a/Octokit.Reactive/Clients/ObservableRepositoryContentsClient.cs b/Octokit.Reactive/Clients/ObservableRepositoryContentsClient.cs index 7001cd4a39..5d9fe64767 100644 --- a/Octokit.Reactive/Clients/ObservableRepositoryContentsClient.cs +++ b/Octokit.Reactive/Clients/ObservableRepositoryContentsClient.cs @@ -138,14 +138,14 @@ public IObservable GetAllContents(string owner, string name, /// /// A collection of representing the content at the specified path /// - public IObservable> GetContents(string owner, string name, string path, string reference) + public IObservable GetContents(string owner, string name, string path, string reference) { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(name, "name"); Ensure.ArgumentNotNullOrEmptyString(path, "path"); Ensure.ArgumentNotNullOrEmptyString(reference, "reference"); - return _client.Repository.Content.GetContents(owner, name, path, reference).ToObservable(); + return _client.Connection.GetAndFlattenAllPages(ApiUrls.RepositoryContent(owner, name, path, reference)); } /// From c6f89b5a18a0632597e4597c2717d6bcca2842b0 Mon Sep 17 00:00:00 2001 From: Chris Heckathorne Date: Fri, 8 May 2015 16:18:52 -0400 Subject: [PATCH 4/5] attempt at adding unit test --- .../Clients/RepositoryContentsClientTests.cs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/Octokit.Tests/Clients/RepositoryContentsClientTests.cs b/Octokit.Tests/Clients/RepositoryContentsClientTests.cs index 6626f7ef13..4a6ade939f 100644 --- a/Octokit.Tests/Clients/RepositoryContentsClientTests.cs +++ b/Octokit.Tests/Clients/RepositoryContentsClientTests.cs @@ -4,6 +4,7 @@ using NSubstitute; using Octokit.Tests.Helpers; using Xunit; +using System.Collections.Generic; namespace Octokit.Tests.Clients { @@ -108,5 +109,23 @@ public async Task EnsuresArgumentsNotNull() AssertEx.Throws(async () => await contentsClient.GetArchiveLink("owner", "")); } } + + public class TheGetContentsMethod + { + [Fact] + public async Task ReturnsContents() + { + List result = new List() { new RepositoryContent() { } }; + + var connection = Substitute.For(); + connection.GetAll(Args.Uri).Returns(Task.FromResult(result.AsReadOnly() as IReadOnlyList)); + var contentsClient = new RepositoryContentsClient(connection); + + var contents = await contentsClient.GetContents("fake", "repo", "readme.md", "master"); + + connection.Received().GetAll(Arg.Is(u => u.ToString() == "repos/fake/repo/contents/readme.md?ref=master")); + Assert.Equal(1, contents.Count); + } + } } } \ No newline at end of file From b324bab413190a4daea53517cadf0af012532200 Mon Sep 17 00:00:00 2001 From: Chris Heckathorne Date: Mon, 11 May 2015 10:31:57 -0400 Subject: [PATCH 5/5] fixed up naming conventions --- Octokit.Reactive/Clients/IObservableRepositoryContentsClient.cs | 2 +- Octokit.Reactive/Clients/ObservableRepositoryContentsClient.cs | 2 +- Octokit.Tests/Clients/RepositoryContentsClientTests.cs | 2 +- Octokit/Clients/IRepositoryContentsClient.cs | 2 +- Octokit/Clients/RepositoryContentsClient.cs | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Octokit.Reactive/Clients/IObservableRepositoryContentsClient.cs b/Octokit.Reactive/Clients/IObservableRepositoryContentsClient.cs index 9c0c5a7de9..e6dfbf6508 100644 --- a/Octokit.Reactive/Clients/IObservableRepositoryContentsClient.cs +++ b/Octokit.Reactive/Clients/IObservableRepositoryContentsClient.cs @@ -92,7 +92,7 @@ public interface IObservableRepositoryContentsClient /// /// A collection of representing the content at the specified path /// - IObservable GetContents(string owner, string name, string path, string reference); + IObservable GetAllContents(string owner, string name, string path, string reference); /// /// Creates a commit that creates a new file in a repository. diff --git a/Octokit.Reactive/Clients/ObservableRepositoryContentsClient.cs b/Octokit.Reactive/Clients/ObservableRepositoryContentsClient.cs index 5d9fe64767..7280ea45c2 100644 --- a/Octokit.Reactive/Clients/ObservableRepositoryContentsClient.cs +++ b/Octokit.Reactive/Clients/ObservableRepositoryContentsClient.cs @@ -138,7 +138,7 @@ public IObservable GetAllContents(string owner, string name, /// /// A collection of representing the content at the specified path /// - public IObservable GetContents(string owner, string name, string path, string reference) + public IObservable GetAllContents(string owner, string name, string path, string reference) { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(name, "name"); diff --git a/Octokit.Tests/Clients/RepositoryContentsClientTests.cs b/Octokit.Tests/Clients/RepositoryContentsClientTests.cs index 4a6ade939f..1879c667b8 100644 --- a/Octokit.Tests/Clients/RepositoryContentsClientTests.cs +++ b/Octokit.Tests/Clients/RepositoryContentsClientTests.cs @@ -121,7 +121,7 @@ public async Task ReturnsContents() connection.GetAll(Args.Uri).Returns(Task.FromResult(result.AsReadOnly() as IReadOnlyList)); var contentsClient = new RepositoryContentsClient(connection); - var contents = await contentsClient.GetContents("fake", "repo", "readme.md", "master"); + var contents = await contentsClient.GetAllContents("fake", "repo", "readme.md", "master"); connection.Received().GetAll(Arg.Is(u => u.ToString() == "repos/fake/repo/contents/readme.md?ref=master")); Assert.Equal(1, contents.Count); diff --git a/Octokit/Clients/IRepositoryContentsClient.cs b/Octokit/Clients/IRepositoryContentsClient.cs index b18689bc5b..ebfd65d379 100644 --- a/Octokit/Clients/IRepositoryContentsClient.cs +++ b/Octokit/Clients/IRepositoryContentsClient.cs @@ -38,7 +38,7 @@ public interface IRepositoryContentsClient /// /// A collection of representing the content at the specified path /// - Task> GetContents(string owner, string name, string path, string reference); + Task> GetAllContents(string owner, string name, string path, string reference); /// /// Gets the preferred README for the specified repository. diff --git a/Octokit/Clients/RepositoryContentsClient.cs b/Octokit/Clients/RepositoryContentsClient.cs index 199ef96b18..640f3a6452 100644 --- a/Octokit/Clients/RepositoryContentsClient.cs +++ b/Octokit/Clients/RepositoryContentsClient.cs @@ -50,7 +50,7 @@ public async Task> GetAllContents(string owner, /// /// A collection of representing the content at the specified path /// - public async Task> GetContents(string owner, string name, string path, string reference) + public async Task> GetAllContents(string owner, string name, string path, string reference) { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(name, "name");