Skip to content

Commit 9a0d3e5

Browse files
authored
Merge pull request #52 from rulasg/improvements
feat(sync): enhance file synchronization and terminal configuration
2 parents 4bdf3bb + ef1d9d1 commit 9a0d3e5

12 files changed

Lines changed: 367 additions & 85 deletions
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
---
2+
agent: agent
3+
---
4+
5+
# Save Branch to PR Workflow
6+
7+
This prompt guides through the complete workflow of saving a feature branch by creating a PR, waiting for checks, merging, and cleaning up.
8+
9+
## Prerequisites
10+
- Git repository with GitHub remote
11+
- GitHub CLI (`gh`) installed and authenticated
12+
- Current branch should be a feature branch (not `main`)
13+
14+
## Workflow Steps
15+
16+
### Step 1: Verify Current Branch
17+
Check that we are NOT on the `main` branch. If on `main`, stop and inform the user.
18+
19+
```powershell
20+
$currentBranch = git branch --show-current
21+
if ($currentBranch -eq "main") {
22+
Write-Error "Cannot run this workflow from the main branch. Please checkout a feature branch first."
23+
return
24+
}
25+
Write-Host "Current branch: $currentBranch"
26+
```
27+
28+
### Step 2: Push Branch and Create PR
29+
Push the current branch to remote and create a Pull Request.
30+
31+
```powershell
32+
# Push branch to remote
33+
git push -u origin $currentBranch
34+
35+
# Create PR with auto-fill from commit messages
36+
gh pr create --fill
37+
```
38+
39+
If a PR already exists for this branch, continue with the existing PR.
40+
41+
### Step 3: Wait for Workflow Checks
42+
Wait for all GitHub Actions workflow checks to complete and verify they pass.
43+
44+
```powershell
45+
# Wait for checks to complete (will block until done)
46+
gh pr checks --watch --required --interval 1 --fail-fast
47+
48+
# Verify all checks passed
49+
$checksResult = gh pr checks
50+
if ($LASTEXITCODE -ne 0) {
51+
Write-Error "Some checks failed. Please review and fix before merging."
52+
return
53+
}
54+
Write-Host "All checks passed!"
55+
```
56+
57+
### Step 4: Merge the PR
58+
Merge the PR using a regular merge to preserve the branch history, and delete the remote branch.
59+
60+
```powershell
61+
# Merge PR and delete remote branch (regular merge to keep history)
62+
gh pr merge --merge --delete-branch
63+
```
64+
65+
### Step 5: Clean Up Local Branch
66+
Switch to main and delete the local feature branch.
67+
68+
```powershell
69+
# Switch to main branch
70+
git checkout main
71+
72+
# Pull latest changes
73+
git pull
74+
75+
# Delete local feature branch
76+
git branch -d $currentBranch
77+
```
78+
79+
### Step 6: Check and Remove Codespaces
80+
Check if there are any codespaces associated with this branch and remove them.
81+
82+
```powershell
83+
# List codespaces for this repository
84+
$codespaces = gh codespace list --json name,gitStatus,repository --jq ".[] | select(.gitStatus.ref == `"$currentBranch`")"
85+
86+
if ($codespaces) {
87+
Write-Host "Found codespaces on branch $currentBranch. Removing..."
88+
# Delete codespaces on this branch
89+
gh codespace list --json name,gitStatus --jq ".[] | select(.gitStatus.ref == `"$currentBranch`") | .name" | ForEach-Object {
90+
gh codespace delete --codespace $_ --force
91+
Write-Host "Deleted codespace: $_"
92+
}
93+
} else {
94+
Write-Host "No codespaces found on branch $currentBranch"
95+
}
96+
```
97+
98+
## Success Criteria
99+
- [ ] Verified not on main branch
100+
- [ ] PR created and pushed to remote
101+
- [ ] All workflow checks passed
102+
- [ ] PR merged successfully
103+
- [ ] Local and remote feature branches deleted
104+
- [ ] Any codespaces on the branch removed
105+
106+
## Error Handling
107+
- If on `main` branch: Stop immediately with clear message
108+
- If checks fail: Stop and inform user to fix issues
109+
- If merge conflicts: Stop and inform user to resolve conflicts
110+
- If codespace deletion fails: Log warning but continue

.vscode/settings.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,9 @@
11
{
2+
"terminal.integrated.profiles.osx": {
3+
"pwsh": {
4+
"path": "pwsh",
5+
"icon": "terminal-powershell",
6+
"args": ["-NoExit", "-Command", "if (Test-Path './tools/Test_Helper') { Import-Module './tools/Test_Helper' -Force }"]
7+
}
8+
}
29
}

Test/include/InvokeMockList.ps1

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,54 @@
11

2-
$MockCommandFile = $testRootPath | Join-Path -ChildPath "mockfiles.log"
2+
# $MockCommandFile = $testRootPath | Join-Path -ChildPath "mockfiles.log"
33

4-
function Trace-MockCommandFile{
5-
[CmdletBinding()]
6-
param(
7-
[string] $Command,
8-
[string] $FileName
9-
)
4+
# function Trace-MockCommandFile{
5+
# [CmdletBinding()]
6+
# param(
7+
# [string] $Command,
8+
# [string] $FileName
9+
# )
1010

11-
# read content
12-
$content = readMockCommandFile
11+
# # read content
12+
# $content = readMockCommandFile
1313

14-
# Check that the entry is already there
15-
$result = $content | Where-Object{$_.command -eq $command}
16-
if($null -ne $result) {return}
14+
# # Check that the entry is already there
15+
# $result = $content | Where-Object{$_.command -eq $command}
16+
# if($null -ne $result) {return}
1717

18-
# add entry
19-
$new = @{
20-
Command = $command
21-
FileName = $fileName
22-
}
18+
# # add entry
19+
# $new = @{
20+
# Command = $command
21+
# FileName = $fileName
22+
# }
2323

24-
$ret = @()
25-
$ret += $content
26-
$ret += $new
24+
# $ret = @()
25+
# $ret += $content
26+
# $ret += $new
2727

28-
# Save list
29-
writeMockCommandFile -Content $ret
30-
}
28+
# # Save list
29+
# writeMockCommandFile -Content $ret
30+
# }
3131

32-
function readMockCommandFile{
32+
# function readMockCommandFile{
3333

34-
# Return empty list if the file does not exist
35-
if(-not (Test-Path -Path $MockCommandFile)){
36-
return @()
37-
}
34+
# # Return empty list if the file does not exist
35+
# if(-not (Test-Path -Path $MockCommandFile)){
36+
# return @()
37+
# }
3838

39-
$ret = Get-Content -Path $MockCommandFile | ConvertFrom-Json
39+
# $ret = Get-Content -Path $MockCommandFile | ConvertFrom-Json
4040

41-
# return an empty aray if content does not exists
42-
$ret = $ret ?? @()
41+
# # return an empty aray if content does not exists
42+
# $ret = $ret ?? @()
4343

44-
return $ret
45-
}
44+
# return $ret
45+
# }
4646

47-
function writeMockCommandFile($Content){
47+
# function writeMockCommandFile($Content){
4848

49-
$list = $Content | ConvertTo-Json
49+
# $list = $Content | ConvertTo-Json
5050

51-
$sorted = $list | Sort-Object fileName
51+
# $sorted = $list | Sort-Object fileName
5252

53-
$sorted | Out-File -FilePath $MockCommandFile
54-
}
53+
# $sorted | Out-File -FilePath $MockCommandFile
54+
# }

Test/include/callPrivateContext.ps1

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ function Invoke-PrivateContext {
1515
param (
1616
[Parameter(Mandatory, Position = 0)]
1717
[scriptblock]$ScriptBlock,
18-
[string]$ModulePath
18+
[string]$ModulePath,
19+
[string[]]$Arguments
1920
)
2021

2122
if ([string]::IsNullOrEmpty($ModulePath)) {
@@ -28,5 +29,11 @@ function Invoke-PrivateContext {
2829
throw "Failed to import the main module."
2930
}
3031

31-
& $module $ScriptBlock
32+
if($Arguments){
33+
& $module $ScriptBlock -Arguments $Arguments
34+
}
35+
else {
36+
& $module $ScriptBlock
37+
}
38+
3239
} Export-ModuleMember -Function Invoke-PrivateContext

Test/include/invokeCommand.mock.ps1

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,4 +303,63 @@ function Assert-MockFileNotfound{
303303
Wait-Debugger
304304
throw "File not found or wrong case name. Expected[ $filename ] - Found[$( $file.name )]"
305305
}
306-
}
306+
}
307+
308+
309+
#region Mock Command File Trace
310+
311+
$MockCommandFile = $testRootPath | Join-Path -ChildPath "mockfiles.log"
312+
313+
function Trace-MockCommandFile{
314+
[CmdletBinding()]
315+
param(
316+
[string] $Command,
317+
[string] $FileName
318+
)
319+
320+
# read content
321+
$content = readMockCommandFile
322+
323+
# Check that the entry is already there
324+
$result = $content | Where-Object{$_.command -eq $command}
325+
if($null -ne $result) {return}
326+
327+
# add entry
328+
$new = @{
329+
Command = $command
330+
FileName = $fileName
331+
}
332+
333+
$ret = @()
334+
$ret += $content
335+
$ret += $new
336+
337+
# Save list
338+
writeMockCommandFile -Content $ret
339+
}
340+
341+
function readMockCommandFile{
342+
343+
# Return empty list if the file does not exist
344+
if(-not (Test-Path -Path $MockCommandFile)){
345+
return @()
346+
}
347+
348+
$ret = Get-Content -Path $MockCommandFile | ConvertFrom-Json
349+
350+
# return an empty aray if content does not exists
351+
$ret = $ret ?? @()
352+
353+
return $ret
354+
}
355+
356+
function writeMockCommandFile($Content){
357+
358+
$list = $Content | ConvertTo-Json
359+
360+
$sorted = $list | Sort-Object fileName
361+
362+
$sorted | Out-File -FilePath $MockCommandFile
363+
}
364+
365+
# End region Mock Command File Trace

