Skip to content

Commit 5a852bd

Browse files
authored
Merge pull request #642 from intersystems/map-expand-env
Parameter expansion of environment name in mapping directory
2 parents def4a75 + b325291 commit 5a852bd

File tree

5 files changed

+54
-2
lines changed

5 files changed

+54
-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
- Added saving settings as system default for new namespaces (#535)
1314
- Added filtering through branch names in UI (#615)
1415
- FullLoad pull event handler allows deploying changes with a full import of the repository (#619)

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: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1729,6 +1729,7 @@ ClassMethod ExportSystemDefaults() As %Status
17291729
{
17301730
new %SourceControl
17311731
do ##class(%Studio.SourceControl.Interface).SourceControlCreate()
1732+
$$$QuitOnError(%SourceControl.AddToSourceControl("Ens.Config.DefaultSettings.ESD"))
17321733
quit %SourceControl.OnAfterSave("Ens.Config.DefaultSettings.ESD")
17331734
}
17341735

@@ -2376,6 +2377,9 @@ ClassMethod Name(InternalName As %String, ByRef MappingExists As %Boolean) As %S
23762377
set MappingExists = 1
23772378
}
23782379

2380+
set settings = ##class(SourceControl.Git.Settings).%New()
2381+
set found = ..ExpandMappingParameters(found)
2382+
23792383
if InternalName["/" {
23802384
// If no specific mapping was specified (p=""), then return the whole csp filename; otherwise return the name without the mapped piece
23812385
set InternalName=$extract(InternalName,$length(p)+2,*)
@@ -2399,6 +2403,14 @@ ClassMethod Name(InternalName As %String, ByRef MappingExists As %Boolean) As %S
23992403
}
24002404
}
24012405

2406+
ClassMethod ExpandMappingParameters(MapDirectory, Settings As SourceControl.Git.Settings = {##class(SourceControl.Git.Settings).%New()})
2407+
{
2408+
return $replace(MapDirectory,"<env>", $zconvert($select(
2409+
Settings.environmentName = "": "DEVELOPMENT",
2410+
1: Settings.environmentName)
2411+
,"l"))
2412+
}
2413+
24022414
/// Implementation copied from %Library.RoutineMgr, but with results cached in a PPG.
24032415
ClassMethod UserTypeCached(Name As %String, ByRef Class As %String, ByRef StudioType As %String, ByRef Schema As %String, ByRef StudioIcon As %Integer) As %Boolean
24042416
{
@@ -2464,6 +2476,7 @@ ClassMethod NameToInternalName(Name, IgnorePercent = 1, IgnoreNonexistent = 1, V
24642476
set Deleted = 1
24652477
}
24662478
}
2479+
set settings = ##class(SourceControl.Git.Settings).%New()
24672480
if (InternalName="") {
24682481
set name=$extract(Name,$length($$$SourceRoot)+1,*)
24692482
set name=$replace(name,"\","/") // standardize slash direction
@@ -2476,6 +2489,7 @@ ClassMethod NameToInternalName(Name, IgnorePercent = 1, IgnoreNonexistent = 1, V
24762489
set bestScore = 0
24772490
set currScore = 0
24782491
while (queryary'="")&&(mappingsSubscript="mappings") {
2492+
set dir = ..ExpandMappingParameters(dir, settings)
24792493
set nam = $extract(name, $length(dir)+1, *)
24802494
if ($zconvert(subscript, "U") = $zconvert($piece(name, ".", *), "U")) {
24812495
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)