forked from Crockan/MercuryToolbox
23 lines
683 B
PowerShell
23 lines
683 B
PowerShell
[CmdletBinding()]
|
|
param(
|
|
[string]$Range = 'HEAD^..HEAD'
|
|
)
|
|
|
|
$ErrorActionPreference = 'Stop'
|
|
Set-StrictMode -Version Latest
|
|
|
|
$pattern = '^(build|chore|ci|docs|feat|fix|perf|refactor|revert|style|test)(\([a-z0-9][a-z0-9._/-]*\))?!?: .+$'
|
|
$lines = @(& git log --no-merges '--format=%H%x09%s' $Range)
|
|
if ($LASTEXITCODE -ne 0) {
|
|
throw "Could not read commits for range '$Range'."
|
|
}
|
|
|
|
foreach ($line in $lines) {
|
|
$fields = ([string]$line) -split "`t", 2
|
|
if ($fields.Count -ne 2 -or -not [regex]::IsMatch($fields[1], $pattern)) {
|
|
throw "Commit must use Conventional Commits: $line"
|
|
}
|
|
}
|
|
|
|
Write-Host "Conventional Commit check passed for $($lines.Count) commit(s)."
|