Skip to content

Commit

Permalink
feat: parameter expansion of environment name in mapping directory
Browse files Browse the repository at this point in the history
  • Loading branch information
isc-pbarton committed Nov 15, 2024
1 parent 7c82a22 commit 54b12d3
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added
- Production Decomposition mode allows controlling interoperability productions as individual files for each host (#469)
- Mapping configuration supports parameter expansion of \<env\> to the environment name (#640)

## [2.7.1] - 2024-11-13

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ Documentation for the various git-source-control menu options can be found [here
To specify where files should go relative to your repository root, add mappings via the "Settings" menu item. A mapping has three parts:
* The file extension to use: e.g., CLS, MAC. As a special case for web application files, use "/CSP/" as the mapping.
* A filter on the files of that type (e.g., a package name or web application folder)
* The folder relative to the repo root that contains the item. This controls behavior for import and export.
* The folder relative to the repo root that contains the item. This controls behavior for import and export. The keyword `<env>` will be expanded into the environment name to support different mapping configurations, for example for system default settings.

This might look like:

Expand Down
13 changes: 13 additions & 0 deletions cls/SourceControl/Git/Utils.cls
Original file line number Diff line number Diff line change
Expand Up @@ -2375,6 +2375,9 @@ ClassMethod Name(InternalName As %String, ByRef MappingExists As %Boolean) As %S
set MappingExists = 1
}

set settings = ##class(SourceControl.Git.Settings).%New()
set found = ..ExpandMappingParameters(found)

if InternalName["/" {
// If no specific mapping was specified (p=""), then return the whole csp filename; otherwise return the name without the mapped piece
set InternalName=$extract(InternalName,$length(p)+2,*)
Expand All @@ -2398,6 +2401,14 @@ ClassMethod Name(InternalName As %String, ByRef MappingExists As %Boolean) As %S
}
}

ClassMethod ExpandMappingParameters(MapDirectory, Settings As SourceControl.Git.Settings = {##class(SourceControl.Git.Settings).%New()})
{
return $replace(MapDirectory,"<env>", $zconvert($select(
Settings.environmentName = "": "DEVELOPMENT",
1: Settings.environmentName)
,"l"))
}

/// Implementation copied from %Library.RoutineMgr, but with results cached in a PPG.
ClassMethod UserTypeCached(Name As %String, ByRef Class As %String, ByRef StudioType As %String, ByRef Schema As %String, ByRef StudioIcon As %Integer) As %Boolean
{
Expand Down Expand Up @@ -2463,6 +2474,7 @@ ClassMethod NameToInternalName(Name, IgnorePercent = 1, IgnoreNonexistent = 1, V
set Deleted = 1
}
}
set settings = ##class(SourceControl.Git.Settings).%New()
if (InternalName="") {
set name=$extract(Name,$length($$$SourceRoot)+1,*)
set name=$replace(name,"\","/") // standardize slash direction
Expand All @@ -2475,6 +2487,7 @@ ClassMethod NameToInternalName(Name, IgnorePercent = 1, IgnoreNonexistent = 1, V
set bestScore = 0
set currScore = 0
while (queryary'="")&&(mappingsSubscript="mappings") {
set dir = ..ExpandMappingParameters(dir, settings)
set nam = $extract(name, $length(dir)+1, *)
if ($zconvert(subscript, "U") = $zconvert($piece(name, ".", *), "U")) {
set extScore = 1
Expand Down
20 changes: 19 additions & 1 deletion test/UnitTest/SourceControl/Git/NameTest.cls
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,25 @@ Method TestMixedFoldering()
do $$$AssertEquals(##class(Utils).Name("TestPackage.Hello.World.mac"),"rtn/TestPackage/Hello/World.mac")
}

Method TestEnvExpansion()
{
try {
set $$$SourceMapping("ESD","*") = "config/<env>/"
set $$$SourceMapping("ESD","*","NoFolders") = 1
set settings = ##class(SourceControl.Git.Settings).%New()
set oldEnvName = settings.environmentName
set settings.environmentName = "TEST"
$$$ThrowOnError(settings.%Save())
do $$$AssertEquals(##class(SourceControl.Git.Utils).Name("Ens.Config.DefaultSettings.esd"),"config/test/Ens.Config.DefaultSettings.esd")
} catch err {
do $$$AssertStatusOK(err.AsStatus())
}
if $data(settings)#2 && $data(oldEnvName)#2 {
set settings.environmentName = oldEnvName
$$$ThrowOnError(settings.%Save())
}
}

Method OnBeforeAllTests() As %Status
{
merge ..Mappings = @##class(SourceControl.Git.Utils).MappingsNode()
Expand Down Expand Up @@ -97,4 +116,3 @@ Method %OnClose() As %Status
}

}

19 changes: 19 additions & 0 deletions test/UnitTest/SourceControl/Git/NameToInternalNameTest.cls
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,25 @@ Method TestNegative()
do $$$AssertEquals(##class(SourceControl.Git.Utils).NameToInternalName("bar\NotMyBarFile1.bar", 1, 0, 1),"")
}

Method TestEnvExpansion()
{
try {
set $$$SourceMapping("ESD","*") = "config/<env>/"
set $$$SourceMapping("ESD","*","NoFolders") = 1
set settings = ##class(SourceControl.Git.Settings).%New()
set oldEnvName = settings.environmentName
set settings.environmentName = "TEST"
$$$ThrowOnError(settings.%Save())
do $$$AssertEquals(##class(SourceControl.Git.Utils).NameToInternalName("config/test/Ens.Config.DefaultSettings.ESD"),"Ens.Config.DefaultSettings.ESD")
} catch err {
do $$$AssertStatusOK(err.AsStatus())
}
if $data(settings)#2 && $data(oldEnvName)#2 {
set settings.environmentName = oldEnvName
$$$ThrowOnError(settings.%Save())
}
}

Method OnBeforeAllTests() As %Status
{
set settings = ##class(SourceControl.Git.Settings).%New()
Expand Down

0 comments on commit 54b12d3

Please sign in to comment.