From c5d5df5b08062eb9223427772ba43abd901db149 Mon Sep 17 00:00:00 2001 From: Ryan Gribble Date: Thu, 19 Jul 2018 08:29:12 +1000 Subject: [PATCH] Implement Check Runs API (#1847) * Add CheckRunEventPayload * add CheckRunEventPayload into all the right places * forgot integration tests for RepositoryId methods (+1 squashed commits) Squashed commits: [b2445bf3] Implement Create CheckRun methods for normal and observable clients including unit and integration tests and xmldoc comments * Implement Update CheckRun method Refactored NewCheckRun to inherit CheckRunUpdate since they share all fields except HeadSha * Implement GetAllForReference method * Implement GetAllForCheckSuite method * tweak XmlDoc to match github documentation * Implement Get method * Implement GetAllAnnotations Moved CheckRunAnnotation model from Request to Common and added a parameterless ctor, since it is now a response model as well as a request model * Split common CheckRunAnnotation model into separate response and request models due to different field and ctor requirements Rename other CheckRun request sub classes to be consistent with NewCheckRunAnnotation (eg NewCheckRunOutput, NewCheckRunImage, etc) * add title field back into CheckRunAnnotation * fix up XmlDocs * fix mutable response property - hooray for convention tests! --- .../Clients/IObservableCheckRunsClient.cs | 261 ++++++++ .../Clients/IObservableChecksClient.cs | 8 + .../Clients/ObservableCheckRunsClient.cs | 409 ++++++++++++ .../Clients/ObservableChecksClient.cs | 13 + .../Clients/CheckRunsClientTests.cs | 460 +++++++++++++ .../ObservableCheckRunsClientTests.cs | 461 +++++++++++++ Octokit.Tests/Clients/CheckRunsClientTests.cs | 631 ++++++++++++++++++ Octokit.Tests/Clients/EventsClientTests.cs | 1 + Octokit.Tests/Models/CheckRunEventTests.cs | 256 +++++++ .../ObservableCheckRunsClientTests.cs | 622 +++++++++++++++++ .../ObservableCheckSuitesClientTests.cs | 1 - Octokit/Clients/CheckRunsClient.cs | 419 ++++++++++++ Octokit/Clients/ChecksClient.cs | 9 + Octokit/Clients/ICheckRunsClient.cs | 262 ++++++++ Octokit/Clients/ICheckSuitesClient.cs | 2 +- Octokit/Clients/IChecksClient.cs | 12 +- Octokit/Helpers/ApiUrls.cs | 113 ++++ Octokit/Http/SimpleJsonSerializer.cs | 2 + Octokit/Models/Common/CheckStatus.cs | 12 + Octokit/Models/Request/CheckRunRequest.cs | 54 ++ Octokit/Models/Request/CheckRunUpdate.cs | 68 ++ Octokit/Models/Request/NewCheckRun.cs | 28 + Octokit/Models/Request/NewCheckRunAction.cs | 39 ++ .../Models/Request/NewCheckRunAnnotation.cs | 70 ++ Octokit/Models/Request/NewCheckRunImage.cs | 37 + Octokit/Models/Request/NewCheckRunOutput.cs | 48 ++ Octokit/Models/Request/NewCheckSuite.cs | 4 +- .../ActivityPayloads/CheckRunEventPayload.cs | 11 + Octokit/Models/Response/CheckRun.cs | 105 +++ Octokit/Models/Response/CheckRunAnnotation.cs | 67 ++ .../Models/Response/CheckRunOutputResponse.cs | 44 ++ Octokit/Models/Response/CheckRunsResponse.cs | 32 + Octokit/Models/Response/CheckSuite.cs | 22 +- 33 files changed, 4566 insertions(+), 17 deletions(-) create mode 100644 Octokit.Reactive/Clients/IObservableCheckRunsClient.cs create mode 100644 Octokit.Reactive/Clients/ObservableCheckRunsClient.cs create mode 100644 Octokit.Tests.Integration/Clients/CheckRunsClientTests.cs create mode 100644 Octokit.Tests.Integration/Reactive/ObservableCheckRunsClientTests.cs create mode 100644 Octokit.Tests/Clients/CheckRunsClientTests.cs create mode 100644 Octokit.Tests/Models/CheckRunEventTests.cs create mode 100644 Octokit.Tests/Reactive/ObservableCheckRunsClientTests.cs create mode 100644 Octokit/Clients/CheckRunsClient.cs create mode 100644 Octokit/Clients/ICheckRunsClient.cs create mode 100644 Octokit/Models/Request/CheckRunRequest.cs create mode 100644 Octokit/Models/Request/CheckRunUpdate.cs create mode 100644 Octokit/Models/Request/NewCheckRun.cs create mode 100644 Octokit/Models/Request/NewCheckRunAction.cs create mode 100644 Octokit/Models/Request/NewCheckRunAnnotation.cs create mode 100644 Octokit/Models/Request/NewCheckRunImage.cs create mode 100644 Octokit/Models/Request/NewCheckRunOutput.cs create mode 100644 Octokit/Models/Response/ActivityPayloads/CheckRunEventPayload.cs create mode 100644 Octokit/Models/Response/CheckRun.cs create mode 100644 Octokit/Models/Response/CheckRunAnnotation.cs create mode 100644 Octokit/Models/Response/CheckRunOutputResponse.cs create mode 100644 Octokit/Models/Response/CheckRunsResponse.cs diff --git a/Octokit.Reactive/Clients/IObservableCheckRunsClient.cs b/Octokit.Reactive/Clients/IObservableCheckRunsClient.cs new file mode 100644 index 0000000000..9980baf349 --- /dev/null +++ b/Octokit.Reactive/Clients/IObservableCheckRunsClient.cs @@ -0,0 +1,261 @@ +using System; + +namespace Octokit.Reactive +{ + /// + /// A client for GitHub's Check Runs API + /// + /// + /// See the Check Runs API documentation for more information. + /// + public interface IObservableCheckRunsClient + { + /// + /// Creates a new check run for a specific commit in a repository + /// + /// + /// See the Check Runs API documentation for more information. + /// + /// The owner of the repository + /// The name of the repository + /// Details of the Check Run to create + IObservable Create(string owner, string name, NewCheckRun newCheckRun); + + /// + /// Creates a new check run for a specific commit in a repository + /// + /// + /// See the Check Runs API documentation for more information. + /// + /// The Id of the repository + /// Details of the Check Run to create + IObservable Create(long repositoryId, NewCheckRun newCheckRun); + + /// + /// Updates a check run for a specific commit in a repository + /// + /// + /// See the Check Runs API documentation for more information. + /// + /// The owner of the repository + /// The name of the repository + /// The Id of the check run + /// The updates to the check run + IObservable Update(string owner, string name, long checkRunId, CheckRunUpdate checkRunUpdate); + + /// + /// Updates a check run for a specific commit in a repository + /// + /// + /// See the Check Runs API documentation for more information. + /// + /// The Id of the repository + /// The Id of the check run + /// The updates to the check run + IObservable Update(long repositoryId, long checkRunId, CheckRunUpdate checkRunUpdate); + + /// + /// Lists check runs for a commit ref. The ref can be a SHA, branch name, or a tag name + /// + /// + /// See the Check Runs API documentation for more information. + /// + /// The owner of the repository + /// The name of the repository + /// The commit reference (can be a SHA, branch name, or a tag name) + IObservable GetAllForReference(string owner, string name, string reference); + + /// + /// Lists check runs for a commit ref. The ref can be a SHA, branch name, or a tag name + /// + /// + /// See the Check Runs API documentation for more information. + /// + /// The Id of the repository + /// The commit reference (can be a SHA, branch name, or a tag name) + IObservable GetAllForReference(long repositoryId, string reference); + + /// + /// Lists check runs for a commit ref. The ref can be a SHA, branch name, or a tag name + /// + /// + /// See the Check Runs API documentation for more information. + /// + /// The owner of the repository + /// The name of the repository + /// The commit reference (can be a SHA, branch name, or a tag name) + /// Details to filter the request, such as by check name + IObservable GetAllForReference(string owner, string name, string reference, CheckRunRequest checkRunRequest); + + /// + /// Lists check runs for a commit ref. The ref can be a SHA, branch name, or a tag name + /// + /// + /// See the Check Runs API documentation for more information. + /// + /// The Id of the repository + /// The commit reference (can be a SHA, branch name, or a tag name) + /// Details to filter the request, such as by check name + IObservable GetAllForReference(long repositoryId, string reference, CheckRunRequest checkRunRequest); + + /// + /// Lists check runs for a commit ref. The ref can be a SHA, branch name, or a tag name + /// + /// + /// See the Check Runs API documentation for more information. + /// + /// The owner of the repository + /// The name of the repository + /// The commit reference (can be a SHA, branch name, or a tag name) + /// Details to filter the request, such as by check name + /// Options to change the API response + IObservable GetAllForReference(string owner, string name, string reference, CheckRunRequest checkRunRequest, ApiOptions options); + + /// + /// Lists check runs for a commit ref. The ref can be a SHA, branch name, or a tag name + /// + /// + /// See the Check Runs API documentation for more information. + /// + /// The Id of the repository + /// The commit reference (can be a SHA, branch name, or a tag name) + /// Details to filter the request, such as by check name + /// Options to change the API response + IObservable GetAllForReference(long repositoryId, string reference, CheckRunRequest checkRunRequest, ApiOptions options); + + /// + /// Lists check runs for a check suite using its Id + /// + /// + /// See the Check Runs API documentation for more information. + /// + /// The owner of the repository + /// The name of the repository + /// The Id of the check suite + IObservable GetAllForCheckSuite(string owner, string name, long checkSuiteId); + + /// + /// Lists check runs for a check suite using its Id + /// + /// + /// See the Check Runs API documentation for more information. + /// + /// The Id of the repository + /// The Id of the check suite + IObservable GetAllForCheckSuite(long repositoryId, long checkSuiteId); + + /// + /// Lists check runs for a check suite using its Id + /// + /// + /// See the Check Runs API documentation for more information. + /// + /// The owner of the repository + /// The name of the repository + /// The Id of the check suite + /// Details to filter the request, such as by check name + IObservable GetAllForCheckSuite(string owner, string name, long checkSuiteId, CheckRunRequest checkRunRequest); + + /// + /// Lists check runs for a check suite using its Id + /// + /// + /// See the Check Runs API documentation for more information. + /// + /// The Id of the repository + /// The Id of the check suite + /// Details to filter the request, such as by check name + IObservable GetAllForCheckSuite(long repositoryId, long checkSuiteId, CheckRunRequest checkRunRequest); + + /// + /// Lists check runs for a check suite using its Id + /// + /// + /// See the Check Runs API documentation for more information. + /// + /// The owner of the repository + /// The name of the repository + /// The Id of the check suite + /// Details to filter the request, such as by check name + /// Options to change the API response + IObservable GetAllForCheckSuite(string owner, string name, long checkSuiteId, CheckRunRequest checkRunRequest, ApiOptions options); + + /// + /// Lists check runs for a check suite using its Id + /// + /// + /// See the Check Runs API documentation for more information. + /// + /// The Id of the repository + /// The Id of the check suite + /// 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 + /// + /// + /// See the Check Runs API documentation for more information. + /// + /// 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 + /// + /// + /// See the Check Runs API documentation for more information. + /// + /// The Id of the repository + /// The Id of the check run + IObservable Get(long repositoryId, long checkRunId); + + /// + /// Lists annotations for a check run using the check run Id + /// + /// + /// See the Check Runs API documentation for more information. + /// + /// The owner of the repository + /// The name of the repository + /// The Id of the check run + IObservable GetAllAnnotations(string owner, string name, long checkRunId); + + /// + /// Lists annotations for a check run using the check run Id + /// + /// + /// See the Check Runs API documentation for more information. + /// + /// The Id of the repository + /// The Id of the check run + /// + IObservable GetAllAnnotations(long repositoryId, long checkRunId); + + /// + /// Lists annotations for a check run using the check run Id + /// + /// + /// See the Check Runs API documentation for more information. + /// + /// The owner of the repository + /// The name of the repository + /// The Id of the check run + /// Options to change the API response + IObservable GetAllAnnotations(string owner, string name, long checkRunId, ApiOptions options); + + /// + /// Lists annotations for a check run using the check run Id + /// + /// + /// See the Check Runs API documentation for more information. + /// + /// The Id of the repository + /// The Id of the check run + /// Options to change the API response + IObservable GetAllAnnotations(long repositoryId, long checkRunId, ApiOptions options); + } +} \ No newline at end of file diff --git a/Octokit.Reactive/Clients/IObservableChecksClient.cs b/Octokit.Reactive/Clients/IObservableChecksClient.cs index a5127ae78f..ad64e42214 100644 --- a/Octokit.Reactive/Clients/IObservableChecksClient.cs +++ b/Octokit.Reactive/Clients/IObservableChecksClient.cs @@ -8,6 +8,14 @@ /// public interface IObservableChecksClient { + /// + /// A client for GitHub's Check Runs API. + /// + /// + /// See the Check Runs API documentation for more information. + /// + IObservableCheckRunsClient Run { get; } + /// /// A client for GitHub's Check Suites API. /// diff --git a/Octokit.Reactive/Clients/ObservableCheckRunsClient.cs b/Octokit.Reactive/Clients/ObservableCheckRunsClient.cs new file mode 100644 index 0000000000..ee5ebb5f03 --- /dev/null +++ b/Octokit.Reactive/Clients/ObservableCheckRunsClient.cs @@ -0,0 +1,409 @@ +using System; +using System.Reactive.Threading.Tasks; +using Octokit.Reactive.Internal; + +namespace Octokit.Reactive +{ + /// + /// A client for GitHub's Check Runs API + /// + /// + /// See the Check Runs API documentation for more information. + /// + public class ObservableCheckRunsClient : IObservableCheckRunsClient + { + readonly ICheckRunsClient _client; + readonly IConnection _connection; + + /// + /// Initializes a new GitHub Check Runs API client + /// + /// An used to make the requests + public ObservableCheckRunsClient(IGitHubClient client) + { + Ensure.ArgumentNotNull(client, nameof(client)); + + _client = client.Check.Run; + _connection = client.Connection; + } + + /// + /// Creates a new check run for a specific commit in a repository + /// + /// + /// See the Check Runs API documentation for more information. + /// + /// The owner of the repository + /// The name of the repository + /// Details of the Check Run to create + public IObservable Create(string owner, string name, NewCheckRun newCheckRun) + { + Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); + Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); + Ensure.ArgumentNotNull(newCheckRun, nameof(newCheckRun)); + + return _client.Create(owner, name, newCheckRun).ToObservable(); + } + + /// + /// Creates a new check run for a specific commit in a repository + /// + /// + /// See the Check Runs API documentation for more information. + /// + /// The Id of the repository + /// Details of the Check Run to create + public IObservable Create(long repositoryId, NewCheckRun newCheckRun) + { + Ensure.ArgumentNotNull(newCheckRun, nameof(newCheckRun)); + + return _client.Create(repositoryId, newCheckRun).ToObservable(); + } + + /// + /// Updates a check run for a specific commit in a repository + /// + /// + /// See the Check Runs API documentation for more information. + /// + /// The owner of the repository + /// The name of the repository + /// The Id of the check run + /// The updates to the check run + public IObservable Update(string owner, string name, long checkRunId, CheckRunUpdate checkRunUpdate) + { + Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); + Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); + Ensure.ArgumentNotNull(checkRunUpdate, nameof(checkRunUpdate)); + + return _client.Update(owner, name, checkRunId, checkRunUpdate).ToObservable(); + } + + /// + /// Updates a check run for a specific commit in a repository + /// + /// + /// See the Check Runs API documentation for more information. + /// + /// The Id of the repository + /// The Id of the check run + /// The updates to the check run + public IObservable Update(long repositoryId, long checkRunId, CheckRunUpdate checkRunUpdate) + { + Ensure.ArgumentNotNull(checkRunUpdate, nameof(checkRunUpdate)); + + return _client.Update(repositoryId, checkRunId, checkRunUpdate).ToObservable(); + } + + /// + /// Lists check runs for a commit ref. The ref can be a SHA, branch name, or a tag name + /// + /// + /// See the Check Runs API documentation for more information. + /// + /// The owner of the repository + /// The name of the repository + /// The commit reference (can be a SHA, branch name, or a tag name) + public IObservable GetAllForReference(string owner, string name, string reference) + { + Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); + Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); + Ensure.ArgumentNotNullOrEmptyString(reference, nameof(reference)); + + return GetAllForReference(owner, name, reference, new CheckRunRequest(), ApiOptions.None); + } + + /// + /// Lists check runs for a commit ref. The ref can be a SHA, branch name, or a tag name + /// + /// + /// See the Check Runs API documentation for more information. + /// + /// The Id of the repository + /// The commit reference (can be a SHA, branch name, or a tag name) + public IObservable GetAllForReference(long repositoryId, string reference) + { + Ensure.ArgumentNotNullOrEmptyString(reference, nameof(reference)); + + return GetAllForReference(repositoryId, reference, new CheckRunRequest(), ApiOptions.None); + } + + /// + /// Lists check runs for a commit ref. The ref can be a SHA, branch name, or a tag name + /// + /// + /// See the Check Runs API documentation for more information. + /// + /// The owner of the repository + /// The name of the repository + /// The commit reference (can be a SHA, branch name, or a tag name) + /// Details to filter the request, such as by check name + public IObservable GetAllForReference(string owner, string name, string reference, CheckRunRequest checkRunRequest) + { + Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); + Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); + Ensure.ArgumentNotNullOrEmptyString(reference, nameof(reference)); + Ensure.ArgumentNotNull(checkRunRequest, nameof(checkRunRequest)); + + return GetAllForReference(owner, name, reference, checkRunRequest, ApiOptions.None); + } + + /// + /// Lists check runs for a commit ref. The ref can be a SHA, branch name, or a tag name + /// + /// + /// See the Check Runs API documentation for more information. + /// + /// The Id of the repository + /// The commit reference (can be a SHA, branch name, or a tag name) + /// Details to filter the request, such as by check name + public IObservable GetAllForReference(long repositoryId, string reference, CheckRunRequest checkRunRequest) + { + Ensure.ArgumentNotNullOrEmptyString(reference, nameof(reference)); + Ensure.ArgumentNotNull(checkRunRequest, nameof(checkRunRequest)); + + return GetAllForReference(repositoryId, reference, checkRunRequest, ApiOptions.None); + } + + /// + /// Lists check runs for a commit ref. The ref can be a SHA, branch name, or a tag name + /// + /// + /// See the Check Runs API documentation for more information. + /// + /// The owner of the repository + /// The name of the repository + /// The commit reference (can be a SHA, branch name, or a tag name) + /// Details to filter the request, such as by check name + /// Options to change the API response + public IObservable GetAllForReference(string owner, string name, string reference, CheckRunRequest checkRunRequest, ApiOptions options) + { + Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); + Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); + Ensure.ArgumentNotNullOrEmptyString(reference, nameof(reference)); + Ensure.ArgumentNotNull(checkRunRequest, nameof(checkRunRequest)); + Ensure.ArgumentNotNull(options, nameof(options)); + + return _connection.GetAndFlattenAllPages(ApiUrls.CheckRunsForReference(owner, name, reference), checkRunRequest.ToParametersDictionary(), AcceptHeaders.ChecksApiPreview, options); + } + + /// + /// Lists check runs for a commit ref. The ref can be a SHA, branch name, or a tag name + /// + /// + /// See the Check Runs API documentation for more information. + /// + /// The Id of the repository + /// The commit reference (can be a SHA, branch name, or a tag name) + /// Details to filter the request, such as by check name + /// Options to change the API response + public IObservable GetAllForReference(long repositoryId, string reference, CheckRunRequest checkRunRequest, ApiOptions options) + { + Ensure.ArgumentNotNullOrEmptyString(reference, nameof(reference)); + Ensure.ArgumentNotNull(checkRunRequest, nameof(checkRunRequest)); + Ensure.ArgumentNotNull(options, nameof(options)); + + return _connection.GetAndFlattenAllPages(ApiUrls.CheckRunsForReference(repositoryId, reference), checkRunRequest.ToParametersDictionary(), AcceptHeaders.ChecksApiPreview, options); + } + + /// + /// Lists check runs for a check suite using its Id + /// + /// + /// See the Check Runs API documentation for more information. + /// + /// The owner of the repository + /// The name of the repository + /// The Id of the check suite + public IObservable GetAllForCheckSuite(string owner, string name, long checkSuiteId) + { + Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); + Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); + + return GetAllForCheckSuite(owner, name, checkSuiteId, new CheckRunRequest(), ApiOptions.None); + } + + /// + /// Lists check runs for a check suite using its Id + /// + /// + /// See the Check Runs API documentation for more information. + /// + /// The Id of the repository + /// The Id of the check suite + public IObservable GetAllForCheckSuite(long repositoryId, long checkSuiteId) + { + return GetAllForCheckSuite(repositoryId, checkSuiteId, new CheckRunRequest(), ApiOptions.None); + } + + /// + /// Lists check runs for a check suite using its Id + /// + /// + /// See the Check Runs API documentation for more information. + /// + /// The owner of the repository + /// The name of the repository + /// The Id of the check suite + /// Details to filter the request, such as by check name + public IObservable GetAllForCheckSuite(string owner, string name, long checkSuiteId, CheckRunRequest checkRunRequest) + { + Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); + Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); + Ensure.ArgumentNotNull(checkRunRequest, nameof(checkRunRequest)); + + return GetAllForCheckSuite(owner, name, checkSuiteId, checkRunRequest, ApiOptions.None); + } + + /// + /// Lists check runs for a check suite using its Id + /// + /// + /// See the Check Runs API documentation for more information. + /// + /// The Id of the repository + /// The Id of the check suite + /// Details to filter the request, such as by check name + public IObservable GetAllForCheckSuite(long repositoryId, long checkSuiteId, CheckRunRequest checkRunRequest) + { + Ensure.ArgumentNotNull(checkRunRequest, nameof(checkRunRequest)); + + return GetAllForCheckSuite(repositoryId, checkSuiteId, checkRunRequest, ApiOptions.None); + } + + /// + /// Lists check runs for a check suite using its Id + /// + /// + /// See the Check Runs API documentation for more information. + /// + /// The owner of the repository + /// The name of the repository + /// The Id of the check suite + /// Details to filter the request, such as by check name + /// Options to change the API response + public IObservable GetAllForCheckSuite(string owner, string name, long checkSuiteId, CheckRunRequest checkRunRequest, ApiOptions options) + { + Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); + Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); + Ensure.ArgumentNotNull(checkRunRequest, nameof(checkRunRequest)); + Ensure.ArgumentNotNull(options, nameof(options)); + + return _connection.GetAndFlattenAllPages(ApiUrls.CheckRunsForCheckSuite(owner, name, checkSuiteId), checkRunRequest.ToParametersDictionary(), AcceptHeaders.ChecksApiPreview, options); + } + + /// + /// Lists check runs for a check suite using its Id + /// + /// + /// See the Check Runs API documentation for more information. + /// + /// The Id of the repository + /// The Id of the check suite + /// Details to filter the request, such as by check name + /// Options to change the API response + public IObservable GetAllForCheckSuite(long repositoryId, long checkSuiteId, CheckRunRequest checkRunRequest, ApiOptions options) + { + Ensure.ArgumentNotNull(checkRunRequest, nameof(checkRunRequest)); + Ensure.ArgumentNotNull(options, nameof(options)); + + return _connection.GetAndFlattenAllPages(ApiUrls.CheckRunsForCheckSuite(repositoryId, checkSuiteId), checkRunRequest.ToParametersDictionary(), AcceptHeaders.ChecksApiPreview, options); + } + + /// + /// Gets a single check run using its Id + /// + /// + /// See the Check Runs API documentation for more information. + /// + /// 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 + /// + /// + /// See the Check Runs API documentation for more information. + /// + /// The Id of the repository + /// The Id of the check run + public IObservable Get(long repositoryId, long checkRunId) + { + return _client.Get(repositoryId, checkRunId).ToObservable(); + } + + /// + /// Lists annotations for a check run using the check run Id + /// + /// + /// See the Check Runs API documentation for more information. + /// + /// The owner of the repository + /// The name of the repository + /// The Id of the check run + public IObservable GetAllAnnotations(string owner, string name, long checkRunId) + { + Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); + Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); + + return GetAllAnnotations(owner, name, checkRunId, ApiOptions.None); + } + + /// + /// Lists annotations for a check run using the check run Id + /// + /// + /// See the Check Runs API documentation for more information. + /// + /// The Id of the repository + /// The Id of the check run + /// + public IObservable GetAllAnnotations(long repositoryId, long checkRunId) + { + return GetAllAnnotations(repositoryId, checkRunId, ApiOptions.None); + } + + /// + /// Lists annotations for a check run using the check run Id + /// + /// + /// See the Check Runs API documentation for more information. + /// + /// The owner of the repository + /// The name of the repository + /// The Id of the check run + /// Options to change the API response + public IObservable GetAllAnnotations(string owner, string name, long checkRunId, ApiOptions options) + { + Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); + Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); + Ensure.ArgumentNotNull(options, nameof(options)); + + return _connection.GetAndFlattenAllPages(ApiUrls.CheckRunAnnotations(owner, name, checkRunId), null, AcceptHeaders.ChecksApiPreview, options); + } + + /// + /// Lists annotations for a check run using the check run Id + /// + /// + /// See the Check Runs API documentation for more information. + /// + /// The Id of the repository + /// The Id of the check run + /// Options to change the API response + public IObservable GetAllAnnotations(long repositoryId, long checkRunId, ApiOptions options) + { + Ensure.ArgumentNotNull(options, nameof(options)); + + return _connection.GetAndFlattenAllPages(ApiUrls.CheckRunAnnotations(repositoryId, checkRunId), null, AcceptHeaders.ChecksApiPreview, options); + } + } +} diff --git a/Octokit.Reactive/Clients/ObservableChecksClient.cs b/Octokit.Reactive/Clients/ObservableChecksClient.cs index 90c4b72dcd..eb3d829f6e 100644 --- a/Octokit.Reactive/Clients/ObservableChecksClient.cs +++ b/Octokit.Reactive/Clients/ObservableChecksClient.cs @@ -8,13 +8,26 @@ /// public class ObservableChecksClient : IObservableChecksClient { + /// + /// Initializes a new GitHub Checks API client. + /// + /// An used to make the requests public ObservableChecksClient(IGitHubClient client) { Ensure.ArgumentNotNull(client, nameof(client)); + Run = new ObservableCheckRunsClient(client); Suite = new ObservableCheckSuitesClient(client); } + /// + /// A client for GitHub's Check Runs API. + /// + /// + /// See the Check Runs API documentation for more information. + /// + public IObservableCheckRunsClient Run { get; private set; } + /// /// A client for GitHub's Check Suites API. /// diff --git a/Octokit.Tests.Integration/Clients/CheckRunsClientTests.cs b/Octokit.Tests.Integration/Clients/CheckRunsClientTests.cs new file mode 100644 index 0000000000..7adaf503e3 --- /dev/null +++ b/Octokit.Tests.Integration/Clients/CheckRunsClientTests.cs @@ -0,0 +1,460 @@ +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Octokit.Tests.Integration.Helpers; +using Xunit; + +namespace Octokit.Tests.Integration.Clients +{ + public class CheckRunsClientTests + { + public class TheCreateMethod + { + IGitHubClient _github; + IGitHubClient _githubAppInstallation; + + public TheCreateMethod() + { + _github = Helper.GetAuthenticatedClient(); + + // Authenticate as a GitHubApp Installation + _githubAppInstallation = Helper.GetAuthenticatedGitHubAppInstallationForOwner(Helper.UserName); + } + + [GitHubAppsTest] + public async Task CreatesCheckRun() + { + 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.Queued + }; + var result = await _githubAppInstallation.Check.Run.Create(repoContext.RepositoryOwner, repoContext.RepositoryName, newCheckRun); + + // Check result + Assert.NotNull(result); + Assert.Equal(featureBranch.Object.Sha, result.HeadSha); + } + } + + [GitHubAppsTest] + public async Task CreatesCheckRunWithRepositoryId() + { + 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.Queued + }; + var result = await _githubAppInstallation.Check.Run.Create(repoContext.RepositoryId, newCheckRun); + + // Check result + Assert.NotNull(result); + Assert.Equal(featureBranch.Object.Sha, result.HeadSha); + } + } + } + + public class TheUpdateMethod + { + IGitHubClient _github; + IGitHubClient _githubAppInstallation; + + public TheUpdateMethod() + { + _github = Helper.GetAuthenticatedClient(); + + // Authenticate as a GitHubApp Installation + _githubAppInstallation = Helper.GetAuthenticatedGitHubAppInstallationForOwner(Helper.UserName); + } + + [GitHubAppsTest] + public async Task UpdatesCheckRun() + { + 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.Queued + }; + var checkRun = await _githubAppInstallation.Check.Run.Create(repoContext.RepositoryOwner, repoContext.RepositoryName, newCheckRun); + + // Update the check run + var update = new CheckRunUpdate("new-name") + { + Status = CheckStatus.InProgress + }; + var result = await _githubAppInstallation.Check.Run.Update(repoContext.RepositoryOwner, repoContext.RepositoryName, checkRun.Id, update); + + // Check result + Assert.NotNull(result); + Assert.Equal(featureBranch.Object.Sha, result.HeadSha); + Assert.Equal("new-name", result.Name); + Assert.Equal(CheckStatus.InProgress, result.Status); + } + } + + [GitHubAppsTest] + public async Task UpdatesCheckRunWithRepositoryId() + { + 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.Queued + }; + var checkRun = await _githubAppInstallation.Check.Run.Create(repoContext.RepositoryId, newCheckRun); + + // Update the check run + var update = new CheckRunUpdate("new-name") + { + Status = CheckStatus.InProgress + }; + var result = await _githubAppInstallation.Check.Run.Update(repoContext.RepositoryId, checkRun.Id, update); + + // Check result + Assert.NotNull(result); + Assert.Equal(featureBranch.Object.Sha, result.HeadSha); + Assert.Equal("new-name", result.Name); + Assert.Equal(CheckStatus.InProgress, result.Status); + } + } + } + + public class TheGetAllForReferenceMethod + { + IGitHubClient _github; + IGitHubClient _githubAppInstallation; + + public TheGetAllForReferenceMethod() + { + _github = Helper.GetAuthenticatedClient(); + + // Authenticate as a GitHubApp Installation + _githubAppInstallation = Helper.GetAuthenticatedGitHubAppInstallationForOwner(Helper.UserName); + } + + [GitHubAppsTest] + public async Task GetsAllCheckRuns() + { + 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 + }; + await _githubAppInstallation.Check.Run.Create(repoContext.RepositoryOwner, repoContext.RepositoryName, newCheckRun); + + // Get the check + var request = new CheckRunRequest + { + CheckName = "name", + Status = CheckStatusFilter.InProgress + }; + var checkRuns = await _githubAppInstallation.Check.Run.GetAllForReference(repoContext.RepositoryOwner, repoContext.RepositoryName, featureBranch.Object.Sha, request); + + // Check result + Assert.NotEmpty(checkRuns.CheckRuns); + foreach (var checkRun in checkRuns.CheckRuns) + { + Assert.Equal(featureBranch.Object.Sha, checkRun.HeadSha); + Assert.Equal("name", checkRun.Name); + Assert.Equal(CheckStatus.InProgress, checkRun.Status); + } + } + } + + [GitHubAppsTest] + public async Task GetsAllCheckRunsWithRepositoryId() + { + 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 + }; + await _githubAppInstallation.Check.Run.Create(repoContext.RepositoryId, newCheckRun); + + // Get the check + var request = new CheckRunRequest + { + CheckName = "name", + Status = CheckStatusFilter.InProgress + }; + var checkRuns = await _githubAppInstallation.Check.Run.GetAllForReference(repoContext.RepositoryId, featureBranch.Object.Sha, request); + + // Check result + Assert.NotEmpty(checkRuns.CheckRuns); + foreach (var checkRun in checkRuns.CheckRuns) + { + Assert.Equal(featureBranch.Object.Sha, checkRun.HeadSha); + Assert.Equal("name", checkRun.Name); + Assert.Equal(CheckStatus.InProgress, checkRun.Status); + } + } + } + } + + public class TheGetAllForCheckSuiteMethod + { + IGitHubClient _github; + IGitHubClient _githubAppInstallation; + + public TheGetAllForCheckSuiteMethod() + { + _github = Helper.GetAuthenticatedClient(); + + // Authenticate as a GitHubApp Installation + _githubAppInstallation = Helper.GetAuthenticatedGitHubAppInstallationForOwner(Helper.UserName); + } + + [GitHubAppsTest] + public async Task GetsAllCheckRuns() + { + 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 request = new CheckRunRequest + { + CheckName = "name", + Status = CheckStatusFilter.InProgress + }; + + var checkRuns = await _githubAppInstallation.Check.Run.GetAllForCheckSuite(repoContext.RepositoryOwner, repoContext.RepositoryName, created.CheckSuite.Id, request); + + // Check result + Assert.NotEmpty(checkRuns.CheckRuns); + foreach (var checkRun in checkRuns.CheckRuns) + { + Assert.Equal(featureBranch.Object.Sha, checkRun.HeadSha); + Assert.Equal("name", checkRun.Name); + Assert.Equal(CheckStatus.InProgress, checkRun.Status); + } + } + } + + [GitHubAppsTest] + public async Task GetsAllCheckRunsWithRepositoryId() + { + 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 request = new CheckRunRequest + { + CheckName = "name", + Status = CheckStatusFilter.InProgress + }; + var checkRuns = await _githubAppInstallation.Check.Run.GetAllForCheckSuite(repoContext.RepositoryId, created.CheckSuite.Id, request); + + // Check result + Assert.NotEmpty(checkRuns.CheckRuns); + foreach (var checkRun in checkRuns.CheckRuns) + { + Assert.Equal(featureBranch.Object.Sha, checkRun.HeadSha); + Assert.Equal("name", checkRun.Name); + Assert.Equal(CheckStatus.InProgress, checkRun.Status); + } + } + } + } + + 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); + } + } + } + + public class TheGetAllAnnotationsMethod + { + IGitHubClient _github; + IGitHubClient _githubAppInstallation; + + public TheGetAllAnnotationsMethod() + { + _github = Helper.GetAuthenticatedClient(); + + // Authenticate as a GitHubApp Installation + _githubAppInstallation = Helper.GetAuthenticatedGitHubAppInstallationForOwner(Helper.UserName); + } + + [GitHubAppsTest] + public async Task GetsAllAnnotations() + { + 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, + Output = new NewCheckRunOutput("title", "summary") + { + Annotations = new[] + { + new NewCheckRunAnnotation("file.txt", "blob", 1, 1, CheckWarningLevel.Warning, "this is a warning") + } + } + }; + var created = await _githubAppInstallation.Check.Run.Create(repoContext.RepositoryOwner, repoContext.RepositoryName, newCheckRun); + + // Get the annotations + var annotations = await _githubAppInstallation.Check.Run.GetAllAnnotations(repoContext.RepositoryOwner, repoContext.RepositoryName, created.Id); + + // Check result + Assert.Equal(1, annotations.Count); + Assert.Equal("this is a warning", annotations.First().Message); + Assert.Equal(CheckWarningLevel.Warning, annotations.First().WarningLevel); + } + } + + [GitHubAppsTest] + public async Task GetsAllAnnotationsWithRepositoryId() + { + 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, + Output = new NewCheckRunOutput("title", "summary") + { + Annotations = new[] + { + new NewCheckRunAnnotation("file.txt", "blob", 1, 1, CheckWarningLevel.Warning, "this is a warning") + } + } + }; + var created = await _githubAppInstallation.Check.Run.Create(repoContext.RepositoryId, newCheckRun); + + // Get the annotations + var annotations = await _githubAppInstallation.Check.Run.GetAllAnnotations(repoContext.RepositoryId, created.Id); + + // Check result + Assert.Equal(1, annotations.Count); + Assert.Equal("this is a warning", annotations.First().Message); + Assert.Equal(CheckWarningLevel.Warning, annotations.First().WarningLevel); + } + } + } + } +} \ No newline at end of file diff --git a/Octokit.Tests.Integration/Reactive/ObservableCheckRunsClientTests.cs b/Octokit.Tests.Integration/Reactive/ObservableCheckRunsClientTests.cs new file mode 100644 index 0000000000..7c8352c45f --- /dev/null +++ b/Octokit.Tests.Integration/Reactive/ObservableCheckRunsClientTests.cs @@ -0,0 +1,461 @@ +using System.Collections.Generic; +using System.Linq; +using System.Reactive.Linq; +using System.Threading.Tasks; +using Octokit.Reactive; +using Octokit.Tests.Integration.Helpers; +using Xunit; + +namespace Octokit.Tests.Integration.Reactive +{ + public class ObservableCheckRunsClientTests + { + public class TheCreateMethod + { + IObservableGitHubClient _github; + IObservableGitHubClient _githubAppInstallation; + + public TheCreateMethod() + { + _github = new ObservableGitHubClient(Helper.GetAuthenticatedClient()); + + // Authenticate as a GitHubApp Installation + _githubAppInstallation = new ObservableGitHubClient(Helper.GetAuthenticatedGitHubAppInstallationForOwner(Helper.UserName)); + } + + [GitHubAppsTest] + public async Task CreatesCheckRun() + { + 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.Queued + }; + var result = await _githubAppInstallation.Check.Run.Create(repoContext.RepositoryOwner, repoContext.RepositoryName, newCheckRun); + + // Check result + Assert.NotNull(result); + Assert.Equal(featureBranch.Object.Sha, result.HeadSha); + } + } + + [GitHubAppsTest] + public async Task CreatesCheckRunWithRepositoryId() + { + 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.Queued + }; + var result = await _githubAppInstallation.Check.Run.Create(repoContext.RepositoryId, newCheckRun); + + // Check result + Assert.NotNull(result); + Assert.Equal(featureBranch.Object.Sha, result.HeadSha); + } + } + } + + public class TheUpdateMethod + { + IObservableGitHubClient _github; + IObservableGitHubClient _githubAppInstallation; + + public TheUpdateMethod() + { + _github = new ObservableGitHubClient(Helper.GetAuthenticatedClient()); + + // Authenticate as a GitHubApp Installation + _githubAppInstallation = new ObservableGitHubClient(Helper.GetAuthenticatedGitHubAppInstallationForOwner(Helper.UserName)); + } + + [GitHubAppsTest] + public async Task UpdatesCheckRun() + { + 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.Queued + }; + var checkRun = await _githubAppInstallation.Check.Run.Create(repoContext.RepositoryOwner, repoContext.RepositoryName, newCheckRun); + + // Update the check run + var update = new CheckRunUpdate("new-name") + { + Status = CheckStatus.InProgress + }; + var result = await _githubAppInstallation.Check.Run.Update(repoContext.RepositoryOwner, repoContext.RepositoryName, checkRun.Id, update); + + // Check result + Assert.NotNull(result); + Assert.Equal(featureBranch.Object.Sha, result.HeadSha); + Assert.Equal("new-name", result.Name); + Assert.Equal(CheckStatus.InProgress, result.Status); + } + } + + [GitHubAppsTest] + public async Task UpdatesCheckRunWithRepositoryId() + { + 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.Queued + }; + var checkRun = await _githubAppInstallation.Check.Run.Create(repoContext.RepositoryId, newCheckRun); + + // Update the check run + var update = new CheckRunUpdate("new-name") + { + Status = CheckStatus.InProgress + }; + var result = await _githubAppInstallation.Check.Run.Update(repoContext.RepositoryId, checkRun.Id, update); + + // Check result + Assert.NotNull(result); + Assert.Equal(featureBranch.Object.Sha, result.HeadSha); + Assert.Equal("new-name", result.Name); + Assert.Equal(CheckStatus.InProgress, result.Status); + } + } + } + + public class TheGetAllForReferenceMethod + { + IObservableGitHubClient _github; + IObservableGitHubClient _githubAppInstallation; + + public TheGetAllForReferenceMethod() + { + _github = new ObservableGitHubClient(Helper.GetAuthenticatedClient()); + + // Authenticate as a GitHubApp Installation + _githubAppInstallation = new ObservableGitHubClient(Helper.GetAuthenticatedGitHubAppInstallationForOwner(Helper.UserName)); + } + + [GitHubAppsTest] + public async Task GetsAllCheckRuns() + { + 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 + }; + await _githubAppInstallation.Check.Run.Create(repoContext.RepositoryOwner, repoContext.RepositoryName, newCheckRun); + + // Get the check + var request = new CheckRunRequest + { + CheckName = "name", + Status = CheckStatusFilter.InProgress + }; + var checkRuns = await _githubAppInstallation.Check.Run.GetAllForReference(repoContext.RepositoryOwner, repoContext.RepositoryName, featureBranch.Object.Sha, request); + + // Check result + Assert.NotEmpty(checkRuns.CheckRuns); + foreach (var checkRun in checkRuns.CheckRuns) + { + Assert.Equal(featureBranch.Object.Sha, checkRun.HeadSha); + Assert.Equal("name", checkRun.Name); + Assert.Equal(CheckStatus.InProgress, checkRun.Status); + } + } + } + + [GitHubAppsTest] + public async Task GetsAllCheckRunsWithRepositoryId() + { + 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 + }; + await _githubAppInstallation.Check.Run.Create(repoContext.RepositoryId, newCheckRun); + + // Get the check + var request = new CheckRunRequest + { + CheckName = "name", + Status = CheckStatusFilter.InProgress + }; + var checkRuns = await _githubAppInstallation.Check.Run.GetAllForReference(repoContext.RepositoryId, featureBranch.Object.Sha, request); + + // Check result + Assert.NotEmpty(checkRuns.CheckRuns); + foreach (var checkRun in checkRuns.CheckRuns) + { + Assert.Equal(featureBranch.Object.Sha, checkRun.HeadSha); + Assert.Equal("name", checkRun.Name); + Assert.Equal(CheckStatus.InProgress, checkRun.Status); + } + } + } + } + + public class TheGetAllForCheckSuiteMethod + { + IObservableGitHubClient _github; + IObservableGitHubClient _githubAppInstallation; + + public TheGetAllForCheckSuiteMethod() + { + _github = new ObservableGitHubClient(Helper.GetAuthenticatedClient()); + + // Authenticate as a GitHubApp Installation + _githubAppInstallation = new ObservableGitHubClient(Helper.GetAuthenticatedGitHubAppInstallationForOwner(Helper.UserName)); + } + + [GitHubAppsTest] + public async Task GetsAllCheckRuns() + { + 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 request = new CheckRunRequest + { + CheckName = "name", + Status = CheckStatusFilter.InProgress + }; + var checkRuns = await _githubAppInstallation.Check.Run.GetAllForCheckSuite(repoContext.RepositoryOwner, repoContext.RepositoryName, created.CheckSuite.Id, request); + + // Check result + Assert.NotEmpty(checkRuns.CheckRuns); + foreach (var checkRun in checkRuns.CheckRuns) + { + Assert.Equal(featureBranch.Object.Sha, checkRun.HeadSha); + Assert.Equal("name", checkRun.Name); + Assert.Equal(CheckStatus.InProgress, checkRun.Status); + } + } + } + + [GitHubAppsTest] + public async Task GetsAllCheckRunsWithRepositoryId() + { + 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 request = new CheckRunRequest + { + CheckName = "name", + Status = CheckStatusFilter.InProgress + }; + var checkRuns = await _githubAppInstallation.Check.Run.GetAllForCheckSuite(repoContext.RepositoryId, created.CheckSuite.Id, request); + + // Check result + Assert.NotEmpty(checkRuns.CheckRuns); + foreach (var checkRun in checkRuns.CheckRuns) + { + Assert.Equal(featureBranch.Object.Sha, checkRun.HeadSha); + Assert.Equal("name", checkRun.Name); + Assert.Equal(CheckStatus.InProgress, checkRun.Status); + } + } + } + } + + 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); + } + } + } + + public class TheGetAllAnnotationsMethod + { + IObservableGitHubClient _github; + IObservableGitHubClient _githubAppInstallation; + + public TheGetAllAnnotationsMethod() + { + _github = new ObservableGitHubClient(Helper.GetAuthenticatedClient()); + + // Authenticate as a GitHubApp Installation + _githubAppInstallation = new ObservableGitHubClient(Helper.GetAuthenticatedGitHubAppInstallationForOwner(Helper.UserName)); + } + + [GitHubAppsTest] + public async Task GetsAllAnnotations() + { + 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, + Output = new NewCheckRunOutput("title", "summary") + { + Annotations = new[] + { + new NewCheckRunAnnotation("file.txt", "blob", 1, 1, CheckWarningLevel.Warning, "this is a warning") + } + } + }; + var created = await _githubAppInstallation.Check.Run.Create(repoContext.RepositoryOwner, repoContext.RepositoryName, newCheckRun); + + // Get the annotations + var annotations = await _githubAppInstallation.Check.Run.GetAllAnnotations(repoContext.RepositoryOwner, repoContext.RepositoryName, created.Id).ToList(); + + // Check result + Assert.Equal(1, annotations.Count); + Assert.Equal("this is a warning", annotations.First().Message); + Assert.Equal(CheckWarningLevel.Warning, annotations.First().WarningLevel); + } + } + + [GitHubAppsTest] + public async Task GetsAllAnnotationsWithRepositoryId() + { + 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, + Output = new NewCheckRunOutput("title", "summary") + { + Annotations = new[] + { + new NewCheckRunAnnotation("file.txt", "blob", 1, 1, CheckWarningLevel.Warning, "this is a warning") + } + } + }; + var created = await _githubAppInstallation.Check.Run.Create(repoContext.RepositoryId, newCheckRun); + + // Get the annotations + var annotations = await _githubAppInstallation.Check.Run.GetAllAnnotations(repoContext.RepositoryId, created.Id).ToList(); + + // Check result + Assert.Equal(1, annotations.Count); + Assert.Equal("this is a warning", annotations.First().Message); + Assert.Equal(CheckWarningLevel.Warning, annotations.First().WarningLevel); + } + } + } + } +} \ No newline at end of file diff --git a/Octokit.Tests/Clients/CheckRunsClientTests.cs b/Octokit.Tests/Clients/CheckRunsClientTests.cs new file mode 100644 index 0000000000..546c9da4e4 --- /dev/null +++ b/Octokit.Tests/Clients/CheckRunsClientTests.cs @@ -0,0 +1,631 @@ +using System; +using System.Collections.Generic; +using System.Threading.Tasks; +using NSubstitute; +using Xunit; + +namespace Octokit.Tests.Clients +{ + public class CheckRunsClientTests + { + public class TheCtor + { + [Fact] + public void EnsuresNonNullArguments() + { + Assert.Throws(() => new CheckRunsClient(null)); + } + } + + public class TheCreateMethod + { + [Fact] + public async Task RequestsCorrectUrl() + { + var connection = Substitute.For(); + var client = new CheckRunsClient(connection); + + var newCheckRun = new NewCheckRun("status", "123abc") { Status = CheckStatus.Queued }; + + await client.Create("fake", "repo", newCheckRun); + + connection.Received().Post( + Arg.Is(u => u.ToString() == "repos/fake/repo/check-runs"), + newCheckRun, + "application/vnd.github.antiope-preview+json"); + } + + [Fact] + public async Task RequestsCorrectUrlWithRepositoryId() + { + var connection = Substitute.For(); + var client = new CheckRunsClient(connection); + + var newCheckRun = new NewCheckRun("status", "123abc") { Status = CheckStatus.Queued }; + + await client.Create(1, newCheckRun); + + connection.Received().Post( + Arg.Is(u => u.ToString() == "repositories/1/check-runs"), + newCheckRun, + "application/vnd.github.antiope-preview+json"); + } + + [Fact] + public async Task EnsuresNonNullArguments() + { + var connection = Substitute.For(); + var client = new CheckRunsClient(connection); + + var newCheckRun = new NewCheckRun("status", "123abc") { Status = CheckStatus.Queued }; + + await Assert.ThrowsAsync(() => client.Create(null, "repo", newCheckRun)); + await Assert.ThrowsAsync(() => client.Create("fake", null, newCheckRun)); + await Assert.ThrowsAsync(() => client.Create("fake", "repo", null)); + + await Assert.ThrowsAsync(() => client.Create(1, null)); + } + + [Fact] + public async Task EnsuresNonEmptyArguments() + { + var connection = Substitute.For(); + var client = new CheckRunsClient(connection); + + var newCheckRun = new NewCheckRun("status", "123abc") { Status = CheckStatus.Queued }; + + await Assert.ThrowsAsync(() => client.Create("", "repo", newCheckRun)); + await Assert.ThrowsAsync(() => client.Create("fake", "", newCheckRun)); + } + } + + public class TheUpdateMethod + { + [Fact] + public async Task RequestsCorrectUrl() + { + var connection = Substitute.For(); + var client = new CheckRunsClient(connection); + + var update = new CheckRunUpdate("status") { Status = CheckStatus.InProgress }; + + await client.Update("fake", "repo", 1, update); + + connection.Received().Patch( + Arg.Is(u => u.ToString() == "repos/fake/repo/check-runs/1"), + update, + "application/vnd.github.antiope-preview+json"); + } + + [Fact] + public async Task RequestsCorrectUrlWithRepositoryId() + { + var connection = Substitute.For(); + var client = new CheckRunsClient(connection); + + var update = new CheckRunUpdate("status") { Status = CheckStatus.InProgress }; + + await client.Update(1, 1, update); + + connection.Received().Patch( + Arg.Is(u => u.ToString() == "repositories/1/check-runs/1"), + update, + "application/vnd.github.antiope-preview+json"); + } + + [Fact] + public async Task EnsuresNonNullArguments() + { + var connection = Substitute.For(); + var client = new CheckRunsClient(connection); + + var update = new CheckRunUpdate("status") { Status = CheckStatus.InProgress }; + + await Assert.ThrowsAsync(() => client.Update(null, "repo", 1, update)); + await Assert.ThrowsAsync(() => client.Update("fake", null, 1, update)); + await Assert.ThrowsAsync(() => client.Update("fake", "repo", 1, null)); + } + + [Fact] + public async Task EnsuresNonEmptyArguments() + { + var connection = Substitute.For(); + var client = new CheckRunsClient(connection); + + var update = new CheckRunUpdate("status") { Status = CheckStatus.InProgress }; + + await Assert.ThrowsAsync(() => client.Update("", "repo", 1, update)); + await Assert.ThrowsAsync(() => client.Update("fake", "", 1, update)); + } + } + + public class TheGetAllForReferenceMethod + { + [Fact] + public async Task RequestsCorrectUrl() + { + var connection = Substitute.For(); + var client = new CheckRunsClient(connection); + + await client.GetAllForReference("fake", "repo", "ref"); + + connection.Received().GetAll( + Arg.Is(u => u.ToString() == "repos/fake/repo/commits/ref/check-runs"), + Args.EmptyDictionary, + "application/vnd.github.antiope-preview+json", + Args.ApiOptions); + } + + [Fact] + public async Task RequestsCorrectUrlWithRepositoryId() + { + var connection = Substitute.For(); + var client = new CheckRunsClient(connection); + + await client.GetAllForReference(1, "ref"); + + connection.Received().GetAll( + Arg.Is(u => u.ToString() == "repositories/1/commits/ref/check-runs"), + Args.EmptyDictionary, + "application/vnd.github.antiope-preview+json", + Args.ApiOptions); + } + + [Fact] + public async Task RequestsCorrectUrlWithRequest() + { + var connection = Substitute.For(); + var client = new CheckRunsClient(connection); + + var request = new CheckRunRequest { CheckName = "build", Filter = CheckRunCompletedAtFilter.Latest, Status = CheckStatusFilter.InProgress }; + + await client.GetAllForReference("fake", "repo", "ref", request); + + connection.Received().GetAll( + Arg.Is(u => u.ToString() == "repos/fake/repo/commits/ref/check-runs"), + Arg.Is>(x => + x.Count == 3 + && x["check_name"] == "build" + && x["status"] == "in_progress" + && x["filter"] == "latest"), + "application/vnd.github.antiope-preview+json", + Args.ApiOptions); + } + + [Fact] + public async Task RequestsCorrectUrlWithRequestWithRepositoryId() + { + var connection = Substitute.For(); + var client = new CheckRunsClient(connection); + + var request = new CheckRunRequest { CheckName = "build", Filter = CheckRunCompletedAtFilter.Latest, Status = CheckStatusFilter.InProgress }; + + await client.GetAllForReference(1, "ref", request); + + connection.Received().GetAll( + Arg.Is(u => u.ToString() == "repositories/1/commits/ref/check-runs"), + Arg.Is>(x => + x.Count == 3 + && x["check_name"] == "build" + && x["status"] == "in_progress" + && x["filter"] == "latest"), + "application/vnd.github.antiope-preview+json", + Args.ApiOptions); + } + + [Fact] + public async Task RequestsCorrectUrlWithRequestWithApiOptions() + { + var connection = Substitute.For(); + var client = new CheckRunsClient(connection); + + var request = new CheckRunRequest { CheckName = "build", Filter = CheckRunCompletedAtFilter.Latest, Status = CheckStatusFilter.InProgress }; + var options = new ApiOptions { PageSize = 1 }; + + await client.GetAllForReference("fake", "repo", "ref", request, options); + + connection.Received().GetAll( + Arg.Is(u => u.ToString() == "repos/fake/repo/commits/ref/check-runs"), + Arg.Is>(x => + x.Count == 3 + && x["check_name"] == "build" + && x["status"] == "in_progress" + && x["filter"] == "latest"), + "application/vnd.github.antiope-preview+json", + options); + } + + [Fact] + public async Task RequestsCorrectUrlWithRequestWithApiOptionsWithRepositoryId() + { + var connection = Substitute.For(); + var client = new CheckRunsClient(connection); + + var request = new CheckRunRequest { CheckName = "build", Filter = CheckRunCompletedAtFilter.Latest, Status = CheckStatusFilter.InProgress }; + var options = new ApiOptions { PageSize = 1 }; + + await client.GetAllForReference(1, "ref", request, options); + + connection.Received().GetAll( + Arg.Is(u => u.ToString() == "repositories/1/commits/ref/check-runs"), + Arg.Is>(x => + x.Count == 3 + && x["check_name"] == "build" + && x["status"] == "in_progress" + && x["filter"] == "latest"), + "application/vnd.github.antiope-preview+json", + options); + } + + [Fact] + public async Task EnsuresNonNullArguments() + { + var connection = Substitute.For(); + var client = new CheckRunsClient(connection); + + var request = new CheckRunRequest { CheckName = "build" }; + + await Assert.ThrowsAsync(() => client.GetAllForReference(null, "repo", "ref")); + await Assert.ThrowsAsync(() => client.GetAllForReference("fake", null, "ref")); + await Assert.ThrowsAsync(() => client.GetAllForReference("fake", "repo", null)); + + await Assert.ThrowsAsync(() => client.GetAllForReference(null, "repo", "ref", request)); + await Assert.ThrowsAsync(() => client.GetAllForReference("fake", null, "ref", request)); + await Assert.ThrowsAsync(() => client.GetAllForReference("fake", "repo", null, request)); + await Assert.ThrowsAsync(() => client.GetAllForReference("fake", "repo", "ref", null)); + + await Assert.ThrowsAsync(() => client.GetAllForReference(null, "repo", "ref", request, ApiOptions.None)); + await Assert.ThrowsAsync(() => client.GetAllForReference("fake", null, "ref", request, ApiOptions.None)); + await Assert.ThrowsAsync(() => client.GetAllForReference("fake", "repo", null, request, ApiOptions.None)); + await Assert.ThrowsAsync(() => client.GetAllForReference("fake", "repo", "ref", null, ApiOptions.None)); + await Assert.ThrowsAsync(() => client.GetAllForReference("fake", "repo", "ref", request, null)); + + await Assert.ThrowsAsync(() => client.GetAllForReference(1, null)); + + await Assert.ThrowsAsync(() => client.GetAllForReference(1, null, request)); + await Assert.ThrowsAsync(() => client.GetAllForReference(1, "ref", null)); + + await Assert.ThrowsAsync(() => client.GetAllForReference(1, null, request, ApiOptions.None)); + await Assert.ThrowsAsync(() => client.GetAllForReference(1, "ref", null, ApiOptions.None)); + await Assert.ThrowsAsync(() => client.GetAllForReference(1, "ref", request, null)); + } + + [Fact] + public async Task EnsuresNonEmptyArguments() + { + var connection = Substitute.For(); + var client = new CheckRunsClient(connection); + + var request = new CheckRunRequest { CheckName = "build" }; + + await Assert.ThrowsAsync(() => client.GetAllForReference("", "repo", "ref")); + await Assert.ThrowsAsync(() => client.GetAllForReference("fake", "", "ref")); + await Assert.ThrowsAsync(() => client.GetAllForReference("fake", "repo", "")); + + await Assert.ThrowsAsync(() => client.GetAllForReference("", "repo", "ref", request)); + await Assert.ThrowsAsync(() => client.GetAllForReference("fake", "", "ref", request)); + await Assert.ThrowsAsync(() => client.GetAllForReference("fake", "repo", "", request)); + + await Assert.ThrowsAsync(() => client.GetAllForReference("", "repo", "ref", request, ApiOptions.None)); + await Assert.ThrowsAsync(() => client.GetAllForReference("fake", "", "ref", request, ApiOptions.None)); + await Assert.ThrowsAsync(() => client.GetAllForReference("fake", "repo", "", request, ApiOptions.None)); + + await Assert.ThrowsAsync(() => client.GetAllForReference(1, "")); + + await Assert.ThrowsAsync(() => client.GetAllForReference(1, "", request)); + + await Assert.ThrowsAsync(() => client.GetAllForReference(1, "", request, ApiOptions.None)); + } + } + + public class TheGetAllForCheckSuiteMethod + { + [Fact] + public async Task RequestsCorrectUrl() + { + var connection = Substitute.For(); + var client = new CheckRunsClient(connection); + + await client.GetAllForCheckSuite("fake", "repo", 1); + + connection.Received().GetAll( + Arg.Is(u => u.ToString() == "repos/fake/repo/check-suites/1/check-runs"), + Args.EmptyDictionary, + "application/vnd.github.antiope-preview+json", + Args.ApiOptions); + } + + [Fact] + public async Task RequestsCorrectUrlWithRepositoryId() + { + var connection = Substitute.For(); + var client = new CheckRunsClient(connection); + + await client.GetAllForCheckSuite(1, 1); + + connection.Received().GetAll( + Arg.Is(u => u.ToString() == "repositories/1/check-suites/1/check-runs"), + Args.EmptyDictionary, + "application/vnd.github.antiope-preview+json", + Args.ApiOptions); + } + + [Fact] + public async Task RequestsCorrectUrlWithRequest() + { + var connection = Substitute.For(); + var client = new CheckRunsClient(connection); + + var request = new CheckRunRequest { CheckName = "build", Filter = CheckRunCompletedAtFilter.Latest, Status = CheckStatusFilter.InProgress }; + + await client.GetAllForCheckSuite("fake", "repo", 1, request); + + connection.Received().GetAll( + Arg.Is(u => u.ToString() == "repos/fake/repo/check-suites/1/check-runs"), + Arg.Is>(x => + x.Count == 3 + && x["check_name"] == "build" + && x["status"] == "in_progress" + && x["filter"] == "latest"), + "application/vnd.github.antiope-preview+json", + Args.ApiOptions); + } + + [Fact] + public async Task RequestsCorrectUrlWithRequestWithRepositoryId() + { + var connection = Substitute.For(); + var client = new CheckRunsClient(connection); + + var request = new CheckRunRequest { CheckName = "build", Filter = CheckRunCompletedAtFilter.Latest, Status = CheckStatusFilter.InProgress }; + + await client.GetAllForCheckSuite(1, 1, request); + + connection.Received().GetAll( + Arg.Is(u => u.ToString() == "repositories/1/check-suites/1/check-runs"), + Arg.Is>(x => + x.Count == 3 + && x["check_name"] == "build" + && x["status"] == "in_progress" + && x["filter"] == "latest"), + "application/vnd.github.antiope-preview+json", + Args.ApiOptions); + } + + [Fact] + public async Task RequestsCorrectUrlWithRequestWithApiOptions() + { + var connection = Substitute.For(); + var client = new CheckRunsClient(connection); + + var request = new CheckRunRequest { CheckName = "build", Filter = CheckRunCompletedAtFilter.Latest, Status = CheckStatusFilter.InProgress }; + var options = new ApiOptions { PageSize = 1 }; + + await client.GetAllForCheckSuite("fake", "repo", 1, request, options); + + connection.Received().GetAll( + Arg.Is(u => u.ToString() == "repos/fake/repo/check-suites/1/check-runs"), + Arg.Is>(x => + x.Count == 3 + && x["check_name"] == "build" + && x["status"] == "in_progress" + && x["filter"] == "latest"), + "application/vnd.github.antiope-preview+json", + options); + } + + [Fact] + public async Task RequestsCorrectUrlWithRequestWithApiOptionsWithRepositoryId() + { + var connection = Substitute.For(); + var client = new CheckRunsClient(connection); + + var request = new CheckRunRequest { CheckName = "build", Filter = CheckRunCompletedAtFilter.Latest, Status = CheckStatusFilter.InProgress }; + var options = new ApiOptions { PageSize = 1 }; + + await client.GetAllForCheckSuite(1, 1, request, options); + + connection.Received().GetAll( + Arg.Is(u => u.ToString() == "repositories/1/check-suites/1/check-runs"), + Arg.Is>(x => + x.Count == 3 + && x["check_name"] == "build" + && x["status"] == "in_progress" + && x["filter"] == "latest"), + "application/vnd.github.antiope-preview+json", + options); + } + + [Fact] + public async Task EnsuresNonNullArguments() + { + var connection = Substitute.For(); + var client = new CheckRunsClient(connection); + + var request = new CheckRunRequest { CheckName = "build" }; + + await Assert.ThrowsAsync(() => client.GetAllForCheckSuite(null, "repo", 1)); + await Assert.ThrowsAsync(() => client.GetAllForCheckSuite("fake", null, 1)); + + await Assert.ThrowsAsync(() => client.GetAllForCheckSuite(null, "repo", 1, request)); + await Assert.ThrowsAsync(() => client.GetAllForCheckSuite("fake", null, 1, request)); + await Assert.ThrowsAsync(() => client.GetAllForCheckSuite("fake", "repo", 1, null)); + + await Assert.ThrowsAsync(() => client.GetAllForCheckSuite(null, "repo", 1, request, ApiOptions.None)); + await Assert.ThrowsAsync(() => client.GetAllForCheckSuite("fake", null, 1, request, ApiOptions.None)); + await Assert.ThrowsAsync(() => client.GetAllForCheckSuite("fake", "repo", 1, null, ApiOptions.None)); + await Assert.ThrowsAsync(() => client.GetAllForCheckSuite("fake", "repo", 1, request, null)); + + await Assert.ThrowsAsync(() => client.GetAllForCheckSuite(1, 1, null)); + + await Assert.ThrowsAsync(() => client.GetAllForCheckSuite(1, 1, null, ApiOptions.None)); + await Assert.ThrowsAsync(() => client.GetAllForCheckSuite(1, 1, request, null)); + } + + [Fact] + public async Task EnsuresNonEmptyArguments() + { + var connection = Substitute.For(); + var client = new CheckRunsClient(connection); + + var request = new CheckRunRequest { CheckName = "build" }; + + await Assert.ThrowsAsync(() => client.GetAllForCheckSuite("", "repo", 1)); + await Assert.ThrowsAsync(() => client.GetAllForCheckSuite("fake", "", 1)); + + await Assert.ThrowsAsync(() => client.GetAllForCheckSuite("", "repo", 1, request)); + await Assert.ThrowsAsync(() => client.GetAllForCheckSuite("fake", "", 1, request)); + + await Assert.ThrowsAsync(() => client.GetAllForCheckSuite("", "repo", 1, request, ApiOptions.None)); + 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)); + } + } + + public class TheGetAllAnnotationsMethod + { + [Fact] + public async Task RequestsCorrectUrl() + { + var connection = Substitute.For(); + var client = new CheckRunsClient(connection); + + await client.GetAllAnnotations("fake", "repo", 1); + + connection.Received().GetAll( + Arg.Is(u => u.ToString() == "repos/fake/repo/check-runs/1/annotations"), + null, + "application/vnd.github.antiope-preview+json", + Args.ApiOptions); + } + + [Fact] + public async Task RequestsCorrectUrlWithRepositoryId() + { + var connection = Substitute.For(); + var client = new CheckRunsClient(connection); + + await client.GetAllAnnotations(1, 1); + + connection.Received().GetAll( + Arg.Is(u => u.ToString() == "repositories/1/check-runs/1/annotations"), + null, + "application/vnd.github.antiope-preview+json", + Args.ApiOptions); + } + + [Fact] + public async Task RequestsCorrectUrlWithApiOptions() + { + var connection = Substitute.For(); + var client = new CheckRunsClient(connection); + + var options = new ApiOptions { PageSize = 1 }; + + await client.GetAllAnnotations("fake", "repo", 1, options); + + connection.Received().GetAll( + Arg.Is(u => u.ToString() == "repos/fake/repo/check-runs/1/annotations"), + null, + "application/vnd.github.antiope-preview+json", + options); + } + + [Fact] + public async Task RequestsCorrectUrlWithApiOptionsWithRepositoryId() + { + var connection = Substitute.For(); + var client = new CheckRunsClient(connection); + + var options = new ApiOptions { PageSize = 1 }; + + await client.GetAllAnnotations(1, 1, options); + + connection.Received().GetAll( + Arg.Is(u => u.ToString() == "repositories/1/check-runs/1/annotations"), + null, + "application/vnd.github.antiope-preview+json", + options); + } + + [Fact] + public async Task EnsuresNonNullArguments() + { + var connection = Substitute.For(); + var client = new CheckRunsClient(connection); + + await Assert.ThrowsAsync(() => client.GetAllAnnotations(null, "repo", 1)); + await Assert.ThrowsAsync(() => client.GetAllAnnotations("fake", null, 1)); + + await Assert.ThrowsAsync(() => client.GetAllAnnotations(null, "repo", 1, ApiOptions.None)); + await Assert.ThrowsAsync(() => client.GetAllAnnotations("fake", null, 1, ApiOptions.None)); + await Assert.ThrowsAsync(() => client.GetAllAnnotations("fake", "repo", 1, null)); + + await Assert.ThrowsAsync(() => client.GetAllAnnotations(1, 1, null)); + } + + [Fact] + public async Task EnsuresNonEmptyArguments() + { + var connection = Substitute.For(); + var client = new CheckRunsClient(connection); + + await Assert.ThrowsAsync(() => client.GetAllAnnotations("", "repo", 1)); + await Assert.ThrowsAsync(() => client.GetAllAnnotations("fake", "", 1)); + + await Assert.ThrowsAsync(() => client.GetAllAnnotations("", "repo", 1, ApiOptions.None)); + await Assert.ThrowsAsync(() => client.GetAllAnnotations("fake", "", 1, ApiOptions.None)); + } + } + } +} \ No newline at end of file diff --git a/Octokit.Tests/Clients/EventsClientTests.cs b/Octokit.Tests/Clients/EventsClientTests.cs index 3c9a79d2ac..99a65a7cd4 100644 --- a/Octokit.Tests/Clients/EventsClientTests.cs +++ b/Octokit.Tests/Clients/EventsClientTests.cs @@ -553,6 +553,7 @@ public async Task EnsuresNonNullArguments() private readonly Dictionary _activityTypes = new Dictionary { + {"CheckRunEvent", typeof(CheckRunEventPayload)}, {"CheckSuiteEvent", typeof(CheckSuiteEventPayload)}, {"CommitCommentEvent", typeof(CommitCommentPayload)}, {"ForkEvent", typeof(ForkEventPayload)}, diff --git a/Octokit.Tests/Models/CheckRunEventTests.cs b/Octokit.Tests/Models/CheckRunEventTests.cs new file mode 100644 index 0000000000..1038fda9f1 --- /dev/null +++ b/Octokit.Tests/Models/CheckRunEventTests.cs @@ -0,0 +1,256 @@ +using Octokit.Internal; +using Xunit; + +namespace Octokit.Tests.Models +{ + public class CheckRunEventTests + { + [Fact] + public void CanBeDeserialized() + { + const string json = @"{ + ""action"": ""rerequested"", + ""check_run"": { + ""id"": 4, + ""head_sha"": ""d6fde92930d4715a2b49857d24b940956b26d2d3"", + ""external_id"": """", + ""url"": ""https://api.github.com/repos/github/hello-world/check-runs/4"", + ""html_url"": ""http://github.com/github/hello-world/runs/4"", + ""status"": ""completed"", + ""conclusion"": ""neutral"", + ""started_at"": ""2018-05-04T01:14:52Z"", + ""completed_at"": ""2018-05-04T01:14:52Z"", + ""output"": { + ""title"": ""Report"", + ""summary"": ""It's all good."", + ""text"": ""Minus odio facilis repudiandae. Soluta odit aut amet magni nobis. Et voluptatibus ex dolorem et eum."", + ""annotations_count"": 2, + ""annotations_url"": ""https://api.github.com/repos/github/hello-world/check-runs/4/annotations"" + }, + ""name"": ""randscape"", + ""check_suite"": { + ""id"": 5, + ""head_branch"": ""master"", + ""head_sha"": ""d6fde92930d4715a2b49857d24b940956b26d2d3"", + ""status"": ""completed"", + ""conclusion"": ""neutral"", + ""url"": ""https://api.github.com/repos/github/hello-world/check-suites/5"", + ""before"": ""146e867f55c26428e5f9fade55a9bbf5e95a7912"", + ""after"": ""d6fde92930d4715a2b49857d24b940956b26d2d3"", + ""pull_requests"": [ + + ], + ""app"": { + ""id"": 2, + ""node_id"": ""MDExOkludGVncmF0aW9uMQ=="", + ""owner"": { + ""login"": ""github"", + ""id"": 340, + ""node_id"": ""MDEyOk9yZ2FuaXphdGlvbjE="", + ""avatar_url"": ""http://alambic.github.com/avatars/u/340?"", + ""gravatar_id"": """", + ""url"": ""https://api.github.com/users/github"", + ""html_url"": ""http://github.com/github"", + ""followers_url"": ""https://api.github.com/users/github/followers"", + ""following_url"": ""https://api.github.com/users/github/following{/other_user}"", + ""gists_url"": ""https://api.github.com/users/github/gists{/gist_id}"", + ""starred_url"": ""https://api.github.com/users/github/starred{/owner}{/repo}"", + ""subscriptions_url"": ""https://api.github.com/users/github/subscriptions"", + ""organizations_url"": ""https://api.github.com/users/github/orgs"", + ""repos_url"": ""https://api.github.com/users/github/repos"", + ""events_url"": ""https://api.github.com/users/github/events{/privacy}"", + ""received_events_url"": ""https://api.github.com/users/github/received_events"", + ""type"": ""Organization"", + ""site_admin"": false + }, + ""name"": ""Super Duper"", + ""description"": null, + ""external_url"": ""http://super-duper.example.com"", + ""html_url"": ""http://github.com/apps/super-duper"", + ""created_at"": ""2018-04-25T20:42:10Z"", + ""updated_at"": ""2018-04-25T20:42:10Z"" + }, + ""created_at"": ""2018-05-04T01:14:52Z"", + ""updated_at"": ""2018-05-04T01:14:52Z"" + }, + ""app"": { + ""id"": 2, + ""node_id"": ""MDExOkludGVncmF0aW9uMQ=="", + ""owner"": { + ""login"": ""github"", + ""id"": 340, + ""node_id"": ""MDEyOk9yZ2FuaXphdGlvbjE="", + ""avatar_url"": ""http://alambic.github.com/avatars/u/340?"", + ""gravatar_id"": """", + ""url"": ""https://api.github.com/users/github"", + ""html_url"": ""http://github.com/github"", + ""followers_url"": ""https://api.github.com/users/github/followers"", + ""following_url"": ""https://api.github.com/users/github/following{/other_user}"", + ""gists_url"": ""https://api.github.com/users/github/gists{/gist_id}"", + ""starred_url"": ""https://api.github.com/users/github/starred{/owner}{/repo}"", + ""subscriptions_url"": ""https://api.github.com/users/github/subscriptions"", + ""organizations_url"": ""https://api.github.com/users/github/orgs"", + ""repos_url"": ""https://api.github.com/users/github/repos"", + ""events_url"": ""https://api.github.com/users/github/events{/privacy}"", + ""received_events_url"": ""https://api.github.com/users/github/received_events"", + ""type"": ""Organization"", + ""site_admin"": false + }, + ""name"": ""Super Duper"", + ""description"": null, + ""external_url"": ""http://super-duper.example.com"", + ""html_url"": ""http://github.com/apps/super-duper"", + ""created_at"": ""2018-04-25T20:42:10Z"", + ""updated_at"": ""2018-04-25T20:42:10Z"" + }, + ""pull_requests"": [ + + ] + }, + ""repository"": { + ""id"": 526, + ""node_id"": ""MDEwOlJlcG9zaXRvcnkxMzU0OTMyMzM="", + ""name"": ""hello-world"", + ""full_name"": ""github/hello-world"", + ""owner"": { + ""login"": ""github"", + ""id"": 340, + ""node_id"": ""MDQ6VXNlcjIxMDMxMDY3"", + ""avatar_url"": ""http://alambic.github.com/avatars/u/340?"", + ""gravatar_id"": """", + ""url"": ""https://api.github.com/users/github"", + ""html_url"": ""http://github.com/github"", + ""followers_url"": ""https://api.github.com/users/github/followers"", + ""following_url"": ""https://api.github.com/users/github/following{/other_user}"", + ""gists_url"": ""https://api.github.com/users/github/gists{/gist_id}"", + ""starred_url"": ""https://api.github.com/users/github/starred{/owner}{/repo}"", + ""subscriptions_url"": ""https://api.github.com/users/github/subscriptions"", + ""organizations_url"": ""https://api.github.com/users/github/orgs"", + ""repos_url"": ""https://api.github.com/users/github/repos"", + ""events_url"": ""https://api.github.com/users/github/events{/privacy}"", + ""received_events_url"": ""https://api.github.com/users/github/received_events"", + ""type"": ""Organization"", + ""site_admin"": false + }, + ""private"": false, + ""html_url"": ""http://github.com/github/hello-world"", + ""description"": null, + ""fork"": false, + ""url"": ""https://api.github.com/repos/github/hello-world"", + ""forks_url"": ""https://api.github.com/repos/github/hello-world/forks"", + ""keys_url"": ""https://api.github.com/repos/github/hello-world/keys{/key_id}"", + ""collaborators_url"": ""https://api.github.com/repos/github/hello-world/collaborators{/collaborator}"", + ""teams_url"": ""https://api.github.com/repos/github/hello-world/teams"", + ""hooks_url"": ""https://api.github.com/repos/github/hello-world/hooks"", + ""issue_events_url"": ""https://api.github.com/repos/github/hello-world/issues/events{/number}"", + ""events_url"": ""https://api.github.com/repos/github/hello-world/events"", + ""assignees_url"": ""https://api.github.com/repos/github/hello-world/assignees{/user}"", + ""branches_url"": ""https://api.github.com/repos/github/hello-world/branches{/branch}"", + ""tags_url"": ""https://api.github.com/repos/github/hello-world/tags"", + ""blobs_url"": ""https://api.github.com/repos/github/hello-world/git/blobs{/sha}"", + ""git_tags_url"": ""https://api.github.com/repos/github/hello-world/git/tags{/sha}"", + ""git_refs_url"": ""https://api.github.com/repos/github/hello-world/git/refs{/sha}"", + ""trees_url"": ""https://api.github.com/repos/github/hello-world/git/trees{/sha}"", + ""statuses_url"": ""https://api.github.com/repos/github/hello-world/statuses/{sha}"", + ""languages_url"": ""https://api.github.com/repos/github/hello-world/languages"", + ""stargazers_url"": ""https://api.github.com/repos/github/hello-world/stargazers"", + ""contributors_url"": ""https://api.github.com/repos/github/hello-world/contributors"", + ""subscribers_url"": ""https://api.github.com/repos/github/hello-world/subscribers"", + ""subscription_url"": ""https://api.github.com/repos/github/hello-world/subscription"", + ""commits_url"": ""https://api.github.com/repos/github/hello-world/commits{/sha}"", + ""git_commits_url"": ""https://api.github.com/repos/github/hello-world/git/commits{/sha}"", + ""comments_url"": ""https://api.github.com/repos/github/hello-world/comments{/number}"", + ""issue_comment_url"": ""https://api.github.com/repos/github/hello-world/issues/comments{/number}"", + ""contents_url"": ""https://api.github.com/repos/github/hello-world/contents/{+path}"", + ""compare_url"": ""https://api.github.com/repos/github/hello-world/compare/{base}...{head}"", + ""merges_url"": ""https://api.github.com/repos/github/hello-world/merges"", + ""archive_url"": ""https://api.github.com/repos/github/hello-world/{archive_format}{/ref}"", + ""downloads_url"": ""https://api.github.com/repos/github/hello-world/downloads"", + ""issues_url"": ""https://api.github.com/repos/github/hello-world/issues{/number}"", + ""pulls_url"": ""https://api.github.com/repos/github/hello-world/pulls{/number}"", + ""milestones_url"": ""https://api.github.com/repos/github/hello-world/milestones{/number}"", + ""notifications_url"": ""https://api.github.com/repos/github/hello-world/notifications{?since,all,participating}"", + ""labels_url"": ""https://api.github.com/repos/github/hello-world/labels{/name}"", + ""releases_url"": ""https://api.github.com/repos/github/hello-world/releases{/id}"", + ""deployments_url"": ""https://api.github.com/repos/github/hello-world/deployments"", + ""created_at"": ""2018-04-25T20:42:10Z"", + ""updated_at"": ""2018-04-25T20:43:34Z"", + ""pushed_at"": ""2018-05-04T01:14:47Z"", + ""git_url"": ""git://github.com/github/hello-world.git"", + ""ssh_url"": ""ssh://git@localhost:3035/github/hello-world.git"", + ""clone_url"": ""http://github.com/github/hello-world.git"", + ""svn_url"": ""http://github.com/github/hello-world"", + ""homepage"": null, + ""size"": 0, + ""stargazers_count"": 0, + ""watchers_count"": 0, + ""language"": null, + ""has_issues"": true, + ""has_projects"": true, + ""has_downloads"": true, + ""has_wiki"": true, + ""has_pages"": false, + ""forks_count"": 0, + ""mirror_url"": null, + ""archived"": false, + ""open_issues_count"": 3, + ""license"": null, + ""forks"": 0, + ""open_issues"": 3, + ""watchers"": 0, + ""default_branch"": ""master"" + }, + ""organization"": { + ""login"": ""github"", + ""id"": 340, + ""node_id"": ""MDEyOk9yZ2FuaXphdGlvbjM4MzAyODk5"", + ""url"": ""https://api.github.com/orgs/github"", + ""repos_url"": ""https://api.github.com/orgs/github/repos"", + ""events_url"": ""https://api.github.com/orgs/github/events"", + ""hooks_url"": ""https://api.github.com/orgs/github/hooks"", + ""issues_url"": ""https://api.github.com/orgs/github/issues"", + ""members_url"": ""https://api.github.com/orgs/github/members{/member}"", + ""public_members_url"": ""https://api.github.com/orgs/github/public_members{/member}"", + ""avatar_url"": ""http://alambic.github.com/avatars/u/340?"", + ""description"": ""How people build software."" + }, + ""sender"": { + ""login"": ""octocat"", + ""id"": 5346, + ""node_id"": ""MDQ6VXNlcjIxMDMxMDY3"", + ""avatar_url"": ""http://alambic.github.com/avatars/u/5346?"", + ""gravatar_id"": """", + ""url"": ""https://api.github.com/users/octocat"", + ""html_url"": ""http://github.com/octocat"", + ""followers_url"": ""https://api.github.com/users/octocat/followers"", + ""following_url"": ""https://api.github.com/users/octocat/following{/other_user}"", + ""gists_url"": ""https://api.github.com/users/octocat/gists{/gist_id}"", + ""starred_url"": ""https://api.github.com/users/octocat/starred{/owner}{/repo}"", + ""subscriptions_url"": ""https://api.github.com/users/octocat/subscriptions"", + ""organizations_url"": ""https://api.github.com/users/octocat/orgs"", + ""repos_url"": ""https://api.github.com/users/octocat/repos"", + ""events_url"": ""https://api.github.com/users/octocat/events{/privacy}"", + ""received_events_url"": ""https://api.github.com/users/octocat/received_events"", + ""type"": ""User"", + ""site_admin"": false + }, + ""installation"": { + ""id"": 1 + } +}"; + + var serializer = new SimpleJsonSerializer(); + + var payload = serializer.Deserialize(json); + + Assert.Equal("rerequested", payload.Action); + Assert.Equal("d6fde92930d4715a2b49857d24b940956b26d2d3", payload.CheckRun.HeadSha); + Assert.Equal(4, payload.CheckRun.Id); + Assert.Equal(CheckStatus.Completed, payload.CheckRun.Status); + Assert.Equal(CheckConclusion.Neutral, payload.CheckRun.Conclusion); + Assert.Equal(5, payload.CheckRun.CheckSuite.Id); + Assert.Equal(CheckStatus.Completed, payload.CheckRun.CheckSuite.Status.Value); + Assert.Equal(CheckConclusion.Neutral, payload.CheckRun.CheckSuite.Conclusion); + } + } +} diff --git a/Octokit.Tests/Reactive/ObservableCheckRunsClientTests.cs b/Octokit.Tests/Reactive/ObservableCheckRunsClientTests.cs new file mode 100644 index 0000000000..8391353e4e --- /dev/null +++ b/Octokit.Tests/Reactive/ObservableCheckRunsClientTests.cs @@ -0,0 +1,622 @@ +using System; +using System.Collections.Generic; +using System.Threading.Tasks; +using NSubstitute; +using Octokit.Reactive; +using Xunit; + +namespace Octokit.Tests.Clients +{ + public class ObservableCheckRunsClientTests + { + public class TheCtor + { + [Fact] + public void EnsuresNonNullArguments() + { + Assert.Throws(() => new ObservableCheckRunsClient(null)); + } + } + + public class TheCreateMethod + { + [Fact] + public async Task RequestsCorrectUrl() + { + var gitHubClient = Substitute.For(); + var client = new ObservableCheckRunsClient(gitHubClient); + + var newCheckRun = new NewCheckRun("status", "123abc") { Status = CheckStatus.Queued }; + + client.Create("fake", "repo", newCheckRun); + + gitHubClient.Check.Run.Received().Create("fake", "repo", newCheckRun); + } + + [Fact] + public async Task RequestsCorrectUrlWithRepositoryId() + { + var gitHubClient = Substitute.For(); + var client = new ObservableCheckRunsClient(gitHubClient); + + var newCheckRun = new NewCheckRun("status", "123abc") { Status = CheckStatus.Queued }; + + client.Create(1, newCheckRun); + + gitHubClient.Check.Run.Received().Create(1, newCheckRun); + } + + [Fact] + public async Task EnsuresNonNullArguments() + { + var gitHubClient = Substitute.For(); + var client = new ObservableCheckRunsClient(gitHubClient); + + var newCheckRun = new NewCheckRun("status", "123abc") { Status = CheckStatus.Queued }; + + Assert.Throws(() => client.Create(null, "repo", newCheckRun)); + Assert.Throws(() => client.Create("fake", null, newCheckRun)); + Assert.Throws(() => client.Create("fake", "repo", null)); + + Assert.Throws(() => client.Create(1, null)); + } + + [Fact] + public async Task EnsuresNonEmptyArguments() + { + var gitHubClient = Substitute.For(); + var client = new ObservableCheckRunsClient(gitHubClient); + + var newCheckRun = new NewCheckRun("status", "123abc") { Status = CheckStatus.Queued }; + + Assert.Throws(() => client.Create("", "repo", newCheckRun)); + Assert.Throws(() => client.Create("fake", "", newCheckRun)); + } + } + + public class TheUpdateMethod + { + [Fact] + public async Task RequestsCorrectUrl() + { + var gitHubClient = Substitute.For(); + var client = new ObservableCheckRunsClient(gitHubClient); + + var update = new CheckRunUpdate("status") { Status = CheckStatus.InProgress }; + + client.Update("fake", "repo", 1, update); + + gitHubClient.Check.Run.Received().Update("fake", "repo", 1, update); + } + + [Fact] + public async Task RequestsCorrectUrlWithRepositoryId() + { + var gitHubClient = Substitute.For(); + var client = new ObservableCheckRunsClient(gitHubClient); + + var update = new CheckRunUpdate("status") { Status = CheckStatus.InProgress }; + + client.Update(1, 1, update); + + gitHubClient.Check.Run.Received().Update(1, 1, update); + } + + [Fact] + public async Task EnsuresNonNullArguments() + { + var gitHubClient = Substitute.For(); + var client = new ObservableCheckRunsClient(gitHubClient); + + var update = new CheckRunUpdate("status") { Status = CheckStatus.InProgress }; + + Assert.Throws(() => client.Update(null, "repo", 1, update)); + Assert.Throws(() => client.Update("fake", null, 1, update)); + Assert.Throws(() => client.Update("fake", "repo", 1, null)); + } + + [Fact] + public async Task EnsuresNonEmptyArguments() + { + var gitHubClient = Substitute.For(); + var client = new ObservableCheckRunsClient(gitHubClient); + + var update = new CheckRunUpdate("status") { Status = CheckStatus.InProgress }; + + Assert.Throws(() => client.Update("", "repo", 1, update)); + Assert.Throws(() => client.Update("fake", "", 1, update)); + } + } + + public class TheGetAllForReferenceMethod + { + [Fact] + public async Task RequestsCorrectUrl() + { + var connection = Substitute.For(); + var gitHubClient = new GitHubClient(connection); + var client = new ObservableCheckRunsClient(gitHubClient); + + client.GetAllForReference("fake", "repo", "ref"); + + connection.Received().Get>( + Arg.Is(u => u.ToString() == "repos/fake/repo/commits/ref/check-runs"), + Args.EmptyDictionary, + "application/vnd.github.antiope-preview+json"); + } + + [Fact] + public async Task RequestsCorrectUrlWithRepositoryId() + { + var connection = Substitute.For(); + var gitHubClient = new GitHubClient(connection); + var client = new ObservableCheckRunsClient(gitHubClient); + + client.GetAllForReference(1, "ref"); + + connection.Received().Get>( + Arg.Is(u => u.ToString() == "repositories/1/commits/ref/check-runs"), + Args.EmptyDictionary, + "application/vnd.github.antiope-preview+json"); + } + + [Fact] + public async Task RequestsCorrectUrlWithRequest() + { + var connection = Substitute.For(); + var gitHubClient = new GitHubClient(connection); + var client = new ObservableCheckRunsClient(gitHubClient); + + var request = new CheckRunRequest { CheckName = "build", Filter = CheckRunCompletedAtFilter.Latest, Status = CheckStatusFilter.InProgress }; + + client.GetAllForReference("fake", "repo", "ref", request); + + connection.Received().Get>( + Arg.Is(u => u.ToString() == "repos/fake/repo/commits/ref/check-runs"), + Arg.Is>(x => + x.Count == 3 + && x["check_name"] == "build" + && x["status"] == "in_progress" + && x["filter"] == "latest"), + "application/vnd.github.antiope-preview+json"); + } + + [Fact] + public async Task RequestsCorrectUrlWithRequestWithRepositoryId() + { + var connection = Substitute.For(); + var gitHubClient = new GitHubClient(connection); + var client = new ObservableCheckRunsClient(gitHubClient); + + var request = new CheckRunRequest { CheckName = "build", Filter = CheckRunCompletedAtFilter.Latest, Status = CheckStatusFilter.InProgress }; + + client.GetAllForReference(1, "ref", request); + + connection.Received().Get>( + Arg.Is(u => u.ToString() == "repositories/1/commits/ref/check-runs"), + Arg.Is>(x => + x.Count == 3 + && x["check_name"] == "build" + && x["status"] == "in_progress" + && x["filter"] == "latest"), + "application/vnd.github.antiope-preview+json"); + } + + [Fact] + public async Task RequestsCorrectUrlWithRequestWithApiOptions() + { + var connection = Substitute.For(); + var gitHubClient = new GitHubClient(connection); + var client = new ObservableCheckRunsClient(gitHubClient); + + var request = new CheckRunRequest { CheckName = "build", Filter = CheckRunCompletedAtFilter.Latest, Status = CheckStatusFilter.InProgress }; + var options = new ApiOptions { PageSize = 1 }; + + client.GetAllForReference("fake", "repo", "ref", request, options); + + connection.Received().Get>( + Arg.Is(u => u.ToString() == "repos/fake/repo/commits/ref/check-runs"), + Arg.Is>(x => + x.Count == 4 + && x["per_page"] == "1" + && x["check_name"] == "build" + && x["status"] == "in_progress" + && x["filter"] == "latest"), + "application/vnd.github.antiope-preview+json"); + } + + [Fact] + public async Task RequestsCorrectUrlWithRequestWithApiOptionsWithRepositoryId() + { + var connection = Substitute.For(); + var gitHubClient = new GitHubClient(connection); + var client = new ObservableCheckRunsClient(gitHubClient); + + var request = new CheckRunRequest { CheckName = "build", Filter = CheckRunCompletedAtFilter.Latest, Status = CheckStatusFilter.InProgress }; + var options = new ApiOptions { PageSize = 1 }; + + client.GetAllForReference(1, "ref", request, options); + + connection.Received().Get>( + Arg.Is(u => u.ToString() == "repositories/1/commits/ref/check-runs"), + Arg.Is>(x => + x.Count == 4 + && x["per_page"] == "1" + && x["check_name"] == "build" + && x["status"] == "in_progress" + && x["filter"] == "latest"), + "application/vnd.github.antiope-preview+json"); + } + + [Fact] + public async Task EnsuresNonNullArguments() + { + var gitHubClient = Substitute.For(); + var client = new ObservableCheckRunsClient(gitHubClient); + + var request = new CheckRunRequest { CheckName = "build" }; + + Assert.Throws(() => client.GetAllForReference(null, "repo", "ref")); + Assert.Throws(() => client.GetAllForReference("fake", null, "ref")); + Assert.Throws(() => client.GetAllForReference("fake", "repo", null)); + + Assert.Throws(() => client.GetAllForReference(null, "repo", "ref", request)); + Assert.Throws(() => client.GetAllForReference("fake", null, "ref", request)); + Assert.Throws(() => client.GetAllForReference("fake", "repo", null, request)); + Assert.Throws(() => client.GetAllForReference("fake", "repo", "ref", null)); + + Assert.Throws(() => client.GetAllForReference(null, "repo", "ref", request, ApiOptions.None)); + Assert.Throws(() => client.GetAllForReference("fake", null, "ref", request, ApiOptions.None)); + Assert.Throws(() => client.GetAllForReference("fake", "repo", null, request, ApiOptions.None)); + Assert.Throws(() => client.GetAllForReference("fake", "repo", "ref", null, ApiOptions.None)); + Assert.Throws(() => client.GetAllForReference("fake", "repo", "ref", request, null)); + + Assert.Throws(() => client.GetAllForReference(1, null)); + + Assert.Throws(() => client.GetAllForReference(1, null, request)); + Assert.Throws(() => client.GetAllForReference(1, "ref", null)); + + Assert.Throws(() => client.GetAllForReference(1, null, request, ApiOptions.None)); + Assert.Throws(() => client.GetAllForReference(1, "ref", null, ApiOptions.None)); + Assert.Throws(() => client.GetAllForReference(1, "ref", request, null)); + } + + [Fact] + public async Task EnsuresNonEmptyArguments() + { + var gitHubClient = Substitute.For(); + var client = new ObservableCheckRunsClient(gitHubClient); + + var request = new CheckRunRequest { CheckName = "build" }; + + Assert.Throws(() => client.GetAllForReference("", "repo", "ref")); + Assert.Throws(() => client.GetAllForReference("fake", "", "ref")); + Assert.Throws(() => client.GetAllForReference("fake", "repo", "")); + + Assert.Throws(() => client.GetAllForReference("", "repo", "ref", request)); + Assert.Throws(() => client.GetAllForReference("fake", "", "ref", request)); + Assert.Throws(() => client.GetAllForReference("fake", "repo", "", request)); + + Assert.Throws(() => client.GetAllForReference("", "repo", "ref", request, ApiOptions.None)); + Assert.Throws(() => client.GetAllForReference("fake", "", "ref", request, ApiOptions.None)); + Assert.Throws(() => client.GetAllForReference("fake", "repo", "", request, ApiOptions.None)); + + Assert.Throws(() => client.GetAllForReference(1, "")); + + Assert.Throws(() => client.GetAllForReference(1, "", request)); + + Assert.Throws(() => client.GetAllForReference(1, "", request, ApiOptions.None)); + } + } + + public class TheGetAllForCheckSuiteMethod + { + [Fact] + public async Task RequestsCorrectUrl() + { + var connection = Substitute.For(); + var gitHubClient = new GitHubClient(connection); + var client = new ObservableCheckRunsClient(gitHubClient); + + client.GetAllForCheckSuite("fake", "repo", 1); + + connection.Received().Get>( + Arg.Is(u => u.ToString() == "repos/fake/repo/check-suites/1/check-runs"), + Args.EmptyDictionary, + "application/vnd.github.antiope-preview+json"); + } + + [Fact] + public async Task RequestsCorrectUrlWithRepositoryId() + { + var connection = Substitute.For(); + var gitHubClient = new GitHubClient(connection); + var client = new ObservableCheckRunsClient(gitHubClient); + + client.GetAllForCheckSuite(1, 1); + + connection.Received().Get>( + Arg.Is(u => u.ToString() == "repositories/1/check-suites/1/check-runs"), + Args.EmptyDictionary, + "application/vnd.github.antiope-preview+json"); + } + + [Fact] + public async Task RequestsCorrectUrlWithRequest() + { + var connection = Substitute.For(); + var gitHubClient = new GitHubClient(connection); + var client = new ObservableCheckRunsClient(gitHubClient); + + var request = new CheckRunRequest { CheckName = "build", Filter = CheckRunCompletedAtFilter.Latest, Status = CheckStatusFilter.InProgress }; + + client.GetAllForCheckSuite("fake", "repo", 1, request); + + connection.Received().Get>( + Arg.Is(u => u.ToString() == "repos/fake/repo/check-suites/1/check-runs"), + Arg.Is>(x => + x.Count == 3 + && x["check_name"] == "build" + && x["status"] == "in_progress" + && x["filter"] == "latest"), + "application/vnd.github.antiope-preview+json"); + } + + [Fact] + public async Task RequestsCorrectUrlWithRequestWithRepositoryId() + { + var connection = Substitute.For(); + var gitHubClient = new GitHubClient(connection); + var client = new ObservableCheckRunsClient(gitHubClient); + + var request = new CheckRunRequest { CheckName = "build", Filter = CheckRunCompletedAtFilter.Latest, Status = CheckStatusFilter.InProgress }; + + client.GetAllForCheckSuite(1, 1, request); + + connection.Received().Get>( + Arg.Is(u => u.ToString() == "repositories/1/check-suites/1/check-runs"), + Arg.Is>(x => + x.Count == 3 + && x["check_name"] == "build" + && x["status"] == "in_progress" + && x["filter"] == "latest"), + "application/vnd.github.antiope-preview+json"); + } + + [Fact] + public async Task RequestsCorrectUrlWithRequestWithApiOptions() + { + var connection = Substitute.For(); + var gitHubClient = new GitHubClient(connection); + var client = new ObservableCheckRunsClient(gitHubClient); + + var request = new CheckRunRequest { CheckName = "build", Filter = CheckRunCompletedAtFilter.Latest, Status = CheckStatusFilter.InProgress }; + var options = new ApiOptions { PageSize = 1 }; + + client.GetAllForCheckSuite("fake", "repo", 1, request, options); + + connection.Received().Get>( + Arg.Is(u => u.ToString() == "repos/fake/repo/check-suites/1/check-runs"), + Arg.Is>(x => + x.Count == 4 + && x["per_page"] == "1" + && x["check_name"] == "build" + && x["status"] == "in_progress" + && x["filter"] == "latest"), + "application/vnd.github.antiope-preview+json"); + } + + [Fact] + public async Task RequestsCorrectUrlWithRequestWithApiOptionsWithRepositoryId() + { + var connection = Substitute.For(); + var gitHubClient = new GitHubClient(connection); + var client = new ObservableCheckRunsClient(gitHubClient); + + var request = new CheckRunRequest { CheckName = "build", Filter = CheckRunCompletedAtFilter.Latest, Status = CheckStatusFilter.InProgress }; + var options = new ApiOptions { PageSize = 1 }; + + client.GetAllForCheckSuite(1, 1, request, options); + + connection.Received().Get>( + Arg.Is(u => u.ToString() == "repositories/1/check-suites/1/check-runs"), + Arg.Is>(x => + x.Count == 4 + && x["per_page"] == "1" + && x["check_name"] == "build" + && x["status"] == "in_progress" + && x["filter"] == "latest"), + "application/vnd.github.antiope-preview+json"); + } + + [Fact] + public async Task EnsuresNonNullArguments() + { + var gitHubClient = Substitute.For(); + var client = new ObservableCheckRunsClient(gitHubClient); + + var request = new CheckRunRequest { CheckName = "build" }; + + Assert.Throws(() => client.GetAllForCheckSuite(null, "repo", 1)); + Assert.Throws(() => client.GetAllForCheckSuite("fake", null, 1)); + + Assert.Throws(() => client.GetAllForCheckSuite(null, "repo", 1, request)); + Assert.Throws(() => client.GetAllForCheckSuite("fake", null, 1, request)); + Assert.Throws(() => client.GetAllForCheckSuite("fake", "repo", 1, null)); + + Assert.Throws(() => client.GetAllForCheckSuite(null, "repo", 1, request, ApiOptions.None)); + Assert.Throws(() => client.GetAllForCheckSuite("fake", null, 1, request, ApiOptions.None)); + Assert.Throws(() => client.GetAllForCheckSuite("fake", "repo", 1, null, ApiOptions.None)); + Assert.Throws(() => client.GetAllForCheckSuite("fake", "repo", 1, request, null)); + + Assert.Throws(() => client.GetAllForCheckSuite(1, 1, null)); + + Assert.Throws(() => client.GetAllForCheckSuite(1, 1, null, ApiOptions.None)); + Assert.Throws(() => client.GetAllForCheckSuite(1, 1, request, null)); + } + + [Fact] + public async Task EnsuresNonEmptyArguments() + { + var gitHubClient = Substitute.For(); + var client = new ObservableCheckRunsClient(gitHubClient); + + var request = new CheckRunRequest { CheckName = "build" }; + + Assert.Throws(() => client.GetAllForCheckSuite("", "repo", 1)); + Assert.Throws(() => client.GetAllForCheckSuite("fake", "", 1)); + + Assert.Throws(() => client.GetAllForCheckSuite("", "repo", 1, request)); + Assert.Throws(() => client.GetAllForCheckSuite("fake", "", 1, request)); + + Assert.Throws(() => client.GetAllForCheckSuite("", "repo", 1, request, ApiOptions.None)); + 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)); + } + } + + public class TheGetAllAnnotationsMethod + { + [Fact] + public async Task RequestsCorrectUrl() + { + var connection = Substitute.For(); + var gitHubClient = new GitHubClient(connection); + var client = new ObservableCheckRunsClient(gitHubClient); + + client.GetAllAnnotations("fake", "repo", 1); + + connection.Received().Get>( + Arg.Is(u => u.ToString() == "repos/fake/repo/check-runs/1/annotations"), + Args.EmptyDictionary, + "application/vnd.github.antiope-preview+json"); + } + + [Fact] + public async Task RequestsCorrectUrlWithRepositoryId() + { + var connection = Substitute.For(); + var gitHubClient = new GitHubClient(connection); + var client = new ObservableCheckRunsClient(gitHubClient); + + client.GetAllAnnotations(1, 1); + + connection.Received().Get>( + Arg.Is(u => u.ToString() == "repositories/1/check-runs/1/annotations"), + Args.EmptyDictionary, + "application/vnd.github.antiope-preview+json"); + } + + [Fact] + public async Task RequestsCorrectUrlWithApiOptions() + { + var connection = Substitute.For(); + var gitHubClient = new GitHubClient(connection); + var client = new ObservableCheckRunsClient(gitHubClient); + + var options = new ApiOptions { PageSize = 1 }; + + client.GetAllAnnotations("fake", "repo", 1, options); + + connection.Received().Get>( + Arg.Is(u => u.ToString() == "repos/fake/repo/check-runs/1/annotations"), + Arg.Is>(x => + x.Count == 1 + && x["per_page"] == "1"), + "application/vnd.github.antiope-preview+json"); + } + + [Fact] + public async Task RequestsCorrectUrlWithApiOptionsWithRepositoryId() + { + var connection = Substitute.For(); + var gitHubClient = new GitHubClient(connection); + var client = new ObservableCheckRunsClient(gitHubClient); + + var options = new ApiOptions { PageSize = 1 }; + + client.GetAllAnnotations(1, 1, options); + + connection.Received().Get>( + Arg.Is(u => u.ToString() == "repositories/1/check-runs/1/annotations"), + Arg.Is>(x => + x.Count == 1 + && x["per_page"] == "1"), + "application/vnd.github.antiope-preview+json"); + } + + [Fact] + public async Task EnsuresNonNullArguments() + { + var gitHubClient = Substitute.For(); + var client = new ObservableCheckRunsClient(gitHubClient); + + Assert.Throws(() => client.GetAllAnnotations(null, "repo", 1)); + Assert.Throws(() => client.GetAllAnnotations("fake", null, 1)); + + Assert.Throws(() => client.GetAllAnnotations(null, "repo", 1, ApiOptions.None)); + Assert.Throws(() => client.GetAllAnnotations("fake", null, 1, ApiOptions.None)); + Assert.Throws(() => client.GetAllAnnotations("fake", "repo", 1, null)); + + Assert.Throws(() => client.GetAllAnnotations(1, 1, null)); + } + + [Fact] + public async Task EnsuresNonEmptyArguments() + { + var gitHubClient = Substitute.For(); + var client = new ObservableCheckRunsClient(gitHubClient); + + Assert.Throws(() => client.GetAllAnnotations("", "repo", 1)); + Assert.Throws(() => client.GetAllAnnotations("fake", "", 1)); + + Assert.Throws(() => client.GetAllAnnotations("", "repo", 1, ApiOptions.None)); + Assert.Throws(() => client.GetAllAnnotations("fake", "", 1, ApiOptions.None)); + } + } + } +} \ No newline at end of file diff --git a/Octokit.Tests/Reactive/ObservableCheckSuitesClientTests.cs b/Octokit.Tests/Reactive/ObservableCheckSuitesClientTests.cs index fd76da6edf..b274e740e6 100644 --- a/Octokit.Tests/Reactive/ObservableCheckSuitesClientTests.cs +++ b/Octokit.Tests/Reactive/ObservableCheckSuitesClientTests.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Reactive.Threading.Tasks; using System.Threading.Tasks; using NSubstitute; using Octokit.Reactive; diff --git a/Octokit/Clients/CheckRunsClient.cs b/Octokit/Clients/CheckRunsClient.cs new file mode 100644 index 0000000000..2bbae335a0 --- /dev/null +++ b/Octokit/Clients/CheckRunsClient.cs @@ -0,0 +1,419 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace Octokit +{ + /// + /// A client for GitHub's Check Runs API + /// + /// + /// See the Check Runs API documentation for more information. + /// + public class CheckRunsClient : ApiClient, ICheckRunsClient + { + /// + /// Initializes a new GitHub Check Runs API client + /// + /// An API connection + public CheckRunsClient(IApiConnection apiConnection) : base(apiConnection) + { + } + + /// + /// Creates a new check run for a specific commit in a repository + /// + /// + /// See the Check Runs API documentation for more information. + /// + /// The owner of the repository + /// The name of the repository + /// Details of the Check Run to create + public Task Create(string owner, string name, NewCheckRun newCheckRun) + { + Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); + Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); + Ensure.ArgumentNotNull(newCheckRun, nameof(newCheckRun)); + + return ApiConnection.Post(ApiUrls.CheckRuns(owner, name), newCheckRun, AcceptHeaders.ChecksApiPreview); + } + + /// + /// Creates a new check run for a specific commit in a repository + /// + /// + /// See the Check Runs API documentation for more information. + /// + /// The Id of the repository + /// Details of the Check Run to create + public Task Create(long repositoryId, NewCheckRun newCheckRun) + { + Ensure.ArgumentNotNull(newCheckRun, nameof(newCheckRun)); + + return ApiConnection.Post(ApiUrls.CheckRuns(repositoryId), newCheckRun, AcceptHeaders.ChecksApiPreview); + } + + /// + /// Updates a check run for a specific commit in a repository + /// + /// + /// See the Check Runs API documentation for more information. + /// + /// The owner of the repository + /// The name of the repository + /// The Id of the check run + /// The updates to the check run + public Task Update(string owner, string name, long checkRunId, CheckRunUpdate checkRunUpdate) + { + Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); + Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); + Ensure.ArgumentNotNull(checkRunUpdate, nameof(checkRunUpdate)); + + return ApiConnection.Patch(ApiUrls.CheckRun(owner, name, checkRunId), checkRunUpdate, AcceptHeaders.ChecksApiPreview); + } + + /// + /// Updates a check run for a specific commit in a repository + /// + /// + /// See the Check Runs API documentation for more information. + /// + /// The Id of the repository + /// The Id of the check run + /// The updates to the check run + public Task Update(long repositoryId, long checkRunId, CheckRunUpdate checkRunUpdate) + { + Ensure.ArgumentNotNull(checkRunUpdate, nameof(checkRunUpdate)); + + return ApiConnection.Patch(ApiUrls.CheckRun(repositoryId, checkRunId), checkRunUpdate, AcceptHeaders.ChecksApiPreview); + } + + /// + /// Lists check runs for a commit ref. The ref can be a SHA, branch name, or a tag name + /// + /// + /// See the Check Runs API documentation for more information. + /// + /// The owner of the repository + /// The name of the repository + /// The commit reference (can be a SHA, branch name, or a tag name) + public Task GetAllForReference(string owner, string name, string reference) + { + Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); + Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); + Ensure.ArgumentNotNullOrEmptyString(reference, nameof(reference)); + + return GetAllForReference(owner, name, reference, new CheckRunRequest(), ApiOptions.None); + } + + /// + /// Lists check runs for a commit ref. The ref can be a SHA, branch name, or a tag name + /// + /// + /// See the Check Runs API documentation for more information. + /// + /// The Id of the repository + /// The commit reference (can be a SHA, branch name, or a tag name) + public Task GetAllForReference(long repositoryId, string reference) + { + Ensure.ArgumentNotNullOrEmptyString(reference, nameof(reference)); + + return GetAllForReference(repositoryId, reference, new CheckRunRequest(), ApiOptions.None); + } + + /// + /// Lists check runs for a commit ref. The ref can be a SHA, branch name, or a tag name + /// + /// + /// See the Check Runs API documentation for more information. + /// + /// The owner of the repository + /// The name of the repository + /// The commit reference (can be a SHA, branch name, or a tag name) + /// Details to filter the request, such as by check name + public Task GetAllForReference(string owner, string name, string reference, CheckRunRequest checkRunRequest) + { + Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); + Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); + Ensure.ArgumentNotNullOrEmptyString(reference, nameof(reference)); + Ensure.ArgumentNotNull(checkRunRequest, nameof(checkRunRequest)); + + return GetAllForReference(owner, name, reference, checkRunRequest, ApiOptions.None); + } + + /// + /// Lists check runs for a commit ref. The ref can be a SHA, branch name, or a tag name + /// + /// + /// See the Check Runs API documentation for more information. + /// + /// The Id of the repository + /// The commit reference (can be a SHA, branch name, or a tag name) + /// Details to filter the request, such as by check name + public Task GetAllForReference(long repositoryId, string reference, CheckRunRequest checkRunRequest) + { + Ensure.ArgumentNotNullOrEmptyString(reference, nameof(reference)); + Ensure.ArgumentNotNull(checkRunRequest, nameof(checkRunRequest)); + + return GetAllForReference(repositoryId, reference, checkRunRequest, ApiOptions.None); + } + + /// + /// Lists check runs for a commit ref. The ref can be a SHA, branch name, or a tag name + /// + /// + /// See the Check Runs API documentation for more information. + /// + /// The owner of the repository + /// The name of the repository + /// The commit reference (can be a SHA, branch name, or a tag name) + /// Details to filter the request, such as by check name + /// Options to change the API response + public async Task GetAllForReference(string owner, string name, string reference, CheckRunRequest checkRunRequest, ApiOptions options) + { + Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); + Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); + Ensure.ArgumentNotNullOrEmptyString(reference, nameof(reference)); + Ensure.ArgumentNotNull(checkRunRequest, nameof(checkRunRequest)); + Ensure.ArgumentNotNull(options, nameof(options)); + + var results = await ApiConnection.GetAll(ApiUrls.CheckRunsForReference(owner, name, reference), checkRunRequest.ToParametersDictionary(), AcceptHeaders.ChecksApiPreview, options).ConfigureAwait(false); + + return new CheckRunsResponse( + results.Count > 0 ? results.Max(x => x.TotalCount) : 0, + results.SelectMany(x => x.CheckRuns).ToList()); + } + + /// + /// Lists check runs for a commit ref. The ref can be a SHA, branch name, or a tag name + /// + /// + /// See the Check Runs API documentation for more information. + /// + /// The Id of the repository + /// The commit reference (can be a SHA, branch name, or a tag name) + /// Details to filter the request, such as by check name + /// Options to change the API response + public async Task GetAllForReference(long repositoryId, string reference, CheckRunRequest checkRunRequest, ApiOptions options) + { + Ensure.ArgumentNotNullOrEmptyString(reference, nameof(reference)); + Ensure.ArgumentNotNull(checkRunRequest, nameof(checkRunRequest)); + Ensure.ArgumentNotNull(options, nameof(options)); + + var results = await ApiConnection.GetAll(ApiUrls.CheckRunsForReference(repositoryId, reference), checkRunRequest.ToParametersDictionary(), AcceptHeaders.ChecksApiPreview, options).ConfigureAwait(false); + + return new CheckRunsResponse( + results.Count > 0 ? results.Max(x => x.TotalCount) : 0, + results.SelectMany(x => x.CheckRuns).ToList()); + } + + /// + /// Lists check runs for a check suite using its Id + /// + /// + /// See the Check Runs API documentation for more information. + /// + /// The owner of the repository + /// The name of the repository + /// The Id of the check suite + public Task GetAllForCheckSuite(string owner, string name, long checkSuiteId) + { + Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); + Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); + + return GetAllForCheckSuite(owner, name, checkSuiteId, new CheckRunRequest(), ApiOptions.None); + } + + /// + /// Lists check runs for a check suite using its Id + /// + /// + /// See the Check Runs API documentation for more information. + /// + /// The Id of the repository + /// The Id of the check suite + public Task GetAllForCheckSuite(long repositoryId, long checkSuiteId) + { + return GetAllForCheckSuite(repositoryId, checkSuiteId, new CheckRunRequest(), ApiOptions.None); + } + + /// + /// Lists check runs for a check suite using its Id + /// + /// + /// See the Check Runs API documentation for more information. + /// + /// The owner of the repository + /// The name of the repository + /// The Id of the check suite + /// Details to filter the request, such as by check name + public Task GetAllForCheckSuite(string owner, string name, long checkSuiteId, CheckRunRequest checkRunRequest) + { + Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); + Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); + Ensure.ArgumentNotNull(checkRunRequest, nameof(checkRunRequest)); + + return GetAllForCheckSuite(owner, name, checkSuiteId, checkRunRequest, ApiOptions.None); + } + + /// + /// Lists check runs for a check suite using its Id + /// + /// + /// See the Check Runs API documentation for more information. + /// + /// The Id of the repository + /// The Id of the check suite + /// Details to filter the request, such as by check name + public Task GetAllForCheckSuite(long repositoryId, long checkSuiteId, CheckRunRequest checkRunRequest) + { + Ensure.ArgumentNotNull(checkRunRequest, nameof(checkRunRequest)); + + return GetAllForCheckSuite(repositoryId, checkSuiteId, checkRunRequest, ApiOptions.None); + } + + /// + /// Lists check runs for a check suite using its Id + /// + /// + /// See the Check Runs API documentation for more information. + /// + /// The owner of the repository + /// The name of the repository + /// The Id of the check suite + /// Details to filter the request, such as by check name + /// Options to change the API response + public async Task GetAllForCheckSuite(string owner, string name, long checkSuiteId, CheckRunRequest checkRunRequest, ApiOptions options) + { + Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); + Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); + Ensure.ArgumentNotNull(checkRunRequest, nameof(checkRunRequest)); + Ensure.ArgumentNotNull(options, nameof(options)); + + var results = await ApiConnection.GetAll(ApiUrls.CheckRunsForCheckSuite(owner, name, checkSuiteId), checkRunRequest.ToParametersDictionary(), AcceptHeaders.ChecksApiPreview, options).ConfigureAwait(false); + + return new CheckRunsResponse( + results.Count > 0 ? results.Max(x => x.TotalCount) : 0, + results.SelectMany(x => x.CheckRuns).ToList()); + } + + /// + /// Lists check runs for a check suite using its Id + /// + /// + /// See the Check Runs API documentation for more information. + /// + /// The Id of the repository + /// The Id of the check suite + /// Details to filter the request, such as by check name + /// Options to change the API response + public async Task GetAllForCheckSuite(long repositoryId, long checkSuiteId, CheckRunRequest checkRunRequest, ApiOptions options) + { + Ensure.ArgumentNotNull(checkRunRequest, nameof(checkRunRequest)); + Ensure.ArgumentNotNull(options, nameof(options)); + + var results = await ApiConnection.GetAll(ApiUrls.CheckRunsForCheckSuite(repositoryId, checkSuiteId), checkRunRequest.ToParametersDictionary(), AcceptHeaders.ChecksApiPreview, options).ConfigureAwait(false); + + return new CheckRunsResponse( + results.Count > 0 ? results.Max(x => x.TotalCount) : 0, + results.SelectMany(x => x.CheckRuns).ToList()); + } + + /// + /// Gets a single check run using its Id + /// + /// + /// See the Check Runs API documentation for more information. + /// + /// 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 + /// + /// + /// See the Check Runs API documentation for more information. + /// + /// 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); + } + + /// + /// Lists annotations for a check run using the check run Id + /// + /// + /// See the Check Runs API documentation for more information. + /// + /// The owner of the repository + /// The name of the repository + /// The Id of the check run + public Task> GetAllAnnotations(string owner, string name, long checkRunId) + { + Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); + Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); + + return GetAllAnnotations(owner, name, checkRunId, ApiOptions.None); + } + + /// + /// Lists annotations for a check run using the check run Id + /// + /// + /// See the Check Runs API documentation for more information. + /// + /// The Id of the repository + /// The Id of the check run + /// + public Task> GetAllAnnotations(long repositoryId, long checkRunId) + { + return GetAllAnnotations(repositoryId, checkRunId, ApiOptions.None); + } + + /// + /// Lists annotations for a check run using the check run Id + /// + /// + /// See the Check Runs API documentation for more information. + /// + /// The owner of the repository + /// The name of the repository + /// The Id of the check run + /// Options to change the API response + public Task> GetAllAnnotations(string owner, string name, long checkRunId, ApiOptions options) + { + Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); + Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); + Ensure.ArgumentNotNull(options, nameof(options)); + + return ApiConnection.GetAll(ApiUrls.CheckRunAnnotations(owner, name, checkRunId), null, AcceptHeaders.ChecksApiPreview, options); + } + + /// + /// Lists annotations for a check run using the check run Id + /// + /// + /// See the Check Runs API documentation for more information. + /// + /// The Id of the repository + /// The Id of the check run + /// Options to change the API response + public Task> GetAllAnnotations(long repositoryId, long checkRunId, ApiOptions options) + { + Ensure.ArgumentNotNull(options, nameof(options)); + + return ApiConnection.GetAll(ApiUrls.CheckRunAnnotations(repositoryId, checkRunId), null, AcceptHeaders.ChecksApiPreview, options); + } + } +} diff --git a/Octokit/Clients/ChecksClient.cs b/Octokit/Clients/ChecksClient.cs index 17dcfcb766..08a6ccfbc2 100644 --- a/Octokit/Clients/ChecksClient.cs +++ b/Octokit/Clients/ChecksClient.cs @@ -14,9 +14,18 @@ public class ChecksClient : IChecksClient /// An API connection public ChecksClient(ApiConnection apiConnection) { + Run = new CheckRunsClient(apiConnection); Suite = new CheckSuitesClient(apiConnection); } + /// + /// A client for GitHub's Check Runs API. + /// + /// + /// See the Check Runs API documentation for more information. + /// + public ICheckRunsClient Run { get; private set; } + /// /// A client for GitHub's Check Suites API. /// diff --git a/Octokit/Clients/ICheckRunsClient.cs b/Octokit/Clients/ICheckRunsClient.cs new file mode 100644 index 0000000000..2a70b810b6 --- /dev/null +++ b/Octokit/Clients/ICheckRunsClient.cs @@ -0,0 +1,262 @@ +using System.Collections.Generic; +using System.Threading.Tasks; + +namespace Octokit +{ + /// + /// A client for GitHub's Check Runs API + /// + /// + /// See the Check Runs API documentation for more information. + /// + public interface ICheckRunsClient + { + /// + /// Creates a new check run for a specific commit in a repository + /// + /// + /// See the Check Runs API documentation for more information. + /// + /// The owner of the repository + /// The name of the repository + /// Details of the Check Run to create + Task Create(string owner, string name, NewCheckRun newCheckRun); + + /// + /// Creates a new check run for a specific commit in a repository + /// + /// + /// See the Check Runs API documentation for more information. + /// + /// The Id of the repository + /// Details of the Check Run to create + Task Create(long repositoryId, NewCheckRun newCheckRun); + + /// + /// Updates a check run for a specific commit in a repository + /// + /// + /// See the Check Runs API documentation for more information. + /// + /// The owner of the repository + /// The name of the repository + /// The Id of the check run + /// The updates to the check run + Task Update(string owner, string name, long checkRunId, CheckRunUpdate checkRunUpdate); + + /// + /// Updates a check run for a specific commit in a repository + /// + /// + /// See the Check Runs API documentation for more information. + /// + /// The Id of the repository + /// The Id of the check run + /// The updates to the check run + Task Update(long repositoryId, long checkRunId, CheckRunUpdate checkRunUpdate); + + /// + /// Lists check runs for a commit ref. The ref can be a SHA, branch name, or a tag name + /// + /// + /// See the Check Runs API documentation for more information. + /// + /// The owner of the repository + /// The name of the repository + /// The commit reference (can be a SHA, branch name, or a tag name) + Task GetAllForReference(string owner, string name, string reference); + + /// + /// Lists check runs for a commit ref. The ref can be a SHA, branch name, or a tag name + /// + /// + /// See the Check Runs API documentation for more information. + /// + /// The Id of the repository + /// The commit reference (can be a SHA, branch name, or a tag name) + Task GetAllForReference(long repositoryId, string reference); + + /// + /// Lists check runs for a commit ref. The ref can be a SHA, branch name, or a tag name + /// + /// + /// See the Check Runs API documentation for more information. + /// + /// The owner of the repository + /// The name of the repository + /// The commit reference (can be a SHA, branch name, or a tag name) + /// Details to filter the request, such as by check name + Task GetAllForReference(string owner, string name, string reference, CheckRunRequest checkRunRequest); + + /// + /// Lists check runs for a commit ref. The ref can be a SHA, branch name, or a tag name + /// + /// + /// See the Check Runs API documentation for more information. + /// + /// The Id of the repository + /// The commit reference (can be a SHA, branch name, or a tag name) + /// Details to filter the request, such as by check name + Task GetAllForReference(long repositoryId, string reference, CheckRunRequest checkRunRequest); + + /// + /// Lists check runs for a commit ref. The ref can be a SHA, branch name, or a tag name + /// + /// + /// See the Check Runs API documentation for more information. + /// + /// The owner of the repository + /// The name of the repository + /// The commit reference (can be a SHA, branch name, or a tag name) + /// Details to filter the request, such as by check name + /// Options to change the API response + Task GetAllForReference(string owner, string name, string reference, CheckRunRequest checkRunRequest, ApiOptions options); + + /// + /// Lists check runs for a commit ref. The ref can be a SHA, branch name, or a tag name + /// + /// + /// See the Check Runs API documentation for more information. + /// + /// The Id of the repository + /// The commit reference (can be a SHA, branch name, or a tag name) + /// Details to filter the request, such as by check name + /// Options to change the API response + Task GetAllForReference(long repositoryId, string reference, CheckRunRequest checkRunRequest, ApiOptions options); + + /// + /// Lists check runs for a check suite using its Id + /// + /// + /// See the Check Runs API documentation for more information. + /// + /// The owner of the repository + /// The name of the repository + /// The Id of the check suite + Task GetAllForCheckSuite(string owner, string name, long checkSuiteId); + + /// + /// Lists check runs for a check suite using its Id + /// + /// + /// See the Check Runs API documentation for more information. + /// + /// The Id of the repository + /// The Id of the check suite + Task GetAllForCheckSuite(long repositoryId, long checkSuiteId); + + /// + /// Lists check runs for a check suite using its Id + /// + /// + /// See the Check Runs API documentation for more information. + /// + /// The owner of the repository + /// The name of the repository + /// The Id of the check suite + /// Details to filter the request, such as by check name + Task GetAllForCheckSuite(string owner, string name, long checkSuiteId, CheckRunRequest checkRunRequest); + + /// + /// Lists check runs for a check suite using its Id + /// + /// + /// See the Check Runs API documentation for more information. + /// + /// The Id of the repository + /// The Id of the check suite + /// Details to filter the request, such as by check name + Task GetAllForCheckSuite(long repositoryId, long checkSuiteId, CheckRunRequest checkRunRequest); + + /// + /// Lists check runs for a check suite using its Id + /// + /// + /// See the Check Runs API documentation for more information. + /// + /// The owner of the repository + /// The name of the repository + /// The Id of the check suite + /// Details to filter the request, such as by check name + /// Options to change the API response + Task GetAllForCheckSuite(string owner, string name, long checkSuiteId, CheckRunRequest checkRunRequest, ApiOptions options); + + /// + /// Lists check runs for a check suite using its Id + /// + /// + /// See the Check Runs API documentation for more information. + /// + /// The Id of the repository + /// The Id of the check suite + /// 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 + /// + /// + /// See the Check Runs API documentation for more information. + /// + /// 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 + /// + /// + /// See the Check Runs API documentation for more information. + /// + /// The Id of the repository + /// The Id of the check run + Task Get(long repositoryId, long checkRunId); + + /// + /// Lists annotations for a check run using the check run Id + /// + /// + /// See the Check Runs API documentation for more information. + /// + /// The owner of the repository + /// The name of the repository + /// The Id of the check run + Task> GetAllAnnotations(string owner, string name, long checkRunId); + + /// + /// Lists annotations for a check run using the check run Id + /// + /// + /// See the Check Runs API documentation for more information. + /// + /// The Id of the repository + /// The Id of the check run + /// + Task> GetAllAnnotations(long repositoryId, long checkRunId); + + /// + /// Lists annotations for a check run using the check run Id + /// + /// + /// See the Check Runs API documentation for more information. + /// + /// The owner of the repository + /// The name of the repository + /// The Id of the check run + /// Options to change the API response + Task> GetAllAnnotations(string owner, string name, long checkRunId, ApiOptions options); + + /// + /// Lists annotations for a check run using the check run Id + /// + /// + /// See the Check Runs API documentation for more information. + /// + /// The Id of the repository + /// The Id of the check run + /// Options to change the API response + Task> GetAllAnnotations(long repositoryId, long checkRunId, ApiOptions options); + } +} diff --git a/Octokit/Clients/ICheckSuitesClient.cs b/Octokit/Clients/ICheckSuitesClient.cs index 1e35b8190f..836920938b 100644 --- a/Octokit/Clients/ICheckSuitesClient.cs +++ b/Octokit/Clients/ICheckSuitesClient.cs @@ -3,7 +3,7 @@ namespace Octokit { /// - /// A client for GitHub's Check Suites API. + /// A client for GitHub's Check Suites API /// /// /// See the Check Suites API documentation for more information. diff --git a/Octokit/Clients/IChecksClient.cs b/Octokit/Clients/IChecksClient.cs index c973bc1e90..cf6401e3df 100644 --- a/Octokit/Clients/IChecksClient.cs +++ b/Octokit/Clients/IChecksClient.cs @@ -1,7 +1,7 @@ namespace Octokit { /// - /// A client for GitHub's Checks API. + /// A client for GitHub's Checks API /// /// /// See the Checks API documentation for more information. @@ -9,7 +9,15 @@ public interface IChecksClient { /// - /// A client for GitHub's Check Suites API. + /// A client for GitHub's Check Runs API + /// + /// + /// See the Check Runs API documentation for more information. + /// + ICheckRunsClient Run { get; } + + /// + /// A client for GitHub's Check Suites API /// /// /// See the Check Suites API documentation for more information. diff --git a/Octokit/Helpers/ApiUrls.cs b/Octokit/Helpers/ApiUrls.cs index e06d70cefb..c7c8d3179b 100644 --- a/Octokit/Helpers/ApiUrls.cs +++ b/Octokit/Helpers/ApiUrls.cs @@ -3829,6 +3829,119 @@ public static Uri RepositoryLicense(long repositoryId) return "repositories/{0}/license".FormatUri(repositoryId); } + /// + /// Returns the that returns the specified check run. + /// + /// The Id of the repository + /// The check run Id + /// The that returns the specified check run. + public static Uri CheckRun(long repositoryId, long id) + { + return "repositories/{0}/check-runs/{1}".FormatUri(repositoryId, id); + } + + /// + /// Returns the that returns the specified check run. + /// + /// The owner of repo + /// The name of repo + /// The check run Id + /// The that returns the specified check run. + public static Uri CheckRun(string owner, string repo, long id) + { + return "repos/{0}/{1}/check-runs/{2}".FormatUri(owner, repo, id); + } + + /// + /// Returns the that handles the check runs for the repository. + /// + /// The Id of the repository + /// The that handles the check runs for the repository. + public static Uri CheckRuns(long repositoryId) + { + return "repositories/{0}/check-runs".FormatUri(repositoryId); + } + + /// + /// Returns the that handles the check runs for the repository. + /// + /// The owner of repo + /// The name of repo + /// The that handles the check runs for the repository. + public static Uri CheckRuns(string owner, string repo) + { + return "repos/{0}/{1}/check-runs".FormatUri(owner, repo); + } + + /// + /// Returns the that lists the check runs for the specified reference. + /// + /// The Id of the repository + /// The git reference + /// The that returns the check runs for the specified reference. + public static Uri CheckRunsForReference(long repositoryId, string reference) + { + return "repositories/{0}/commits/{1}/check-runs".FormatUri(repositoryId, reference); + } + + /// + /// Returns the that lists the check runs for the specified reference. + /// + /// The owner of repo + /// The name of repo + /// The git reference + /// The that returns the check runs for the specified reference. + public static Uri CheckRunsForReference(string owner, string repo, string reference) + { + return "repos/{0}/{1}/commits/{2}/check-runs".FormatUri(owner, repo, reference); + } + + /// + /// Returns the that lists the check runs for the specified reference. + /// + /// The Id of the repository + /// The Id of the check suite + /// The that returns the check runs for the specified reference. + public static Uri CheckRunsForCheckSuite(long repositoryId, long checkSuiteId) + { + return "repositories/{0}/check-suites/{1}/check-runs".FormatUri(repositoryId, checkSuiteId); + } + + /// + /// Returns the that lists the check runs for the specified reference. + /// + /// The owner of repo + /// The name of repo + /// The Id of the check suite + /// The that returns the check runs for the specified reference. + public static Uri CheckRunsForCheckSuite(string owner, string repo, long checkSuiteId) + { + return "repos/{0}/{1}/check-suites/{2}/check-runs".FormatUri(owner, repo, checkSuiteId); + } + + /// + /// Returns the that lists the annotations for the specified check run. + /// + /// The Id of the repository + /// The Id of the check run + /// The that returns the annotations for the specified check run. + public static Uri CheckRunAnnotations(long repositoryId, long checkRunId) + { + return "repositories/{0}/check-runs/{1}/annotations".FormatUri(repositoryId, checkRunId); + } + + /// + /// Returns the that lists the annotations for the specified check run. + /// + /// The owner of repo + /// The name of repo + /// The Id of the check run + /// The that returns the annotations for the specified check run. + public static Uri CheckRunAnnotations(string owner, string repo, long checkRunId) + { + return "repos/{0}/{1}/check-runs/{2}/annotations".FormatUri(owner, repo, checkRunId); + } + /// /// Returns the that returns the specified check suite. /// diff --git a/Octokit/Http/SimpleJsonSerializer.cs b/Octokit/Http/SimpleJsonSerializer.cs index 1fd2bc55bc..0e6aa45ba3 100644 --- a/Octokit/Http/SimpleJsonSerializer.cs +++ b/Octokit/Http/SimpleJsonSerializer.cs @@ -206,6 +206,8 @@ private static Type GetPayloadType(string activityType) { switch (activityType) { + case "CheckRunEvent": + return typeof(CheckRunEventPayload); case "CheckSuiteEvent": return typeof(CheckSuiteEventPayload); case "CommitCommentEvent": diff --git a/Octokit/Models/Common/CheckStatus.cs b/Octokit/Models/Common/CheckStatus.cs index c940781a23..129da9d687 100644 --- a/Octokit/Models/Common/CheckStatus.cs +++ b/Octokit/Models/Common/CheckStatus.cs @@ -34,4 +34,16 @@ public enum CheckConclusion [Parameter(Value = "action_required")] ActionRequired, } + + public enum CheckWarningLevel + { + [Parameter(Value = "notice")] + Notice, + + [Parameter(Value = "warning")] + Warning, + + [Parameter(Value = "failure")] + Failure, + } } diff --git a/Octokit/Models/Request/CheckRunRequest.cs b/Octokit/Models/Request/CheckRunRequest.cs new file mode 100644 index 0000000000..f117d3f09e --- /dev/null +++ b/Octokit/Models/Request/CheckRunRequest.cs @@ -0,0 +1,54 @@ +using System.Diagnostics; +using System.Globalization; +using Octokit.Internal; + +namespace Octokit +{ + /// + /// Details to filter a check suite request, such as by App Id or check run name + /// + [DebuggerDisplay("{DebuggerDisplay,nq}")] + public class CheckRunRequest : RequestParameters + { + /// + /// Returns check runs with the specified name. + /// + [Parameter(Key = "check_name")] + public string CheckName { get; set; } + + /// + /// Returns check runs with the specified status. Can be one of queued, in_progress, or completed. + /// + [Parameter(Key = "status")] + public StringEnum? Status { get; set; } + + /// + /// Filters check runs by their completed_at timestamp. Can be one of latest (returning the most recent check runs) or all. Default: latest + /// + [Parameter(Key = "filter")] + public StringEnum? Filter { get; set; } + + internal string DebuggerDisplay => string.Format(CultureInfo.InvariantCulture, "CheckName: {0}, Status: {1}", CheckName, Status); + } + + public enum CheckStatusFilter + { + [Parameter(Value = "queued")] + Queued, + + [Parameter(Value = "in_progress")] + InProgress, + + [Parameter(Value = "completed")] + Completed, + } + + public enum CheckRunCompletedAtFilter + { + [Parameter(Value = "latest")] + Latest, + + [Parameter(Value = "all")] + All + } +} diff --git a/Octokit/Models/Request/CheckRunUpdate.cs b/Octokit/Models/Request/CheckRunUpdate.cs new file mode 100644 index 0000000000..b42ca3cd01 --- /dev/null +++ b/Octokit/Models/Request/CheckRunUpdate.cs @@ -0,0 +1,68 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Globalization; + +namespace Octokit +{ + [DebuggerDisplay("{DebuggerDisplay,nq}")] + public class CheckRunUpdate + { + /// + /// Creates a new Check Run + /// + /// Required. The name of the check. For example, "code-coverage". + public CheckRunUpdate(string name) + { + Name = name; + } + + /// + /// Required. The name of the check. For example, "code-coverage". + /// + public string Name { get; private set; } + + /// + /// The URL of the integrator's site that has the full details of the check. + /// + public string DetailsUrl { get; set; } + + /// + /// A reference for the run on the integrator's system. + /// + public string ExternalId { get; set; } + + /// + /// The current status. Can be one of queued, in_progress, or completed. Default: queued + /// + public StringEnum Status { get; set; } + + /// + /// The time that the check run began + /// + public DateTimeOffset StartedAt { get; set; } + + /// + /// Required if you provide a status of completed. The final conclusion of the check. Can be one of success, failure, neutral, cancelled, timed_out, or action_required. When the conclusion is action_required, additional details should be provided on the site specified by details_url. + /// Note: Providing conclusion will automatically set the status parameter to completed. + /// + public StringEnum? Conclusion { get; set; } + + /// + /// Required if you provide conclusion. The time the check completed. + /// + public DateTimeOffset? CompletedAt { get; set; } + + /// + /// Check runs can accept a variety of data in the output object, including a title and summary and can optionally provide descriptive details about the run. + /// + public NewCheckRunOutput Output { get; set; } + + /// + /// Possible further actions the integrator can perform, which a user may trigger. Each action includes a label, identifier and description. A maximum of three actions are accepted. + /// + public IReadOnlyList Actions { get; set; } + + internal string DebuggerDisplay => string.Format(CultureInfo.InvariantCulture, "Name: {0}, Status: {1}, Conclusion: {2}", Name, Status, Conclusion); + } +} diff --git a/Octokit/Models/Request/NewCheckRun.cs b/Octokit/Models/Request/NewCheckRun.cs new file mode 100644 index 0000000000..6828a32c3e --- /dev/null +++ b/Octokit/Models/Request/NewCheckRun.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Globalization; + +namespace Octokit +{ + [DebuggerDisplay("{DebuggerDisplay,nq}")] + public class NewCheckRun : CheckRunUpdate + { + /// + /// Creates a new Check Run + /// + /// Required. The name of the check. For example, "code-coverage" + /// Required. The SHA of the commit + public NewCheckRun(string name, string headSha) : base(name) + { + HeadSha = headSha; + } + + /// + /// Required. The SHA of the commit + /// + public string HeadSha { get; private set; } + + internal new string DebuggerDisplay => string.Format(CultureInfo.InvariantCulture, "Name: {0}, HeadSha: {1}, Status: {2}, Conclusion: {3}", Name, HeadSha, Status, Conclusion); + } +} diff --git a/Octokit/Models/Request/NewCheckRunAction.cs b/Octokit/Models/Request/NewCheckRunAction.cs new file mode 100644 index 0000000000..fcbc21989f --- /dev/null +++ b/Octokit/Models/Request/NewCheckRunAction.cs @@ -0,0 +1,39 @@ +using System.Diagnostics; +using System.Globalization; + +namespace Octokit +{ + [DebuggerDisplay("{DebuggerDisplay,nq}")] + public class NewCheckRunAction + { + /// + /// Constructs a CheckRunAction request object + /// + /// Required. The text to be displayed on a button in the web UI. The maximum size is 20 characters + /// Required. A short explanation of what this action would do. The maximum size is 40 characters + /// Required. A reference for the action on the integrator's system. The maximum size is 20 characters + public NewCheckRunAction(string label, string description, string identifier) + { + Label = label; + Description = description; + Identifier = identifier; + } + + /// + /// Required. The text to be displayed on a button in the web UI. The maximum size is 20 characters + /// + public string Label { get; protected set; } + + /// + /// Required. A short explanation of what this action would do. The maximum size is 40 characters + /// + public string Description { get; protected set; } + + /// + /// Required. A reference for the action on the integrator's system. The maximum size is 20 characters + /// + public string Identifier { get; protected set; } + + internal string DebuggerDisplay => string.Format(CultureInfo.CurrentCulture, "Label: {0}", Label); + } +} \ No newline at end of file diff --git a/Octokit/Models/Request/NewCheckRunAnnotation.cs b/Octokit/Models/Request/NewCheckRunAnnotation.cs new file mode 100644 index 0000000000..3b0eced38b --- /dev/null +++ b/Octokit/Models/Request/NewCheckRunAnnotation.cs @@ -0,0 +1,70 @@ +using System.Diagnostics; +using System.Globalization; + +namespace Octokit +{ + [DebuggerDisplay("{DebuggerDisplay,nq}")] + public class NewCheckRunAnnotation + { + /// + /// Constructs a CheckRunCreateAnnotation request object + /// + /// Required. The path of the file to add an annotation to. For example, assets/css/main.css + /// Required. The file's full blob URL. You can find the blob_href in the response of the Get a single commit endpoint, by reading the blob_url from an element of the files array. You can also construct the blob URL from the head_sha, the repository, and the filename: https://github.com/:owner/:repo/blob/:head_sha/:filename + /// Required. The start line of the annotation + /// Required. The end line of the annotation + /// Required. The warning level of the annotation. Can be one of notice, warning, or failure + /// Required. A short description of the feedback for these lines of code. The maximum size is 64 KB + public NewCheckRunAnnotation(string filename, string blobHref, int startLine, int endLine, CheckWarningLevel warningLevel, string message) + { + Filename = filename; + BlobHref = blobHref; + StartLine = startLine; + EndLine = endLine; + WarningLevel = warningLevel; + Message = message; + } + + /// + /// Required. The path of the file to add an annotation to. For example, assets/css/main.css + /// + public string Filename { get; protected set; } + + /// + /// Required. The file's full blob URL. You can find the blob_href in the response of the Get a single commit endpoint, by reading the blob_url from an element of the files array. You can also construct the blob URL from the head_sha, the repository, and the filename: https://github.com/:owner/:repo/blob/:head_sha/:filename + /// + public string BlobHref { get; protected set; } + + /// + /// Required. The start line of the annotation + /// + public int StartLine { get; protected set; } + + /// + /// Required. The end line of the annotation + /// + public int EndLine { get; protected set; } + + /// + /// Required. The warning level of the annotation. Can be one of notice, warning, or failure + /// + public StringEnum WarningLevel { get; protected set; } + + /// + /// Required. A short description of the feedback for these lines of code. The maximum size is 64 KB + /// + public string Message { get; protected set; } + + /// + /// The title that represents the annotation. The maximum size is 255 characters + /// + public string Title { get; set; } + + /// + /// Details about this annotation. The maximum size is 64 KB + /// + public string RawDetails { get; set; } + + internal string DebuggerDisplay => string.Format(CultureInfo.InvariantCulture, "Filename: {0}, StartLine: {1}, WarningLevel: {2}", Filename, StartLine, WarningLevel.DebuggerDisplay); + } +} \ No newline at end of file diff --git a/Octokit/Models/Request/NewCheckRunImage.cs b/Octokit/Models/Request/NewCheckRunImage.cs new file mode 100644 index 0000000000..ee5acd1b1c --- /dev/null +++ b/Octokit/Models/Request/NewCheckRunImage.cs @@ -0,0 +1,37 @@ +using System.Diagnostics; +using System.Globalization; + +namespace Octokit +{ + [DebuggerDisplay("{DebuggerDisplay,nq}")] + public class NewCheckRunImage + { + /// + /// Constructs a CheckRunImage request object + /// + /// Required. The alternative text for the image + /// Required. The full URL of the image + public NewCheckRunImage(string alt, string imageUrl) + { + Alt = alt; + ImageUrl = imageUrl; + } + + /// + /// Required. The alternative text for the image + /// + public string Alt { get; protected set; } + + /// + /// Required. The full URL of the image + /// + public string ImageUrl { get; protected set; } + + /// + /// A short image description + /// + public string Caption { get; set; } + + internal string DebuggerDisplay => string.Format(CultureInfo.InvariantCulture, "Alt: {0}, ImageUrl: {1}", Alt, ImageUrl); + } +} \ No newline at end of file diff --git a/Octokit/Models/Request/NewCheckRunOutput.cs b/Octokit/Models/Request/NewCheckRunOutput.cs new file mode 100644 index 0000000000..071227bb98 --- /dev/null +++ b/Octokit/Models/Request/NewCheckRunOutput.cs @@ -0,0 +1,48 @@ +using System.Collections.Generic; +using System.Diagnostics; +using System.Globalization; + +namespace Octokit +{ + [DebuggerDisplay("{DebuggerDisplay,nq}")] + public class NewCheckRunOutput + { + /// + /// Constructs a CheckRunOutput request object + /// + /// Required. The title of the check run + /// Required. The summary of the check run. This parameter supports Markdown + public NewCheckRunOutput(string title, string summary) + { + Title = title; + Summary = summary; + } + + /// + /// Required. The title of the check run + /// + public string Title { get; protected set; } + + /// + /// Required. The summary of the check run. This parameter supports Markdown + /// + public string Summary { get; protected set; } + + /// + /// The details of the check run. This parameter supports Markdown + /// + public string Text { get; set; } + + /// + /// Adds information from your analysis to specific lines of code. Annotations are visible in GitHub's pull request UI. For details about annotations in the UI, see "About status checks" + /// + public IReadOnlyList Annotations { get; set; } + + /// + /// Adds images to the output displayed in the GitHub pull request UI + /// + public IReadOnlyList Images { get; set; } + + internal string DebuggerDisplay => string.Format(CultureInfo.CurrentCulture, "Title: {0}", Title); + } +} \ No newline at end of file diff --git a/Octokit/Models/Request/NewCheckSuite.cs b/Octokit/Models/Request/NewCheckSuite.cs index d841b37ef5..e4590db615 100644 --- a/Octokit/Models/Request/NewCheckSuite.cs +++ b/Octokit/Models/Request/NewCheckSuite.cs @@ -9,14 +9,14 @@ public class NewCheckSuite /// /// Creates a new Check Suite /// - /// Required. The sha of the head commit. + /// Required. The sha of the head commit public NewCheckSuite(string headSha) { HeadSha = headSha; } /// - /// Required. The sha of the head commit. + /// Required. The sha of the head commit /// public string HeadSha { get; private set; } diff --git a/Octokit/Models/Response/ActivityPayloads/CheckRunEventPayload.cs b/Octokit/Models/Response/ActivityPayloads/CheckRunEventPayload.cs new file mode 100644 index 0000000000..a3b76b1a45 --- /dev/null +++ b/Octokit/Models/Response/ActivityPayloads/CheckRunEventPayload.cs @@ -0,0 +1,11 @@ +using System.Diagnostics; + +namespace Octokit +{ + [DebuggerDisplay("{DebuggerDisplay,nq}")] + public class CheckRunEventPayload : ActivityPayload + { + public string Action { get; protected set; } + public CheckRun CheckRun { get; protected set; } + } +} diff --git a/Octokit/Models/Response/CheckRun.cs b/Octokit/Models/Response/CheckRun.cs new file mode 100644 index 0000000000..6642e61a1b --- /dev/null +++ b/Octokit/Models/Response/CheckRun.cs @@ -0,0 +1,105 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Globalization; + +namespace Octokit +{ + [DebuggerDisplay("{DebuggerDisplay,nq}")] + public class CheckRun + { + public CheckRun() + { + } + + public CheckRun(long id, string headSha, string externalId, string url, string htmlUrl, CheckStatus status, CheckConclusion? conclusion, DateTimeOffset startedAt, DateTimeOffset? completedAt, CheckRunOutputResponse output, string name, CheckSuite checkSuite, GitHubApp app, IReadOnlyList pullRequests) + { + Id = id; + HeadSha = headSha; + ExternalId = externalId; + Url = url; + HtmlUrl = htmlUrl; + Status = status; + Conclusion = conclusion; + StartedAt = startedAt; + CompletedAt = completedAt; + Output = output; + Name = name; + CheckSuite = checkSuite; + App = app; + PullRequests = pullRequests; + } + + /// + /// The Id of the check run + /// + public long Id { get; protected set; } + + /// + /// The SHA of the commit the check run is associated with + /// + public string HeadSha { get; protected set; } + + /// + /// A reference for the run on the integrator's system + /// + public string ExternalId { get; protected set; } + + /// + /// The GitHub Api URL of the check run + /// + public string Url { get; protected set; } + + /// + /// The GitHub.com URL of the check run + /// + public string HtmlUrl { get; protected set; } + + /// + /// The check run status + /// + public StringEnum Status { get; protected set; } + + /// + /// The final conclusion of the check + /// + public StringEnum? Conclusion { get; protected set; } + + /// + /// The time that the check run began + /// + public DateTimeOffset StartedAt { get; protected set; } + + /// + /// The time the check run completed + /// + public DateTimeOffset? CompletedAt { get; protected set; } + + /// + /// Descriptive details about the run + /// + public CheckRunOutputResponse Output { get; protected set; } + + /// + /// The name of the check + /// + public string Name { get; protected set; } + + /// + /// The check suite that is associated with this check run + /// + public CheckSuite CheckSuite { get; protected set; } + + /// + /// The GitHub App that is associated with this check run + /// + public GitHubApp App { get; protected set; } + + /// + /// The pull requests that are associated with this check run + /// + public IReadOnlyList PullRequests { get; protected set; } + + internal string DebuggerDisplay => string.Format(CultureInfo.InvariantCulture, "Id: {0}, HeadSha: {1}, Conclusion: {2}", Id, HeadSha, Conclusion); + } +} diff --git a/Octokit/Models/Response/CheckRunAnnotation.cs b/Octokit/Models/Response/CheckRunAnnotation.cs new file mode 100644 index 0000000000..790b155076 --- /dev/null +++ b/Octokit/Models/Response/CheckRunAnnotation.cs @@ -0,0 +1,67 @@ +using System.Diagnostics; +using System.Globalization; + +namespace Octokit +{ + [DebuggerDisplay("{DebuggerDisplay,nq}")] + public class CheckRunAnnotation + { + public CheckRunAnnotation() + { + } + + public CheckRunAnnotation(string filename, string blobHref, int startLine, int endLine, CheckWarningLevel warningLevel, string message, string title, string rawDetails) + { + Filename = filename; + BlobHref = blobHref; + StartLine = startLine; + EndLine = endLine; + WarningLevel = warningLevel; + Message = message; + Title = title; + RawDetails = rawDetails; + } + + /// + /// The path of the file the annotation refers to + /// + public string Filename { get; protected set; } + + /// + /// The file's full blob URL + /// + public string BlobHref { get; protected set; } + + /// + /// The start line of the annotation + /// + public int StartLine { get; protected set; } + + /// + /// The end line of the annotation + /// + public int EndLine { get; protected set; } + + /// + /// The warning level of the annotation. Can be one of notice, warning, or failure + /// + public StringEnum WarningLevel { get; protected set; } + + /// + /// A short description of the feedback for these lines of code + /// + public string Message { get; protected set; } + + /// + /// The title that represents the annotation + /// + public string Title { get; protected set; } + + /// + /// Details about this annotation + /// + public string RawDetails { get; protected set; } + + internal string DebuggerDisplay => string.Format(CultureInfo.InvariantCulture, "Filename: {0}, StartLine: {1}, WarningLevel: {2}", Filename, StartLine, WarningLevel.DebuggerDisplay); + } +} \ No newline at end of file diff --git a/Octokit/Models/Response/CheckRunOutputResponse.cs b/Octokit/Models/Response/CheckRunOutputResponse.cs new file mode 100644 index 0000000000..7503ff9b55 --- /dev/null +++ b/Octokit/Models/Response/CheckRunOutputResponse.cs @@ -0,0 +1,44 @@ +using System.Collections.Generic; +using System.Diagnostics; +using System.Globalization; + +namespace Octokit +{ + [DebuggerDisplay("{DebuggerDisplay,nq}")] + public class CheckRunOutputResponse + { + public CheckRunOutputResponse() + { + } + + public CheckRunOutputResponse(string title, string summary, string text, long annotationsCount) + { + Title = title; + Summary = summary; + Text = text; + AnnotationsCount = annotationsCount; + } + + /// + /// The title of the check run + /// + public string Title { get; protected set; } + + /// + /// The summary of the check run + /// + public string Summary { get; protected set; } + + /// + /// The details of the check run + /// + public string Text { get; protected set; } + + /// + /// The number of annotation entries for the check run (use to get annotation details) + /// + public long AnnotationsCount { get; protected set; } + + internal string DebuggerDisplay => string.Format(CultureInfo.CurrentCulture, "Title: {0}", Title); + } +} \ No newline at end of file diff --git a/Octokit/Models/Response/CheckRunsResponse.cs b/Octokit/Models/Response/CheckRunsResponse.cs new file mode 100644 index 0000000000..ffdc26e116 --- /dev/null +++ b/Octokit/Models/Response/CheckRunsResponse.cs @@ -0,0 +1,32 @@ +using System.Collections.Generic; +using System.Diagnostics; +using System.Globalization; + +namespace Octokit +{ + [DebuggerDisplay("{DebuggerDisplay,nq}")] + public class CheckRunsResponse + { + public CheckRunsResponse() + { + } + + public CheckRunsResponse(int totalCount, IReadOnlyList checkRuns) + { + TotalCount = totalCount; + CheckRuns = checkRuns; + } + + /// + /// The total number of check runs that match the request filter + /// + public int TotalCount { get; protected set; } + + /// + /// The retrieved check runs + /// + public IReadOnlyList CheckRuns { get; protected set; } + + internal string DebuggerDisplay => string.Format(CultureInfo.CurrentCulture, "TotalCount: {0}, CheckRuns: {1}", TotalCount, CheckRuns.Count); + } +} diff --git a/Octokit/Models/Response/CheckSuite.cs b/Octokit/Models/Response/CheckSuite.cs index d2eac05171..ecfdb3ce95 100644 --- a/Octokit/Models/Response/CheckSuite.cs +++ b/Octokit/Models/Response/CheckSuite.cs @@ -27,57 +27,57 @@ public CheckSuite(long id, string headBranch, string headSha, CheckStatus status } /// - /// The Id of this check suite + /// The Id of the check suite /// public long Id { get; protected set; } /// - /// The head branch of the commit this check suite is associated with + /// The branch the check suite is associated with /// public string HeadBranch { get; protected set; } /// - /// The commit this check suite is associated with + /// The SHA of the head commit in the push that created the check suite /// public string HeadSha { get; protected set; } /// - /// The summarized status of the check runs included in this check suite + /// The summarized status of the check runs included in the check suite /// public StringEnum Status { get; protected set; } /// - /// The summarized conclusion of the check runs included in this check suite + /// The summarized conclusion of the check runs included in the check suite /// public StringEnum? Conclusion { get; protected set; } /// - /// The GitHub Api URL of this check suite + /// The GitHub Api URL of the check suite /// public string Url { get; protected set; } /// - /// The hash of the commit prior to the HeadSha + /// The hash of the commit prior to the push that created the check suite /// public string Before { get; protected set; } /// - /// The hash of the commit after the HeadSha + /// The hash of the commit after the push that created the check suite (or HeadSha if no later commits exist) /// public string After { get; protected set; } /// - /// The pull requests that are associated with the check suite (via the HeadSha) + /// The pull requests that are associated with the check suite /// public IReadOnlyList PullRequests { get; protected set; } /// - /// The GitHub App that is associated with this check suite + /// The GitHub App for the check suite /// public GitHubApp App { get; protected set; } /// - /// The repository that is associated with this check suite + /// The repository for the check suite /// public Repository Repository { get; protected set; }