forked from octokit/octokit.net
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
480 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using System; | ||
using System.Threading.Tasks; | ||
|
||
namespace Octokit.Reactive | ||
{ | ||
/// <summary> | ||
/// A client for GitHub's Codespaces API. | ||
/// </summary> | ||
/// <remarks> | ||
/// See the codespaces API documentation for more information. | ||
/// </remarks> | ||
public interface IObservableCodespacesClient | ||
{ | ||
IObservable<CodespacesCollection> GetAll(); | ||
IObservable<CodespacesCollection> GetForRepository(string owner, string repo); | ||
IObservable<Codespace> Get(string codespaceName); | ||
IObservable<Codespace> Start(string codespaceName); | ||
IObservable<Codespace> Stop(string codespaceName); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
using System; | ||
using System.Reactive.Threading.Tasks; | ||
|
||
namespace Octokit.Reactive | ||
{ | ||
public class ObservableCodespacesClient : IObservableCodespacesClient | ||
{ | ||
private ICodespacesClient _client; | ||
private IConnection _connection; | ||
|
||
public ObservableCodespacesClient(IGitHubClient githubClient) | ||
{ | ||
_client = githubClient.Codespaces; | ||
_connection = githubClient.Connection; | ||
} | ||
|
||
public IObservable<Codespace> Get(string codespaceName) | ||
{ | ||
Ensure.ArgumentNotNull(codespaceName, nameof(codespaceName)); | ||
return _client.Get(codespaceName).ToObservable(); | ||
} | ||
|
||
public IObservable<CodespacesCollection> GetAll() | ||
{ | ||
return _client.GetAll().ToObservable(); | ||
} | ||
|
||
public IObservable<CodespacesCollection> GetForRepository(string owner, string repo) | ||
{ | ||
Ensure.ArgumentNotNull(owner, nameof(owner)); | ||
Ensure.ArgumentNotNull(repo, nameof(repo)); | ||
return _client.GetForRepository(owner, repo).ToObservable(); | ||
} | ||
|
||
public IObservable<Codespace> Start(string codespaceName) | ||
{ | ||
Ensure.ArgumentNotNull(codespaceName, nameof(codespaceName)); | ||
return _client.Start(codespaceName).ToObservable(); | ||
} | ||
|
||
public IObservable<Codespace> Stop(string codespaceName) | ||
{ | ||
Ensure.ArgumentNotNull(codespaceName, nameof(codespaceName)); | ||
return _client.Stop(codespaceName).ToObservable(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
Octokit.Tests.Integration/Clients/CodespacesClientTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
using System; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Octokit; | ||
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
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; | ||
|
||
public class CodespacesClientTests | ||
{ | ||
public class TheCtor | ||
{ | ||
[Fact] | ||
public void EnsuresNonNullArguments() | ||
{ | ||
Assert.Throws<ArgumentNullException>(() => new CodespacesClient(null)); | ||
} | ||
} | ||
|
||
public class TheGetAllMethod | ||
{ | ||
[Fact] | ||
public void RequestsCorrectGetAllUrl() | ||
{ | ||
var connection = Substitute.For<IApiConnection>(); | ||
var client = new CodespacesClient(connection); | ||
|
||
client.GetAll(); | ||
connection.Received().Get<CodespacesCollection>(Arg.Is<Uri>(u => u.ToString() == "user/codespaces")); | ||
} | ||
|
||
[Fact] | ||
public void RequestsCorrectGetForRepositoryUrl() | ||
{ | ||
var connection = Substitute.For<IApiConnection>(); | ||
var client = new CodespacesClient(connection); | ||
client.GetForRepository("owner", "repo"); | ||
connection.Received().Get<CodespacesCollection>(Arg.Is<Uri>(u => u.ToString() == "repos/owner/repo/codespaces")); | ||
} | ||
|
||
[Fact] | ||
public void RequestsCorrectGetUrl() | ||
{ | ||
var connection = Substitute.For<IApiConnection>(); | ||
var client = new CodespacesClient(connection); | ||
client.Get("codespaceName"); | ||
connection.Received().Get<Codespace>(Arg.Is<Uri>(u => u.ToString() == "user/codespaces/codespaceName")); | ||
} | ||
|
||
[Fact] | ||
public void RequestsCorrectStartUrl() | ||
{ | ||
var connection = Substitute.For<IApiConnection>(); | ||
var client = new CodespacesClient(connection); | ||
client.Start("codespaceName"); | ||
connection.Received().Post<Codespace>(Arg.Is<Uri>(u => u.ToString() == "user/codespaces/codespaceName/start")); | ||
} | ||
|
||
[Fact] | ||
public void RequestsCorrectStopUrl() | ||
{ | ||
var connection = Substitute.For<IApiConnection>(); | ||
var client = new CodespacesClient(connection); | ||
client.Stop("codespaceName"); | ||
connection.Received().Post<Codespace>(Arg.Is<Uri>(u => u.ToString() == "user/codespaces/codespaceName/stop")); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
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; } | ||
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 StringEnum<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; } | ||
|
||
public Codespace(int id, string name, User owner, User billableOwner, Repository repository, Machine machine, DateTime createdAt, DateTime updatedAt, DateTime lastUsedAt, StringEnum<CodespaceState> 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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
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, | ||
} | ||
} |
Oops, something went wrong.