diff --git a/Octokit.Reactive/Clients/IObservableCheckRunsClient.cs b/Octokit.Reactive/Clients/IObservableCheckRunsClient.cs index ae8e9dc235..1d8f4822fd 100644 --- a/Octokit.Reactive/Clients/IObservableCheckRunsClient.cs +++ b/Octokit.Reactive/Clients/IObservableCheckRunsClient.cs @@ -155,5 +155,20 @@ public interface IObservableCheckRunsClient /// Details to filter the request, such as by check name /// Options to change the API response IObservable GetAllForCheckSuite(long repositoryId, long checkSuiteId, CheckRunRequest checkRunRequest, ApiOptions options); + + /// + /// Gets a single check run using its Id. + /// + /// The owner of the repository + /// The name of the repository + /// The Id of the check run + IObservable Get(string owner, string name, long checkRunId); + + /// + /// Gets a single check run using its Id. + /// + /// The Id of the repository + /// The Id of the check run + IObservable Get(long repositoryId, long checkRunId); } } \ No newline at end of file diff --git a/Octokit.Reactive/Clients/ObservableCheckRunsClient.cs b/Octokit.Reactive/Clients/ObservableCheckRunsClient.cs index b47d53ade5..ccc29c7081 100644 --- a/Octokit.Reactive/Clients/ObservableCheckRunsClient.cs +++ b/Octokit.Reactive/Clients/ObservableCheckRunsClient.cs @@ -273,5 +273,29 @@ public IObservable GetAllForCheckSuite(long repositoryId, lon return _connection.GetAndFlattenAllPages(ApiUrls.CheckRunsForCheckSuite(repositoryId, checkSuiteId), checkRunRequest.ToParametersDictionary(), AcceptHeaders.ChecksApiPreview, options); } + + /// + /// Gets a single check run using its Id. + /// + /// The owner of the repository + /// The name of the repository + /// The Id of the check run + public IObservable Get(string owner, string name, long checkRunId) + { + Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); + Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); + + return _client.Get(owner, name, checkRunId).ToObservable(); + } + + /// + /// Gets a single check run using its Id. + /// + /// The Id of the repository + /// The Id of the check run + public IObservable Get(long repositoryId, long checkRunId) + { + return _client.Get(repositoryId, checkRunId).ToObservable(); + } } } diff --git a/Octokit.Tests.Integration/Clients/CheckRunsClientTests.cs b/Octokit.Tests.Integration/Clients/CheckRunsClientTests.cs index 3a85d35844..cedbd16b54 100644 --- a/Octokit.Tests.Integration/Clients/CheckRunsClientTests.cs +++ b/Octokit.Tests.Integration/Clients/CheckRunsClientTests.cs @@ -307,6 +307,72 @@ public async Task GetsAllCheckRunsWithRepositoryId() } } } + + public class TheGetMethod + { + IGitHubClient _github; + IGitHubClient _githubAppInstallation; + + public TheGetMethod() + { + _github = Helper.GetAuthenticatedClient(); + + // Authenticate as a GitHubApp Installation + _githubAppInstallation = Helper.GetAuthenticatedGitHubAppInstallationForOwner(Helper.UserName); + } + + [GitHubAppsTest] + public async Task GetsCheckRun() + { + using (var repoContext = await _github.CreateRepositoryContext(new NewRepository(Helper.MakeNameWithTimestamp("public-repo")) { AutoInit = true })) + { + // Create a new feature branch + var headCommit = await _github.Repository.Commit.Get(repoContext.RepositoryId, "master"); + var featureBranch = await Helper.CreateFeatureBranch(repoContext.RepositoryOwner, repoContext.RepositoryName, headCommit.Sha, "my-feature"); + + // Create a check run for the feature branch + var newCheckRun = new NewCheckRun("name", featureBranch.Object.Sha) + { + Status = CheckStatus.InProgress + }; + var created = await _githubAppInstallation.Check.Run.Create(repoContext.RepositoryOwner, repoContext.RepositoryName, newCheckRun); + + // Get the check + var checkRun = await _githubAppInstallation.Check.Run.Get(repoContext.RepositoryOwner, repoContext.RepositoryName, created.Id); + + // Check result + Assert.Equal(featureBranch.Object.Sha, checkRun.HeadSha); + Assert.Equal("name", checkRun.Name); + Assert.Equal(CheckStatus.InProgress, checkRun.Status); + } + } + + [GitHubAppsTest] + public async Task GetsCheckRunWithRepositoryId() + { + using (var repoContext = await _github.CreateRepositoryContext(new NewRepository(Helper.MakeNameWithTimestamp("public-repo")) { AutoInit = true })) + { + // Create a new feature branch + var headCommit = await _github.Repository.Commit.Get(repoContext.RepositoryId, "master"); + var featureBranch = await Helper.CreateFeatureBranch(repoContext.RepositoryOwner, repoContext.RepositoryName, headCommit.Sha, "my-feature"); + + // Create a check run for the feature branch + var newCheckRun = new NewCheckRun("name", featureBranch.Object.Sha) + { + Status = CheckStatus.InProgress + }; + var created = await _githubAppInstallation.Check.Run.Create(repoContext.RepositoryId, newCheckRun); + + // Get the check + var checkRun = await _githubAppInstallation.Check.Run.Get(repoContext.RepositoryId, created.Id); + + // Check result + Assert.Equal(featureBranch.Object.Sha, checkRun.HeadSha); + Assert.Equal("name", checkRun.Name); + Assert.Equal(CheckStatus.InProgress, checkRun.Status); + } + } + } } } } \ No newline at end of file diff --git a/Octokit.Tests.Integration/Reactive/ObservableCheckRunsClientTests.cs b/Octokit.Tests.Integration/Reactive/ObservableCheckRunsClientTests.cs index 6dfd13cf28..af65c81155 100644 --- a/Octokit.Tests.Integration/Reactive/ObservableCheckRunsClientTests.cs +++ b/Octokit.Tests.Integration/Reactive/ObservableCheckRunsClientTests.cs @@ -310,5 +310,71 @@ public async Task GetsAllCheckRunsWithRepositoryId() } } } + + public class TheGetMethod + { + IObservableGitHubClient _github; + IObservableGitHubClient _githubAppInstallation; + + public TheGetMethod() + { + _github = new ObservableGitHubClient(Helper.GetAuthenticatedClient()); + + // Authenticate as a GitHubApp Installation + _githubAppInstallation = new ObservableGitHubClient(Helper.GetAuthenticatedGitHubAppInstallationForOwner(Helper.UserName)); + } + + [GitHubAppsTest] + public async Task GetsCheckRun() + { + using (var repoContext = await _github.CreateRepositoryContext(new NewRepository(Helper.MakeNameWithTimestamp("public-repo")) { AutoInit = true })) + { + // Create a new feature branch + var headCommit = await _github.Repository.Commit.Get(repoContext.RepositoryId, "master"); + var featureBranch = await Helper.CreateFeatureBranch(repoContext.RepositoryOwner, repoContext.RepositoryName, headCommit.Sha, "my-feature"); + + // Create a check run for the feature branch + var newCheckRun = new NewCheckRun("name", featureBranch.Object.Sha) + { + Status = CheckStatus.InProgress + }; + var created = await _githubAppInstallation.Check.Run.Create(repoContext.RepositoryOwner, repoContext.RepositoryName, newCheckRun); + + // Get the check + var checkRun = await _githubAppInstallation.Check.Run.Get(repoContext.RepositoryOwner, repoContext.RepositoryName, created.Id); + + // Check result + Assert.Equal(featureBranch.Object.Sha, checkRun.HeadSha); + Assert.Equal("name", checkRun.Name); + Assert.Equal(CheckStatus.InProgress, checkRun.Status); + } + } + + [GitHubAppsTest] + public async Task GetsCheckRunWithRepositoryId() + { + using (var repoContext = await _github.CreateRepositoryContext(new NewRepository(Helper.MakeNameWithTimestamp("public-repo")) { AutoInit = true })) + { + // Create a new feature branch + var headCommit = await _github.Repository.Commit.Get(repoContext.RepositoryId, "master"); + var featureBranch = await Helper.CreateFeatureBranch(repoContext.RepositoryOwner, repoContext.RepositoryName, headCommit.Sha, "my-feature"); + + // Create a check run for the feature branch + var newCheckRun = new NewCheckRun("name", featureBranch.Object.Sha) + { + Status = CheckStatus.InProgress + }; + var created = await _githubAppInstallation.Check.Run.Create(repoContext.RepositoryId, newCheckRun); + + // Get the check + var checkRun = await _githubAppInstallation.Check.Run.Get(repoContext.RepositoryId, created.Id); + + // Check result + Assert.Equal(featureBranch.Object.Sha, checkRun.HeadSha); + Assert.Equal("name", checkRun.Name); + Assert.Equal(CheckStatus.InProgress, checkRun.Status); + } + } + } } } \ No newline at end of file diff --git a/Octokit.Tests/Clients/CheckRunsClientTests.cs b/Octokit.Tests/Clients/CheckRunsClientTests.cs index 8d155323a5..a1b5f8672b 100644 --- a/Octokit.Tests/Clients/CheckRunsClientTests.cs +++ b/Octokit.Tests/Clients/CheckRunsClientTests.cs @@ -472,5 +472,56 @@ public async Task EnsuresNonEmptyArguments() await Assert.ThrowsAsync(() => client.GetAllForCheckSuite("fake", "", 1, request, ApiOptions.None)); } } + + public class TheGetMethod + { + [Fact] + public async Task RequestsCorrectUrl() + { + var connection = Substitute.For(); + var client = new CheckRunsClient(connection); + + await client.Get("fake", "repo", 1); + + connection.Received().Get( + Arg.Is(u => u.ToString() == "repos/fake/repo/check-runs/1"), + null, + "application/vnd.github.antiope-preview+json"); + } + + [Fact] + public async Task RequestsCorrectUrlWithRepositoryId() + { + var connection = Substitute.For(); + var client = new CheckRunsClient(connection); + + await client.Get(1, 1); + + connection.Received().Get( + Arg.Is(u => u.ToString() == "repositories/1/check-runs/1"), + null, + "application/vnd.github.antiope-preview+json"); + } + + [Fact] + public async Task EnsuresNonNullArguments() + { + var connection = Substitute.For(); + var client = new CheckRunsClient(connection); + + await Assert.ThrowsAsync(() => client.Get(null, "repo", 1)); + await Assert.ThrowsAsync(() => client.Get("fake", null, 1)); + } + + [Fact] + public async Task EnsuresNonEmptyArguments() + { + var connection = Substitute.For(); + var client = new CheckRunsClient(connection); + + await Assert.ThrowsAsync(() => client.Get("", "repo", 1)); + await Assert.ThrowsAsync(() => client.Get("fake", "", 1)); + } + } } } \ No newline at end of file diff --git a/Octokit.Tests/Reactive/ObservableCheckRunsClientTests.cs b/Octokit.Tests/Reactive/ObservableCheckRunsClientTests.cs index 73a4a327ff..608bcda7b0 100644 --- a/Octokit.Tests/Reactive/ObservableCheckRunsClientTests.cs +++ b/Octokit.Tests/Reactive/ObservableCheckRunsClientTests.cs @@ -461,5 +461,50 @@ public async Task EnsuresNonEmptyArguments() Assert.Throws(() => client.GetAllForCheckSuite("fake", "", 1, request, ApiOptions.None)); } } + + public class TheGetMethod + { + [Fact] + public async Task RequestsCorrectUrl() + { + var gitHubClient = Substitute.For(); + var client = new ObservableCheckRunsClient(gitHubClient); + + client.Get("fake", "repo", 1); + + gitHubClient.Check.Run.Received().Get("fake", "repo", 1); + } + + [Fact] + public async Task RequestsCorrectUrlWithRepositoryId() + { + var gitHubClient = Substitute.For(); + var client = new ObservableCheckRunsClient(gitHubClient); + + client.Get(1, 1); + + gitHubClient.Check.Run.Received().Get(1, 1); + } + + [Fact] + public async Task EnsuresNonNullArguments() + { + var gitHubClient = Substitute.For(); + var client = new ObservableCheckRunsClient(gitHubClient); + + Assert.Throws(() => client.Get(null, "repo", 1)); + Assert.Throws(() => client.Get("fake", null, 1)); + } + + [Fact] + public async Task EnsuresNonEmptyArguments() + { + var gitHubClient = Substitute.For(); + var client = new ObservableCheckRunsClient(gitHubClient); + + Assert.Throws(() => client.Get("", "repo", 1)); + Assert.Throws(() => client.Get("fake", "", 1)); + } + } } } \ No newline at end of file diff --git a/Octokit/Clients/CheckRunsClient.cs b/Octokit/Clients/CheckRunsClient.cs index 04f37a9c90..dd62b8c093 100644 --- a/Octokit/Clients/CheckRunsClient.cs +++ b/Octokit/Clients/CheckRunsClient.cs @@ -282,5 +282,29 @@ public async Task GetAllForCheckSuite(long repositoryId, long results.Count > 0 ? results.Max(x => x.TotalCount) : 0, results.SelectMany(x => x.CheckRuns).ToList()); } + + /// + /// Gets a single check run using its Id. + /// + /// The owner of the repository + /// The name of the repository + /// The Id of the check run + public Task Get(string owner, string name, long checkRunId) + { + Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); + Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); + + return ApiConnection.Get(ApiUrls.CheckRun(owner, name, checkRunId), null, AcceptHeaders.ChecksApiPreview); + } + + /// + /// Gets a single check run using its Id. + /// + /// The Id of the repository + /// The Id of the check run + public Task Get(long repositoryId, long checkRunId) + { + return ApiConnection.Get(ApiUrls.CheckRun(repositoryId, checkRunId), null, AcceptHeaders.ChecksApiPreview); + } } } diff --git a/Octokit/Clients/ICheckRunsClient.cs b/Octokit/Clients/ICheckRunsClient.cs index ab2a438553..253e1fa0dc 100644 --- a/Octokit/Clients/ICheckRunsClient.cs +++ b/Octokit/Clients/ICheckRunsClient.cs @@ -155,5 +155,20 @@ public interface ICheckRunsClient /// Details to filter the request, such as by check name /// Options to change the API response Task GetAllForCheckSuite(long repositoryId, long checkSuiteId, CheckRunRequest checkRunRequest, ApiOptions options); + + /// + /// Gets a single check run using its Id. + /// + /// The owner of the repository + /// The name of the repository + /// The Id of the check run + Task Get(string owner, string name, long checkRunId); + + /// + /// Gets a single check run using its Id. + /// + /// The Id of the repository + /// The Id of the check run + Task Get(long repositoryId, long checkRunId); } }