diff --git a/Octokit.Reactive/Clients/IObservableRepositoryCommitsClients.cs b/Octokit.Reactive/Clients/IObservableRepositoryCommitsClients.cs index d845d1f3..927b34c0 100644 --- a/Octokit.Reactive/Clients/IObservableRepositoryCommitsClients.cs +++ b/Octokit.Reactive/Clients/IObservableRepositoryCommitsClients.cs @@ -16,6 +16,17 @@ namespace Octokit.Reactive [SuppressMessage("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "base")] IObservable Compare(string owner, string name, string @base, string @head); + /// + /// Gets all commits for a given repository + /// + /// The owner of the repository + /// The name of the repository + /// The reference for the commit + /// + [SuppressMessage("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "Get", + Justification = "Method makes a network request")] + IObservable Get(string owner, string name, string reference); + /// /// Gets all commits for a given repository /// diff --git a/Octokit.Reactive/Clients/ObservableRepositoryCommitsClients.cs b/Octokit.Reactive/Clients/ObservableRepositoryCommitsClients.cs index 1fc54f98..2ff37d88 100644 --- a/Octokit.Reactive/Clients/ObservableRepositoryCommitsClients.cs +++ b/Octokit.Reactive/Clients/ObservableRepositoryCommitsClients.cs @@ -8,6 +8,7 @@ namespace Octokit.Reactive { readonly IGitHubClient _client; readonly IConnection _connection; + readonly IRepositoryCommitsClient _commit; public ObservableRepositoryCommitsClient(IGitHubClient client) { @@ -15,6 +16,7 @@ namespace Octokit.Reactive _client = client; _connection = client.Connection; + _commit = client.Repository.Commits; } /// @@ -30,6 +32,22 @@ namespace Octokit.Reactive return _client.Repository.Commits.Compare(owner, name, @base, head).ToObservable(); } + /// + /// Gets all commits for a given repository + /// + /// The owner of the repository + /// The name of the repository + /// The reference for the commit + /// + public IObservable Get(string owner, string name, string reference) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + Ensure.ArgumentNotNull(reference, "reference"); + + return _commit.Get(owner, name, reference).ToObservable(); + } + /// /// Gets all commits for a given repository /// diff --git a/Octokit.Tests.Integration/Clients/RepositoryCommitsClientTests.cs b/Octokit.Tests.Integration/Clients/RepositoryCommitsClientTests.cs index 46fc5de2..f8623667 100644 --- a/Octokit.Tests.Integration/Clients/RepositoryCommitsClientTests.cs +++ b/Octokit.Tests.Integration/Clients/RepositoryCommitsClientTests.cs @@ -26,6 +26,13 @@ public class RepositoryCommitsClientTests : IDisposable _repository = _client.Repository.Create(new NewRepository { Name = repoName, AutoInit = true }).Result; } + [IntegrationTest] + public async Task CanGetCommit() + { + var commit = await _fixture.Get("octokit", "octokit.net", "65a22f4d2cff94a286ac3e96440c810c5509196f"); + Assert.NotNull(commit); + } + [IntegrationTest] public async Task CanGetListOfCommits() { diff --git a/Octokit.Tests/Clients/RepositoriesClientTests.cs b/Octokit.Tests/Clients/RepositoriesClientTests.cs index 2eee3e79..7d35952d 100644 --- a/Octokit.Tests/Clients/RepositoriesClientTests.cs +++ b/Octokit.Tests/Clients/RepositoriesClientTests.cs @@ -605,6 +605,36 @@ namespace Octokit.Tests.Clients } } + public class TheGetCommitMethod + { + [Fact] + public void EnsureNonNullArguments() + { + var client = new RepositoryCommitsClient(Substitute.For()); + + Assert.Throws(() => client.Get(null, "repo", "reference")); + Assert.Throws(() => client.Get("", "repo", "reference")); + + Assert.Throws(() => client.Get("owner", null, "reference")); + Assert.Throws(() => client.Get("owner", "", "reference")); + + Assert.Throws(() => client.Get("owner", "repo", null)); + Assert.Throws(() => client.Get("owner", "repo", "")); + } + + [Fact] + public void GetsCorrectUrl() + { + var connection = Substitute.For(); + var client = new RepositoryCommitsClient(connection); + + client.Get("owner", "name", "reference"); + + connection.Received() + .Get(Arg.Is(u => u.ToString() == "repos/owner/name/commits/reference"), null); + } + } + public class TheGetAllCommitsMethod { [Fact] diff --git a/Octokit/Clients/IRepositoryCommitsClient.cs b/Octokit/Clients/IRepositoryCommitsClient.cs index 1364fc8b..3495934c 100644 --- a/Octokit/Clients/IRepositoryCommitsClient.cs +++ b/Octokit/Clients/IRepositoryCommitsClient.cs @@ -17,6 +17,17 @@ namespace Octokit [SuppressMessage("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "base")] Task Compare(string owner, string name, string @base, string head); + /// + /// Gets a single commit for a given repository + /// + /// The owner of the repository + /// The name of the repository + /// The reference for the commit (SHA) + /// + [SuppressMessage("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "Get", + Justification = "Makes a network request")] + Task Get(string owner, string name, string reference); + /// /// Gets all commits for a given repository /// diff --git a/Octokit/Clients/RepositoryCommitsClient.cs b/Octokit/Clients/RepositoryCommitsClient.cs index 110b0518..92881864 100644 --- a/Octokit/Clients/RepositoryCommitsClient.cs +++ b/Octokit/Clients/RepositoryCommitsClient.cs @@ -30,6 +30,22 @@ namespace Octokit return _apiConnection.Get(ApiUrls.RepoCompare(owner, name, @base, head)); } + /// + /// Gets a single commit for a given repository + /// + /// The owner of the repository + /// The name of the repository + /// The reference for the commit (SHA) + /// + public Task Get(string owner, string name, string reference) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + Ensure.ArgumentNotNullOrEmptyString(reference, "reference"); + + return _apiConnection.Get(ApiUrls.RepositoryCommit(owner, name, reference)); + } + /// /// Gets all commits for a given repository /// diff --git a/Octokit/Helpers/ApiUrls.cs b/Octokit/Helpers/ApiUrls.cs index 16bdd431..9016fec5 100644 --- a/Octokit/Helpers/ApiUrls.cs +++ b/Octokit/Helpers/ApiUrls.cs @@ -1056,6 +1056,18 @@ namespace Octokit return "repos/{0}/{1}/tags".FormatUri(owner, name); } + /// + /// Returns the for repository commits. + /// + /// The owner of the repository + /// The name of the repository + /// The commit reference (SHA) + /// + public static Uri RepositoryCommit(string owner, string name, string reference) + { + return "repos/{0}/{1}/commits/{2}".FormatUri(owner, name, reference); + } + /// /// Returns the for repository commits. ///