Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
54 changes: 54 additions & 0 deletions src/classes/public/Codespaces/GitHubCodespace.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
class GitHubCodespace {
# Unique identifier of the delivery.
[uint64] $ID

[string] $Name

[Guid] $environment_id

# Time when the delivery was delivered.
[object] $Owner
[object] $Billable_Owner
[object] $Repository
[object] $Machine
[bool] $Prebuild
[datetime] $created_at
[Nullable[datetime]] $updated_at
[Nullable[datetime]] $last_used_at
[string]$State
[string] $url
[object] $git_status
[string] $location
[uint16] $idle_timeout_minutes
[string] $web_url
[string] $machines_url
[string] $start_url
[string] $stop_url
[string] $pulls_url
[string[]] $recent_folders
[object] $runtime_constraints
[string] $display_name
[string] $devcontainer_path
[bool] $pending_operation
[UInt32] $retention_period_minutes
[Nullable[datetime]] $retention_expires_at
[string] $template
[string] $publish_url

# Simple parameterless constructor
GitHubCodespace() {}

# Creates a context object from a hashtable of key-vaule pairs.
GitHubCodespace([hashtable]$Properties) {
foreach ($Property in $Properties.Keys) {
$this.$Property = $Properties.$Property
}
}

# Creates a context object from a PSCustomObject.
GitHubCodespace([PSCustomObject]$Object) {
$Object.PSObject.Properties | ForEach-Object {
$this.($_.Name) = $_.Value
}
}
}
173 changes: 173 additions & 0 deletions src/formats/GitHubCodespace.Format.ps1xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
<?xml version="1.0" encoding="utf-8"?>
<Configuration>
<ViewDefinitions>
<!-- Table View Definition -->
<View>
<Name>GitHubCodespaceTableView</Name>
<ViewSelectedBy>
<TypeName>GitHubCodespace</TypeName>
</ViewSelectedBy>
<TableControl>
<TableHeaders>
<TableColumnHeader>
<Label>Name</Label>
</TableColumnHeader>
<TableColumnHeader>
<Label>DisplayName</Label>
</TableColumnHeader>
<TableColumnHeader>
<Label>Location</Label>
</TableColumnHeader>
<TableColumnHeader>
<Label>State</Label>
</TableColumnHeader>
<TableColumnHeader>
<Label>Created</Label>
</TableColumnHeader>
<TableColumnHeader>
<Label>Updated</Label>
</TableColumnHeader>
<TableColumnHeader>
<Label>LastUsed</Label>
</TableColumnHeader>
</TableHeaders>
<TableRowEntries>
<TableRowEntry>
<TableColumnItems>
<TableColumnItem>
<PropertyName>Name</PropertyName>
</TableColumnItem>
<TableColumnItem>
<PropertyName>display_name</PropertyName>
</TableColumnItem>
<TableColumnItem>
<PropertyName>location</PropertyName>
</TableColumnItem>
<TableColumnItem>
<PropertyName>state</PropertyName>
</TableColumnItem>
<TableColumnItem>
<PropertyName>created_at</PropertyName>
</TableColumnItem>
<TableColumnItem>
<PropertyName>updated_at</PropertyName>
</TableColumnItem>
<TableColumnItem>
<PropertyName>last_used_at</PropertyName>
</TableColumnItem>
</TableColumnItems>
</TableRowEntry>
</TableRowEntries>
</TableControl>
</View>