Test/include/run_BeforeAfter.ps1

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,23 @@
55
# - After each test
66
# - Before all tests
77
# - After all tests
8+
#
9+
# Copy this file to Test Private to avoid being replaced by updates
810

9-
function Run_BeforeAll{
10-
Write-Verbose "Run_BeforeAll"
11-
}
11+
# function Run_BeforeAll{
12+
# Write-Verbose "Run_BeforeAll"
13+
# }
1214

13-
function Run_AfterAll{
14-
Write-Verbose "Run_AfterAll"
15-
}
15+
# function Run_AfterAll{
16+
# Write-Verbose "Run_AfterAll"
17+
# }
1618

17-
function Run_BeforeEach{
18-
Write-Verbose "Run_BeforeEach"
19-
}
19+
# function Run_BeforeEach{
20+
# Write-Verbose "Run_BeforeEach"
21+
# }
2022

21-
function Run_AfterEach{
22-
Write-Verbose "Run_AfterEach"
23-
}
23+
# function Run_AfterEach{
24+
# Write-Verbose "Run_AfterEach"
25+
# }
2426

2527
Export-ModuleMember -Function Run_*

Test/public/dependencies.test.ps1

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -272,13 +272,19 @@ function Mock_GetMyModuleRootPath{
272272
[Parameter(Mandatory,Position=2)][string]$Folder
273273
)
274274

275-
# Mock GetMyModuleRootPath on SideBySide
276-
# Check that happens before ImportFromModuleManager
277-
# that we are testing here
275+
# Mock "$($MODULE_NAME)RootPath" on SideBySide
276+
277+
# Module path that pretends to be me
278278
$modulePath = "$Folder/$Name"
279+
280+
# Ceate the fake me module
279281
New-ModuleV3 -Name $Name -Path $folder
282+
283+
# Resolve the absolute path
280284
$path = Convert-Path -Path $modulePath
281-
MockCallToString -Command 'GetMyModuleRootPath' -OutString "$path"
285+
286+
# As we are testing this code in IncludeHelper module this is the command "Invoke-$($MODULE_NAME)RootPath"
287+
MockCallToString -Command 'Invoke-IncludeHelperRootPath' -OutString "$path"
282288
}
283289

284290
# Set-MyInvokeCommandAlias -Alias "TestGitHubRepo" -Command 'Invoke-WebRequest -Uri "{url}" -Method Head -ErrorAction SilentlyContinue | ForEach-Object { $_.StatusCode -eq 200 }'

0 commit comments

Comments
 (0)