-
Notifications
You must be signed in to change notification settings - Fork 13
Add Codespaces Page #296
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Noraa Junker (noraa-junker)
wants to merge
9
commits into
microsoft:main
Choose a base branch
from
noraa-junker:addCodespaces
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Add Codespaces Page #296
Changes from 1 commit
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
e911478
Add Codespaces Page
noraa-junker 60340e0
Potential fix for pull request finding
noraa-junker 5f47a98
Fix copilot comments
noraa-junker 1673cea
Merge branch 'addCodespaces' of https://github.com/noraa-junker/CmdPa…
noraa-junker 19be6bf
Add tests (thanks copilot)
noraa-junker 14c8e76
Add start, stop and copy URL context menu items
noraa-junker e244899
Merge remote-tracking branch 'upstream/main' into addCodespaces
noraa-junker b2d5a41
Fix build error
noraa-junker 1bee802
Fix trimming error
noraa-junker File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or 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,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() | ||
| { | ||
| CodespacesCollection codespaces = _gitHubClientProvider.GetClientForLoggedInDeveloper().Result.Codespaces.GetAll().Result; | ||
| List<IListItem> result = []; | ||
| try | ||
| { | ||
|
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") })); | ||
| } | ||
|
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; | ||
| } | ||
| } | ||
|
noraa-junker marked this conversation as resolved.
|
||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.