Skip to content

Compile items after Import All #368

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

Merged
merged 6 commits into from
Jun 27, 2024
Merged
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
@@ -19,6 +19,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Command-line utility to do a baseline export of items in a namespace
- 'New Branch' menu option in basic now will create new branches from the configured default merge branch (#366)
- Merging back with the default merge branch is now a part of the basic mode's Sync flow (#366)
- Added a new option "compileOnImport". If true, Import options will compile files using the pull event handler. (#362)

### Fixed
- Modifications to local repo files are now synced with IRIS (#153)
33 changes: 26 additions & 7 deletions cls/SourceControl/Git/PullEventHandler/IncrementalLoad.cls
Original file line number Diff line number Diff line change
@@ -38,17 +38,36 @@ Method OnPull() As %Status
quit $system.OBJ.CompileList(.compilelist, "cukb")
}

Method DeleteFile(item As %String)
Method DeleteFile(item As %String) As %Status
{
set sc = $$$OK
set type = ##class(SourceControl.Git.Utils).Type(item)
if (type = "cls") {
quit $System.OBJ.Delete(item)
} elseif (type = "csp") {
quit $System.CSP.DeletePage(item)
set name = ##class(SourceControl.Git.Utils).NameWithoutExtension(item)
set deleted = 1
if type = "prj" {
set sc = $system.OBJ.DeleteProject(name)
}elseif type = "cls" {
set sc = $system.OBJ.Delete(item)
}elseif $listfind($listbuild("mac","int","inc","bas","mvb","mvi"), type) > 0 {
set sc = ##class(%Routine).Delete(item)
}elseif type = "csp" {
set sc = $System.CSP.DeletePage(item)
}elseif ##class(SourceControl.Git.Utils).UserTypeCached(item) {
set sc = ##class(%Library.RoutineMgr).Delete(item)
} else {
quit ##class(%Library.RoutineMgr).Delete(item)
set deleted = 0
}

if deleted && $$$ISOK(sc) {
do ##class(SourceControl.Git.Utils).RemoveRoutineTSH(item)
kill $$$TrackedItems(##class(SourceControl.Git.Utils).NormalizeExtension(item))
} else {
if +$system.Status.GetErrorCodes(sc) = $$$ClassDoesNotExist {
// if something we wanted to delete is already deleted -- good!
set sc = $$$OK
}
}
return sc
}

}

5 changes: 4 additions & 1 deletion cls/SourceControl/Git/Settings.cls
Original file line number Diff line number Diff line change
@@ -44,6 +44,9 @@ Property systemBasicMode As %Boolean [ InitialExpression = {##class(SourceContro
/// In Basic mode, Sync will merge changes from this remote branch
Property defaultMergeBranch As %String [ InitialExpression = {##class(SourceControl.Git.Utils).DefaultMergeBranch()} ];

/// Import All options compile imported options using the configured pull event handler
Property compileOnImport As %Boolean [ InitialExpression = {##class(SourceControl.Git.Utils).CompileOnImport()} ];

Property Mappings [ MultiDimensional ];

Method %OnNew() As %Status
@@ -97,6 +100,7 @@ Method %Save() As %Status
set @storage@("settings","settingsUIReadOnly") = ..settingsUIReadOnly
set @storage@("settings", "mappedItemsReadOnly") = ..mappedItemsReadOnly
set @storage@("settings", "defaultMergeBranch") = ..defaultMergeBranch
set @storage@("settings", "compileOnImport") = ..compileOnImport
set @storage@("settings", "basicMode") = ..systemBasicMode
if ..basicMode = "system" {
kill @storage@("settings", "user", $username, "basicMode")
@@ -206,4 +210,3 @@ Method OnAfterConfigure() As %Boolean
}

}

61 changes: 29 additions & 32 deletions cls/SourceControl/Git/Utils.cls
Original file line number Diff line number Diff line change
@@ -153,6 +153,11 @@ ClassMethod PrivateKeyFile() As %String
quit $get(@..#Storage@("settings","ssh","privateKeyFile"))
}

ClassMethod CompileOnImport() As %Boolean
{
quit $get(@..#Storage@("settings","compileOnImport"),1)
}

ClassMethod NeedSettings() As %Boolean [ CodeMode = expression ]
{
(..TempFolder() = "") || (..GitBinPath() = "") || (..GitBinPath() = """")
@@ -1294,13 +1299,17 @@ ClassMethod ImportRoutines(force As %Boolean = 0) As %Status

#dim ec as %Status = ..ListItemsInFiles(.itemList, .err)
quit:'ec ec

kill files

set settings = ##class(SourceControl.Git.Settings).%New()
#dim internalName as %String = ""
for {
set internalName = $order(itemList(internalName))
quit:internalName=""
set context = ##class(SourceControl.Git.PackageManagerContext).ForInternalName(internalName)
continue:context.Package'=refPackage
set doImport = ..IsRoutineOutdated(internalName) || force
if ..IsInSourceControl(internalName) {
set sc = ..ImportItem(internalName, force)
} else {
@@ -1309,7 +1318,15 @@ ClassMethod ImportRoutines(force As %Boolean = 0) As %Status
if $$$ISERR(sc) {
set ec = $$$ADDSC(ec, sc)
}
if doImport && settings.compileOnImport {
set modification = ##class(SourceControl.Git.Modification).%New()
set modification.changeType = "M"
set modification.internalName = internalName
set modification.externalName = ..FullExternalName(internalName)
set files($increment(files)) = modification
}
}


//let's delete all items for which corresponding files had been deleted
#dim item as %String = ""
@@ -1323,41 +1340,21 @@ ClassMethod ImportRoutines(force As %Boolean = 0) As %Status
set fullExternalName = ..FullExternalName(item)
if '##class(%File).Exists(fullExternalName) {
write !,fullExternalName," does not exist - deleting ",item
#dim type as %String = ..Type(item)
#dim name as %String = ..NameWithoutExtension(item)
#dim deleted as %Boolean = 1
if type = "prj" {
set ec = $$$ADDSC(ec, $system.OBJ.DeleteProject(name))
}elseif type = "cls" {
set ec = $$$ADDSC(ec, $system.OBJ.Delete(item))
}elseif $listfind($listbuild("mac","int","inc","bas","mvb","mvi"), type) > 0 {
set ec = $$$ADDSC(ec, ##class(%Routine).Delete(item))
}elseif type = "csp" {
#dim filename = $system.CSP.GetFileName(item)
if ##class(%File).Exists(filename) && '##class(%File).Delete(filename) {
set ec = $$$ADDSC(ec, ..MakeError("Error while removing "_item))
}
}elseif ..UserTypeCached(item) {
set ec = $$$ADDSC(ec, ##class(%Library.RoutineMgr).Delete(item))
} else {
set deleted = 0
}

if deleted && ec {
do ..RemoveRoutineTSH(item)
kill $$$TrackedItems(..NormalizeExtension(item))
write !, item, " was deleted"
} else {
if +$system.Status.GetErrorCodes(ec) '= $$$ClassDoesNotExist {
write !, "Error: could not delete ", item
} else {
// if something we wanted to delete is already deleted -- good!
set ec = $$$OK
}
}
set modification = ##class(SourceControl.Git.Modification).%New()
set modification.changeType = "D"
set modification.internalName = item
set modification.externalName = fullExternalName
set files($increment(files)) = modification
}
}

set eventHandler = $classmethod(..PullEventClass(),"%New")
set eventHandler.LocalRoot = ..TempFolder()
merge eventHandler.ModifiedFiles = files
set sc = eventHandler.OnPull()
if $$$ISERR(sc) {
set ec = $$$ADDSC(ec,sc)
}
write !, "==import done=="
quit ec
}
12 changes: 12 additions & 0 deletions csp/gitprojectsettings.csp
Original file line number Diff line number Diff line change
@@ -90,6 +90,8 @@ body {
set settings.mappedItemsReadOnly = 0
}

set settings.compileOnImport = ($Get(%request.Data("compileOnImport", 1)) = 1)

if ($Get(%request.Data("basicMode", 1)) = 1) {
set settings.basicMode = 1
} elseif ($Get(%request.Data("basicMode", 1)) = "system"){
@@ -336,6 +338,16 @@ body {


</div>
<div class="form-group row mb-3">
<label for="compileOnImport" class="offset-sm-1 col-sm-3 col-form-label" data-toggle="tooltip" data-placement="top" title="If true, the Import All options will compile imported options using the configured pull event handler">Compile Items on Import</label>
<div class="col-sm-7">
<div class="custom-control custom-switch custom-switch-no-border">
<input class="custom-control-input" name="compileOnImport" type="checkbox"
id="compileOnImport" #($select(settings.compileOnImport:"checked",1:""))# value="1">
<label class="custom-control-label" for="compileOnImport"></label>
</div>
</div>
</div>

<div class="form-group row mb-3 mapping-input-group">
<div class="offset-sm-1 col-sm-3">