Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion GitHubExtension.Test/Helpers/TestSetupHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ public static GitHubExtensionCommandsProvider CreateGitHubExtensionCommandsProvi
var mockSignInForm = new Mock<SignInForm>(mockAuthenticationMediator, mockResources, mockDeveloperIdProvider, mockSignInCommand).Object;
var signOutPage = new SignOutPage(mockResources, mockSignOutForm, mockSignOutCommand, mockAuthenticationMediator);
var signInPage = new SignInPage(mockSignInForm, mockResources, mockSignInCommand, mockAuthenticationMediator);
return new GitHubExtensionCommandsProvider(savedSearchesPage, signOutPage, signInPage, mockDeveloperIdProvider, persistentDataManager, mockResources, searchPageFactory, savedSearchesMediator, mockAuthenticationMediator);
var codespacesPage = new CodespacesPage(mockResources, new Client.GitHubClientProvider(mockDeveloperIdProvider));
return new GitHubExtensionCommandsProvider(savedSearchesPage, signOutPage, signInPage, mockDeveloperIdProvider, persistentDataManager, mockResources, searchPageFactory, savedSearchesMediator, mockAuthenticationMediator, codespacesPage);
}
}
37 changes: 37 additions & 0 deletions GitHubExtension/Assets/vscode-insiders.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
41 changes: 41 additions & 0 deletions GitHubExtension/Assets/vscode.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
87 changes: 87 additions & 0 deletions GitHubExtension/Controls/Pages/CodespacesPage.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using GitHubExtension.Client;
using GitHubExtension.Helpers;
using Microsoft.CommandPalette.Extensions;
using Microsoft.CommandPalette.Extensions.Toolkit;
using Octokit;

namespace GitHubExtension.Controls.Pages;

public sealed class CodespacesPage : ListPage
{
private readonly GitHubClientProvider _gitHubClientProvider;
private readonly IResources _resources;

public CodespacesPage(IResources resources, GitHubClientProvider gitHubClientProvider)
{
_gitHubClientProvider = gitHubClientProvider;
_resources = resources;
Icon = GitHubIcon.IconDictionary["logo"];
Title = resources.GetResource("Pages_Codespaces");
Name = Title; // Title is for the Page, Name is for the Command
this.PlaceholderText = resources.GetResource("Pages_Codespaces_Placeholder");
this.IsLoading = true;
}

public override IListItem[] GetItems()
Comment thread
noraa-junker marked this conversation as resolved.
{
CodespacesCollection codespaces = _gitHubClientProvider.GetClientForLoggedInDeveloper().Result.Codespaces.GetAll().Result;
List<IListItem> result = [];
try
{
Comment thread
noraa-junker marked this conversation as resolved.
foreach (Codespace c in codespaces.Codespaces)
{
List<IContextItem> moreCommands = [];

if (IsExecutableInPath("code-insiders"))
{
moreCommands.Add(new CommandContextItem(new OpenUrlCommand("vscode-insiders://github.codespaces/connect?name=" + c.Name + "&windowId=_blank") { Name = _resources.GetResource("Commands_Open_VS_Code_Insiders"), Icon = IconHelpers.FromRelativePath("Assets\\vscode-insiders.svg") }));
}

if (IsExecutableInPath("code"))
{
moreCommands.Add(new CommandContextItem(new OpenUrlCommand("vscode://github.codespaces/connect?name=" + c.Name + "&windowId=_blank") { Name = _resources.GetResource("Commands_Open_VS_Code"), Icon = IconHelpers.FromRelativePath("Assets\\vscode.svg") }));
}
Comment thread
noraa-junker marked this conversation as resolved.

result.Add(new ListItem(new OpenUrlCommand(c.WebUrl))
{
Title = $"{c.Repository.Owner.Login}/{c.Repository.Name}",
Subtitle = $"{c.Name} - {c.Machine.DisplayName} ({c.State.StringValue})",
Icon = GitHubIcon.IconDictionary["logo"],
MoreCommands = [.. moreCommands],
});
}
}
catch (Exception)
{
this.IsLoading = false;
return [new ListItem(new NoOpCommand()) { Title = _resources.GetResource("Message_Codespaces_LoadFail"), Subtitle = _resources.GetResource("Message_Codespaces_LoadFail_Description") }];
}

this.IsLoading = false;
return [.. result];
}

private bool IsExecutableInPath(string searchPath)
{
var values = Environment.GetEnvironmentVariable("PATH");
if (values is null)
{
return false;
}

foreach (var path in values.Split(Path.PathSeparator))
{
var fullPath = Path.Combine(path, searchPath);
if (File.Exists(fullPath))
{
return true;
}
}

return false;
}
}
Comment thread
noraa-junker marked this conversation as resolved.
2 changes: 1 addition & 1 deletion GitHubExtension/DeveloperId/OAuthRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ private Uri CreateOauthRequestUri()

