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
55 changes: 55 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,59 @@

A powershell module that will hold Powershell functionality.

## Use cases

### Create a Octodemo project issue

Use bootstrap template to create a new issue in the Octodemo project.
We have not created automation to create a new issue in the Octodemo project yet.

### List Octodemo project issues

List all issues in the Octodemo project.

```powershell
> Get-OctodemoDemos

Title : Demo :: octodemo/animated-octo-carnival :: copilot_nodejs_basic_v1.5
Repository : octodemo/bootstrap
Url : https://github.com/octodemo/bootstrap/issues/1086
Repo : octodemo/animated-octo-carnival
RepoUrl : https://github.com/octodemo/animated-octo-carnival
Labels : template , demo , demo::provisioned
```
### Create Codespaces for each demo

Create a Codespace for each demo in the Octodemo project.

```powershell
> Get-OctodemoDemos | New-LabCodespace
✓ Codespaces usage for this repository is paid for by octodemo
```
### Check if the octodemo demos have a Codespace

Check if the octodemo demos have a Codespace.

```powershell
> Get-OctodemoDemos -codespacesInfo

Title : Demo :: octodemo/animated-octo-carnival :: copilot_nodejs_basic_v1.5
Repository : octodemo/bootstrap
Url : https://github.com/octodemo/bootstrap/issues/1086
Repo : octodemo/animated-octo-carnival
RepoUrl : https://github.com/octodemo/animated-octo-carnival
Labels : template , demo , demo::provisioned
CodespaceDisplayName : redesigned waffle
CodespaceName : redesigned-waffle-gwrv5v5vvxcvv5g
```
### Remove Octodemo demo issues

Remove all issues in the Octodemo issue to destroy the demos.

```powershell
Get-OctodemoDemos | Remove-OctodemoDemo
```

This command will close the issue to have the demo removed and removes the Codespace associated with the demo.

