Skip to content

Commit 1e39855

Browse files
committed
feat: parameter expansion of environment name in mapping directory
1 parent 7c82a22 commit 1e39855

File tree

5 files changed

+53
-2
lines changed

5 files changed

+53
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

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

1314
## [2.7.1] - 2024-11-13
1415

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ Documentation for the various git-source-control menu options can be found [here
8181
To specify where files should go relative to your repository root, add mappings via the "Settings" menu item. A mapping has three parts:
8282
* The file extension to use: e.g., CLS, MAC. As a special case for web application files, use "/CSP/" as the mapping.
8383
* A filter on the files of that type (e.g., a package name or web application folder)
84-
* The folder relative to the repo root that contains the item. This controls behavior for import and export.
84+
* 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.
8585
8686
This might look like:
8787

cls/SourceControl/Git/Utils.cls

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2375,6 +2375,9 @@ ClassMethod Name(InternalName As %String, ByRef MappingExists As %Boolean) As %S
23752375
set MappingExists = 1
23762376
}
23772377

2378+
set settings = ##class(SourceControl.Git.Settings).%New()
2379+
set found = ..ExpandMappingParameters(found)
2380+
23782381
if InternalName["/" {
23792382
// If no specific mapping was specified (p=""), then return the whole csp filename; otherwise return the name without the mapped piece
23802383
set InternalName=$extract(InternalName,$length(p)+2,*)
@@ -2398,6 +2401,14 @@ ClassMethod Name(InternalName As %String, ByRef MappingExists As %Boolean) As %S
23982401
}
23992402
}
24002403

2404+
ClassMethod ExpandMappingParameters(MapDirectory, Settings As SourceControl.Git.Settings = {##class(SourceControl.Git.Settings).%New()})
2405+
{
2406+
return $replace(MapDirectory,"<env>", $zconvert($select(
2407+
Settings.environmentName = "": "DEVELOPMENT",
2408+
1: Settings.environmentName)
2409+
,"l"))
2410+
}
2411+
24012412
/// Implementation copied from %Library.RoutineMgr, but with results cached in a PPG.
24022413
ClassMethod UserTypeCached(Name As %String, ByRef Class As %String, ByRef StudioType As %String, ByRef Schema As %String, ByRef StudioIcon As %Integer) As %Boolean
24032414
{
@@ -2463,6 +2474,7 @@ ClassMethod NameToInternalName(Name, IgnorePercent = 1, IgnoreNonexistent = 1, V
24632474
set Deleted = 1
24642475
}
24652476
}
2477+
set settings = ##class(SourceControl.Git.Settings).%New()
24662478
if (InternalName="") {
24672479
set name=$extract(Name,$length($$$SourceRoot)+1,*)
24682480
set name=$replace(name,"\","/") // standardize slash direction
@@ -2475,6 +2487,7 @@ ClassMethod NameToInternalName(Name, IgnorePercent = 1, IgnoreNonexistent = 1, V
24752487
set bestScore = 0
24762488
set currScore = 0
24772489
while (queryary'="")&&(mappingsSubscript="mappings") {
2490+
set dir = ..ExpandMappingParameters(dir, settings)
24782491
set nam = $extract(name, $length(dir)+1, *)
24792492
if ($zconvert(subscript, "U") = $zconvert($piece(name, ".", *), "U")) {
24802493
set extScore = 1

test/UnitTest/SourceControl/Git/NameTest.cls

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,25 @@ Method TestMixedFoldering()
6464
do $$$AssertEquals(##class(Utils).Name("TestPackage.Hello.World.mac"),"rtn/TestPackage/Hello/World.mac")
6565
}
6666

67+
Method TestEnvExpansion()
68+
{
69+
try {
70+
set $$$SourceMapping("ESD","*") = "config/<env>/"
71+
set $$$SourceMapping("ESD","*","NoFolders") = 1
72+
set settings = ##class(SourceControl.Git.Settings).%New()
73+
set oldEnvName = settings.environmentName
74+
set settings.environmentName = "TEST"
75+
$$$ThrowOnError(settings.%Save())
76+
do $$$AssertEquals(##class(SourceControl.Git.Utils).Name("Ens.Config.DefaultSettings.esd"),"config/test/Ens.Config.DefaultSettings.esd")
77+
} catch err {
78+
do $$$AssertStatusOK(err.AsStatus())
79+
}
80+
if $data(settings)#2 && $data(oldEnvName)#2 {
81+
set settings.environmentName = oldEnvName
82+
$$$ThrowOnError(settings.%Save())
83+
}
84+
}
85+
6786
Method OnBeforeAllTests() As %Status
6887
{
6988
merge ..Mappings = @##class(SourceControl.Git.Utils).MappingsNode()
@@ -97,4 +116,3 @@ Method %OnClose() As %Status
97116
}
98117

99118
}
100-

test/UnitTest/SourceControl/Git/NameToInternalNameTest.cls

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,25 @@ Method TestNegative()
9191
do $$$AssertEquals(##class(SourceControl.Git.Utils).NameToInternalName("bar\NotMyBarFile1.bar", 1, 0, 1),"")
9292
}
9393

94+
Method TestEnvExpansion()
95+
{
96+
try {
97+
set $$$SourceMapping("ESD","*") = "config/<env>/"
98+
set $$$SourceMapping("ESD","*","NoFolders") = 1
99+
set settings = ##class(SourceControl.Git.Settings).%New()
100+
set oldEnvName = settings.environmentName
101+
set settings.environmentName = "TEST"
102+
$$$ThrowOnError(settings.%Save())
103+
do $$$AssertEquals(##class(SourceControl.Git.Utils).NameToInternalName("config/test/Ens.Config.DefaultSettings.ESD",1,0,1),"Ens.Config.DefaultSettings.ESD")
104+
} catch err {
105+
do $$$AssertStatusOK(err.AsStatus())
106+
}
107+
if $data(settings)#2 && $data(oldEnvName)#2 {
108+
set settings.environmentName = oldEnvName
109+
$$$ThrowOnError(settings.%Save())
110+
}
111+
}
112+
94113
Method OnBeforeAllTests() As %Status
95114
{
96115
set settings = ##class(SourceControl.Git.Settings).%New()

0 commit comments

Comments
 (0)