-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from dfinke/add-build-prompt-from-repo
Add build prompt from repo
- Loading branch information
Showing
10 changed files
with
151 additions
and
4 deletions.
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,28 @@ | ||
on: | ||
push: | ||
paths-ignore: | ||
- "README.md" | ||
- "changelog.md" | ||
- ".github/workflows/docs.yml" | ||
- "docs/**" | ||
- "mkdocs.yml" | ||
- "examples/**" | ||
|
||
branches: | ||
- main | ||
|
||
pull_request: | ||
|
||
jobs: | ||
validate: | ||
runs-on: ${{ matrix.os }} | ||
strategy: | ||
matrix: | ||
os: [windows-latest] | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Run Continuous Integration | ||
shell: pwsh | ||
run: | | ||
cd ./__tests__ | ||
Invoke-Pester -Output Detailed |
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 |
---|---|---|
@@ -1,3 +1,7 @@ | ||
foreach ($directory in @('Private', 'Public')) { | ||
if ($IsWindows -eq $false) { | ||
throw "This module is only supported on Windows operating systems." | ||
} | ||
|
||
foreach ($directory in @('Private', 'Public')) { | ||
Get-ChildItem -Path "$PSScriptRoot\$directory\*.ps1" | ForEach-Object { . $_.FullName } | ||
} |
File renamed without changes.
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,35 @@ | ||
function Build-PromptFromGitHubRepo { | ||
[CmdletBinding()] | ||
param( | ||
$slug | ||
) | ||
|
||
if (!(Test-RepoExists -slug $slug)) { | ||
throw "Repo $slug does not exist" | ||
} | ||
|
||
$branch = Get-GHBranch -slug $slug | ||
|
||
# test if github repo exists | ||
|
||
$url = "https://api.github.com/repos/{0}/zipball/{1}" -f $slug, $branch | ||
|
||
Write-Verbose "[$(Get-Date)] Retrieving $url" | ||
|
||
$fileName = $slug.replace("/", "-") | ||
$folderName = [System.IO.Path]::GetTempPath() | ||
$OutFile = "$folderName\$($fileName).zip" | ||
|
||
$DestinationPath = "$folderName\$fileName" | ||
|
||
Invoke-RestMethod $url -OutFile $OutFile | ||
Expand-Archive -Path $OutFile -DestinationPath $DestinationPath -Force | ||
$targetFullName = (Get-ChildItem $folderName -Recurse $fileName -Directory | Get-ChildItem).FullName | ||
|
||
Write-Verbose "[$(Get-Date)] $OutFile" | ||
Write-Verbose "[$(Get-Date)] $DestinationPath" | ||
Build-PromptFromFiles $targetFullName | ||
|
||
$null = Remove-Item $OutFile -Force -Verbose:$Verbose | ||
$null = Remove-Item $DestinationPath -Recurse -Force -Verbose:$Verbose | ||
} |
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,11 @@ | ||
function Get-GHBranch { | ||
[CmdletBinding()] | ||
param( | ||
[string]$slug | ||
) | ||
|
||
$branches = Invoke-RestMethod "https://api.github.com/repos/$slug/branches" | ||
|
||
$branchName = $branches.name | ||
return ($branchName -eq 'main') ? 'main' : ($branchName -eq 'master') ? 'master' : $branches[0].name | ||
} |
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,18 @@ | ||
function Test-RepoExists { | ||
[CmdletBinding()] | ||
param( | ||
$slug | ||
) | ||
|
||
$repoExists = $false | ||
|
||
try { | ||
$null = Invoke-RestMethod "https://api.github.com/repos/$slug" | ||
$repoExists = $true | ||
} | ||
catch { | ||
Write-Verbose "Repo $slug does not exist" | ||
} | ||
|
||
$repoExists | ||
} |
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,35 @@ | ||
Describe "TestFunctionsExist" -Tag "TestFunctionsExist" { | ||
BeforeAll { | ||
Import-Module "$PSScriptRoot/../BuildPromptFromFiles.psd1" -Force | ||
} | ||
|
||
It "Should have Build-PromptFromGitHubRepo" { | ||
$actual = Get-Command -module BuildPromptFromFiles Build-PromptFromGitHubRepo -ErrorAction SilentlyContinue | ||
|
||
$actual | Should -Not -BeNullOrEmpty | ||
} | ||
|
||
It "Should have Build-PromptFromFiles" { | ||
$actual = Get-Command -module BuildPromptFromFiles Build-PromptFromFiles -ErrorAction SilentlyContinue | ||
|
||
$actual | Should -Not -BeNullOrEmpty | ||
} | ||
|
||
It "Should have Get-GHBranch" { | ||
$actual = Get-Command -module BuildPromptFromFiles Get-GHBranch -ErrorAction SilentlyContinue | ||
|
||
$actual | Should -Not -BeNullOrEmpty | ||
} | ||
|
||
It "Should have Get-GitIgnoreContent" { | ||
$actual = Get-Command -module BuildPromptFromFiles Get-GitIgnoreContent -ErrorAction SilentlyContinue | ||
|
||
$actual | Should -Not -BeNullOrEmpty | ||
} | ||
|
||
It "Should have Test-RepoExists" { | ||
$actual = Get-Command -module BuildPromptFromFiles Test-RepoExists -ErrorAction SilentlyContinue | ||
|
||
$actual | Should -Not -BeNullOrEmpty | ||
} | ||
} |
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,4 @@ | ||
Import-Module "$PSScriptRoot/../BuildPromptFromFiles.psd1" -Force | ||
|
||
$prompt = Build-PromptFromGitHubRepo dfinke/psai #-Verbose | ||
$prompt |