-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement sign-off enforcement in Powershell (#75)
I forgot to translate the sign-off enforcement in the pull request #74.
- Loading branch information
Showing
3 changed files
with
137 additions
and
1 deletion.
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 |
---|---|---|
|
@@ -402,6 +402,70 @@ function TestOKWithLinkDefinition | |
return $true | ||
} | ||
|
||
function TestOKSignedOff | ||
{ | ||
$message = ( | ||
"Do something`n`nIt does something.`n" + | ||
"Signed-off-by: Somebody <[email protected]>`n`n" + | ||
"Signed-off is not necessarily the last line.`n`n" + | ||
"And multiple sign-offs are possible!`n" + | ||
"Signed-off-by: Somebody Else <[email protected]>`n" | ||
) | ||
$got = (powershell -File OpinionatedCommitMessage.ps1 -message $message -dontThrow)|Out-String | ||
|
||
$nl = [Environment]::NewLine | ||
$expected = "The message is OK.${nl}" | ||
|
||
if ($got -ne $expected) | ||
{ | ||
Write-Host "TestOKSignedOff: FAILED" | ||
WriteExpectedGot -expected $expected -got $got | ||
return $false | ||
} | ||
|
||
Write-Host "TestOKSignedOff: OK" | ||
return $true | ||
} | ||
|
||
function TestFailSignedOff | ||
{ | ||
$message = ( | ||
"Do something`n`n" + | ||
"It does something.`n`n" + | ||
"None of the following satisfy the sign-off:`n" + | ||
"Signed-off-by Random Developer <[email protected]>`n" + | ||
"signed-off-by: Random Developer <[email protected]>`n" + | ||
"Signed-off-by: Random Developer <randomdeveloper.example.org>`n" + | ||
"Signed-off-by: Random Developer ([email protected])`n" + | ||
"Signed-off-by: Random Developer [email protected]`n" + | ||
"Signed off by: Random Developer <[email protected]>`n" + | ||
"Signed_off_by: Random Developer <[email protected]>`n" + | ||
"Signed-off-by: Random Developer`n" | ||
) | ||
|
||
$got = (powershell ` | ||
-File OpinionatedCommitMessage.ps1 ` | ||
-message $message ` | ||
-enforceSignOff ` | ||
-dontThrow | ||
)|Out-String | ||
|
||
$nl = [Environment]::NewLine | ||
$expected = ( | ||
"* The body does not contain any 'Signed-off-by: ' line. " + | ||
"Did you sign off the commit with ``git commit --signoff``?${nl}" | ||
) | ||
|
||
if ($got -ne $expected) | ||
{ | ||
Write-Host "TestFailSignedOff: FAILED" | ||
WriteExpectedGot -expected $expected -got $got | ||
return $false | ||
} | ||
|
||
Write-Host "TestFailSignedOff: OK" | ||
return $true | ||
} | ||
|
||
function Main | ||
{ | ||
|
@@ -428,7 +492,9 @@ function Main | |
$success = TestFailWithAllowOneLiners -and $success | ||
$success = TestOKWithURLOnSeparateLine -and $success | ||
$success = TestOKWithLinkDefinition -and $success | ||
|
||
$success = TestOKSignedOff -and $success | ||
$success = TestFailSignedOff -and $success | ||
|
||
if(!$success) | ||
{ | ||
throw "One or more unit tests failed." | ||
|
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