> Module generated with [TestingHelper Powershell Module](https://www.powershellgallery.com/packages/TestingHelper/)
49 changes: 49 additions & 0 deletions private/importMyModule.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# function Import-DemoHelper{

# ## Check if demohelper avaialble in the peer folder

# $local = $PSScriptRoot | Split-Path -Parent

# $sideBySide = $local | Split-Path -Parent | Join-Path -ChildPath "DemoHelper"

# if(Test-Path -path $sideBySide){
# Import-Module $sideBySide -Force
# } else {
# Import-MyModule -Name Import-DemoHelper -PassThru
# }


# }


# function Import-DependencyModule{
# [CmdletBinding()]
# param (
# [Parameter(Mandatory)][string]$Name,
# [Parameter()][string]$Version,
# [Parameter()][switch]$AllowPrerelease,
# [Parameter()][switch]$PassThru
# )

Check notice

Code scanning / PSScriptAnalyzer

Line has trailing whitespace Note

Line has trailing whitespace
# if ($Version) {
# $V = $Version.Split('-')
# $semVer = $V[0]
# $AllowPrerelease = ($AllowPrerelease -or ($null -ne $V[1]))
# }

# # Check if module is already installed. Use the version parameter transformation
# $module = Import-Module -Name $Name -PassThru -ErrorAction SilentlyContinue -RequiredVersion:$semVer -Verbose

# # If module not installed, install it
# if ($null -eq $module) {
# # Install module from PowershellGallery
# $installed = Install-Module -Name $Name -Force -PassThru -AllowPrerelease:$AllowPrerelease -RequiredVersion:$Version -Verbose

# # Now install the module that we have just installed
# $module = Import-Module -Name $installed.Name -Force -PassThru -RequiredVersion ($installed.Version.Split('-')[0]) -Verbose
# }

# if ($PassThru) {
# $module
# }
# }
104 changes: 0 additions & 104 deletions public/OctodemoDemoIssues/getdemoissues.ps1

This file was deleted.

132 changes: 132 additions & 0 deletions public/codespaces/codespaces.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
<#
.SYNOPSIS
Creates a codespace in the main branch of a specified GitHub repository.

.DESCRIPTION
The `New-Codespace` function creates a new codespace in the main branch of a specified GitHub repository using the GitHub CLI (`gh`).

.PARAMETER Repo
The repository name with the owner in the format 'owner/repo'.

.EXAMPLE
New-Codespace -RepoWithOwner 'octodemo/mushy-chainsaw'
This example creates a codespace in the main branch of the 'octodemo/mushy-chainsaw' repository.

.NOTES
Requires GitHub CLI (gh) to be installed and authenticated.
#>
function New-LabCodespace {

Check warning

Code scanning / PSScriptAnalyzer

Function 'New-LabCodespace' has verb that could change system state. Therefore, the function has to support 'ShouldProcess'. Warning

Function 'New-LabCodespace' has verb that could change system state. Therefore, the function has to support 'ShouldProcess'.
[CmdletBinding()]
param(
[Parameter(Position=0,ValueFromPipelineByPropertyName)][string]$Repo,
[Parameter(Position=1)][string]$DisplayName,
[switch]$CheckIfExists
)

begin{

if($CheckIfExists){
$codespaces = Get-LabCodespaces
}
}

process{

if ($CheckIfExists ) {

# Check if repo name starts with $LAB_ORG
$orgName, $repoName = $Repo -split '/'
if ($orgName -ne $LAB_ORG) {
Write-Error "Repository $Repo does not belong to organization $LAB_ORG"
return
}

# check if codespace already exists
$existingCodespace = $codespaces | Where-Object { $_.Repository -eq $Repo }
if ($existingCodespace) {
Write-Warning "Codespace in repository $Repo already exists"
return
}
}

"Creating codespace in the main branch of $Repo" | Write-Verbose

Check notice

Code scanning / PSScriptAnalyzer

Line has trailing whitespace Note

Line has trailing whitespace
$ghCommand = "gh cs create -b main -m 'standardLinux32gb' -R $Repo"
if ($PSCmdlet.MyInvocation.BoundParameters.ContainsKey('DisplayName')) {
$ghCommand += " --display-name '$DisplayName'"
}

$result = Invoke-Expression $ghCommand

Check warning

Code scanning / PSScriptAnalyzer

Invoke-Expression is used. Please remove Invoke-Expression from script and find other options instead. Warning

Invoke-Expression is used. Please remove Invoke-Expression from script and find other options instead.

Check notice

Code scanning / PSScriptAnalyzer

Line has trailing whitespace Note

Line has trailing whitespace
$result | Write-Verbose

Check notice

Code scanning / PSScriptAnalyzer

Line has trailing whitespace Note

Line has trailing whitespace
return $result
}

} Export-ModuleMember -Function 'New-LabCodespace'


function Get-LabCodespaces {

Check notice

Code scanning / PSScriptAnalyzer

The cmdlet 'Get-LabCodespaces' does not have a help comment. Note

The cmdlet 'Get-LabCodespaces' does not have a help comment.

Check warning

Code scanning / PSScriptAnalyzer

The cmdlet 'Get-LabCodespaces' uses a plural noun. A singular noun should be used instead. Warning

The cmdlet 'Get-LabCodespaces' uses a plural noun. A singular noun should be used instead.
[CmdletBinding()]
param(
[Parameter(Position=0)][string]$owner = 'octodemo'
)

"Getting codespaces in the $Repo repository" | Write-Verbose

$json = gh cs list --json name,displayName,owner,repository

$json | Write-Verbose

$codespaces = $json | ConvertFrom-Json -Depth 10

$result = $codespaces | Where-Object { $_.repository -Like "$owner/*" } | ForEach-Object {
[PSCustomObject]@{
Name = $_.name
DisplayName = $_.displayName
Owner = $_.owner
Repository = $_.repository
}
}

$result | Write-Verbose

return $result
} Export-ModuleMember -Function 'Get-LabCodespaces'

function Remove-LabCodespace{

Check notice

Code scanning / PSScriptAnalyzer

The cmdlet 'Remove-LabCodespace' does not have a help comment. Note

The cmdlet 'Remove-LabCodespace' does not have a help comment.
[CmdletBinding(SupportsShouldProcess)]
param(
[Parameter(Mandatory,ValueFromPipelineByPropertyName,Position=0)]
[Alias("CodespaceName")]
[string]$Name,
[Parameter()][object]$CodespaceList

Check warning

Code scanning / PSScriptAnalyzer

The parameter 'CodespaceList' has been declared but not used. Warning

The parameter 'CodespaceList' has been declared but not used.
)

begin{
$codespacesList ??= Get-LabCodespaces

$codespacesList | Write-Verbose
}

process{

$command = "gh codespace delete --codespace $Name --force"

$codespacesList ??= Get-LabCodespaces

$codespace = $codespacesList | Where-Object { $_.Name -eq $Name }

if($codespace){
if ($PSCmdlet.ShouldProcess($Command)) {
"Removing codespace $Name" | Write-Verbose
$result = Invoke-Expression $command

Check warning

Code scanning / PSScriptAnalyzer

Invoke-Expression is used. Please remove Invoke-Expression from script and find other options instead. Warning

Invoke-Expression is used. Please remove Invoke-Expression from script and find other options instead.
$result | Write-Output
"Codespace $Name removed" | Write-Host

Check warning

Code scanning / PSScriptAnalyzer

File 'codespaces.ps1' uses Write-Host. Avoid using Write-Host because it might not work in all hosts, does not work when there is no host, and (prior to PS 5.0) cannot be suppressed, captured, or redirected. Instead, use Write-Output, Write-Verbose, or Write-Information. Warning

File 'codespaces.ps1' uses Write-Host. Avoid using Write-Host because it might not work in all hosts, does not work when there is no host, and (prior to PS 5.0) cannot be suppressed, captured, or redirected. Instead, use Write-Output, Write-Verbose, or Write-Information.
}
} else {
"Codespace $Name not found" | Write-Host

Check warning

Code scanning / PSScriptAnalyzer

File 'codespaces.ps1' uses Write-Host. Avoid using Write-Host because it might not work in all hosts, does not work when there is no host, and (prior to PS 5.0) cannot be suppressed, captured, or redirected. Instead, use Write-Output, Write-Verbose, or Write-Information. Warning

File 'codespaces.ps1' uses Write-Host. Avoid using Write-Host because it might not work in all hosts, does not work when there is no host, and (prior to PS 5.0) cannot be suppressed, captured, or redirected. Instead, use Write-Output, Write-Verbose, or Write-Information.
}

}
} Export-ModuleMember -Function 'Remove-LabCodespace'
3 changes: 3 additions & 0 deletions public/globals.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@


$LAB_ORG= "octodemo"

Check warning

Code scanning / PSScriptAnalyzer

The variable 'LAB_ORG' is assigned but never used. Warning

The variable 'LAB_ORG' is assigned but never used.
29 changes: 29 additions & 0 deletions public/issues/closedemoissues.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
function Remove-OctodemoDemo{

Check notice

Code scanning / PSScriptAnalyzer

The cmdlet 'Remove-OctodemoDemo' does not have a help comment. Note

The cmdlet 'Remove-OctodemoDemo' does not have a help comment.
[CmdletBinding(SupportsShouldProcess)]
param(
[Parameter(Mandatory,ValueFromPipelineByPropertyName,Position=0)][string]$Url,
[Parameter(ValueFromPipelineByPropertyName,Position=0)][string]$CodespaceName
)

process{

$command = "gh issue close $Url"

Check notice

Code scanning / PSScriptAnalyzer

Line has trailing whitespace Note

Line has trailing whitespace
if ($PSCmdlet.ShouldProcess($Command)) {
$result = Invoke-Expression $command

Check warning

Code scanning / PSScriptAnalyzer

Invoke-Expression is used. Please remove Invoke-Expression from script and find other options instead. Warning

Invoke-Expression is used. Please remove Invoke-Expression from script and find other options instead.
}

$result | Write-Output

if($CodespaceName){
if ($PSCmdlet.ShouldProcess($CodespaceName)) {
Remove-LabCodespace -Name $CodespaceName
} else {
Remove-LabCodespace -Name $CodespaceName -WhatIf
}
}

Check notice

Code scanning / PSScriptAnalyzer

Line has trailing whitespace Note

Line has trailing whitespace

}

} Export-ModuleMember -Function Remove-OctodemoDemo
Loading
Loading