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
34 changes: 34 additions & 0 deletions .github/copilot-commit-message-instructions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Semantic Commit Messages

See how a minor change to your commit message style can make you a better programmer.

Format: `<type>(<scope>): <subject>`

`<scope>` 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
44 changes: 44 additions & 0 deletions .github/copilot-instructions.md
Original file line number Diff line number Diff line change
@@ -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
}
```
41 changes: 41 additions & 0 deletions .github/copilot-pull-request-description-instructions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Pull Request Code Instructions

## PR TITLE

Follow this guidelines to construct the title of your pull request.

Format: `<type>(<scope>): <subject>`

`<scope>` 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.

24 changes: 24 additions & 0 deletions Test/include/base64.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
function ConvertTo-Base64 {
[CmdletBinding()]
param (
[Parameter(Mandatory,ValueFromPipeline, Position=0)][string[]]$Text
)

process{
# Encode the string to base64
$ret = [System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes($Text))
return $ret

Check notice

Code scanning / PSScriptAnalyzer

The cmdlet 'ConvertTo-Base64' returns an object of type 'System.String' but this type is not declared in the OutputType attribute. Note

The cmdlet 'ConvertTo-Base64' returns an object of type 'System.String' but this type is not declared in the OutputType attribute.
}
}

function ConvertFrom-Base64 {
[CmdletBinding()]
param (
[Parameter(Mandatory,ValueFromPipeline, Position=0)][string[]]$Text
)

process{
$ret = [System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String($Text))
return $ret
}
}
16 changes: 16 additions & 0 deletions Test/private/mocks/sforgdisplayVerbose.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"status": 0,
"result": {
"id": "00Dd0000000hHE0EAM",
"apiVersion": "63.0",
"accessToken": "***",
"instanceUrl": "https://contoso.my.salesforce.com",
"username": "me@contoso.com",
"clientId": "PlatformCLI",
"connectedStatus": "Connected",
"sfdxAuthUrl": "force://PlatformCLI::xxx@contoso.my.salesforce.com"
},
"warnings": [
"This command will expose sensitive information that allows for subsequent activity using your current authenticated session.\nSharing this information is equivalent to logging someone in under the current credential, resulting in unintended access and escalation of privilege.\nFor additional information, please review the authorization section of the https://developer.salesforce.com/docs/atlas.en-us.sfdx_dev.meta/sfdx_dev/sfdx_dev_auth_web_flow.htm."
]
}
16 changes: 16 additions & 0 deletions Test/private/mocks/sforgloginweb.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"status": 0,
"result": {
"accessToken": "***",
"instanceUrl": "https://contoso.my.salesforce.com",
"orgId": "00Ddxxx0000hHE0EAM",
"username": "me@contoso.com",
"loginUrl": "https://contoso.my.salesforce.com/",
"refreshToken": "***",
"clientId": "PlatformCLI",
"isDevHub": false,
"instanceApiVersion": "63.0",
"instanceApiVersionLastRetrieved": "3/28/2025, 12:18:01 PM"
},
"warnings": []
}
75 changes: 75 additions & 0 deletions Test/public/sfAuth.test.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
function Test_SaveSfAuthInfoToSecret{

Reset-InvokeCommandMock
$filename = "sforgdisplayVerbose.json"
$base64 = Get-MockFileContent -filename $filename | ConvertTo-Base64
MockCallToString -Command "gh api user --jq '.email'" -OutString "me@contoso.com"
MockCall -Command "sf org display --target-org me@contoso.com --verbose --json" -filename $filename

MockCallToNull -Command "gh secret set SFDX_AUTH_URL --body '$base64'"

$result = Save-SfAuthInfoToSecret

Assert-IsNull -Object $result

# TODO: Assert that we are in fact callinggh secret set with the proper parameters

}

function Test_SaveSfAuthInfoToSecret{

Reset-InvokeCommandMock
$filename = "sforgdisplayVerbose.json"
$base64 = Get-MockFileContent -filename $filename | ConvertTo-Base64
MockCallToString -Command "gh api user --jq '.email'" -OutString "me@contoso.com"
MockCall -Command "sf org display --target-org me@contoso.com --verbose --json" -filename $filename
MockCallToNull -Command "gh secret set SFDX_AUTH_URL --body '$base64' -u -r 'ownername/reponame'"
MockCallToString -Command "git remote get-url origin" -OutString "https://github.com/ownername/reponame.git"

$result = Save-SfAuthInfoToSecret -User

Assert-IsNull -Object $result

# TODO: Assert that we are in fact callinggh secret set with the proper parameters

}

function Test_ConnectSfAuthWeb{

Reset-InvokeCommandMock
MockCallToString -Command "gh api user --jq '.email'" -OutString "me@contoso.com"
MockCall -Command "sf org login web --instance-url https://contoso.my.salesforce.com --json" -fileName "sforgloginweb.json"

$result = Connect-SfAuthWeb -InstanceUrl "https://contoso.my.salesforce.com"

Assert-AreEqual -Presented $result.username -Expected "me@contoso.com"
Assert-AreEqual -Presented $result.instanceUrl -Expected "https://contoso.my.salesforce.com"

Assert-IsNull -Object $result.accessToken
Assert-IsNull -Object $result.refreshToken

}

function Test_ConnectSfAuthBase64{
Reset-InvokeCommandMock

$filename = "sforgdisplayVerbose.json"
$SDX_AUTH_URL = Get-MockFileContent -filename $filename | ConvertTo-Base64 | Out-String

$command = "'force://PlatformCLI::xxx@contoso.my.salesforce.com'| sf org login sfdx-url --sfdx-url-stdin --json"
MockCall -Command $command -filename $filename

$result = Connect-SfAuthBase64 -Base64 $SDX_AUTH_URL

Assert-AreEqual -Expected "me@contoso.com" -Presented $result
}
function Test_GetRepoName{

Reset-InvokeCommandMock
MockCallToString -Command "git remote get-url origin" -OutString "https://github.com/contoso/reponame.git"

$result = Get-RepoName

Assert-AreEqual -Expected "contoso/reponame" -Presented $result

}
10 changes: 10 additions & 0 deletions docs/sample.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# SfHelper


## Sample commands

### Get-SfAccount

```powershell
Get-SfAccount https://github.lightning.force.com/lightning/r/Account/0013o00002ZKSfaAAH/view
```
3 changes: 0 additions & 3 deletions helper/mySetInvokeCommandAlias.config.ps1

This file was deleted.

26 changes: 0 additions & 26 deletions helper/mySetInvokeCommandAlias.ps1

This file was deleted.

24 changes: 24 additions & 0 deletions include/base64.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
function ConvertTo-Base64 {
[CmdletBinding()]
param (
[Parameter(Mandatory,ValueFromPipeline, Position=0)][string[]]$Text
)

process{
# Encode the string to base64
$ret = [System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes($Text))
return $ret

Check notice

Code scanning / PSScriptAnalyzer

The cmdlet 'ConvertTo-Base64' returns an object of type 'System.String' but this type is not declared in the OutputType attribute. Note

The cmdlet 'ConvertTo-Base64' returns an object of type 'System.String' but this type is not declared in the OutputType attribute.
}
}

function ConvertFrom-Base64 {
[CmdletBinding()]
param (
[Parameter(Mandatory,ValueFromPipeline, Position=0)][string[]]$Text
)

process{
$ret = [System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String($Text))
return $ret
}
}
23 changes: 23 additions & 0 deletions public/resolveEmail.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
Set-MyInvokeCommandAlias -Alias GetUserEmail -Command "gh api user --jq '.email'"

function Resolve-Email{

Check notice

Code scanning / PSScriptAnalyzer

The cmdlet 'Resolve-Email' does not have a help comment. Note

The cmdlet 'Resolve-Email' does not have a help comment.
[CmdletBinding(SupportsShouldProcess)]

Check warning

Code scanning / PSScriptAnalyzer

'Resolve-Email' has the ShouldProcess attribute but does not call ShouldProcess/ShouldContinue. Warning

'Resolve-Email' has the ShouldProcess attribute but does not call ShouldProcess/ShouldContinue.
param(
[Parameter()][string]$Email
)

if(-not [string]::IsNullOrEmpty($Email)){
"Resolving email [$Email] from parameter" | Write-MyVerbose
return $Email

Check notice

Code scanning / PSScriptAnalyzer

The cmdlet 'Resolve-Email' returns an object of type 'System.String' but this type is not declared in the OutputType attribute. Note

The cmdlet 'Resolve-Email' returns an object of type 'System.String' but this type is not declared in the OutputType attribute.
}

$Email = Invoke-MyCommand -Command GetUserEmail -ErrorAction SilentlyContinue
"Resolved email [$Email] from github" | Write-MyVerbose

if ($null -eq $Email){
throw "Unable to resolve user email. Please provide email as parameter or set proper gh cli credentials and user github profile email." | Write-MyError
}

return $Email

} Export-ModuleMember -Function Resolve-Email
Loading
Loading