diff --git a/Octokit.Reactive/Clients/IObservableCheckSuitesClient.cs b/Octokit.Reactive/Clients/IObservableCheckSuitesClient.cs
new file mode 100644
index 0000000000..07e0a5937b
--- /dev/null
+++ b/Octokit.Reactive/Clients/IObservableCheckSuitesClient.cs
@@ -0,0 +1,166 @@
+using System;
+
+namespace Octokit.Reactive
+{
+ ///
+ /// A client for GitHub's Check Suites API.
+ ///
+ ///
+ /// See the Check Suites API documentation for more information.
+ ///
+ public interface IObservableCheckSuitesClient
+ {
+ ///
+ /// Gets a single Check Suite by Id
+ ///
+ ///
+ /// See the Check Suites API documentation for more information.
+ ///
+ /// The owner of the repository
+ /// The name of the repository
+ /// The Id of the check suite
+ IObservable Get(string owner, string name, long checkSuiteId);
+
+ ///
+ /// Gets a single Check Suite by Id
+ ///
+ ///
+ /// See the Check Suites API documentation for more information.
+ ///
+ /// The Id of the repository
+ /// The Id of the check suite
+ IObservable Get(long repositoryId, long checkSuiteId);
+
+ ///
+ /// Lists Check Suites for a commit reference (SHA, branch name or tag name)
+ ///
+ ///
+ /// See the Check Suites API documentation for more information.
+ ///
+ /// The owner of the repository
+ /// The name of the repository
+ /// The reference (SHA, branch name or tag name) to list check suites for
+ IObservable GetAllForReference(string owner, string name, string reference);
+
+ ///
+ /// Lists Check Suites for a commit reference (SHA, branch name or tag name)
+ ///
+ ///
+ /// See the Check Suites API documentation for more information.
+ ///
+ /// The Id of the repository
+ /// The reference (SHA, branch name or tag name) to list check suites for
+ IObservable GetAllForReference(long repositoryId, string reference);
+
+ ///
+ /// Lists Check Suites for a commit reference (SHA, branch name or tag name)
+ ///
+ ///
+ /// See the Check Suites API documentation for more information.
+ ///
+ /// The owner of the repository
+ /// The name of the repository
+ /// The reference (SHA, branch name or tag name) to list check suites for
+ /// Details to filter the request, such as by App Id or Check Name
+ IObservable GetAllForReference(string owner, string name, string reference, CheckSuiteRequest request);
+
+ ///
+ /// Lists Check Suites for a commit reference (SHA, branch name or tag name)
+ ///
+ ///
+ /// See the Check Suites API documentation for more information.
+ ///
+ /// The Id of the repository
+ /// The reference (SHA, branch name or tag name) to list check suites for
+ /// Details to filter the request, such as by App Id or Check Name
+ IObservable GetAllForReference(long repositoryId, string reference, CheckSuiteRequest request);
+
+ ///
+ /// Lists Check Suites for a commit reference (SHA, branch name or tag name)
+ ///
+ ///
+ /// See the Check Suites API documentation for more information.
+ ///
+ /// The owner of the repository
+ /// The name of the repository
+ /// The reference (SHA, branch name or tag name) to list check suites for
+ /// Details to filter the request, such as by App Id or Check Name
+ /// Options to change the API response
+ IObservable GetAllForReference(string owner, string name, string reference, CheckSuiteRequest request, ApiOptions options);
+
+ ///
+ /// Lists Check Suites for a commit reference (SHA, branch name or tag name)
+ ///
+ ///
+ /// See the Check Suites API documentation for more information.
+ ///
+ /// The Id of the repository
+ /// The reference (SHA, branch name or tag name) to list check suites for
+ /// Details to filter the request, such as by App Id or Check Name
+ /// Options to change the API response
+ IObservable GetAllForReference(long repositoryId, string reference, CheckSuiteRequest request, ApiOptions options);
+
+ ///
+ /// Updates Check Suites prefrences on a repository, such as disabling automatic creation when code is pushed
+ ///
+ ///
+ /// See the Check Suites API documentation for more information.
+ ///
+ /// The owner of the repository
+ /// The name of the repository
+ /// The check suite preferences
+ IObservable UpdatePreferences(string owner, string name, CheckSuitePreferences preferences);
+
+ ///
+ /// Updates Check Suites prefrences on a repository, such as disabling automatic creation when code is pushed
+ ///
+ ///
+ /// See the Check Suites API documentation for more information.
+ ///
+ /// The Id of the repository
+ /// The check suite preferences
+ IObservable UpdatePreferences(long repositoryId, CheckSuitePreferences preferences);
+
+ ///
+ /// Creates a new Check Suite
+ ///
+ ///
+ /// See the Check Suites API documentation for more information.
+ ///
+ /// The owner of the repository
+ /// The name of the repository
+ /// Details of the Check Suite to create
+ IObservable Create(string owner, string name, NewCheckSuite newCheckSuite);
+
+ ///
+ /// Creates a new Check Suite
+ ///
+ ///
+ /// See the Check Suites API documentation for more information.
+ ///
+ /// The Id of the repository
+ /// Details of the Check Suite to create
+ IObservable Create(long repositoryId, NewCheckSuite newCheckSuite);
+
+ ///
+ /// Triggers GitHub to create a new check suite, without pushing new code to a repository
+ ///
+ ///
+ /// See the Check Suites API documentation for more information.
+ ///
+ /// The owner of the repository
+ /// The name of the repository
+ /// Details of the Check Suite request
+ IObservable Request(string owner, string name, CheckSuiteTriggerRequest request);
+
+ ///
+ /// Triggers GitHub to create a new check suite, without pushing new code to a repository
+ ///
+ ///
+ /// See the Check Suites API documentation for more information.
+ ///
+ /// The Id of the repository
+ /// Details of the Check Suite request
+ IObservable Request(long repositoryId, CheckSuiteTriggerRequest request);
+ }
+}
\ No newline at end of file
diff --git a/Octokit.Reactive/Clients/IObservableChecksClient.cs b/Octokit.Reactive/Clients/IObservableChecksClient.cs
new file mode 100644
index 0000000000..a5127ae78f
--- /dev/null
+++ b/Octokit.Reactive/Clients/IObservableChecksClient.cs
@@ -0,0 +1,19 @@
+namespace Octokit.Reactive
+{
+ ///
+ /// A client for GitHub's Checks API.
+ ///
+ ///
+ /// See the Checks API documentation for more information.
+ ///
+ public interface IObservableChecksClient
+ {
+ ///
+ /// A client for GitHub's Check Suites API.
+ ///
+ ///
+ /// See the Check Suites API documentation for more information.
+ ///
+ IObservableCheckSuitesClient Suite { get; }
+ }
+}
diff --git a/Octokit.Reactive/Clients/ObservableCheckSuitesClient.cs b/Octokit.Reactive/Clients/ObservableCheckSuitesClient.cs
new file mode 100644
index 0000000000..78c67d2096
--- /dev/null
+++ b/Octokit.Reactive/Clients/ObservableCheckSuitesClient.cs
@@ -0,0 +1,271 @@
+using System;
+using System.Reactive.Threading.Tasks;
+using Octokit.Reactive.Internal;
+
+namespace Octokit.Reactive
+{
+ ///
+ /// A client for GitHub's Check Suites API.
+ ///
+ ///
+ /// See the Check Suites API documentation for more information.
+ ///
+ public class ObservableCheckSuitesClient : IObservableCheckSuitesClient
+ {
+ readonly ICheckSuitesClient _client;
+ readonly IConnection _connection;
+
+ ///
+ /// Initializes a new GitHub Check Suites API client.
+ ///
+ /// An used to make the requests
+ public ObservableCheckSuitesClient(IGitHubClient client)
+ {
+ Ensure.ArgumentNotNull(client, nameof(client));
+
+ _client = client.Check.Suite;
+ _connection = client.Connection;
+ }
+
+ ///
+ /// Gets a single Check Suite by Id
+ ///
+ ///
+ /// See the Check Suites API documentation for more information.
+ ///
+ /// The owner of the repository
+ /// The name of the repository
+ /// The Id of the check suite
+ public IObservable Get(string owner, string name, long checkSuiteId)
+ {
+ Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner));
+ Ensure.ArgumentNotNullOrEmptyString(name, nameof(name));
+
+ return _client.Get(owner, name, checkSuiteId).ToObservable();
+ }
+
+ ///
+ /// Gets a single Check Suite by Id
+ ///
+ ///
+ /// See the Check Suites API documentation for more information.
+ ///
+ /// The Id of the repository
+ /// The Id of the check suite
+ public IObservable Get(long repositoryId, long checkSuiteId)
+ {
+ return _client.Get(repositoryId, checkSuiteId).ToObservable();
+ }
+
+ ///
+ /// Lists Check Suites for a commit reference (SHA, branch name or tag name)
+ ///
+ ///
+ /// See the Check Suites API documentation for more information.
+ ///
+ /// The owner of the repository
+ /// The name of the repository
+ /// The reference (SHA, branch name or tag name) to list check suites for
+ 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 CheckSuiteRequest(), ApiOptions.None);
+ }
+
+ ///
+ /// Lists Check Suites for a commit reference (SHA, branch name or tag name)
+ ///
+ ///
+ /// See the Check Suites API documentation for more information.
+ ///
+ /// The Id of the repository
+ /// The reference (SHA, branch name or tag name) to list check suites for
+ public IObservable GetAllForReference(long repositoryId, string reference)
+ {
+ Ensure.ArgumentNotNullOrEmptyString(reference, nameof(reference));
+
+ return GetAllForReference(repositoryId, reference, new CheckSuiteRequest(), ApiOptions.None);
+ }
+
+ ///
+ /// Lists Check Suites for a commit reference (SHA, branch name or tag name)
+ ///
+ ///
+ /// See the Check Suites API documentation for more information.
+ ///
+ /// The owner of the repository
+ /// The name of the repository
+ /// The reference (SHA, branch name or tag name) to list check suites for
+ /// Details to filter the request, such as by App Id or Check Name
+ public IObservable GetAllForReference(string owner, string name, string reference, CheckSuiteRequest request)
+ {
+ Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner));
+ Ensure.ArgumentNotNullOrEmptyString(name, nameof(name));
+ Ensure.ArgumentNotNullOrEmptyString(reference, nameof(reference));
+ Ensure.ArgumentNotNull(request, nameof(request));
+
+ return GetAllForReference(owner, name, reference, request, ApiOptions.None);
+ }
+
+ ///
+ /// Lists Check Suites for a commit reference (SHA, branch name or tag name)
+ ///
+ ///
+ /// See the Check Suites API documentation for more information.
+ ///
+ /// The Id of the repository
+ /// The reference (SHA, branch name or tag name) to list check suites for
+ /// Details to filter the request, such as by App Id or Check Name
+ public IObservable GetAllForReference(long repositoryId, string reference, CheckSuiteRequest request)
+ {
+ Ensure.ArgumentNotNullOrEmptyString(reference, nameof(reference));
+ Ensure.ArgumentNotNull(request, nameof(request));
+
+ return GetAllForReference(repositoryId, reference, request, ApiOptions.None);
+ }
+
+ ///
+ /// Lists Check Suites for a commit reference (SHA, branch name or tag name)
+ ///
+ ///
+ /// See the Check Suites API documentation for more information.
+ ///
+ /// The owner of the repository
+ /// The name of the repository
+ /// The reference (SHA, branch name or tag name) to list check suites for
+ /// Details to filter the request, such as by App Id or Check Name
+ /// Options to change the API response
+ public IObservable GetAllForReference(string owner, string name, string reference, CheckSuiteRequest request, ApiOptions options)
+ {
+ Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner));
+ Ensure.ArgumentNotNullOrEmptyString(name, nameof(name));
+ Ensure.ArgumentNotNullOrEmptyString(reference, nameof(reference));
+ Ensure.ArgumentNotNull(request, nameof(request));
+ Ensure.ArgumentNotNull(options, nameof(options));
+
+ return _connection.GetAndFlattenAllPages(ApiUrls.CheckSuitesForReference(owner, name, reference), request.ToParametersDictionary(), AcceptHeaders.ChecksApiPreview, options);
+ }
+
+ ///
+ /// Lists Check Suites for a commit reference (SHA, branch name or tag name)
+ ///
+ ///
+ /// See the Check Suites API documentation for more information.
+ ///
+ /// The Id of the repository
+ /// The reference (SHA, branch name or tag name) to list check suites for
+ /// Details to filter the request, such as by App Id or Check Name
+ /// Options to change the API response
+ public IObservable GetAllForReference(long repositoryId, string reference, CheckSuiteRequest request, ApiOptions options)
+ {
+ Ensure.ArgumentNotNullOrEmptyString(reference, nameof(reference));
+ Ensure.ArgumentNotNull(request, nameof(request));
+ Ensure.ArgumentNotNull(options, nameof(options));
+
+ return _connection.GetAndFlattenAllPages(ApiUrls.CheckSuitesForReference(repositoryId, reference), request.ToParametersDictionary(), AcceptHeaders.ChecksApiPreview, options);
+ }
+
+ ///
+ /// Updates Check Suites prefrences on a repository, such as disabling automatic creation when code is pushed
+ ///
+ ///
+ /// See the Check Suites API documentation for more information.
+ ///
+ /// The owner of the repository
+ /// The name of the repository
+ /// The check suite preferences
+ public IObservable UpdatePreferences(string owner, string name, CheckSuitePreferences preferences)
+ {
+ Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner));
+ Ensure.ArgumentNotNullOrEmptyString(name, nameof(name));
+ Ensure.ArgumentNotNull(preferences, nameof(preferences));
+
+ return _client.UpdatePreferences(owner, name, preferences).ToObservable();
+ }
+
+ ///
+ /// Updates Check Suites prefrences on a repository, such as disabling automatic creation when code is pushed
+ ///
+ ///
+ /// See the Check Suites API documentation for more information.
+ ///
+ /// The Id of the repository
+ /// The check suite preferences
+ public IObservable UpdatePreferences(long repositoryId, CheckSuitePreferences preferences)
+ {
+ Ensure.ArgumentNotNull(preferences, nameof(preferences));
+
+ return _client.UpdatePreferences(repositoryId, preferences).ToObservable();
+ }
+
+ ///
+ /// Creates a new Check Suite
+ ///
+ ///
+ /// See the Check Suites API documentation for more information.
+ ///
+ /// The owner of the repository
+ /// The name of the repository
+ /// Details of the Check Suite to create
+ public IObservable Create(string owner, string name, NewCheckSuite newCheckSuite)
+ {
+ Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner));
+ Ensure.ArgumentNotNullOrEmptyString(name, nameof(name));
+ Ensure.ArgumentNotNull(newCheckSuite, nameof(newCheckSuite));
+
+ return _client.Create(owner, name, newCheckSuite).ToObservable();
+ }
+
+ ///
+ /// Creates a new Check Suite
+ ///
+ ///
+ /// See the Check Suites API documentation for more information.
+ ///
+ /// The Id of the repository
+ /// Details of the Check Suite to create
+ public IObservable Create(long repositoryId, NewCheckSuite newCheckSuite)
+ {
+ Ensure.ArgumentNotNull(newCheckSuite, nameof(newCheckSuite));
+
+ return _client.Create(repositoryId, newCheckSuite).ToObservable();
+ }
+
+ ///
+ /// Triggers GitHub to create a new check suite, without pushing new code to a repository
+ ///
+ ///
+ /// See the Check Suites API documentation for more information.
+ ///
+ /// The owner of the repository
+ /// The name of the repository
+ /// Details of the Check Suite request
+ public IObservable Request(string owner, string name, CheckSuiteTriggerRequest request)
+ {
+ Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner));
+ Ensure.ArgumentNotNullOrEmptyString(name, nameof(name));
+ Ensure.ArgumentNotNull(request, nameof(request));
+
+ return _client.Request(owner, name, request).ToObservable();
+ }
+
+ ///
+ /// Triggers GitHub to create a new check suite, without pushing new code to a repository
+ ///
+ ///
+ /// See the Check Suites API documentation for more information.
+ ///
+ /// The Id of the repository
+ /// Details of the Check Suite request
+
+ public IObservable Request(long repositoryId, CheckSuiteTriggerRequest request)
+ {
+ Ensure.ArgumentNotNull(request, nameof(request));
+
+ return _client.Request(repositoryId, request).ToObservable();
+ }
+ }
+}
\ No newline at end of file
diff --git a/Octokit.Reactive/Clients/ObservableChecksClient.cs b/Octokit.Reactive/Clients/ObservableChecksClient.cs
new file mode 100644
index 0000000000..90c4b72dcd
--- /dev/null
+++ b/Octokit.Reactive/Clients/ObservableChecksClient.cs
@@ -0,0 +1,26 @@
+namespace Octokit.Reactive
+{
+ ///
+ /// A client for GitHub's Checks API.
+ ///
+ ///
+ /// See the Checks API documentation for more information.
+ ///
+ public class ObservableChecksClient : IObservableChecksClient
+ {
+ public ObservableChecksClient(IGitHubClient client)
+ {
+ Ensure.ArgumentNotNull(client, nameof(client));
+
+ Suite = new ObservableCheckSuitesClient(client);
+ }
+
+ ///
+ /// A client for GitHub's Check Suites API.
+ ///
+ ///
+ /// See the Check Suites API documentation for more information.
+ ///
+ public IObservableCheckSuitesClient Suite { get; private set; }
+ }
+}
\ No newline at end of file
diff --git a/Octokit.Reactive/IObservableGitHubClient.cs b/Octokit.Reactive/IObservableGitHubClient.cs
index 2de5664e3e..bacdc13d72 100644
--- a/Octokit.Reactive/IObservableGitHubClient.cs
+++ b/Octokit.Reactive/IObservableGitHubClient.cs
@@ -32,5 +32,6 @@ public interface IObservableGitHubClient : IApiInfoProvider
IObservableEnterpriseClient Enterprise { get; }
IObservableMigrationClient Migration { get; }
IObservableReactionsClient Reaction { get; }
+ IObservableChecksClient Check { get; }
}
}
\ No newline at end of file
diff --git a/Octokit.Reactive/ObservableGitHubClient.cs b/Octokit.Reactive/ObservableGitHubClient.cs
index a7fd8ce636..f891ec847d 100644
--- a/Octokit.Reactive/ObservableGitHubClient.cs
+++ b/Octokit.Reactive/ObservableGitHubClient.cs
@@ -48,6 +48,7 @@ public ObservableGitHubClient(IGitHubClient gitHubClient)
Enterprise = new ObservableEnterpriseClient(gitHubClient);
Migration = new ObservableMigrationClient(gitHubClient);
Reaction = new ObservableReactionsClient(gitHubClient);
+ Check = new ObservableChecksClient(gitHubClient);
}
public IConnection Connection
@@ -85,6 +86,7 @@ public void SetRequestTimeout(TimeSpan timeout)
public IObservableEnterpriseClient Enterprise { get; private set; }
public IObservableMigrationClient Migration { get; private set; }
public IObservableReactionsClient Reaction { get; private set; }
+ public IObservableChecksClient Check { get; private set; }
///
/// Gets the latest API Info - this will be null if no API calls have been made
diff --git a/Octokit.Tests.Integration/Clients/CheckSuitesClientTests.cs b/Octokit.Tests.Integration/Clients/CheckSuitesClientTests.cs
new file mode 100644
index 0000000000..f2f4901db0
--- /dev/null
+++ b/Octokit.Tests.Integration/Clients/CheckSuitesClientTests.cs
@@ -0,0 +1,256 @@
+using System.Linq;
+using System.Threading.Tasks;
+using Octokit.Tests.Integration.Helpers;
+using Xunit;
+
+namespace Octokit.Tests.Integration.Clients
+{
+ public class CheckSuitesClientTests
+ {
+ 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 GetsCheckSuite()
+ {
+ using (var repoContext = await _github.CreateRepositoryContext(new NewRepository(Helper.MakeNameWithTimestamp("public-repo")) { AutoInit = true }))
+ {
+ // Need to get a CheckSuiteId so we can test the Get method
+ var headCommit = await _github.Repository.Commit.Get(repoContext.RepositoryOwner, repoContext.RepositoryName, "master");
+ var checkSuite = (await _githubAppInstallation.Check.Suite.GetAllForReference(repoContext.RepositoryOwner, repoContext.RepositoryName, headCommit.Sha)).CheckSuites.First();
+
+ // Get Check Suite by Id
+ var result = await _github.Check.Suite.Get(repoContext.RepositoryOwner, repoContext.RepositoryName, checkSuite.Id);
+
+ // Check result
+ Assert.Equal(checkSuite.Id, result.Id);
+ Assert.Equal(headCommit.Sha, result.HeadSha);
+ }
+ }
+
+ [GitHubAppsTest]
+ public async Task GetsCheckSuiteWithRepositoryId()
+ {
+ using (var repoContext = await _github.CreateRepositoryContext(new NewRepository(Helper.MakeNameWithTimestamp("public-repo")) { AutoInit = true }))
+ {
+ // Need to get a CheckSuiteId so we can test the Get method
+ var headCommit = await _github.Repository.Commit.Get(repoContext.RepositoryId, "master");
+ var checkSuite = (await _githubAppInstallation.Check.Suite.GetAllForReference(repoContext.RepositoryId, headCommit.Sha)).CheckSuites.First();
+
+ // Get Check Suite by Id
+ var result = await _github.Check.Suite.Get(repoContext.RepositoryId, checkSuite.Id);
+
+ // Check result
+ Assert.Equal(checkSuite.Id, result.Id);
+ Assert.Equal(headCommit.Sha, result.HeadSha);
+ }
+ }
+ }
+
+ 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 GetsAllCheckSuites()
+ {
+ using (var repoContext = await _github.CreateRepositoryContext(new NewRepository(Helper.MakeNameWithTimestamp("public-repo")) { AutoInit = true }))
+ {
+ var headCommit = await _github.Repository.Commit.Get(repoContext.RepositoryOwner, repoContext.RepositoryName, "master");
+
+ var checkSuites = await _githubAppInstallation.Check.Suite.GetAllForReference(repoContext.RepositoryOwner, repoContext.RepositoryName, headCommit.Sha);
+
+ Assert.NotEmpty(checkSuites.CheckSuites);
+ foreach (var checkSuite in checkSuites.CheckSuites)
+ {
+ Assert.Equal(headCommit.Sha, checkSuite.HeadSha);
+ }
+ }
+ }
+
+ [GitHubAppsTest]
+ public async Task GetsAllCheckSuitesWithRepositoryId()
+ {
+ using (var repoContext = await _github.CreateRepositoryContext(new NewRepository(Helper.MakeNameWithTimestamp("public-repo")) { AutoInit = true }))
+ {
+ var headCommit = await _github.Repository.Commit.Get(repoContext.RepositoryId, "master");
+
+ var checkSuites = await _githubAppInstallation.Check.Suite.GetAllForReference(repoContext.RepositoryId, headCommit.Sha);
+
+ Assert.NotEmpty(checkSuites.CheckSuites);
+ foreach (var checkSuite in checkSuites.CheckSuites)
+ {
+ Assert.Equal(headCommit.Sha, checkSuite.HeadSha);
+ }
+ }
+ }
+ }
+
+ public class TheUpdatePreferencesMethod
+ {
+ IGitHubClient _github;
+ IGitHubClient _githubAppInstallation;
+
+ public TheUpdatePreferencesMethod()
+ {
+ _github = Helper.GetAuthenticatedClient();
+
+ // Authenticate as a GitHubApp Installation
+ _githubAppInstallation = Helper.GetAuthenticatedGitHubAppInstallationForOwner(Helper.UserName);
+ }
+
+ [GitHubAppsTest]
+ public async Task UpdatesPreferences()
+ {
+ using (var repoContext = await _github.CreateRepositoryContext(new NewRepository(Helper.MakeNameWithTimestamp("public-repo")) { AutoInit = true }))
+ {
+ var preference = new CheckSuitePreferences(new[]
+ {
+ new CheckSuitePreferenceAutoTrigger(Helper.GitHubAppId, false)
+ });
+ var result = await _githubAppInstallation.Check.Suite.UpdatePreferences(repoContext.RepositoryOwner, repoContext.RepositoryName, preference);
+
+ Assert.Equal(repoContext.RepositoryId, result.Repository.Id);
+ Assert.Equal(Helper.GitHubAppId, result.Preferences.AutoTriggerChecks[0].AppId);
+ Assert.Equal(false, result.Preferences.AutoTriggerChecks[0].Setting);
+ }
+ }
+
+ [GitHubAppsTest]
+ public async Task UpdatesPreferencesWithRepositoryId()
+ {
+ using (var repoContext = await _github.CreateRepositoryContext(new NewRepository(Helper.MakeNameWithTimestamp("public-repo")) { AutoInit = true }))
+ {
+ var preference = new CheckSuitePreferences(new[]
+ {
+ new CheckSuitePreferenceAutoTrigger(Helper.GitHubAppId, false)
+ });
+ var result = await _githubAppInstallation.Check.Suite.UpdatePreferences(repoContext.RepositoryId, preference);
+
+ Assert.Equal(repoContext.RepositoryId, result.Repository.Id);
+ Assert.Equal(Helper.GitHubAppId, result.Preferences.AutoTriggerChecks[0].AppId);
+ Assert.Equal(false, result.Preferences.AutoTriggerChecks[0].Setting);
+ }
+ }
+ }
+
+ 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 CreatesCheckSuite()
+ {
+ using (var repoContext = await _github.CreateRepositoryContext(new NewRepository(Helper.MakeNameWithTimestamp("public-repo")) { AutoInit = true }))
+ {
+ // Turn off auto creation of check suite for this repo
+ var preference = new CheckSuitePreferences(new[] { new CheckSuitePreferenceAutoTrigger(Helper.GitHubAppId, false) });
+ await _githubAppInstallation.Check.Suite.UpdatePreferences(repoContext.RepositoryOwner, repoContext.RepositoryName, preference);
+
+ // Create a new feature branch
+ var headCommit = await _github.Repository.Commit.Get(repoContext.RepositoryOwner, repoContext.RepositoryName, "master");
+ var featureBranch = await Helper.CreateFeatureBranch(repoContext.RepositoryOwner, repoContext.RepositoryName, headCommit.Sha, "my-feature");
+
+ // Create a check suite for the feature branch
+ var newCheckSuite = new NewCheckSuite(featureBranch.Object.Sha);
+ var result = await _githubAppInstallation.Check.Suite.Create(repoContext.RepositoryOwner, repoContext.RepositoryName, newCheckSuite);
+
+ // Check result
+ Assert.NotNull(result);
+ Assert.Equal(featureBranch.Object.Sha, result.HeadSha);
+ }
+ }
+
+ [GitHubAppsTest]
+ public async Task CreatesCheckSuiteWithRepositoryId()
+ {
+ using (var repoContext = await _github.CreateRepositoryContext(new NewRepository(Helper.MakeNameWithTimestamp("public-repo")) { AutoInit = true }))
+ {
+ // Turn off auto creation of check suite for this repo
+ var preference = new CheckSuitePreferences(new[] { new CheckSuitePreferenceAutoTrigger(Helper.GitHubAppId, false) });
+ await _githubAppInstallation.Check.Suite.UpdatePreferences(repoContext.RepositoryId, preference);
+
+ // 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 suite for the feature branch
+ var newCheckSuite = new NewCheckSuite(featureBranch.Object.Sha);
+ var result = await _githubAppInstallation.Check.Suite.Create(repoContext.RepositoryId, newCheckSuite);
+
+ // Check result
+ Assert.NotNull(result);
+ Assert.Equal(featureBranch.Object.Sha, result.HeadSha);
+ }
+ }
+ }
+
+ public class TheRequestMethod
+ {
+ IGitHubClient _github;
+ IGitHubClient _githubAppInstallation;
+
+ public TheRequestMethod()
+ {
+ _github = Helper.GetAuthenticatedClient();
+
+ // Authenticate as a GitHubApp Installation
+ _githubAppInstallation = Helper.GetAuthenticatedGitHubAppInstallationForOwner(Helper.UserName);
+ }
+
+ [GitHubAppsTest]
+ public async Task RequestsCheckSuite()
+ {
+ using (var repoContext = await _github.CreateRepositoryContext(new NewRepository(Helper.MakeNameWithTimestamp("public-repo")) { AutoInit = true }))
+ {
+ var headCommit = await _github.Repository.Commit.Get(repoContext.RepositoryOwner, repoContext.RepositoryName, "master");
+
+ var result = await _githubAppInstallation.Check.Suite.Request(repoContext.RepositoryOwner, repoContext.RepositoryName, new CheckSuiteTriggerRequest(headCommit.Sha));
+
+ Assert.True(result);
+ }
+ }
+
+ [GitHubAppsTest]
+ public async Task RequestsCheckSuiteWithRepositoryId()
+ {
+ using (var repoContext = await _github.CreateRepositoryContext(new NewRepository(Helper.MakeNameWithTimestamp("public-repo")) { AutoInit = true }))
+ {
+ var headCommit = await _github.Repository.Commit.Get(repoContext.RepositoryId, "master");
+
+ var result = await _githubAppInstallation.Check.Suite.Request(repoContext.RepositoryId, new CheckSuiteTriggerRequest(headCommit.Sha));
+
+ Assert.True(result);
+ }
+ }
+ }
+ }
+}
diff --git a/Octokit.Tests.Integration/Clients/GitHubAppsClientTests.cs b/Octokit.Tests.Integration/Clients/GitHubAppsClientTests.cs
index c62e654718..84c416ea27 100644
--- a/Octokit.Tests.Integration/Clients/GitHubAppsClientTests.cs
+++ b/Octokit.Tests.Integration/Clients/GitHubAppsClientTests.cs
@@ -65,7 +65,6 @@ public async Task GetsAllInstallations()
{
var result = await _github.GitHubApps.GetAllInstallationsForCurrent();
- Assert.True(result.Any(x => x.Id == Helper.GitHubAppInstallationId));
foreach (var installation in result)
{
Assert.Equal(Helper.GitHubAppId, installation.AppId);
@@ -91,8 +90,10 @@ public TheGetInstallationMethod()
[GitHubAppsTest]
public async Task GetsInstallation()
{
- var installationId = Helper.GitHubAppInstallationId;
+ // Get the installation Id
+ var installationId = Helper.GetGitHubAppInstallationForOwner(Helper.UserName).Id;
+ // Get the installation by Id
var result = await _github.GitHubApps.GetInstallation(installationId);
Assert.True(result.AppId == Helper.GitHubAppId);
@@ -116,10 +117,12 @@ public TheCreateInstallationTokenMethod()
}
[GitHubAppsTest]
- public async Task GetsInstallation()
+ public async Task CreatesInstallationToken()
{
- var installationId = Helper.GitHubAppInstallationId;
+ // Get the installation Id
+ var installationId = Helper.GetGitHubAppInstallationForOwner(Helper.UserName).Id;
+ // Create installation token
var result = await _github.GitHubApps.CreateInstallationToken(installationId);
Assert.NotNull(result.Token);
diff --git a/Octokit.Tests.Integration/Helper.cs b/Octokit.Tests.Integration/Helper.cs
index 32b67b4180..f005e0ffb9 100644
--- a/Octokit.Tests.Integration/Helper.cs
+++ b/Octokit.Tests.Integration/Helper.cs
@@ -2,7 +2,9 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
+using System.Linq;
using System.Reflection;
+using System.Threading.Tasks;
namespace Octokit.Tests.Integration
{
@@ -171,11 +173,6 @@ public static string GitHubAppSlug
get { return Environment.GetEnvironmentVariable("OCTOKIT_GITHUBAPP_SLUG"); }
}
- public static long GitHubAppInstallationId
- {
- get { return Convert.ToInt64(Environment.GetEnvironmentVariable("OCTOKIT_GITHUBAPP_INSTALLATIONID")); }
- }
-
public static void DeleteRepo(IConnection connection, Repository repository)
{
if (repository != null)
@@ -304,6 +301,28 @@ public static GitHubClient GetAuthenticatedGitHubAppsClient()
};
}
+ public static Installation GetGitHubAppInstallationForOwner(string owner)
+ {
+ var client = GetAuthenticatedGitHubAppsClient();
+ var installations = client.GitHubApps.GetAllInstallationsForCurrent().Result;
+ var installation = installations.First(x => x.Account.Login == owner);
+
+ return installation;
+ }
+
+ public static GitHubClient GetAuthenticatedGitHubAppInstallationForOwner(string owner)
+ {
+ var client = GetAuthenticatedGitHubAppsClient();
+ var installation = GetGitHubAppInstallationForOwner(owner);
+
+ var token = client.GitHubApps.CreateInstallationToken(installation.Id).Result.Token;
+
+ return new GitHubClient(new ProductHeaderValue("OctokitTests"), TargetUrl)
+ {
+ Credentials = new Credentials(token)
+ };
+ }
+
public static void DeleteInvitations(IConnection connection, List invitees, int teamId)
{
try
@@ -327,5 +346,42 @@ public static string InviteMemberToTeam(IConnection connection, int teamId, stri
return login;
}
+
+ public async static Task CreateFeatureBranch(string owner, string repo, string parentSha, string branchName)
+ {
+ var github = Helper.GetAuthenticatedClient();
+
+ // Create content blob
+ var baselineBlob = new NewBlob
+ {
+ Content = "I am overwriting this blob with something new",
+ Encoding = EncodingType.Utf8
+ };
+ var baselineBlobResult = await github.Git.Blob.Create(owner, repo, baselineBlob);
+
+ // Create tree item
+ var treeItem = new NewTreeItem
+ {
+ Type = TreeType.Blob,
+ Mode = FileMode.File,
+ Path = "README.md",
+ Sha = baselineBlobResult.Sha
+ };
+
+ // Create tree
+ var newTree = new NewTree();
+ newTree.Tree.Add(treeItem);
+ var tree = await github.Git.Tree.Create(owner, repo, newTree);
+
+ // Create commit
+ var newCommit = new NewCommit("this is the new commit", tree.Sha, parentSha);
+ var commit = await github.Git.Commit.Create(owner, repo, newCommit);
+
+ // Create branch
+ var branch = await github.Git.Reference.Create(owner, repo, new NewReference($"refs/heads/{branchName}", commit.Sha));
+
+ // Return commit
+ return branch;
+ }
}
}
diff --git a/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj b/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj
index 9ed8fc2720..c38f326981 100644
--- a/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj
+++ b/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj
@@ -19,7 +19,7 @@
false
-
+
$(DefineConstants);GITHUBJWT_HELPER_AVAILABLE
@@ -45,7 +45,7 @@
-
+
0.0.2
diff --git a/Octokit.Tests.Integration/Reactive/ObservableCheckSuitesClientTests.cs b/Octokit.Tests.Integration/Reactive/ObservableCheckSuitesClientTests.cs
new file mode 100644
index 0000000000..61983e0b2c
--- /dev/null
+++ b/Octokit.Tests.Integration/Reactive/ObservableCheckSuitesClientTests.cs
@@ -0,0 +1,258 @@
+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 ObservableCheckSuitesClientTests
+ {
+ 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 GetsCheckSuite()
+ {
+ using (var repoContext = await _github.CreateRepositoryContext(new NewRepository(Helper.MakeNameWithTimestamp("public-repo")) { AutoInit = true }))
+ {
+ // Need to get a CheckSuiteId so we can test the Get method
+ var headCommit = await _github.Repository.Commit.Get(repoContext.RepositoryOwner, repoContext.RepositoryName, "master");
+ var checkSuite = (await _githubAppInstallation.Check.Suite.GetAllForReference(repoContext.RepositoryOwner, repoContext.RepositoryName, headCommit.Sha)).CheckSuites.First();
+
+ // Get Check Suite by Id
+ var result = await _github.Check.Suite.Get(repoContext.RepositoryOwner, repoContext.RepositoryName, checkSuite.Id);
+
+ // Check result
+ Assert.Equal(checkSuite.Id, result.Id);
+ Assert.Equal(headCommit.Sha, result.HeadSha);
+ }
+ }
+
+ [GitHubAppsTest]
+ public async Task GetsCheckSuiteWithRepositoryId()
+ {
+ using (var repoContext = await _github.CreateRepositoryContext(new NewRepository(Helper.MakeNameWithTimestamp("public-repo")) { AutoInit = true }))
+ {
+ // Need to get a CheckSuiteId so we can test the Get method
+ var headCommit = await _github.Repository.Commit.Get(repoContext.RepositoryId, "master");
+ var checkSuite = (await _githubAppInstallation.Check.Suite.GetAllForReference(repoContext.RepositoryId, headCommit.Sha)).CheckSuites.First();
+
+ // Get Check Suite by Id
+ var result = await _github.Check.Suite.Get(repoContext.RepositoryId, checkSuite.Id);
+
+ // Check result
+ Assert.Equal(checkSuite.Id, result.Id);
+ Assert.Equal(headCommit.Sha, result.HeadSha);
+ }
+ }
+ }
+
+ 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 GetsAllCheckSuites()
+ {
+ using (var repoContext = await _github.CreateRepositoryContext(new NewRepository(Helper.MakeNameWithTimestamp("public-repo")) { AutoInit = true }))
+ {
+ var headCommit = await _github.Repository.Commit.Get(repoContext.RepositoryOwner, repoContext.RepositoryName, "master");
+
+ var checkSuites = await _githubAppInstallation.Check.Suite.GetAllForReference(repoContext.RepositoryOwner, repoContext.RepositoryName, headCommit.Sha);
+
+ Assert.NotEmpty(checkSuites.CheckSuites);
+ foreach (var checkSuite in checkSuites.CheckSuites)
+ {
+ Assert.Equal(headCommit.Sha, checkSuite.HeadSha);
+ }
+ }
+ }
+
+ [GitHubAppsTest]
+ public async Task GetsAllCheckSuitesWithRepositoryId()
+ {
+ using (var repoContext = await _github.CreateRepositoryContext(new NewRepository(Helper.MakeNameWithTimestamp("public-repo")) { AutoInit = true }))
+ {
+ var headCommit = await _github.Repository.Commit.Get(repoContext.RepositoryId, "master");
+
+ var checkSuites = await _githubAppInstallation.Check.Suite.GetAllForReference(repoContext.RepositoryId, headCommit.Sha);
+
+ Assert.NotEmpty(checkSuites.CheckSuites);
+ foreach (var checkSuite in checkSuites.CheckSuites)
+ {
+ Assert.Equal(headCommit.Sha, checkSuite.HeadSha);
+ }
+ }
+ }
+ }
+
+ public class TheUpdatePreferencesMethod
+ {
+ IObservableGitHubClient _github;
+ IObservableGitHubClient _githubAppInstallation;
+
+ public TheUpdatePreferencesMethod()
+ {
+ _github = new ObservableGitHubClient(Helper.GetAuthenticatedClient());
+
+ // Authenticate as a GitHubApp Installation
+ _githubAppInstallation = new ObservableGitHubClient(Helper.GetAuthenticatedGitHubAppInstallationForOwner(Helper.UserName));
+ }
+
+ [GitHubAppsTest]
+ public async Task UpdatesPreferences()
+ {
+ using (var repoContext = await _github.CreateRepositoryContext(new NewRepository(Helper.MakeNameWithTimestamp("public-repo")) { AutoInit = true }))
+ {
+ var preference = new CheckSuitePreferences(new[]
+ {
+ new CheckSuitePreferenceAutoTrigger(Helper.GitHubAppId, false)
+ });
+ var result = await _githubAppInstallation.Check.Suite.UpdatePreferences(repoContext.RepositoryOwner, repoContext.RepositoryName, preference);
+
+ Assert.Equal(repoContext.RepositoryId, result.Repository.Id);
+ Assert.Equal(Helper.GitHubAppId, result.Preferences.AutoTriggerChecks[0].AppId);
+ Assert.Equal(false, result.Preferences.AutoTriggerChecks[0].Setting);
+ }
+ }
+
+ [GitHubAppsTest]
+ public async Task UpdatesPreferencesWithRepositoryId()
+ {
+ using (var repoContext = await _github.CreateRepositoryContext(new NewRepository(Helper.MakeNameWithTimestamp("public-repo")) { AutoInit = true }))
+ {
+ var preference = new CheckSuitePreferences(new[]
+ {
+ new CheckSuitePreferenceAutoTrigger(Helper.GitHubAppId, false)
+ });
+ var result = await _githubAppInstallation.Check.Suite.UpdatePreferences(repoContext.RepositoryId, preference);
+
+ Assert.Equal(repoContext.RepositoryId, result.Repository.Id);
+ Assert.Equal(Helper.GitHubAppId, result.Preferences.AutoTriggerChecks[0].AppId);
+ Assert.Equal(false, result.Preferences.AutoTriggerChecks[0].Setting);
+ }
+ }
+ }
+
+ 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 CreatesCheckSuite()
+ {
+ using (var repoContext = await _github.CreateRepositoryContext(new NewRepository(Helper.MakeNameWithTimestamp("public-repo")) { AutoInit = true }))
+ {
+ // Turn off auto creation of check suite for this repo
+ var preference = new CheckSuitePreferences(new[] { new CheckSuitePreferenceAutoTrigger(Helper.GitHubAppId, false) });
+ await _githubAppInstallation.Check.Suite.UpdatePreferences(repoContext.RepositoryOwner, repoContext.RepositoryName, preference);
+
+ // Create a new feature branch
+ var headCommit = await _github.Repository.Commit.Get(repoContext.RepositoryOwner, repoContext.RepositoryName, "master");
+ var featureBranch = await Helper.CreateFeatureBranch(repoContext.RepositoryOwner, repoContext.RepositoryName, headCommit.Sha, "my-feature");
+
+ // Create a check suite for the feature branch
+ var newCheckSuite = new NewCheckSuite(featureBranch.Object.Sha);
+ var result = await _githubAppInstallation.Check.Suite.Create(repoContext.RepositoryOwner, repoContext.RepositoryName, newCheckSuite);
+
+ // Check result
+ Assert.NotNull(result);
+ Assert.Equal(featureBranch.Object.Sha, result.HeadSha);
+ }
+ }
+
+ [GitHubAppsTest]
+ public async Task CreatesCheckSuiteWithRepositoryId()
+ {
+ using (var repoContext = await _github.CreateRepositoryContext(new NewRepository(Helper.MakeNameWithTimestamp("public-repo")) { AutoInit = true }))
+ {
+ // Turn off auto creation of check suite for this repo
+ var preference = new CheckSuitePreferences(new[] { new CheckSuitePreferenceAutoTrigger(Helper.GitHubAppId, false) });
+ await _githubAppInstallation.Check.Suite.UpdatePreferences(repoContext.RepositoryId, preference);
+
+ // 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 suite for the feature branch
+ var newCheckSuite = new NewCheckSuite(featureBranch.Object.Sha);
+ var result = await _githubAppInstallation.Check.Suite.Create(repoContext.RepositoryId, newCheckSuite);
+
+ // Check result
+ Assert.NotNull(result);
+ Assert.Equal(featureBranch.Object.Sha, result.HeadSha);
+ }
+ }
+ }
+
+ public class TheRequestMethod
+ {
+ IObservableGitHubClient _github;
+ IObservableGitHubClient _githubAppInstallation;
+
+ public TheRequestMethod()
+ {
+ _github = new ObservableGitHubClient(Helper.GetAuthenticatedClient());
+
+ // Authenticate as a GitHubApp Installation
+ _githubAppInstallation = new ObservableGitHubClient(Helper.GetAuthenticatedGitHubAppInstallationForOwner(Helper.UserName));
+ }
+
+ [GitHubAppsTest]
+ public async Task RequestsCheckSuite()
+ {
+ using (var repoContext = await _github.CreateRepositoryContext(new NewRepository(Helper.MakeNameWithTimestamp("public-repo")) { AutoInit = true }))
+ {
+ var headCommit = await _github.Repository.Commit.Get(repoContext.RepositoryOwner, repoContext.RepositoryName, "master");
+
+ var result = await _githubAppInstallation.Check.Suite.Request(repoContext.RepositoryOwner, repoContext.RepositoryName, new CheckSuiteTriggerRequest(headCommit.Sha));
+
+ Assert.True(result);
+ }
+ }
+
+ [GitHubAppsTest]
+ public async Task RequestsCheckSuiteWithRepositoryId()
+ {
+ using (var repoContext = await _github.CreateRepositoryContext(new NewRepository(Helper.MakeNameWithTimestamp("public-repo")) { AutoInit = true }))
+ {
+ var headCommit = await _github.Repository.Commit.Get(repoContext.RepositoryId, "master");
+
+ var result = await _githubAppInstallation.Check.Suite.Request(repoContext.RepositoryId, new CheckSuiteTriggerRequest(headCommit.Sha));
+
+ Assert.True(result);
+ }
+ }
+ }
+ }
+}
diff --git a/Octokit.Tests/Clients/CheckSuitesClientTests.cs b/Octokit.Tests/Clients/CheckSuitesClientTests.cs
new file mode 100644
index 0000000000..5223dd0a59
--- /dev/null
+++ b/Octokit.Tests/Clients/CheckSuitesClientTests.cs
@@ -0,0 +1,397 @@
+using System;
+using System.Collections.Generic;
+using System.Net;
+using System.Threading.Tasks;
+using NSubstitute;
+using Octokit.Tests.Helpers;
+using Xunit;
+
+namespace Octokit.Tests.Clients
+{
+ public class CheckSuitesClientTests
+ {
+ public class TheCtor
+ {
+ [Fact]
+ public void EnsuresNonNullArguments()
+ {
+ Assert.Throws(() => new CheckSuitesClient(null));
+ }
+ }
+
+ public class TheGetMethod
+ {
+ [Fact]
+ public async Task RequestsCorrectUrl()
+ {
+ var connection = Substitute.For();
+ var client = new CheckSuitesClient(connection);
+
+ await client.Get("fake", "repo", 1);
+
+ connection.Received().Get(
+ Arg.Is(u => u.ToString() == "repos/fake/repo/check-suites/1"),
+ Arg.Any>(),
+ "application/vnd.github.antiope-preview+json");
+ }
+
+ [Fact]
+ public async Task RequestsCorrectUrlWithRepositoryId()
+ {
+ var connection = Substitute.For();
+ var client = new CheckSuitesClient(connection);
+
+ await client.Get(1, 1);
+
+ connection.Received().Get(
+ Arg.Is(u => u.ToString() == "repositories/1/check-suites/1"),
+ Arg.Any>(),
+ "application/vnd.github.antiope-preview+json");
+ }
+
+ [Fact]
+ public async Task EnsuresNonNullArguments()
+ {
+ var connection = Substitute.For();
+ var client = new CheckSuitesClient(connection);
+
+ await Assert.ThrowsAsync(() => client.Get(null, "repo", 1));
+ await Assert.ThrowsAsync(() => client.Get("fake", null, 1));
+ await Assert.ThrowsAsync(() => client.Get(null, "repo", 1));
+ }
+
+ [Fact]
+ public async Task EnsuresNonEmptyArguments()
+ {
+ var connection = Substitute.For();
+ var client = new CheckSuitesClient(connection);
+
+ await Assert.ThrowsAsync(() => client.Get("", "repo", 1));
+ await Assert.ThrowsAsync(() => client.Get("fake", "", 1));
+ }
+ }
+
+ public class TheGetAllForReferenceMethod
+ {
+ [Fact]
+ public async Task RequestsCorrectUrl()
+ {
+ var connection = Substitute.For();
+ var client = new CheckSuitesClient(connection);
+
+ await client.GetAllForReference("fake", "repo", "ref");
+
+ connection.Received().GetAll(
+ Arg.Is(u => u.ToString() == "repos/fake/repo/commits/ref/check-suites"),
+ Args.EmptyDictionary,
+ "application/vnd.github.antiope-preview+json",
+ Args.ApiOptions);
+ }
+
+ [Fact]
+ public async Task RequestsCorrectUrlWithRepositoryId()
+ {
+ var connection = Substitute.For();
+ var client = new CheckSuitesClient(connection);
+
+ await client.GetAllForReference(1, "ref");
+
+ connection.Received().GetAll(
+ Arg.Is(u => u.ToString() == "repositories/1/commits/ref/check-suites"),
+ Args.EmptyDictionary,
+ "application/vnd.github.antiope-preview+json",
+ Args.ApiOptions);
+ }
+
+ [Fact]
+ public async Task RequestsCorrectUrlWithRequest()
+ {
+ var connection = Substitute.For();
+ var client = new CheckSuitesClient(connection);
+
+ var request = new CheckSuiteRequest
+ {
+ AppId = 123,
+ CheckName = "build"
+ };
+
+ await client.GetAllForReference("fake", "repo", "ref", request);
+
+ connection.Received().GetAll(
+ Arg.Is(u => u.ToString() == "repos/fake/repo/commits/ref/check-suites"),
+ Arg.Is>(x =>
+ x["app_id"] == "123"
+ && x["check_name"] == "build"),
+ "application/vnd.github.antiope-preview+json",
+ Args.ApiOptions);
+ }
+
+ [Fact]
+ public async Task RequestsCorrectUrlWithRequestWithRepositoryId()
+ {
+ var connection = Substitute.For();
+ var client = new CheckSuitesClient(connection);
+
+ var request = new CheckSuiteRequest
+ {
+ AppId = 123,
+ CheckName = "build"
+ };
+
+ await client.GetAllForReference(1, "ref", request);
+
+ connection.Received().GetAll(
+ Arg.Is(u => u.ToString() == "repositories/1/commits/ref/check-suites"),
+ Arg.Is>(x =>
+ x["app_id"] == "123"
+ && x["check_name"] == "build"),
+ "application/vnd.github.antiope-preview+json",
+ Args.ApiOptions);
+ }
+
+ [Fact]
+ public async Task EnsuresNonNullArguments()
+ {
+ var connection = Substitute.For();
+ var client = new CheckSuitesClient(connection);
+
+ var request = new CheckSuiteRequest();
+
+ 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 CheckSuitesClient(connection);
+
+ var request = new CheckSuiteRequest();
+
+ 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 TheUpdatePreferencesMethod
+ {
+ [Fact]
+ public async Task RequestsCorrectUrl()
+ {
+ var connection = Substitute.For();
+ var client = new CheckSuitesClient(connection);
+
+ var preferences = new CheckSuitePreferences(new[] { new CheckSuitePreferenceAutoTrigger(123, true) });
+
+ await client.UpdatePreferences("fake", "repo", preferences);
+
+ connection.Received().Patch(
+ Arg.Is(u => u.ToString() == "repos/fake/repo/check-suites/preferences"),
+ preferences,
+ "application/vnd.github.antiope-preview+json");
+ }
+
+ [Fact]
+ public async Task RequestsCorrectUrlWithRepositoryId()
+ {
+ var connection = Substitute.For();
+ var client = new CheckSuitesClient(connection);
+
+ var preferences = new CheckSuitePreferences(new[] { new CheckSuitePreferenceAutoTrigger(123, true) });
+
+ await client.UpdatePreferences(1, preferences);
+
+ connection.Received().Patch(
+ Arg.Is(u => u.ToString() == "repositories/1/check-suites/preferences"),
+ preferences,
+ "application/vnd.github.antiope-preview+json");
+ }
+
+ [Fact]
+ public async Task EnsuresNonNullArguments()
+ {
+ var connection = Substitute.For();
+ var client = new CheckSuitesClient(connection);
+
+ var preferences = new CheckSuitePreferences(new[] { new CheckSuitePreferenceAutoTrigger(123, true) });
+
+ await Assert.ThrowsAsync(() => client.UpdatePreferences(null, "repo", preferences));
+ await Assert.ThrowsAsync(() => client.UpdatePreferences("fake", null, preferences));
+ await Assert.ThrowsAsync(() => client.UpdatePreferences("fake", "repo", null));
+ }
+
+ [Fact]
+ public async Task EnsuresNonEmptyArguments()
+ {
+ var connection = Substitute.For();
+ var client = new CheckSuitesClient(connection);
+
+ var preferences = new CheckSuitePreferences(new[] { new CheckSuitePreferenceAutoTrigger(123, true) });
+
+ await Assert.ThrowsAsync(() => client.UpdatePreferences("", "repo", preferences));
+ await Assert.ThrowsAsync(() => client.UpdatePreferences("fake", "", preferences));
+ }
+ }
+
+ public class TheCreateMethod
+ {
+ [Fact]
+ public async Task RequestsCorrectUrl()
+ {
+ var connection = Substitute.For();
+ var client = new CheckSuitesClient(connection);
+
+ var newCheckSuite = new NewCheckSuite("123abc");
+
+ await client.Create("fake", "repo", newCheckSuite);
+
+ connection.Received().Post(
+ Arg.Is(u => u.ToString() == "repos/fake/repo/check-suites"),
+ newCheckSuite,
+ "application/vnd.github.antiope-preview+json");
+ }
+
+ [Fact]
+ public async Task RequestsCorrectUrlWithRepositoryId()
+ {
+ var connection = Substitute.For();
+ var client = new CheckSuitesClient(connection);
+
+ var newCheckSuite = new NewCheckSuite("123abc");
+
+ await client.Create(1, newCheckSuite);
+
+ connection.Received().Post(
+ Arg.Is(u => u.ToString() == "repositories/1/check-suites"),
+ newCheckSuite,
+ "application/vnd.github.antiope-preview+json");
+ }
+
+ [Fact]
+ public async Task EnsuresNonNullArguments()
+ {
+ var connection = Substitute.For();
+ var client = new CheckSuitesClient(connection);
+
+ var newCheckSuite = new NewCheckSuite("123abc");
+
+ await Assert.ThrowsAsync(() => client.Create(null, "repo", newCheckSuite));
+ await Assert.ThrowsAsync(() => client.Create("fake", null, newCheckSuite));
+ 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 CheckSuitesClient(connection);
+
+ var newCheckSuite = new NewCheckSuite("123abc");
+
+ await Assert.ThrowsAsync(() => client.Create("", "repo", newCheckSuite));
+ await Assert.ThrowsAsync(() => client.Create("fake", "", newCheckSuite));
+ }
+ }
+
+ public class TheRequestMethod
+ {
+ [Fact]
+ public async Task RequestsCorrectUrl()
+ {
+ var connection = MockedIApiConnection.PostReturnsHttpStatus(HttpStatusCode.Created);
+ var client = new CheckSuitesClient(connection);
+
+ var request = new CheckSuiteTriggerRequest("123abc");
+
+ await client.Request("fake", "repo", request);
+
+ connection.Connection.Received().Post(
+ Arg.Is(u => u.ToString() == "repos/fake/repo/check-suite-requests"),
+ request,
+ "application/vnd.github.antiope-preview+json");
+ }
+
+ [Fact]
+ public async Task RequestsCorrectUrlWithRepositoryId()
+ {
+ var connection = MockedIApiConnection.PostReturnsHttpStatus(HttpStatusCode.Created);
+ var client = new CheckSuitesClient(connection);
+
+ var request = new CheckSuiteTriggerRequest("123abc");
+
+ await client.Request(1, request);
+
+ connection.Connection.Received().Post(
+ Arg.Is(u => u.ToString() == "repositories/1/check-suite-requests"),
+ request,
+ "application/vnd.github.antiope-preview+json");
+ }
+
+ [Fact]
+ public async Task EnsuresNonNullArguments()
+ {
+ var connection = Substitute.For();
+ var client = new CheckSuitesClient(connection);
+
+ var request = new CheckSuiteTriggerRequest("123abc");
+
+ await Assert.ThrowsAsync(() => client.Request(null, "repo", request));
+ await Assert.ThrowsAsync(() => client.Request("fake", null, request));
+ await Assert.ThrowsAsync(() => client.Request("fake", "repo", null));
+
+ await Assert.ThrowsAsync(() => client.Request(1, null));
+ }
+
+ [Fact]
+ public async Task EnsuresNonEmptyArguments()
+ {
+ var connection = Substitute.For();
+ var client = new CheckSuitesClient(connection);
+
+ var request = new CheckSuiteTriggerRequest("123abc");
+
+ await Assert.ThrowsAsync(() => client.Request("", "repo", request));
+ await Assert.ThrowsAsync(() => client.Request("fake", "", request));
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/Octokit.Tests/Clients/ChecksClientTests.cs b/Octokit.Tests/Clients/ChecksClientTests.cs
new file mode 100644
index 0000000000..dfed4391d5
--- /dev/null
+++ b/Octokit.Tests/Clients/ChecksClientTests.cs
@@ -0,0 +1,17 @@
+using System;
+using Xunit;
+
+namespace Octokit.Tests.Clients
+{
+ public class ChecksClientTests
+ {
+ public class TheCtor
+ {
+ [Fact]
+ public void EnsuresNonNullArguments()
+ {
+ Assert.Throws(() => new ChecksClient(null));
+ }
+ }
+ }
+}
diff --git a/Octokit.Tests/Clients/EventsClientTests.cs b/Octokit.Tests/Clients/EventsClientTests.cs
index 803f6fb487..3c9a79d2ac 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
{
+ {"CheckSuiteEvent", typeof(CheckSuiteEventPayload)},
{"CommitCommentEvent", typeof(CommitCommentPayload)},
{"ForkEvent", typeof(ForkEventPayload)},
{"IssueCommentEvent", typeof(IssueCommentPayload)},
diff --git a/Octokit.Tests/Helpers/MockedIApiConnection.cs b/Octokit.Tests/Helpers/MockedIApiConnection.cs
new file mode 100644
index 0000000000..8d40a37f5d
--- /dev/null
+++ b/Octokit.Tests/Helpers/MockedIApiConnection.cs
@@ -0,0 +1,21 @@
+using System;
+using System.Net;
+using NSubstitute;
+
+namespace Octokit.Tests.Helpers
+{
+ public static class MockedIApiConnection
+ {
+ public static IApiConnection PostReturnsHttpStatus(HttpStatusCode status)
+ {
+ var connection = Substitute.For();
+ connection.Post(Arg.Any(), Arg.Any