<!-- List View Definition -->
<View>
<Name>GitHubCodespaceListView</Name>
<ViewSelectedBy>
<TypeName>GitHubCodespace</TypeName>
</ViewSelectedBy>
<ListControl>
<ListEntries>
<ListEntry>
<ListItems>
<ListItem>
<PropertyName>ID</PropertyName>
</ListItem>
<ListItem>
<PropertyName>Name</PropertyName>
</ListItem>
<ListItem>
<PropertyName>environment_id</PropertyName>
</ListItem>
<ListItem>
<PropertyName>Owner</PropertyName>
</ListItem>
<ListItem>
<PropertyName>Billable_Owner</PropertyName>
</ListItem>
<ListItem>
<PropertyName>Repository</PropertyName>
</ListItem>
<ListItem>
<PropertyName>Machine</PropertyName>
</ListItem>
<ListItem>
<PropertyName>Prebuild</PropertyName>
</ListItem>
<ListItem>
<Label>Created</Label>
<PropertyName>created_at</PropertyName>
</ListItem>
<ListItem>
<Label>Updated</Label>
<PropertyName>updated_at</PropertyName>
</ListItem>
<ListItem>
<Label>LastUsed</Label>
<PropertyName>last_used_at</PropertyName>
</ListItem>
<ListItem>
<PropertyName>State</PropertyName>
</ListItem>
<ListItem>
<PropertyName>url</PropertyName>
</ListItem>
<ListItem>
<PropertyName>git_status</PropertyName>
</ListItem>
<ListItem>
<PropertyName>location</PropertyName>
</ListItem>
<ListItem>
<PropertyName>idle_timeout_minutes</PropertyName>
</ListItem>
<ListItem>
<PropertyName>web_url</PropertyName>
</ListItem>
<ListItem>
<PropertyName>machines_url</PropertyName>
</ListItem>
<ListItem>
<PropertyName>start_url</PropertyName>
</ListItem>
<ListItem>
<PropertyName>stop_url</PropertyName>
</ListItem>
<ListItem>
<PropertyName>pulls_url</PropertyName>
</ListItem>
<ListItem>
<PropertyName>recent_folders</PropertyName>
</ListItem>
<ListItem>
<PropertyName>runtime_constraints</PropertyName>
</ListItem>
<ListItem>
<PropertyName>display_name</PropertyName>
</ListItem>
<ListItem>
<PropertyName>devcontainer_path</PropertyName>
</ListItem>
<ListItem>
<PropertyName>pending_operation</PropertyName>
</ListItem>
<ListItem>
<PropertyName>retention_period_minutes</PropertyName>
</ListItem>
<ListItem>
<PropertyName>retention_expires_at</PropertyName>
</ListItem>
<ListItem>
<PropertyName>template</PropertyName>
</ListItem>
<ListItem>
<PropertyName>publish_url</PropertyName>
</ListItem>
</ListItems>
</ListEntry>
</ListEntries>
</ListControl>
</View>
</ViewDefinitions>
</Configuration>
11 changes: 11 additions & 0 deletions src/functions/private/Codespaces/ConvertTo-GitHubCodespace.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
function ConvertTo-GitHubCodespace {
[OutputType([GitHubCodespace])]
[CmdletBinding()]
param(
[Parameter(ValueFromPipeline)]
$InputObject
)
process {
[GitHubCodespace]$InputObject
}
}
54 changes: 54 additions & 0 deletions src/functions/public/Codespaces/Add-GitHubCodespaceUser.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
function Add-GitHubCodespaceUser {
<#
.SYNOPSIS
Adds users to Codespaces access for an organization.

.DESCRIPTION
Codespaces for the specified users will be billed to the organization.
To use this endpoint, the access settings for the organization must be set to selected_members.
For information on how to change this setting please see [these docs](https://docs.github.com/rest/codespaces/organizations#manage-access-control-for-organization-codespaces)
You must authenticate using an access token with the admin:org scope to use this endpoint.

.PARAMETER Organization
The organization name. The name is not case sensitive.

.PARAMETER User
Handle for the GitHub user account(s).

.EXAMPLE
> Add-GitHubCodespaceUser -Organization PSModule -user fake_user_name

.OUTPUTS
[PSObject[]]

.LINK
https://docs.github.com/en/rest/codespaces/organizations?apiVersion=2022-11-28#add-users-to-codespaces-access-for-an-organization
#>
[CmdletBinding(SupportsShouldProcess)]
param (
[Parameter(Mandatory)]
[string]$Organization,
[Parameter(Mandatory, ValueFromPipeline, ValueFromPipelineByPropertyName)]
[string[]]$User,

# The context to run the command in. Used to get the details for the API call.
# Can be either a string or a GitHubContext object.
[Parameter()]
[object] $Context = (Get-GitHubContext)
)
process {
if ($PSCmdLet.ShouldProcess(
"Adding users [$($User -join ',')] to GitHub codespace access",
"Are you sure you want to add $($User -join ',')?",
'Add codespace users'
)) {
$postParams = @{
APIEndpoint = "/orgs/$Organization/codespaces/access/selected_users"
Body = [PSCustomObject]@{ selected_usernames = @($User) } | ConvertTo-Json
Context = $Context
Method = 'POST'
}
Invoke-GitHubAPI @postParams | Select-Object -ExpandProperty Response
}
}
}
59 changes: 59 additions & 0 deletions src/functions/public/Codespaces/Export-GitHubCodespace.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
function Export-GitHubCodespace {
<#
.SYNOPSIS
Exports a codespace.

.DESCRIPTION
Triggers an export of the specified codespace and returns a URL and ID where the status of the export can be monitored.
If changes cannot be pushed to the codespace's repository, they will be pushed to a new or previously-existing fork instead.
You must authenticate using a personal access token with the codespace scope to use this endpoint.
GitHub Apps must have write access to the codespaces_lifecycle_admin repository permission to use this endpoint.

.PARAMETER Name
The name of the codespace.

.PARAMETER Wait
If present will wait for the export to complete.

.EXAMPLE
> Export-GitHubCodespace -Name fluffy-disco-v7xgv7j4j52pvw9

.EXAMPLE
> Export-GitHubCodespace -Name $ominousSpace.name -Wait

.OUTPUTS
[PSObject[]]

.LINK
https://docs.github.com/en/rest/codespaces/codespaces?apiVersion=2022-11-28#export-a-codespace-for-the-authenticated-user
#>
[CmdletBinding()]
param (
[Parameter(Mandatory)]
[string]$Name,

[switch]$Wait,

# The context to run the command in. Used to get the details for the API call.
# Can be either a string or a GitHubContext object.
[Parameter()]
[object] $Context = (Get-GitHubContext)
)
process {
$postParams = @{
APIEndpoint = "/user/codespaces/$Name/exports"
Context = $Context
Method = 'POST'
}
$export = Invoke-GitHubAPI @postParams | Select-Object -ExpandProperty Response
if ($Wait.IsPresent) {
$waitParams = @{
Context = $Context
Id = $export.id
Name = $Name
}
$export = Wait-GitHubCodespaceExport @waitParams
}
$export
}
}
Loading