Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parameter expansion of environment name in mapping directory #642

Merged
merged 3 commits into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
- Added saving settings as system default for new namespaces (#535)
- Added filtering through branch names in UI (#615)

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
14 changes: 14 additions & 0 deletions cls/SourceControl/Git/Utils.cls
Original file line number Diff line number Diff line change
Expand Up @@ -1728,6 +1728,7 @@ ClassMethod ExportSystemDefaults() As %Status
{
new %SourceControl
do ##class(%Studio.SourceControl.Interface).SourceControlCreate()
$$$QuitOnError(%SourceControl.AddToSourceControl("Ens.Config.DefaultSettings.ESD"))
quit %SourceControl.OnAfterSave("Ens.Config.DefaultSettings.ESD")
}

Expand Down Expand Up @@ -2374,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 @@ -2397,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 @@ -2462,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 @@ -2474,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",1,0,1),"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
Loading