-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Added private functions: - `Out-GitResult` - Displays `Invoke-Git` returned hashtable via Write-Verbose and Write-Debug localized messages. Fixes [Issue 90](#90) - `Hide-GitToken` - Used to redact the token from the specified git command so that the command can be safely outputted in logs. - `Publish-WikiContent` - Restored to original structure. - `Invoke-Git` - Added `-PassThru` switch to return result hashtable and not throw regardless of ExitCode value when used. - Throws when ExitCode -ne 0 and `-PassThru` switch not used. - Calls `Out-GitResult` when using `-Debug` or `-Verbose`.
- Loading branch information
Showing
11 changed files
with
726 additions
and
172 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
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 @@ | ||
<# | ||
.SYNOPSIS | ||
Redacts token from Invoke-Git command. | ||
.DESCRIPTION | ||
Redacts the token from the specified git command so that the command can be safely outputted in logs. | ||
.PARAMETER Command | ||
Command passed to Invoke-Git | ||
.EXAMPLE | ||
Hide-GitToken -Command @( 'remote', 'add', 'origin', 'https://user:[email protected]/Owner/Repo.git' ) | ||
Returns a string to be used for logs. | ||
#> | ||
|
||
function Hide-GitToken | ||
{ | ||
[CmdletBinding()] | ||
[OutputType([System.String])] | ||
param | ||
( | ||
[Parameter(Mandatory=$true)] | ||
[System.String[]] | ||
$Command | ||
) | ||
|
||
[System.String] $returnValue = $Command -join ' ' | ||
|
||
[System.String] $returnValue = $returnValue -replace "gh(p|o|u|s|r)_([A-Za-z0-9]{1,251})",'**REDACTED-TOKEN**' | ||
|
||
[System.String] $returnValue = $returnValue -replace "[0-9a-f]{40}",'**REDACTED-TOKEN**' | ||
|
||
return $returnValue | ||
} |
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,92 @@ | ||
<# | ||
.SYNOPSIS | ||
Shows return object from Invoke-Git. | ||
.DESCRIPTION | ||
When Invoke-Git returns a non-zero exit code, this function shows the result. | ||
.PARAMETER ExitCode | ||
ExitCode returned from running git command. | ||
.PARAMETER StandardOutput | ||
Standard Output returned from running git command. | ||
.PARAMETER StandardError | ||
Standard Error returned from running git command. | ||
.PARAMETER Command | ||
Command arguments passed to git. | ||
.PARAMETER WorkingDirectory | ||
Working Directory used when running git command. | ||
.EXAMPLE | ||
$splatParameters = @{ | ||
'ExitCode' = 128 | ||
'StandardOutput' = 'StandardOutput-128' | ||
'StandardError' = 'StandardError-128' | ||
'Command' = 'commit --message "some message"' | ||
'WorkingDirectory' = 'C:\some\path\' | ||
} | ||
Out-GitResult @splatParameters | ||
Shows the Invoke-Git result of a commit. | ||
.NOTES | ||
$NULL values are allowed since string formatter `-f` will convert it to an | ||
empty string before Write-Verbose/Write-Debug process `-Message`. | ||
#> | ||
|
||
function Out-GitResult | ||
{ | ||
[CmdletBinding()] | ||
[OutputType()] | ||
param | ||
( | ||
[Parameter(Mandatory = $true)] | ||
[System.Int32] | ||
$ExitCode, | ||
|
||
[Parameter()] | ||
[System.String] | ||
$StandardOutput, | ||
|
||
[Parameter()] | ||
[System.String] | ||
$StandardError, | ||
|
||
[Parameter(Mandatory = $true)] | ||
[System.String[]] | ||
$Command, | ||
|
||
[Parameter(Mandatory = $true)] | ||
[System.String] | ||
$WorkingDirectory | ||
) | ||
|
||
switch ($Command[0].ToUpper()) | ||
{ | ||
'CLONE' | ||
{ | ||
if ($ExitCode -eq 128) | ||
{ | ||
Write-Verbose -Message $script:localizedData.WikiGitCloneFailMessage | ||
} | ||
} | ||
'COMMIT' | ||
{ | ||
if ($ExitCode -eq 1) | ||
{ | ||
Write-Verbose -Message $localizedData.NothingToCommitToWiki | ||
} | ||
} | ||
} | ||
|
||
Write-Verbose -Message ($script:localizedData.InvokeGitStandardOutputMessage -f $StandardOutput) | ||
Write-Verbose -Message ($script:localizedData.InvokeGitStandardErrorMessage -f $StandardError) | ||
Write-Verbose -Message ($script:localizedData.InvokeGitExitCodeMessage -f $ExitCode) | ||
|
||
Write-Debug -Message ($script:localizedData.InvokeGitCommandDebug -f $(Hide-GitToken -Command $Command)) | ||
Write-Debug -Message ($script:localizedData.InvokeGitWorkingDirectoryDebug -f $WorkingDirectory) | ||
} |
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
Oops, something went wrong.