From 48aaa42f76fad00fcb8c97655929f606fe6e2347 Mon Sep 17 00:00:00 2001 From: Alexander Sklar Date: Tue, 30 May 2023 16:28:06 -0700 Subject: [PATCH 1/5] add basic codespaces api --- .../Clients/CodespacesClientTests.cs | 60 ++++++++++++++ Octokit.Tests.Integration/Helper.cs | 5 ++ .../Clients/CodespacesClientTests.cs | 64 +++++++++++++++ Octokit/Clients/Codespace.cs | 24 ++++++ Octokit/Clients/CodespaceState.cs | 23 ++++++ Octokit/Clients/CodespacesClient.cs | 80 +++++++++++++++++++ Octokit/Clients/CodespacesCollection.cs | 14 ++++ Octokit/Clients/ICodespacesClient.cs | 14 ++++ Octokit/Clients/Machine.cs | 12 +++ Octokit/GitHubClient.cs | 4 + Octokit/Helpers/ApiUrls.cs | 25 ++++++ Octokit/Http/SimpleJsonSerializer.cs | 1 + Octokit/IGitHubClient.cs | 5 +- script/configure-integration-tests.ps1 | 4 +- 14 files changed, 333 insertions(+), 2 deletions(-) create mode 100644 Octokit.Tests.Integration/Clients/CodespacesClientTests.cs create mode 100644 Octokit.Tests/Clients/CodespacesClientTests.cs create mode 100644 Octokit/Clients/Codespace.cs create mode 100644 Octokit/Clients/CodespaceState.cs create mode 100644 Octokit/Clients/CodespacesClient.cs create mode 100644 Octokit/Clients/CodespacesCollection.cs create mode 100644 Octokit/Clients/ICodespacesClient.cs create mode 100644 Octokit/Clients/Machine.cs diff --git a/Octokit.Tests.Integration/Clients/CodespacesClientTests.cs b/Octokit.Tests.Integration/Clients/CodespacesClientTests.cs new file mode 100644 index 0000000000..8cc26a4610 --- /dev/null +++ b/Octokit.Tests.Integration/Clients/CodespacesClientTests.cs @@ -0,0 +1,60 @@ +using System; +using System.Linq; +using System.Threading.Tasks; +using Octokit; +using Octokit.Clients; +using Octokit.Tests.Helpers; +using Octokit.Tests.Integration; +using Xunit; + +public class CodespacesClientTests +{ + readonly ICodespacesClient _fixture; + + public CodespacesClientTests() + { + var github = Helper.GetAuthenticatedClient(); + _fixture = github.Codespaces; + } + + [IntegrationTest] + public async Task CanGetCodespaces() + { + var retrieved = await _fixture.GetAll(); + Assert.NotNull(retrieved); + } + + [IntegrationTest] + public async Task CanGetCodespacesForRepo() + { + var retrieved = await _fixture.GetForRepository(Helper.UserName, Helper.RepositoryWithCodespaces); + Assert.NotNull(retrieved); + } + + [IntegrationTest] + public async Task CanGetCodespaceByName() + { + var collection = await _fixture.GetForRepository(Helper.UserName, Helper.RepositoryWithCodespaces); + var codespaceName = collection.Codespaces.First().Name; + var retrieved = await _fixture.Get(codespaceName); + Assert.NotNull(retrieved); + } + + [IntegrationTest] + public async Task CanStartCodespace() + { + var collection = await _fixture.GetForRepository(Helper.UserName, Helper.RepositoryWithCodespaces); + var codespaceName = collection.Codespaces.First().Name; + var retrieved = await _fixture.Start(codespaceName); + Assert.NotNull(retrieved); + } + + [IntegrationTest] + public async Task CanStopCodespace() + { + var collection = await _fixture.GetForRepository(Helper.UserName, Helper.RepositoryWithCodespaces); + var codespaceName = collection.Codespaces.First().Name; + var retrieved = await _fixture.Stop(codespaceName); + Assert.NotNull(retrieved); + } +} diff --git a/Octokit.Tests.Integration/Helper.cs b/Octokit.Tests.Integration/Helper.cs index 9c94d78f64..001613cdf8 100644 --- a/Octokit.Tests.Integration/Helper.cs +++ b/Octokit.Tests.Integration/Helper.cs @@ -171,6 +171,11 @@ public static string GitHubAppSlug get { return Environment.GetEnvironmentVariable("OCTOKIT_GITHUBAPP_SLUG"); } } + public static string RepositoryWithCodespaces + { + get { return Environment.GetEnvironmentVariable("OCTOKIT_REPOSITORY_WITH_CODESPACES"); } + } + public static void DeleteRepo(IConnection connection, Repository repository) { if (repository != null) diff --git a/Octokit.Tests/Clients/CodespacesClientTests.cs b/Octokit.Tests/Clients/CodespacesClientTests.cs new file mode 100644 index 0000000000..c699467033 --- /dev/null +++ b/Octokit.Tests/Clients/CodespacesClientTests.cs @@ -0,0 +1,64 @@ +using System; +using System.Collections.Generic; +using System.Net; +using System.Threading.Tasks; +using NSubstitute; +using Octokit.Internal; +using Octokit; +using Octokit.Tests; +using Xunit; + +using static Octokit.Internal.TestSetup; +using Octokit.Clients; + +public class CodespacesClientTests +{ + public class TheGetAllMethod + { + [Fact] + public void RequestsCorrectGetAllUrl() + { + var connection = Substitute.For(); + var client = new CodespacesClient(connection); + + client.GetAll(); + connection.Received().Get(Arg.Is(u => u.ToString() == "user/codespaces")); + } + + [Fact] + public void RequestsCorrectGetForRepositoryUrl() + { + var connection = Substitute.For(); + var client = new CodespacesClient(connection); + client.GetForRepository("owner", "repo"); + connection.Received().Get(Arg.Is(u => u.ToString() == "repos/owner/repo/codespaces")); + } + + [Fact] + public void RequestsCorrectGetUrl() + { + var connection = Substitute.For(); + var client = new CodespacesClient(connection); + client.Get("codespaceName"); + connection.Received().Get(Arg.Is(u => u.ToString() == "user/codespaces/codespaceName")); + } + + [Fact] + public void RequestsCorrectStartUrl() + { + var connection = Substitute.For(); + var client = new CodespacesClient(connection); + client.Start("codespaceName"); + connection.Received().Post(Arg.Is(u => u.ToString() == "user/codespaces/codespaceName/start")); + } + + [Fact] + public void RequestsCorrectStopUrl() + { + var connection = Substitute.For(); + var client = new CodespacesClient(connection); + client.Stop("codespaceName"); + connection.Received().Post(Arg.Is(u => u.ToString() == "user/codespaces/codespaceName/stop")); + } + } +} diff --git a/Octokit/Clients/Codespace.cs b/Octokit/Clients/Codespace.cs new file mode 100644 index 0000000000..368cf77f63 --- /dev/null +++ b/Octokit/Clients/Codespace.cs @@ -0,0 +1,24 @@ +using System; +using System.Runtime.CompilerServices; + +namespace Octokit.Clients +{ + public class Codespace + { + public int Id { get; private set; } + public string Name { get; private set; } + public User Owner { get; private set; } + public User BillableOwner { get; private set; } + public Repository Repository { get; private set; } + public Machine Machine { get; private set; } + public DateTime CreatedAt { get;private set; } + public DateTime UpdatedAt { get; private set; } + public DateTime LastUsedAt { get; private set; } + public CodespaceState State { get; private set; } + public string Url { get; private set; } + public string MachinesUrl { get; private set; } + public string WebUrl { get; private set; } + public string StartUrl { get; private set; } + public string StopUrl { get; private set; } + } +} \ No newline at end of file diff --git a/Octokit/Clients/CodespaceState.cs b/Octokit/Clients/CodespaceState.cs new file mode 100644 index 0000000000..ab701aa544 --- /dev/null +++ b/Octokit/Clients/CodespaceState.cs @@ -0,0 +1,23 @@ +namespace Octokit.Clients +{ + public enum CodespaceState + { + Unknown, + Created, + Queued, + Provisioning, + Available, + Awaiting, + Unavailable, + Deleted, + Moved, + Shutdown, + Archived, + Starting, + ShuttingDown, + Failed, + Exporting, + Updating, + Rebuilding, + } +} \ No newline at end of file diff --git a/Octokit/Clients/CodespacesClient.cs b/Octokit/Clients/CodespacesClient.cs new file mode 100644 index 0000000000..eb1ed04662 --- /dev/null +++ b/Octokit/Clients/CodespacesClient.cs @@ -0,0 +1,80 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.Threading.Tasks; + +namespace Octokit.Clients +{ + /// + /// A client for GitHub's Codespaces API. + /// Gets and creates Codespaces. + /// + /// + /// See the Codespaces API documentation for more information. + /// + internal class CodespacesClient : ApiClient, ICodespacesClient + { + /// + /// Instantiates a new GitHub Codespaces API client. + /// + /// + public CodespacesClient(IApiConnection apiConnection) : base(apiConnection) + { + } + + /// + /// Returns all the codespaces for the authenticated user. + /// + /// A codespaces collection + [ManualRoute("GET", "/user/codespaces")] + public Task GetAll() + { + return ApiConnection.Get(ApiUrls.Codespaces()); + } + + /// + /// Returns all the codespaces for the specified repository. + /// + /// + /// + /// A codespaces collection + [ManualRoute("GET", "/repos/{owner}/{repo}/codespaces")] + public Task GetForRepository(string owner, string repo) + { + return ApiConnection.Get(ApiUrls.CodespacesForRepository(owner, repo)); + } + + /// + /// Gets a codespace for the authenticated user. + /// + /// + /// A codespace + [ManualRoute("GET", "/user/codespaces/{codespace_name}")] + public Task Get(string codespaceName) + { + return ApiConnection.Get(ApiUrls.Codespace(codespaceName)); + } + + /// + /// Starts a codespace for the authenticated user. + /// + /// + /// + [ManualRoute("POST", "/user/codespaces/{codespace_name}/start")] + public Task Start(string codespaceName) + { + return ApiConnection.Post(ApiUrls.CodespaceStart(codespaceName)); + } + + /// + /// Stops a codespace for the authenticated user. + /// + /// + /// + [ManualRoute("POST", "/user/codespaces/{codespace_name}/stop")] + public Task Stop(string codespaceName) + { + return ApiConnection.Post(ApiUrls.CodespaceStop(codespaceName)); + } + } +} diff --git a/Octokit/Clients/CodespacesCollection.cs b/Octokit/Clients/CodespacesCollection.cs new file mode 100644 index 0000000000..5f50fe463f --- /dev/null +++ b/Octokit/Clients/CodespacesCollection.cs @@ -0,0 +1,14 @@ +using Octokit.Internal; +using System.Collections.Generic; + +namespace Octokit.Clients +{ + public class CodespacesCollection + { + public CodespacesCollection() { } + [Parameter(Key = "total_count")] + public int Count { get; private set; } + [Parameter(Key = "codespaces")] + public IReadOnlyList Codespaces { get; private set; } + } +} \ No newline at end of file diff --git a/Octokit/Clients/ICodespacesClient.cs b/Octokit/Clients/ICodespacesClient.cs new file mode 100644 index 0000000000..ba8892c980 --- /dev/null +++ b/Octokit/Clients/ICodespacesClient.cs @@ -0,0 +1,14 @@ +using System.Collections.Generic; +using System.Threading.Tasks; + +namespace Octokit.Clients +{ + public interface ICodespacesClient + { + Task GetAll(); + Task GetForRepository(string owner, string repo); + Task Get(string codespaceName); + Task Start(string codespaceName); + Task Stop(string codespaceName); + } +} \ No newline at end of file diff --git a/Octokit/Clients/Machine.cs b/Octokit/Clients/Machine.cs new file mode 100644 index 0000000000..e9b9c99c61 --- /dev/null +++ b/Octokit/Clients/Machine.cs @@ -0,0 +1,12 @@ +namespace Octokit.Clients +{ + public class Machine + { + public string Name { get; private set; } + public string DisplayName { get; private set; } + public string OperatingSystem { get; private set; } + public long StorageInBytes { get; private set; } + public long MemoryInBytes { get; private set; } + public long CpuCount { get; private set; } + } +} \ No newline at end of file diff --git a/Octokit/GitHubClient.cs b/Octokit/GitHubClient.cs index 367dbdf5c1..f2b9863a4b 100644 --- a/Octokit/GitHubClient.cs +++ b/Octokit/GitHubClient.cs @@ -1,5 +1,6 @@ using System; using Octokit.Caching; +using Octokit.Clients; using Octokit.Internal; namespace Octokit @@ -120,6 +121,7 @@ public GitHubClient(IConnection connection) RateLimit = new RateLimitClient(apiConnection); Meta = new MetaClient(apiConnection); Actions = new ActionsClient(apiConnection); + Codespaces = new CodespacesClient(apiConnection); } /// @@ -393,6 +395,8 @@ public Uri BaseAddress /// public IActionsClient Actions { get; private set; } + public ICodespacesClient Codespaces { get; private set; } + static Uri FixUpBaseUri(Uri uri) { Ensure.ArgumentNotNull(uri, nameof(uri)); diff --git a/Octokit/Helpers/ApiUrls.cs b/Octokit/Helpers/ApiUrls.cs index 0c870a42c7..20765f96cc 100644 --- a/Octokit/Helpers/ApiUrls.cs +++ b/Octokit/Helpers/ApiUrls.cs @@ -17,6 +17,7 @@ public static partial class ApiUrls static readonly Uri _currentUserNotificationsEndpoint = new Uri("notifications", UriKind.Relative); static readonly Uri _currentUserAllIssues = new Uri("issues", UriKind.Relative); static readonly Uri _currentUserOwnedAndMemberIssues = new Uri("user/issues", UriKind.Relative); + static readonly Uri _currentUserAllCodespaces = new Uri("user/codespaces", UriKind.Relative); /// /// Returns the that returns all public repositories in @@ -5447,5 +5448,29 @@ public static Uri ActionsListOrganizationRunnerGroupRepositories(string org, lon return "orgs/{0}/actions/runner-groups/{1}/repositories".FormatUri(org, runnerGroupId); } + public static Uri Codespaces() + { + return _currentUserAllCodespaces; + } + + public static Uri CodespacesForRepository(string owner, string repo) + { + return "repos/{0}/{1}/codespaces".FormatUri(owner, repo); + } + + public static Uri Codespace(string codespaceName) + { + return "user/codespaces/{0}".FormatUri(codespaceName); + } + + public static Uri CodespaceStart(string codespaceName) + { + return "user/codespaces/{0}/start".FormatUri(codespaceName); + } + + public static Uri CodespaceStop(string codespaceName) + { + return "user/codespaces/{0}/stop".FormatUri(codespaceName); + } } } diff --git a/Octokit/Http/SimpleJsonSerializer.cs b/Octokit/Http/SimpleJsonSerializer.cs index b4bb555828..751a924ce5 100644 --- a/Octokit/Http/SimpleJsonSerializer.cs +++ b/Octokit/Http/SimpleJsonSerializer.cs @@ -5,6 +5,7 @@ using System.Linq; using System.Reflection; using Octokit.Reflection; +using Octokit.Clients; namespace Octokit.Internal { diff --git a/Octokit/IGitHubClient.cs b/Octokit/IGitHubClient.cs index 9bd53eb802..5780017cb8 100644 --- a/Octokit/IGitHubClient.cs +++ b/Octokit/IGitHubClient.cs @@ -1,4 +1,5 @@ -using System; +using Octokit.Clients; +using System; namespace Octokit { @@ -215,5 +216,7 @@ public interface IGitHubClient : IApiInfoProvider /// ILicensesClient Licenses { get; } IEmojisClient Emojis { get; } + + ICodespacesClient Codespaces { get; } } } diff --git a/script/configure-integration-tests.ps1 b/script/configure-integration-tests.ps1 index 4a3d6cdd6d..6a4f07aa5c 100644 --- a/script/configure-integration-tests.ps1 +++ b/script/configure-integration-tests.ps1 @@ -118,4 +118,6 @@ if (AskYesNoQuestion "Do you wish to enable GitHub Enterprise (GHE) Integration VerifyEnvironmentVariable "GitHub Enterprise application ClientID" "OCTOKIT_GHE_CLIENTID" $true VerifyEnvironmentVariable "GitHub Enterprise application Secret" "OCTOKIT_GHE_CLIENTSECRET" $true -} \ No newline at end of file +} + +VerifyEnvironmentVariable "Repository with codespaces" "OCTOKIT_REPOSITORY_WITH_CODESPACES" $true From ed9548584fbe0a60d9c369fb9130eaae27930ca3 Mon Sep 17 00:00:00 2001 From: Alexander Sklar Date: Thu, 1 Jun 2023 14:07:48 -0700 Subject: [PATCH 2/5] fix test failure due to CodespacesClient not being marked public --- Octokit/Clients/CodespacesClient.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Octokit/Clients/CodespacesClient.cs b/Octokit/Clients/CodespacesClient.cs index eb1ed04662..5adc743e4a 100644 --- a/Octokit/Clients/CodespacesClient.cs +++ b/Octokit/Clients/CodespacesClient.cs @@ -12,7 +12,7 @@ namespace Octokit.Clients /// /// See the Codespaces API documentation for more information. /// - internal class CodespacesClient : ApiClient, ICodespacesClient + public class CodespacesClient : ApiClient, ICodespacesClient { /// /// Instantiates a new GitHub Codespaces API client. From f8ac35113a2399e4935fde412c8dcc345efcba8e Mon Sep 17 00:00:00 2001 From: Alexander Sklar Date: Fri, 2 Jun 2023 11:45:33 -0700 Subject: [PATCH 3/5] add empty ObservableCodespacesClient --- Octokit.Reactive/IObservableCodespacesClient.cs | 12 ++++++++++++ Octokit.Reactive/IObservableGitHubClient.cs | 1 + Octokit.Reactive/ObservableCodespacesClient.cs | 12 ++++++++++++ Octokit.Reactive/ObservableGitHubClient.cs | 2 ++ 4 files changed, 27 insertions(+) create mode 100644 Octokit.Reactive/IObservableCodespacesClient.cs create mode 100644 Octokit.Reactive/ObservableCodespacesClient.cs diff --git a/Octokit.Reactive/IObservableCodespacesClient.cs b/Octokit.Reactive/IObservableCodespacesClient.cs new file mode 100644 index 0000000000..45feb5942a --- /dev/null +++ b/Octokit.Reactive/IObservableCodespacesClient.cs @@ -0,0 +1,12 @@ +namespace Octokit.Reactive +{ + /// + /// A client for GitHub's Codespaces API. + /// + /// + /// See the codespaces API documentation for more information. + /// + public interface IObservableCodespacesClient + { + } +} \ No newline at end of file diff --git a/Octokit.Reactive/IObservableGitHubClient.cs b/Octokit.Reactive/IObservableGitHubClient.cs index 10cd16e933..bc610f7fca 100644 --- a/Octokit.Reactive/IObservableGitHubClient.cs +++ b/Octokit.Reactive/IObservableGitHubClient.cs @@ -42,5 +42,6 @@ public interface IObservableGitHubClient : IApiInfoProvider IObservableRateLimitClient RateLimit { get; } IObservableMetaClient Meta { get; } IObservableActionsClient Actions { get; } + IObservableCodespacesClient Codespaces { get; } } } diff --git a/Octokit.Reactive/ObservableCodespacesClient.cs b/Octokit.Reactive/ObservableCodespacesClient.cs new file mode 100644 index 0000000000..b0f4ee5b6d --- /dev/null +++ b/Octokit.Reactive/ObservableCodespacesClient.cs @@ -0,0 +1,12 @@ +namespace Octokit.Reactive +{ + public class ObservableCodespacesClient : IObservableCodespacesClient + { + private IGitHubClient githubClient; + + public ObservableCodespacesClient(IGitHubClient githubClient) + { + this.githubClient = githubClient; + } + } +} \ No newline at end of file diff --git a/Octokit.Reactive/ObservableGitHubClient.cs b/Octokit.Reactive/ObservableGitHubClient.cs index 7507a382cf..7b8da221a3 100644 --- a/Octokit.Reactive/ObservableGitHubClient.cs +++ b/Octokit.Reactive/ObservableGitHubClient.cs @@ -57,6 +57,7 @@ public ObservableGitHubClient(IGitHubClient gitHubClient) RateLimit = new ObservableRateLimitClient(gitHubClient); Meta = new ObservableMetaClient(gitHubClient); Actions = new ObservableActionsClient(gitHubClient); + Codespaces = new ObservableCodespacesClient(gitHubClient); } public IConnection Connection @@ -105,6 +106,7 @@ public void SetRequestTimeout(TimeSpan timeout) public IObservableMetaClient Meta { get; private set; } public IObservableActionsClient Actions { get; private set; } + public IObservableCodespacesClient Codespaces { get; private set; } /// /// Gets the latest API Info - this will be null if no API calls have been made /// From 7cf0e3a3419d55f7290c106fd96ff966ecda7b72 Mon Sep 17 00:00:00 2001 From: Alexander Sklar Date: Tue, 6 Jun 2023 02:04:23 -0700 Subject: [PATCH 4/5] fix for convention tests --- .../Clients/CodespacesClientTests.cs | 1 - Octokit.Tests/Clients/CodespacesClientTests.cs | 10 +++++++++- Octokit/Clients/Codespace.cs | 2 +- Octokit/Clients/CodespaceState.cs | 2 +- Octokit/Clients/CodespacesClient.cs | 2 +- Octokit/Clients/CodespacesCollection.cs | 2 +- Octokit/Clients/ICodespacesClient.cs | 2 +- Octokit/Clients/Machine.cs | 2 +- Octokit/GitHubClient.cs | 1 - Octokit/Http/SimpleJsonSerializer.cs | 1 - Octokit/IGitHubClient.cs | 3 +-- 11 files changed, 16 insertions(+), 12 deletions(-) diff --git a/Octokit.Tests.Integration/Clients/CodespacesClientTests.cs b/Octokit.Tests.Integration/Clients/CodespacesClientTests.cs index 8cc26a4610..f1b6342384 100644 --- a/Octokit.Tests.Integration/Clients/CodespacesClientTests.cs +++ b/Octokit.Tests.Integration/Clients/CodespacesClientTests.cs @@ -2,7 +2,6 @@ using System.Linq; using System.Threading.Tasks; using Octokit; -using Octokit.Clients; using Octokit.Tests.Helpers; using Octokit.Tests.Integration; using Xunit; diff --git a/Octokit.Tests/Clients/CodespacesClientTests.cs b/Octokit.Tests/Clients/CodespacesClientTests.cs index c699467033..41fad4a51c 100644 --- a/Octokit.Tests/Clients/CodespacesClientTests.cs +++ b/Octokit.Tests/Clients/CodespacesClientTests.cs @@ -9,10 +9,18 @@ using Xunit; using static Octokit.Internal.TestSetup; -using Octokit.Clients; public class CodespacesClientTests { + public class TheCtor + { + [Fact] + public void EnsuresNonNullArguments() + { + Assert.Throws(() => new CodespacesClient(null)); + } + } + public class TheGetAllMethod { [Fact] diff --git a/Octokit/Clients/Codespace.cs b/Octokit/Clients/Codespace.cs index 368cf77f63..fd27fc3b94 100644 --- a/Octokit/Clients/Codespace.cs +++ b/Octokit/Clients/Codespace.cs @@ -1,7 +1,7 @@ using System; using System.Runtime.CompilerServices; -namespace Octokit.Clients +namespace Octokit { public class Codespace { diff --git a/Octokit/Clients/CodespaceState.cs b/Octokit/Clients/CodespaceState.cs index ab701aa544..48774a9291 100644 --- a/Octokit/Clients/CodespaceState.cs +++ b/Octokit/Clients/CodespaceState.cs @@ -1,4 +1,4 @@ -namespace Octokit.Clients +namespace Octokit { public enum CodespaceState { diff --git a/Octokit/Clients/CodespacesClient.cs b/Octokit/Clients/CodespacesClient.cs index 5adc743e4a..afe47ce8ad 100644 --- a/Octokit/Clients/CodespacesClient.cs +++ b/Octokit/Clients/CodespacesClient.cs @@ -3,7 +3,7 @@ using System.Text; using System.Threading.Tasks; -namespace Octokit.Clients +namespace Octokit { /// /// A client for GitHub's Codespaces API. diff --git a/Octokit/Clients/CodespacesCollection.cs b/Octokit/Clients/CodespacesCollection.cs index 5f50fe463f..e9391e21c1 100644 --- a/Octokit/Clients/CodespacesCollection.cs +++ b/Octokit/Clients/CodespacesCollection.cs @@ -1,7 +1,7 @@ using Octokit.Internal; using System.Collections.Generic; -namespace Octokit.Clients +namespace Octokit { public class CodespacesCollection { diff --git a/Octokit/Clients/ICodespacesClient.cs b/Octokit/Clients/ICodespacesClient.cs index ba8892c980..a3c630d5b7 100644 --- a/Octokit/Clients/ICodespacesClient.cs +++ b/Octokit/Clients/ICodespacesClient.cs @@ -1,7 +1,7 @@ using System.Collections.Generic; using System.Threading.Tasks; -namespace Octokit.Clients +namespace Octokit { public interface ICodespacesClient { diff --git a/Octokit/Clients/Machine.cs b/Octokit/Clients/Machine.cs index e9b9c99c61..38948dc42e 100644 --- a/Octokit/Clients/Machine.cs +++ b/Octokit/Clients/Machine.cs @@ -1,4 +1,4 @@ -namespace Octokit.Clients +namespace Octokit { public class Machine { diff --git a/Octokit/GitHubClient.cs b/Octokit/GitHubClient.cs index f2b9863a4b..2a839b3b1f 100644 --- a/Octokit/GitHubClient.cs +++ b/Octokit/GitHubClient.cs @@ -1,6 +1,5 @@ using System; using Octokit.Caching; -using Octokit.Clients; using Octokit.Internal; namespace Octokit diff --git a/Octokit/Http/SimpleJsonSerializer.cs b/Octokit/Http/SimpleJsonSerializer.cs index 751a924ce5..b4bb555828 100644 --- a/Octokit/Http/SimpleJsonSerializer.cs +++ b/Octokit/Http/SimpleJsonSerializer.cs @@ -5,7 +5,6 @@ using System.Linq; using System.Reflection; using Octokit.Reflection; -using Octokit.Clients; namespace Octokit.Internal { diff --git a/Octokit/IGitHubClient.cs b/Octokit/IGitHubClient.cs index 5780017cb8..0fe8d3d3af 100644 --- a/Octokit/IGitHubClient.cs +++ b/Octokit/IGitHubClient.cs @@ -1,5 +1,4 @@ -using Octokit.Clients; -using System; +using System; namespace Octokit { From 72e6dc44a21ceff89e0ec11d1893cffcb4cf21f9 Mon Sep 17 00:00:00 2001 From: Alexander Sklar Date: Tue, 6 Jun 2023 20:59:07 -0700 Subject: [PATCH 5/5] tests pass --- .../IObservableCodespacesClient.cs | 10 ++++- .../ObservableCodespacesClient.cs | 41 +++++++++++++++++-- Octokit/Clients/Codespace.cs | 27 +++++++++++- Octokit/Clients/CodespaceState.cs | 21 +++++++++- Octokit/Clients/CodespacesCollection.cs | 14 ++++++- Octokit/Clients/Machine.cs | 20 ++++++++- 6 files changed, 125 insertions(+), 8 deletions(-) diff --git a/Octokit.Reactive/IObservableCodespacesClient.cs b/Octokit.Reactive/IObservableCodespacesClient.cs index 45feb5942a..cb3e67ba25 100644 --- a/Octokit.Reactive/IObservableCodespacesClient.cs +++ b/Octokit.Reactive/IObservableCodespacesClient.cs @@ -1,4 +1,7 @@ -namespace Octokit.Reactive +using System; +using System.Threading.Tasks; + +namespace Octokit.Reactive { /// /// A client for GitHub's Codespaces API. @@ -8,5 +11,10 @@ /// public interface IObservableCodespacesClient { + IObservable GetAll(); + IObservable GetForRepository(string owner, string repo); + IObservable Get(string codespaceName); + IObservable Start(string codespaceName); + IObservable Stop(string codespaceName); } } \ No newline at end of file diff --git a/Octokit.Reactive/ObservableCodespacesClient.cs b/Octokit.Reactive/ObservableCodespacesClient.cs index b0f4ee5b6d..74ce55a872 100644 --- a/Octokit.Reactive/ObservableCodespacesClient.cs +++ b/Octokit.Reactive/ObservableCodespacesClient.cs @@ -1,12 +1,47 @@ -namespace Octokit.Reactive +using System; +using System.Reactive.Threading.Tasks; + +namespace Octokit.Reactive { public class ObservableCodespacesClient : IObservableCodespacesClient { - private IGitHubClient githubClient; + private ICodespacesClient _client; + private IConnection _connection; public ObservableCodespacesClient(IGitHubClient githubClient) { - this.githubClient = githubClient; + _client = githubClient.Codespaces; + _connection = githubClient.Connection; + } + + public IObservable Get(string codespaceName) + { + Ensure.ArgumentNotNull(codespaceName, nameof(codespaceName)); + return _client.Get(codespaceName).ToObservable(); + } + + public IObservable GetAll() + { + return _client.GetAll().ToObservable(); + } + + public IObservable GetForRepository(string owner, string repo) + { + Ensure.ArgumentNotNull(owner, nameof(owner)); + Ensure.ArgumentNotNull(repo, nameof(repo)); + return _client.GetForRepository(owner, repo).ToObservable(); + } + + public IObservable Start(string codespaceName) + { + Ensure.ArgumentNotNull(codespaceName, nameof(codespaceName)); + return _client.Start(codespaceName).ToObservable(); + } + + public IObservable Stop(string codespaceName) + { + Ensure.ArgumentNotNull(codespaceName, nameof(codespaceName)); + return _client.Stop(codespaceName).ToObservable(); } } } \ No newline at end of file diff --git a/Octokit/Clients/Codespace.cs b/Octokit/Clients/Codespace.cs index fd27fc3b94..e0a3da4ce0 100644 --- a/Octokit/Clients/Codespace.cs +++ b/Octokit/Clients/Codespace.cs @@ -1,8 +1,11 @@ using System; +using System.Diagnostics; +using System.Globalization; using System.Runtime.CompilerServices; namespace Octokit { + [DebuggerDisplay("{DebuggerDisplay,nq}")] public class Codespace { public int Id { get; private set; } @@ -14,11 +17,33 @@ public class Codespace public DateTime CreatedAt { get;private set; } public DateTime UpdatedAt { get; private set; } public DateTime LastUsedAt { get; private set; } - public CodespaceState State { get; private set; } + public StringEnum State { get; private set; } public string Url { get; private set; } public string MachinesUrl { get; private set; } public string WebUrl { get; private set; } public string StartUrl { get; private set; } public string StopUrl { get; private set; } + + public Codespace(int id, string name, User owner, User billableOwner, Repository repository, Machine machine, DateTime createdAt, DateTime updatedAt, DateTime lastUsedAt, StringEnum state, string url, string machinesUrl, string webUrl, string startUrl, string stopUrl) + { + Id = id; + Name = name; + Owner = owner; + BillableOwner = billableOwner; + Repository = repository; + Machine = machine; + CreatedAt = createdAt; + UpdatedAt = updatedAt; + LastUsedAt = lastUsedAt; + State = state; + Url = url; + MachinesUrl = machinesUrl; + WebUrl = webUrl; + StartUrl = startUrl; + StopUrl = stopUrl; + } + + public Codespace() { } + internal string DebuggerDisplay => string.Format(CultureInfo.CurrentCulture, "Codespace: Id: {0}", Id); } } \ No newline at end of file diff --git a/Octokit/Clients/CodespaceState.cs b/Octokit/Clients/CodespaceState.cs index 48774a9291..1cff50d5cf 100644 --- a/Octokit/Clients/CodespaceState.cs +++ b/Octokit/Clients/CodespaceState.cs @@ -1,23 +1,42 @@ -namespace Octokit +using Octokit.Internal; + +namespace Octokit { public enum CodespaceState { + [Parameter(Value = "Unknown")] Unknown, + [Parameter(Value = "Created")] Created, + [Parameter(Value = "Queued")] Queued, + [Parameter(Value = "Provisioning")] Provisioning, + [Parameter(Value = "Available")] Available, + [Parameter(Value = "Awaiting")] Awaiting, + [Parameter(Value = "Unavailable")] Unavailable, + [Parameter(Value = "Deleted")] Deleted, + [Parameter(Value = "Moved")] Moved, + [Parameter(Value = "Shutdown")] Shutdown, + [Parameter(Value = "Archived")] Archived, + [Parameter(Value = "Starting")] Starting, + [Parameter(Value = "ShuttingDown")] ShuttingDown, + [Parameter(Value = "Failed")] Failed, + [Parameter(Value = "Exporting")] Exporting, + [Parameter(Value = "Updating")] Updating, + [Parameter(Value = "Rebuilding")] Rebuilding, } } \ No newline at end of file diff --git a/Octokit/Clients/CodespacesCollection.cs b/Octokit/Clients/CodespacesCollection.cs index e9391e21c1..e91282ab53 100644 --- a/Octokit/Clients/CodespacesCollection.cs +++ b/Octokit/Clients/CodespacesCollection.cs @@ -1,14 +1,26 @@ using Octokit.Internal; using System.Collections.Generic; +using System.Diagnostics; +using System.Globalization; namespace Octokit { + [DebuggerDisplay("{DebuggerDisplay,nq}")] public class CodespacesCollection { + public CodespacesCollection(IReadOnlyList codespaces, int count) + { + Codespaces = codespaces; + Count = count; + } + public CodespacesCollection() { } + [Parameter(Key = "total_count")] public int Count { get; private set; } [Parameter(Key = "codespaces")] - public IReadOnlyList Codespaces { get; private set; } + public IReadOnlyList Codespaces { get; private set; } = new List(); + + internal string DebuggerDisplay => string.Format(CultureInfo.CurrentCulture, "CodespacesCollection: Count: {0}", Count); } } \ No newline at end of file diff --git a/Octokit/Clients/Machine.cs b/Octokit/Clients/Machine.cs index 38948dc42e..2153ffbb2f 100644 --- a/Octokit/Clients/Machine.cs +++ b/Octokit/Clients/Machine.cs @@ -1,5 +1,9 @@ -namespace Octokit +using System.Diagnostics; +using System.Globalization; + +namespace Octokit { + [DebuggerDisplay("{DebuggerDisplay,nq}")] public class Machine { public string Name { get; private set; } @@ -8,5 +12,19 @@ public class Machine public long StorageInBytes { get; private set; } public long MemoryInBytes { get; private set; } public long CpuCount { get; private set; } + + public Machine(string name, string displayName, string operatingSystem, long storageInBytes, long memoryInBytes, long cpuCount) + { + Name = name; + DisplayName = displayName; + OperatingSystem = operatingSystem; + StorageInBytes = storageInBytes; + MemoryInBytes = memoryInBytes; + CpuCount = cpuCount; + } + + public Machine() { } + + internal string DebuggerDisplay => string.Format(CultureInfo.CurrentCulture, "Machine: {0}", DisplayName); } } \ No newline at end of file