Skip to content

Commit

Permalink
Merge af36c49 into a66ba94
Browse files Browse the repository at this point in the history
  • Loading branch information
mieel committed Nov 26, 2019
2 parents a66ba94 + af36c49 commit 0bfc881
Show file tree
Hide file tree
Showing 6 changed files with 148 additions and 129 deletions.
Binary file modified PSGitChangeLog/PSGitChangeLog.Config.psd1
Binary file not shown.
115 changes: 58 additions & 57 deletions PSGitChangeLog/Public/Get-ConventialCommit.Tools.ps1
@@ -1,96 +1,97 @@
Function Get-ConventialCommit {
<#
.SYNOPSIS
.EXAMPLE
Get-ConventialCommit -CommitMessage 'feat(webapi): Add new feature'
Get-ConventialCommit -CommitMessage 'feat: Add new feature no mention of scope'
Get-ConventialCommit -CommitMessage '👷‍♂️ CI Change'
Get-ConventialCommit -CommitMessage '👷‍♂️(Deployment) CI Change in Azure Devops'
Get-ConventialCommit -CommitMessage 'plain text commit message'
#>
#>
Param (
[string]
$CommitMessage = 'feat(webapi): Add new feature'
,
[string]
$ConfigFile = '$PSScriptRoot\..\PSGitChangeLog.Config.psd1'
$ConfigFile
)
If (!$ConfigFile) { $ConfigFile = "$PSScriptRoot\..\PSGitChangeLog.Config.psd1" }
$config = Import-PowerShellDataFile -Path $ConfigFile
$Intents = $config.Intents

$MatchedIntents = $Intents.Code |
ForEach-Object {
$CurrentCode = $_
If ( $CommitMessage -match ("{0}" -f $CurrentCode )) {
$MatchedIntents = $Intents.Code |
ForEach-Object {
$CurrentCode = $_
If ( $CommitMessage -match ("{0}" -f $CurrentCode )) {
$Match = $matches[0]
$Matchedcode = $CurrentCode
Write-Host $Matchedcode
# Scope is mentioned after the code with no semicolon ':'
If ( $CommitMessage -match ("{0}\(\w*\)" -f $Matchedcode )) {
$Match = $matches[0]
$Matchedcode = $CurrentCode
Write-Host $Matchedcode
# Scope is mentioned after the code with no semicolon ':'
If ( $CommitMessage -match ("{0}\(\w*\)" -f $Matchedcode )) {
$Match = $matches[0]
$Matchedcode = $CurrentCode

If ($Match -match "\(\w*\)") {
$MatchedScope = Get-ConventialCommitScope $matches[0]
}
Write-Host $Matchedcode mentions Scope $MatchedScope
}
} Else {
# Scope is mentioned between brackets () before a semecolon ':'
$CodeBase = $CurrentCode -replace ':',''
If ( $CommitMessage -match ("{0}\(\w*\):" -f $CodeBase )) {
$Match = $matches[0]
$Matchedcode = $CurrentCode

If ($Match -match "\(\w*\):") {
$MatchedScope = Get-ConventialCommitScope $matches[0]
}
Write-Host $Matchedcode with codebase $codebase mentions Scope $MatchedScope

If ($Match -match "\(\w*\)") {
$MatchedScope = Get-ConventialCommitScope $matches[0]
}
Write-Host $Matchedcode mentions Scope $MatchedScope
}
If ($Matchedcode) {
} Else {
# Scope is mentioned between brackets () before a semecolon ':'
$CodeBase = $CurrentCode -replace ':', ''
If ( $CommitMessage -match ("{0}\(\w*\):" -f $CodeBase )) {
$Match = $matches[0]
$Matchedcode = $CurrentCode

Write-Output @{
Match = $Match
Code = $Matchedcode
Scope = $MatchedScope
If ($Match -match "\(\w*\):") {
$MatchedScope = Get-ConventialCommitScope $matches[0]
}
}
Write-Host $Matchedcode with codebase $codebase mentions Scope $MatchedScope
}
}
If ($Matchedcode) {

Write-Output @{
Match = $Match
Code = $Matchedcode
Scope = $MatchedScope
}
}
}
If ($MatchedIntents) {
$Intent = ($MatchedIntents | Select-Object -first 1)

# Filter out the Intentcode and scope out of the message
IF ($Intent.Code -like '*:') {
$CommitMessage = $CommitMessage.Replace("$($Intent.Match) ",'')
$CommitMessage = $CommitMessage.Replace("$($Intent.Match) ", '')

} Else {
# Keep intent code with no semicolon (emoji's), filter out the (Scope)
$CommitMessage = $CommitMessage.Replace("`($($Intent.Scope)`)",'')
$CommitMessage = $CommitMessage.Replace("`($($Intent.Scope)`)", '')
}
} Else {
$Intent = @{Code ='Other'}
$Intent = @{Code = 'Other' }
}
$IntentConfiguration = $Intents | Where-Object { $_.Code -contains $Intent.Code }
$output = [PSCustomObject]@{
Message = $CommitMessage
IntentCode = $Intent.Code
$IntentConfiguration = $Intents | Where-Object { $_.Code -contains $Intent.Code }
$output = [PSCustomObject]@{
Message = $CommitMessage
IntentCode = $Intent.Code
IntentDescription = $IntentConfiguration.Description
IntentAudience = $IntentConfiguration.Audience
Order = $IntentConfiguration.Order
Scope = $Intent.Scope
Match = $Intent.Match
IntentAudience = $IntentConfiguration.Audience
Order = $IntentConfiguration.Order
Scope = $Intent.Scope
Match = $Intent.Match
}
Write-Output $output
}
Function Get-ConventialCommitScope {
Param (
$Match
)
$Scope = $Match -replace '\(',''
$Scope = $Scope -replace '\)',''
$Scope = $Scope -replace ':',''
$Scope = $Match -replace '\(', ''
$Scope = $Scope -replace '\)', ''
$Scope = $Scope -replace ':', ''
Write-Output $Scope
}

Expand All @@ -103,22 +104,22 @@ Function Get-ConventialCommitScope2 {
Param (
$CommitMessage = 'feat: new feature'
,
[switch]
[switch]
$ScopeIsSuffixedWithSemicolon
,
$Code
)
If ($ScopeIsSuffixedWithSemicolon) {
If ($ScopeIsSuffixedWithSemicolon) {
$SC = ':'
$CodeBase = $Code -replace ':',''
$CodeBase = $Code -replace ':', ''
} Else {
$CodeBase= $Code
$CodeBase = $Code
}

If ( $CommitMessage -match ("{0}\(\w*\)$SC" -f $CodeBase )) {
$Match = $matches[0]
$Matchedcode = $Code

If ($Match -match "\(\w*\)$SC") {
$MatchedScope = Get-ConventialCommitScope $matches[0]
}
Expand Down
44 changes: 21 additions & 23 deletions PSGitChangeLog/Public/Get-GitHistory.Tools.ps1
Expand Up @@ -36,8 +36,8 @@
[string]
$RemoteName = 'origin'
,
[ValidateSet("psobject", "json","md","html")]
[string]
[ValidateSet("psobject", "json", "md", "html")]
[string]
$OutputAs
,
[String]
Expand Down Expand Up @@ -71,8 +71,6 @@
$gitHist = $gitlog | ConvertFrom-Csv -Delimiter "`t" -Header ("Date", "CommitId", "Author", "Subject")

$Releases = Get-GitTagList -TagPrefix $TagPrefix
# Normalizing log entries
$logs = @()

$TagValue = 'Unreleased'

Expand All @@ -88,7 +86,7 @@

#Skip output if match with Omit
If ($Omit | Where-Object { $Commit.Subject -match $_ }) { Continue }

$ConventialCommitLog = Get-ConventialCommit -CommitMessage $Commit.Subject
Write-Debug $ConventialCommitLog

Expand All @@ -98,7 +96,7 @@
If ( $null -eq $IntentCode) {
$IntentCode = 'Other'
}

If ($Message -lt $RequiredCommitMessageLength) {
Write-Host "Commit message: $message is considered too short ($RequiredCommitMessageLength). Ommitting from changelog..."
Continue
Expand All @@ -118,11 +116,11 @@
CommitId = $Commit.CommitId
Order = $ConventialCommitLog.Order
}

Write-Output $log
} #ForEach
} #ForEach
}
}
}

Function Get-GitChangeLog {
Param (
Expand All @@ -145,8 +143,8 @@ Function Get-GitChangeLog {
[string]
$RemoteName = 'origin'
,
[ValidateSet("psobject", "json","md","html")]
[string]
[ValidateSet("psobject", "json", "md", "html")]
[string]
$OutputAs
,
[String]
Expand All @@ -160,7 +158,7 @@ Function Get-GitChangeLog {
$Releases = Get-GitTagList -TagPrefix $TagPrefix

If ($Audience -eq 'Public' ) {
$logs = $logs | Where-Object {$_.IntentAudience -ne 'Internal'}
$logs = $logs | Where-Object { $_.IntentAudience -ne 'Internal' }
}
If ($OutputAs -eq 'psobject') { return $logs }

Expand All @@ -183,13 +181,13 @@ Function Get-GitChangeLog {
}
If ($logs | Where-Object { $_.Release -eq 'Unreleased' } ) {
$Releasedata += [ordered]@{
Release = 'Unreleased'
ReleaseDate = ''
Component = ''
Version = ''
ReleaseCommit = ''
Commits = $logs | Where-Object { $_.Release -eq 'Unreleased'} | SOrt-Object -Property Order | Select-Object -Property * -ExcludeProperty Project, Release, Order
}
Release = 'Unreleased'
ReleaseDate = ''
Component = ''
Version = ''
ReleaseCommit = ''
Commits = $logs | Where-Object { $_.Release -eq 'Unreleased' } | SOrt-Object -Property Order | Select-Object -Property * -ExcludeProperty Project, Release, Order
}
}
Write-Host $Releases.Count Releases
$Releasedata += ForEach ($Release in $Releases) {
Expand All @@ -209,14 +207,14 @@ Function Get-GitChangeLog {
}

$Json = $Data | ConvertTo-Json -depth 4

If ($OutputAs -eq 'json') { Return $json }

If ($OutputAs -eq 'md'){
If ($OutputAs -eq 'md') {
$Changelog = ConvertTo-Changelog($Json) -FormatAs md
Return $Changelog
} elseif ($OutputAs -eq 'html') {
$Changelog = ConvertTo-Changelog($Json) -FormatAs html
Return $Changelog
}
Return $Changelog
}
}
1 change: 1 addition & 0 deletions Tests/.Project.Tests.ps1
Expand Up @@ -11,6 +11,7 @@ Describe "PSScriptAnalyzer rule-sets" -Tag Build {
'PSAvoidUsingConvertToSecureStringWithPlainText'
'PSAvoidTrailingWhitespace'
'PSUseShouldProcessForStateChangingFunctions'
'PSUseBOMForUnicodeEncodedFile'
)
$Rules = Get-ScriptAnalyzerRule | Where-Object { $_.RuleName -notin $IgnoreRules }
$scriptfiles = Get-ChildItem -Path $projectRoot -File -recurse -Include '*.ps1' | Where-Object { ($_.Directory).Name -ne 'TestSets' }
Expand Down
20 changes: 17 additions & 3 deletions Tests/Unit.Tests.ps1
@@ -1,17 +1,31 @@
# $projectRoot = Resolve-Path "F:\rdcinmotiv\Plumber\Tests\.."
# $projectRoot = Resolve-Path "F:\rdcinmotiv\Plumber\Tests\.."
. $PSScriptRoot\TestHeader.Template.ps1

Describe "Test-IssueKey" -Tag Unit {
$keys = @('ISSUE-1','ISSUE-1213','KEY-23')
$keys = @('ISSUE-1', 'ISSUE-1213', 'KEY-23')
$keys | ForEach-Object {
it "$_ in a commit message should be parsed as a key" {
$key = Test-IssueKey("Commit message mentions $_ somwhere ")
$key | Should -Be $_
}
}

}
Describe 'Get-ConventialCommit' {


it 'should detect a scope' {
$Result = Get-ConventialCommit -CommitMessage 'feat(webapi): Add new feature'
$Result.scope | Should -be 'webapi'

$Result = Get-ConventialCommit -CommitMessage '👷‍♂️(Deployment) CI Change in Azure Devops'
$Result.scope | Should -be 'Deployment'

$Result = Get-ConventialCommit -CommitMessage 'feat: Add new feature no mention of scope'
$Result.scope | Should -be $null
}

}
Describe Get-GitHistory {
$result = Get-GitHistory -OutputAs psobject
it 'should return results' {
Expand Down

0 comments on commit 0bfc881

Please sign in to comment.