Skip to content
Open
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 @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Change context menu now lists IPM packages from all Git-enabled namespaces, prefixed with the namespace name (#952)
- Pull event handler option in settings page now displays user-friendly names for options (#908)
- Validation that SSH key file path is not a directory when configuring Embedded Git (#943)
- Customization of IPM load flags using `##class(SourceControl.Git.PullEventHandler.PackageManager).ConfigureLoadFlags(.flags)` (#974)

### Fixed
- Changes to % routines mapped to the current namespace may now be added to source control and committed (#944)
Expand Down
17 changes: 17 additions & 0 deletions cls/SourceControl/Git/PullEventHandler/PackageManager.cls
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,27 @@ Parameter DESCRIPTION = "Does zpm ""load <repo root>""";
Method OnPull() As %Status
{
set command = "load "_..LocalRoot
set additionalFlags = ..GetLoadFlags()
if (additionalFlags'="") set command = command _ " " _ additionalFlags
quit $select(
$$$comClassDefined("%IPM.Main"): ##class(%IPM.Main).Shell(command),
1: ##class(%ZPM.PackageManager).Shell(command)
)
}

/// Configures additional flags to be used with zpm "load" by Package Manager pull event handlers

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does this handle flags that look different, e.g. load -dev -DNoMapping=1 -extra-pip-flags "--timeout 30"?
Should also probably test that these get handled correctly.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. I don't want to implement full argument parsing here so I'm going to go with the simple solution of just having a string of flags that gets injected directly into the zpm shell command.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@isc-dchui This is done, and ready for another round of review please

/// Example: to use `zpm "load -DNoMapping=1"` run the following:
/// ```
/// do ##class(SourceControl.Git.PullEventHandler.PackageManager).ConfigureLoadFlags("-DNoMapping=1")
/// ```
ClassMethod ConfigureLoadFlags(flags = "")
{
set @##class(SourceControl.Git.Utils).#Storage@("settings","IPM","loadFlags") = flags
}

ClassMethod GetLoadFlags() As %String
{
return $get(@##class(SourceControl.Git.Utils).#Storage@("settings","IPM","loadFlags"))
}

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Class SourceControl.Git.PullEventHandler.PackageManagerReload Extends SourceControl.Git.PullEventHandler
Class SourceControl.Git.PullEventHandler.PackageManagerReload Extends SourceControl.Git.PullEventHandler.PackageManager
{

Parameter NAME = "Package Manager Reload";
Expand All @@ -20,11 +20,8 @@ Method OnPull() As %Status
)
$$$QuitOnError(sc)
}
set command = "load "_..LocalRoot
quit $select(
$$$comClassDefined("%IPM.Main"): ##class(%IPM.Main).Shell(command),
1: ##class(%ZPM.PackageManager).Shell(command)
)
/// super class loads the IPM package
return ##super()
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/// integration tests for the Package Manager Reload pull event handler
Class UnitTest.SourceControl.Git.PullEventHandler.PackageManagerReload Extends UnitTest.SourceControl.Git.AbstractTest
{

Method TestLoadUninstallsThenInstalls()
{
set testModulePath = ##class(SourceControl.Git.PackageManagerContext).ForInternalName("git-source-control.zpm").Package.Root_"test/_resources/simplest-module"
set pullEventHandler = ##class(SourceControl.Git.PullEventHandler.PackageManagerReload).%New()
set pullEventHandler.LocalRoot = testModulePath
// pull once to install simplest-module
do $$$AssertStatusOK(pullEventHandler.OnPull())
// pull again to verify uninstall + install
do $$$AssertStatusOK(pullEventHandler.OnPull())
set history = ##class(%IPM.General.History).GetHistory(,,2)
do $$$AssertTrue(history.%Next())
do $$$AssertEquals(history.Action,"load")
do $$$AssertTrue(history.%Next())
do $$$AssertEquals(history.Action,"uninstall")
do $$$AssertEquals(history.CommandString,"uninstall simplest-module")
zpm "uninstall simplest-module"
}

Method TestLoadUsesConfiguredFlags()
{
set testModulePath = ##class(SourceControl.Git.PackageManagerContext).ForInternalName("git-source-control.zpm").Package.Root_"test/_resources/simplest-module"
set initFlags = $get(@##class(SourceControl.Git.Utils).#Storage@("settings","IPM","loadFlags"))
set flags = "-DNoMapping=1 -extra-pip-flags ""--timeout 30"""
do ##class(SourceControl.Git.PullEventHandler.PackageManagerReload).ConfigureLoadFlags(flags)
set pullEventHandler = ##class(SourceControl.Git.PullEventHandler.PackageManagerReload).%New()
set pullEventHandler.LocalRoot = testModulePath
do $$$AssertStatusOK(pullEventHandler.OnPull())
set history = ##class(%IPM.General.History).GetHistory(,,2)
do $$$AssertTrue(history.%Next())
do $$$AssertEquals(history.Action,"load")
do $$$AssertEquals(history.CommandString, "load "_testModulePath_" -DNoMapping=1 -extra-pip-flags ""--timeout 30""")
zpm "uninstall simplest-module"
do ##class(SourceControl.Git.PullEventHandler.PackageManagerReload).ConfigureLoadFlags(initFlags)
}

}
10 changes: 10 additions & 0 deletions test/_resources/simplest-module/module.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<Export generator="Cache" version="25">
<Document name="simplest-module.ZPM">
<Module>
<Name>simplest-module</Name>
<Version>1.0.0</Version>
<Packaging>module</Packaging>
</Module>
</Document>
</Export>
Loading