diff --git a/.github/copilot-commit-message-instructions.md b/.github/copilot-commit-message-instructions.md new file mode 100644 index 0000000..2297468 --- /dev/null +++ b/.github/copilot-commit-message-instructions.md @@ -0,0 +1,34 @@ +# Semantic Commit Messages + +See how a minor change to your commit message style can make you a better programmer. + +Format: `(): ` + +`` is optional + +## Example + +``` +feat: add hat wobble +^--^ ^------------^ +| | +| +-> Summary in present tense. +| ++-------> Type: chore, docs, feat, fix, refactor, style, or test. +``` + +More Examples: + +- `feat`: (new feature for the user, not a new feature for build script) +- `fix`: (bug fix for the user, not a fix to a build script) +- `docs`: (changes to the documentation) +- `style`: (formatting, missing semi colons, etc; no production code change) +- `refactor`: (refactoring production code, eg. renaming a variable) +- `test`: (adding missing tests, refactoring tests; no production code change) +- `chore`: (updating grunt tasks etc; no production code change) + +References: + +- https://www.conventionalcommits.org/ +- https://seesparkbox.com/foundry/semantic_commit_messages +- http://karma-runner.github.io/1.0/dev/git-commit-msg.html diff --git a/.github/copilot-instructions.md b/.github/copilot-instructions.md new file mode 100644 index 0000000..aea90af --- /dev/null +++ b/.github/copilot-instructions.md @@ -0,0 +1,44 @@ +# Copilot Instructions + +## Powershell Modules Code Instructions + +### PowerShell Functions Instructions + +Every powershell function will contain the `CmdletBinding` attribute and the `parm`iven if there are no parameters. +If the function is on the public folder of the module, we will add the Èxport-ModuleFunction` statement in the same line as the closing `}` of the function + +Sample of function will be: + +```powershell + +function Get-UserName{ + [CmdletBinding()] + param() + + #Logic of the function +} Export-ModuleFunction -FunctionName 'Get-UserName' +``` + +### PowerShell Test Instructions + +Every public function on the Test module will have the following format + +- Name will start with `Test_` will follow the name of the function that we are testing with no '-'. It will follow the intention of the test splited with a '_' +- Every time we create a new function with no body we will add the `Assert-NotImplemented` statement at the end +- We will add the 3 sections as with comments `Arrange`, `Act` and `Assert` to make the test more readable. +- Sample of a test function to test `Get-UserName` function will be `Test_GetUserName_UserNotFound` + +Full sample will be as follows + +```powershell +function Test_GetUserName_UserNotFound{ + + # Arrange + + # Act + + # Assert + + Assert-NotImplemented +} +``` diff --git a/.github/copilot-pull-request-description-instructions.md b/.github/copilot-pull-request-description-instructions.md new file mode 100644 index 0000000..6047249 --- /dev/null +++ b/.github/copilot-pull-request-description-instructions.md @@ -0,0 +1,42 @@ +# Pull Request Code Instructions + +## PR TITLE + +Follow this guidelines to construct the title of your pull request. + +Format: `(): ` + +`` is optional + +## Example + +``` +feat: add hat wobble +^--^ ^------------^ +| | +| +-> Summary in present tense. +| ++-------> Type: chore, docs, feat, fix, refactor, style, or test. +``` + +More Examples: + +- `feat`: (new feature for the user, not a new feature for build script) +- `fix`: (bug fix for the user, not a fix to a build script) +- `docs`: (changes to the documentation) +- `style`: (formatting, missing semi colons, etc; no production code change) +- `refactor`: (refactoring production code, eg. renaming a variable) +- `test`: (adding missing tests, refactoring tests; no production code change) +- `chore`: (updating grunt tasks etc; no production code change) + +References: + +- https://www.conventionalcommits.org/ +- https://seesparkbox.com/foundry/semantic_commit_messages +- http://karma-runner.github.io/1.0/dev/git-commit-msg.html + +## Pull Reques description + +- Add a summery of the intention of the PR. Use the title and the messages of the commits to create a summary. +- Add a list with all the commit messages in the PR. + diff --git a/public/getCommitPrompt.ps1 b/public/getCommitPrompt.ps1 new file mode 100644 index 0000000..cb26c2a --- /dev/null +++ b/public/getCommitPrompt.ps1 @@ -0,0 +1,70 @@ +function Get-AiMessageForCommit{ + [CmdletBinding()] + [alias("aicm")] + param( + [Parameter()]$Model = "openai/gpt-4.1", + [Parameter()]$Prompt + ) + + $gitdifff = git diff --staged + + if ([string]::IsNullOrWhiteSpace($gitdifff)) { + Write-Host "No staged changes found. Please stage your changes before generating a commit message." -ForegroundColor Yellow + return $null + } + + $instructions = Get-Instructions -Type CommitMessage + + if ($null -eq $instructions) { + Write-Verbose "No instructions found at .github/$instFileName. Using default commit message format." + } else { + Write-Verbose "Instructions: .github [$($instructions.Length)] characters." + } + + $p = @() + $p += "Follow these instructions: [ $instructions ]" + $sysPrompt = $p -join "`n" + + $p = @() + $p += "Propose a git commit message." + $p += "Output just the message." + $p += "Make the message a single line." + $p += "Result of git diff --staged: [ $gitdifff ]" + $p += "User description of the changes: [ $Prompt ]" + $usrprompt = $p -join "`n" + + Write-Verbose "Module: $Model" + Write-Verbose "SysPrompt: $sysPrompt" + Write-Verbose "UsrPrompt: $usrprompt" + + $message = gh models run $Model "$usrprompt" --system-prompt $sysPrompt + + $global:message = $message | Out-String + + return $message + +} Export-ModuleMember -Function Get-AiMessageForCommit -Alias aicm + +function Get-Instructions{ + [CmdletBinding()] + param( + [Parameter(Mandatory = $true)] + [ValidateSet("CommitMessage", "CodeInstructions", "PrDescription")] + [string]$Type + + ) + switch ($Type) { + CommitMessage { $instFileName = "copilot-commit-message-instructions.md" ; break } + CodeInstructions { $instFileName = "copilot-instructions.md" ; break } + PrDescription { $instFileName = "copilot-pull-request-description-instructions.md" ; break } + } + + $instructionsPath = ".github" | Join-Path -ChildPath $instFileName + + if (Test-Path $instructionsPath) { + $content = Get-Content -Path $instructionsPath -Raw + return $content + } + + return $null +} \ No newline at end of file diff --git a/sync.ps1 b/sync.ps1 deleted file mode 100644 index 82ebdbf..0000000 --- a/sync.ps1 +++ /dev/null @@ -1,34 +0,0 @@ -<# -.SYNOPSIS - Synchronizes with TestingHelper templates files - -.DESCRIPTION - Synchronizes with TestingHelper templates to the local repo. - TestingHelper uses templates to create a new module. - This script will update the local module with the latest templates. -.LINK - https://raw.githubusercontent.com/rulasg/TestingHelper/main/sync.ps1 -#> - -[cmdletbinding(SupportsShouldProcess)] -param() - -$MODULE_PATH = $PSScriptRoot -$TOOLS_PATH = $MODULE_PATH | Join-Path -ChildPath "tools" -$WORKFLOW_PATH = $MODULE_PATH | Join-Path -ChildPath ".github" -AdditionalChildPath "workflows" - -. ($TOOLS_PATH | Join-Path -ChildPath "sync.Helper.ps1") - -Save-UrlContentToFile -File 'deploy_module_on_release.yml' -Folder $WORKFLOW_PATH -Url 'https://raw.githubusercontent.com/rulasg/TestingHelper/main/private/templates/template.v3.deploy_module_on_release.yml' -Save-UrlContentToFile -File 'powershell.yml' -Folder $WORKFLOW_PATH -Url 'https://raw.githubusercontent.com/rulasg/TestingHelper/main/private/templates/template.v3.powershell.yml' -Save-UrlContentToFile -File 'test_with_TestingHelper.yml' -Folder $WORKFLOW_PATH -Url 'https://raw.githubusercontent.com/rulasg/TestingHelper/main/private/templates/template.v3.test_with_TestingHelper.yml' - -Save-UrlContentToFile -File 'deploy.Helper.ps1' -Folder $TOOLS_PATH -Url 'https://raw.githubusercontent.com/rulasg/TestingHelper/main/private/templates/template.v3.deploy.Helper.ps1' -Save-UrlContentToFile -File 'deploy.ps1' -Folder $MODULE_PATH -Url 'https://raw.githubusercontent.com/rulasg/TestingHelper/main/private/templates/template.v3.deploy.ps1' - -Save-UrlContentToFile -File 'sync.Helper.ps1' -Folder $TOOLS_PATH -Url 'https://raw.githubusercontent.com/rulasg/TestingHelper/main/private/templates/template.v3.sync.Helper.ps1' -Save-UrlContentToFile -File 'sync.ps1' -Folder $MODULE_PATH -Url 'https://raw.githubusercontent.com/rulasg/TestingHelper/main/private/templates/template.v3.sync.ps1' - -Save-UrlContentToFile -File 'release.ps1' -Folder $MODULE_PATH -Url 'https://raw.githubusercontent.com/rulasg/TestingHelper/main/private/templates/template.v3.release.ps1' -Save-UrlContentToFile -File 'test.ps1' -Folder $MODULE_PATH -Url 'https://raw.githubusercontent.com/rulasg/TestingHelper/main/private/templates/template.v3.test.ps1' - diff --git a/tools/sync.Helper.ps1 b/tools/sync.Helper.ps1 deleted file mode 100644 index e953ac1..0000000 --- a/tools/sync.Helper.ps1 +++ /dev/null @@ -1,62 +0,0 @@ -<# -.SYNOPSIS - Helper functions to Synchronize TestingHelper templates files - -.DESCRIPTION - Helper functions Synchronize TestingHelper templates to the local repo. - TestingHelper uses templates to create a new module. - This script will update the local module with the latest templates. -.LINK - https://raw.githubusercontent.com/rulasg/DemoPsModule/main/sync.ps1 -#> - -[cmdletbinding()] -param() - -function Get-UrlContent { - [cmdletbinding()] - param( - [Parameter(Mandatory=$true)][string]$url - ) - $wc = New-Object -TypeName System.Net.WebClient - $fileContent = $wc.DownloadString($url) - - return $fileContent -} - -function Out-ContentToFile { - [cmdletbinding(SupportsShouldProcess)] - param( - [Parameter(ValueFromPipeline)][string]$content, - [Parameter(Mandatory=$true)][string]$filePath - ) - - process{ - - if ($PSCmdlet.ShouldProcess($filePath, "Save content [{0}] to file" -f $content.Length)) { - $content | Out-File -FilePath $filePath -Force - } - } -} - -function Save-UrlContentToFile { - [cmdletbinding(SupportsShouldProcess)] - param( - [Parameter(Mandatory=$true)][string]$Url, - [Parameter(Mandatory=$true)][string]$File, - [Parameter()][string]$Folder - ) - - $fileContent = Get-UrlContent -Url $url - - if ([string]::IsNullOrWhiteSpace($fileContent)) { - Write-Error -Message "Content from [$url] is empty" - return - } - - $filePath = $Folder ? (Join-Path -Path $Folder -ChildPath $File) : $File - - Set-Content -Path $filePath -Value $fileContent - Write-Information -MessageData "Saved content to [$filePath] from [$url]" -} -