var request = new OauthLoginRequest(OauthConfiguration.GetClientId())
{
Scopes = { "read:user", "notifications", "repo", "read:org", "write:org" },
Scopes = { "read:user", "notifications", "repo", "read:org", "write:org", "codespace" },
State = State,
RedirectUri = new Uri(OauthConfiguration.RedirectUri),
};
Expand Down
6 changes: 5 additions & 1 deletion GitHubExtension/GitHubExtensionCommandsProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public partial class GitHubExtensionCommandsProvider : CommandProvider, IDisposa
private readonly SavedSearchesPage _savedSearchesPage;
private readonly SignOutPage _signOutPage;
private readonly SignInPage _signInPage;
private readonly CodespacesPage _codespacesPage;
private readonly IDeveloperIdProvider _developerIdProvider;
private readonly ISearchRepository _persistentDataManager;
private readonly ISearchPageFactory _searchPageFactory;
Expand All @@ -33,7 +34,8 @@ public GitHubExtensionCommandsProvider(
IResources resources,
ISearchPageFactory searchPageFactory,
SavedSearchesMediator savedSearchesMediator,
AuthenticationMediator authenticationMediator)
AuthenticationMediator authenticationMediator,
CodespacesPage codespacesPage)
{
_savedSearchesPage = savedSearchesPage;
_signOutPage = signOutPage;
Expand All @@ -44,6 +46,7 @@ public GitHubExtensionCommandsProvider(
_searchPageFactory = searchPageFactory;
_savedSearchesMediator = savedSearchesMediator;
_authenticationMediator = authenticationMediator;
_codespacesPage = codespacesPage;

DisplayName = _resources.GetResource("ExtensionTitle");

Expand Down Expand Up @@ -94,6 +97,7 @@ public override ICommandItem[] TopLevelCommands()
{
new(_savedSearchesPage),
new(_signOutPage),
new(_codespacesPage),
};

commands.AddRange(defaultCommands);
Expand Down
4 changes: 3 additions & 1 deletion GitHubExtension/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,9 @@ private static async Task HandleCOMServerActivationAsync()
using var signInForm = new SignInForm(authenticationMediator, resources, developerIdProvider, signInCommand);
using var signInPage = new SignInPage(signInForm, resources, signInCommand, authenticationMediator);

using var commandProvider = new GitHubExtensionCommandsProvider(savedSearchesPage, signOutPage, signInPage, developerIdProvider, searchRepository, resources, searchPageFactory, savedSearchesMediator, authenticationMediator);
var codespacesPage = new CodespacesPage(resources, gitHubClientProvider);

using var commandProvider = new GitHubExtensionCommandsProvider(savedSearchesPage, signOutPage, signInPage, developerIdProvider, searchRepository, resources, searchPageFactory, savedSearchesMediator, authenticationMediator, codespacesPage);
var extensionInstance = new GitHubExtension(extensionDisposedEvent, commandProvider);

// We are instantiating an extension instance once above, and returning it every time the callback in RegisterExtension below is called.
Expand Down
21 changes: 21 additions & 0 deletions GitHubExtension/Strings/en-US/Resources.resw
Original file line number Diff line number Diff line change
Expand Up @@ -401,4 +401,25 @@
<value>Sign in to the GitHub Extension (Preview)</value>
<comment>The title for the SignInPage</comment>
</data>
<data name="Pages_Codespaces" xml:space="preserve">
<value>Your Codespaces</value>
</data>
<data name="Pages_Codespaces_Placeholder" xml:space="preserve">
<value>Search Codespaces</value>
</data>
<data name="Commands_Open_VS_Code" xml:space="preserve">
<value>Open in Visual Studio Code</value>
</data>
<data name="Commands_Open_VS_Code1" xml:space="preserve">
<value>Open in Visual Studio Code</value>
</data>
Comment thread
noraa-junker marked this conversation as resolved.
Outdated
<data name="Commands_Open_VS_Code_Insiders" xml:space="preserve">
<value>Open in Visual Studio Code Insiders</value>
</data>
<data name="Message_Codespaces_LoadFail" xml:space="preserve">
<value>There was an error loading your codespaces</value>
</data>
<data name="Message_Codespaces_LoadFail_Description" xml:space="preserve">
<value>You may need to log out and log in again to get the necessary permissions</value>
</data>
</root>