Skip to content

Commit

Permalink
Implement Get method
Browse files Browse the repository at this point in the history
  • Loading branch information
ryangribble committed Jul 14, 2018
1 parent fb76528 commit 9396bae
Show file tree
Hide file tree
Showing 8 changed files with 306 additions and 0 deletions.
15 changes: 15 additions & 0 deletions Octokit.Reactive/Clients/IObservableCheckRunsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -155,5 +155,20 @@ public interface IObservableCheckRunsClient
/// <param name="checkRunRequest">Details to filter the request, such as by check name</param>
/// <param name="options">Options to change the API response</param>
IObservable<CheckRunsResponse> GetAllForCheckSuite(long repositoryId, long checkSuiteId, CheckRunRequest checkRunRequest, ApiOptions options);

/// <summary>
/// Gets a single check run using its Id.
/// </summary>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <param name="checkRunId">The Id of the check run</param>
IObservable<CheckRun> Get(string owner, string name, long checkRunId);

/// <summary>
/// Gets a single check run using its Id.
/// </summary>
/// <param name="repositoryId">The Id of the repository</param>
/// <param name="checkRunId">The Id of the check run</param>
IObservable<CheckRun> Get(long repositoryId, long checkRunId);
}
}
24 changes: 24 additions & 0 deletions Octokit.Reactive/Clients/ObservableCheckRunsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -273,5 +273,29 @@ public IObservable<CheckRunsResponse> GetAllForCheckSuite(long repositoryId, lon

return _connection.GetAndFlattenAllPages<CheckRunsResponse>(ApiUrls.CheckRunsForCheckSuite(repositoryId, checkSuiteId), checkRunRequest.ToParametersDictionary(), AcceptHeaders.ChecksApiPreview, options);
}

/// <summary>
/// Gets a single check run using its Id.
/// </summary>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <param name="checkRunId">The Id of the check run</param>
public IObservable<CheckRun> Get(string owner, string name, long checkRunId)
{
Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner));
Ensure.ArgumentNotNullOrEmptyString(name, nameof(name));

return _client.Get(owner, name, checkRunId).ToObservable();
}

/// <summary>
/// Gets a single check run using its Id.
/// </summary>
/// <param name="repositoryId">The Id of the repository</param>
/// <param name="checkRunId">The Id of the check run</param>
public IObservable<CheckRun> Get(long repositoryId, long checkRunId)
{
return _client.Get(repositoryId, checkRunId).ToObservable();
}
}
}
66 changes: 66 additions & 0 deletions Octokit.Tests.Integration/Clients/CheckRunsClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
}
}
51 changes: 51 additions & 0 deletions Octokit.Tests/Clients/CheckRunsClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -472,5 +472,56 @@ public async Task EnsuresNonEmptyArguments()
await Assert.ThrowsAsync<ArgumentException>(() => client.GetAllForCheckSuite("fake", "", 1, request, ApiOptions.None));
}
}

public class TheGetMethod
{
[Fact]
public async Task RequestsCorrectUrl()
{
var connection = Substitute.For<IApiConnection>();
var client = new CheckRunsClient(connection);

await client.Get("fake", "repo", 1);

connection.Received().Get<CheckRun>(
Arg.Is<Uri>(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<IApiConnection>();
var client = new CheckRunsClient(connection);

await client.Get(1, 1);

connection.Received().Get<CheckRun>(
Arg.Is<Uri>(u => u.ToString() == "repositories/1/check-runs/1"),
null,
"application/vnd.github.antiope-preview+json");
}

[Fact]
public async Task EnsuresNonNullArguments()
{
var connection = Substitute.For<IApiConnection>();
var client = new CheckRunsClient(connection);

await Assert.ThrowsAsync<ArgumentNullException>(() => client.Get(null, "repo", 1));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Get("fake", null, 1));
}

[Fact]
public async Task EnsuresNonEmptyArguments()
{
var connection = Substitute.For<IApiConnection>();
var client = new CheckRunsClient(connection);

await Assert.ThrowsAsync<ArgumentException>(() => client.Get("", "repo", 1));
await Assert.ThrowsAsync<ArgumentException>(() => client.Get("fake", "", 1));
}
}
}
}
45 changes: 45 additions & 0 deletions Octokit.Tests/Reactive/ObservableCheckRunsClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -461,5 +461,50 @@ public async Task EnsuresNonEmptyArguments()
Assert.Throws<ArgumentException>(() => client.GetAllForCheckSuite("fake", "", 1, request, ApiOptions.None));
}
}

public class TheGetMethod
{
[Fact]
public async Task RequestsCorrectUrl()
{
var gitHubClient = Substitute.For<IGitHubClient>();
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<IGitHubClient>();
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<IGitHubClient>();
var client = new ObservableCheckRunsClient(gitHubClient);

Assert.Throws<ArgumentNullException>(() => client.Get(null, "repo", 1));
Assert.Throws<ArgumentNullException>(() => client.Get("fake", null, 1));
}

[Fact]
public async Task EnsuresNonEmptyArguments()
{
var gitHubClient = Substitute.For<IGitHubClient>();
var client = new ObservableCheckRunsClient(gitHubClient);

Assert.Throws<ArgumentException>(() => client.Get("", "repo", 1));
Assert.Throws<ArgumentException>(() => client.Get("fake", "", 1));
}
}
}
}
24 changes: 24 additions & 0 deletions Octokit/Clients/CheckRunsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -282,5 +282,29 @@ public async Task<CheckRunsResponse> GetAllForCheckSuite(long repositoryId, long
results.Count > 0 ? results.Max(x => x.TotalCount) : 0,
results.SelectMany(x => x.CheckRuns).ToList());
}

/// <summary>
/// Gets a single check run using its Id.
/// </summary>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <param name="checkRunId">The Id of the check run</param>
public Task<CheckRun> Get(string owner, string name, long checkRunId)
{
Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner));
Ensure.ArgumentNotNullOrEmptyString(name, nameof(name));

return ApiConnection.Get<CheckRun>(ApiUrls.CheckRun(owner, name, checkRunId), null, AcceptHeaders.ChecksApiPreview);
}

/// <summary>
/// Gets a single check run using its Id.
/// </summary>
/// <param name="repositoryId">The Id of the repository</param>
/// <param name="checkRunId">The Id of the check run</param>
public Task<CheckRun> Get(long repositoryId, long checkRunId)
{
return ApiConnection.Get<CheckRun>(ApiUrls.CheckRun(repositoryId, checkRunId), null, AcceptHeaders.ChecksApiPreview);
}
}
}
15 changes: 15 additions & 0 deletions Octokit/Clients/ICheckRunsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -155,5 +155,20 @@ public interface ICheckRunsClient
/// <param name="checkRunRequest">Details to filter the request, such as by check name</param>
/// <param name="options">Options to change the API response</param>
Task<CheckRunsResponse> GetAllForCheckSuite(long repositoryId, long checkSuiteId, CheckRunRequest checkRunRequest, ApiOptions options);

/// <summary>
/// Gets a single check run using its Id.
/// </summary>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <param name="checkRunId">The Id of the check run</param>
Task<CheckRun> Get(string owner, string name, long checkRunId);

/// <summary>
/// Gets a single check run using its Id.
/// </summary>
/// <param name="repositoryId">The Id of the repository</param>
/// <param name="checkRunId">The Id of the check run</param>
Task<CheckRun> Get(long repositoryId, long checkRunId);
}
}

0 comments on commit 9396bae

Please sign in to comment.