Skip to content

Commit ebc44c0

Browse files
committed
Merge branch 'main' into production-change-control
2 parents b22e84b + a7e343a commit ebc44c0

File tree

15 files changed

+166
-68
lines changed

15 files changed

+166
-68
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
4949
- Fixed sending OS error when git pull encounters error (#545)
5050
- Fixed suppressing editing of locked classes (#301)
5151
- Fixed importing CSP files (#251)
52+
- Fixed changing favorites for users without permissions (#587)
53+
- Fix creating new branch from Git Web UI (#591)
54+
- Fix wording for Git Repo Root Directory (#601)
5255

5356
## [2.6.0] - 2024-10-07
5457

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,9 @@ git-source control is the recommended source control for Health Connect Cloud. [
5454
5555
### VSCode
5656
57-
Source control menus will appear under "Server Source Control..." when right-clicking in a file (in the editor) or on a file when exploring an isfs folder. The top level "source control" menu is accessible through the command palette or the source control icon in the top right of the editor.
57+
Source control menus will appear under "Server Source Control..." when right-clicking in a file (in the editor) or on a file when exploring an isfs folder. The top level "source control" menu is accessible through the command palette or the source control icon near the top right of the editor.
58+
59+
![Source control icon in VSCode](/docs/images/source-control-menu.gif)
5860
5961
For full details on all of the menu items, see [this reference page](/docs/menu-items.md).
6062
@@ -85,6 +87,9 @@ This might look like:
8587
8688
![Example of mapping configuration](docs/images/settings.PNG "Example of mapping configuration")
8789
90+
### Baselining Source Code
91+
If enabling source control on an existing system, you will need to create a baseline by exporting all existing items to the Git repository. See [our documentation on baselining](/docs/baselining.md).
92+
8893
### Pull Event Handlers
8994
9095
The class `SourceControl.Git.PullEventHandler` is a base class that can be extended in order to develop functionality that should be run when the repository pulls from remote. The code placed inside the subclass' OnPull() method will be executed any time a pull occurs.

cls/SourceControl/Git/Settings.cls

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Class SourceControl.Git.Settings Extends %RegisteredObject
88
/// Path to git executable
99
Property gitBinPath As %String(MAXLEN = "");
1010

11-
/// Local git repo root folder
11+
/// Local git repo root directory
1212
Property namespaceTemp As %String(MAXLEN = "") [ InitialExpression = {##class(SourceControl.Git.Utils).TempFolder()}, Required ];
1313

1414
/// Path to private key file for SSH remotes; if file does not exist, later prompts will help set it up with proper ownership
@@ -178,7 +178,7 @@ Method %Save() As %Status
178178
kill @##class(SourceControl.Git.Utils).MappingsNode()
179179
merge @##class(SourceControl.Git.Utils).MappingsNode() = ..Mappings
180180

181-
do ##class(SourceControl.Git.Utils).ConfigureFavoriteNamespaces($username, ..favoriteNamespaces)
181+
do ##class(%zpkg.isc.sc.git.Favorites).ConfigureFavoriteNamespaces($username, ..favoriteNamespaces)
182182

183183
quit $$$OK
184184
}

cls/SourceControl/Git/Utils.cls

Lines changed: 1 addition & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ $Get(@..#Storage@("settings","decomposeProdAllowIDE"), 0)
8585
ClassMethod FavoriteNamespaces() As %String
8686
{
8787
set favNamespaces = []
88-
do ..GetFavoriteNamespaces(.favNamespaces,[])
88+
do ##class(%zpkg.isc.sc.git.Favorites).GetFavoriteNamespaces(.favNamespaces,[])
8989
return favNamespaces
9090
}
9191

@@ -3016,56 +3016,4 @@ ClassMethod InDefaultBranchBasicMode() As %Boolean
30163016
quit 0
30173017
}
30183018

3019-
ClassMethod ConfigureFavoriteNamespaces(username As %String, newNamespaces As %String)
3020-
{
3021-
// Delete all the GIT favorite links for the user
3022-
&sql(DELETE FROM %SYS_Portal.Users WHERE Username = :username AND Page LIKE '%Git%')
3023-
3024-
set iterator = newNamespaces.%GetIterator()
3025-
while iterator.%GetNext(.key, .value) {
3026-
set installNamespace = value
3027-
3028-
// Insert Git link
3029-
set caption = "Git: " _ installNamespace
3030-
set link = "/isc/studio/usertemplates/gitsourcecontrol/webuidriver.csp/" _ installNamespace _ "/"
3031-
&sql(INSERT OR UPDATE INTO %SYS_Portal.Users (Username, Page, Data) VALUES (:username, :caption, :link))
3032-
3033-
// Insert Git Pull link
3034-
set caption = "Git Pull: " _ installNamespace
3035-
set link = "/isc/studio/usertemplates/gitsourcecontrol/pull.csp?$NAMESPACE=" _ installNamespace
3036-
&sql(INSERT OR UPDATE INTO %SYS_Portal.Users (Username, Page, Data) VALUES (:username, :caption, :link))
3037-
}
3038-
}
3039-
3040-
ClassMethod GetFavoriteNamespaces(ByRef favNamespaces As %DynamicArray, ByRef nonFavNamespaces As %DynamicArray)
3041-
{
3042-
set allNamespaces = ..GetContexts(1)
3043-
set iterator = allNamespaces.%GetIterator()
3044-
3045-
set username = $USERNAME
3046-
set pagePrefix = "Git:"
3047-
&sql(DECLARE FavCursor CURSOR FOR SELECT Page into :page from %SYS_Portal.Users where username = :username and page %STARTSWITH :pagePrefix)
3048-
3049-
while iterator.%GetNext(.key, .value) {
3050-
set foundFlag = 0
3051-
&sql(OPEN FavCursor)
3052-
throw:SQLCODE<0 ##class(%Exception.SQL).CreateFromSQLCODE(SQLCODE, %msg)
3053-
&sql(FETCH FavCursor)
3054-
while (SQLCODE = 0) {
3055-
set pageValue = "Git: "_value
3056-
if (page = pageValue) {
3057-
do favNamespaces.%Push(value)
3058-
set foundFlag = 1
3059-
}
3060-
&sql(FETCH FavCursor)
3061-
}
3062-
&sql(CLOSE FavCursor)
3063-
3064-
if ('foundFlag) {
3065-
do nonFavNamespaces.%Push(value)
3066-
}
3067-
}
3068-
}
3069-
30703019
}
3071-

cls/SourceControl/Git/WebUIDriver.cls

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ ClassMethod HandleRequest(pagePath As %String, InternalName As %String = "", Out
102102
do %request.Set("EXPIRES",0)
103103
do ##class(%CSP.StreamServer).OnPreHTTP() // Need to call this to set headers properly
104104
set %stream = 1 // Leak this to webuidriver.csp
105-
} elseif $match(pathStart,"git-command|git|dirname|hostname|viewonly|discarded-states|restore-discarded|contexts") {
105+
} elseif $match(pathStart,"git-command|git|dirname|hostname|viewonly|discarded-states|restore-discarded|contexts|create-branch") {
106106
if (%request.Method = "GET") {
107107
set %data = ##class(%Stream.TmpCharacter).%New()
108108
// Things not handled from Python backend:
@@ -218,6 +218,7 @@ ClassMethod HandleRequest(pagePath As %String, InternalName As %String = "", Out
218218
} else {
219219
set inFile = ""
220220
}
221+
221222
set returnCode = ##class(SourceControl.Git.Utils).RunGitCommandWithInput("-c",inFile,.errStream,.outStream,gitArgs...)
222223

223224
set %data = ##class(%Stream.TmpCharacter).%New()
@@ -328,6 +329,21 @@ ClassMethod HandleRequest(pagePath As %String, InternalName As %String = "", Out
328329
do %data.Rewind()
329330
do ##class(SourceControl.Git.Change).RefreshUncommitted(,,,1)
330331
set handled = 1
332+
} elseif (pathStart = "create-branch") {
333+
set branchName = $get(%request.Data("branch",1),"")
334+
if (branchName = "") {
335+
do %data.Write("ERROR! Enter a valid branch name")
336+
} else {
337+
set %data = ##class(%Stream.TmpCharacter).%New()
338+
339+
set st = ##class(SourceControl.Git.Utils).NewBranch(branchName)
340+
if $$$ISERR(st) {
341+
do %data.Write("Error! "_$System.Status.GetErrorText(st))
342+
} else {
343+
do %data.Write(branchName_" branch created!")
344+
}
345+
set handled = 1
346+
}
331347
}
332348
}
333349
}
@@ -426,4 +442,3 @@ ClassMethod GetRemote() As %Library.DynamicObject
426442
}
427443

428444
}
429-

cls/_zpkg/isc/sc/git/Favorites.cls

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
Class %zpkg.isc.sc.git.Favorites
2+
{
3+
ClassMethod ConfigureFavoriteNamespaces(username As %String, newNamespaces As %Library.DynamicObject)
4+
{
5+
// Convert to $listbuild
6+
set namespaces = $lb()
7+
set iterator = newNamespaces.%GetIterator()
8+
9+
while iterator.%GetNext(.key, .value) {
10+
set namespaces = namespaces_$lb(value)
11+
}
12+
13+
// Call the private method
14+
try {
15+
do ..SetFavs(username, namespaces)
16+
} catch e {
17+
return e.AsStatus()
18+
}
19+
return $$$OK
20+
}
21+
22+
ClassMethod GetFavoriteNamespaces(ByRef favNamespaces As %DynamicArray, ByRef nonFavNamespaces As %DynamicArray)
23+
{
24+
try {
25+
set namespaces = ..GetFavs()
26+
set favNamespaces = namespaces.%Get("Favorites")
27+
set nonFavNamespaces = namespaces.%Get("NonFavorites")
28+
} catch e {
29+
return e.AsStatus()
30+
}
31+
return $$$OK
32+
}
33+
34+
ClassMethod GetFavs() As %Library.DynamicObject [ Private, NotInheritable ] {
35+
$$$AddAllRoleTemporary
36+
set allNamespaces = ##class(SourceControl.Git.Utils).GetContexts(1)
37+
38+
set favNamespaces = []
39+
set nonFavNamespaces = []
40+
41+
set username = $USERNAME
42+
set pagePrefix = "Git:"
43+
&sql(DECLARE FavCursor CURSOR FOR SELECT Page into :page from %SYS_Portal.Users where username = :username and page %STARTSWITH :pagePrefix)
44+
45+
for i=0:1:(allNamespaces.%Size() - 1) {
46+
set namespace = allNamespaces.%Get(i)
47+
set foundFlag = 0
48+
&sql(OPEN FavCursor)
49+
throw:SQLCODE<0 ##class(%Exception.SQL).CreateFromSQLCODE(SQLCODE, %msg)
50+
&sql(FETCH FavCursor)
51+
while (SQLCODE = 0) {
52+
set pageValue = "Git: "_namespace
53+
if (page = pageValue) {
54+
do favNamespaces.%Push(namespace)
55+
set foundFlag = 1
56+
}
57+
&sql(FETCH FavCursor)
58+
}
59+
&sql(CLOSE FavCursor)
60+
61+
if ('foundFlag) {
62+
do nonFavNamespaces.%Push(namespace)
63+
}
64+
}
65+
return {"Favorites": (favNamespaces), "NonFavorites": (nonFavNamespaces)}
66+
}
67+
68+
ClassMethod SetFavs(username As %String, namespaces As %List) [ Private, NotInheritable ] {
69+
$$$AddAllRoleTemporary
70+
&sql(DELETE FROM %SYS_Portal.Users WHERE Username = :username AND Page LIKE '%Git%')
71+
72+
for i=1:1:$listlength(namespaces) {
73+
set namespace = $listget(namespaces, i)
74+
if (namespace '= "") {
75+
set installNamespace = namespace
76+
77+
// Insert Git link
78+
set caption = "Git: " _ installNamespace
79+
set link = "/isc/studio/usertemplates/gitsourcecontrol/webuidriver.csp/" _ installNamespace _ "/"
80+
&sql(INSERT OR UPDATE INTO %SYS_Portal.Users (Username, Page, Data) VALUES (:username, :caption, :link))
81+
82+
// Insert Git Pull link
83+
set caption = "Git Pull: " _ installNamespace
84+
set link = "/isc/studio/usertemplates/gitsourcecontrol/pull.csp?$NAMESPACE=" _ installNamespace
85+
&sql(INSERT OR UPDATE INTO %SYS_Portal.Users (Username, Page, Data) VALUES (:username, :caption, :link))
86+
}
87+
}
88+
}
89+
}

csp/gitprojectsettings.csp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ body {
258258
</div>
259259

260260
<div class="form-group row mb-3">
261-
<label for="namespaceTemp" class="offset-sm-1 col-sm-3 col-form-label" data-toggle="tooltip" data-placement="top" title="Absolute path to you project">Temp folder for this namespace<br/></label>
261+
<label for="namespaceTemp" class="offset-sm-1 col-sm-3 col-form-label" data-toggle="tooltip" data-placement="top" title="Absolute path to you project">Git Repo Root Directory<br/></label>
262262
<server>
263263
set dir = ##class(%File).NormalizeDirectory(settings.namespaceTemp)
264264
if (settings.namespaceTemp '= "") && ##class(%File).DirectoryExists(dir_".git") {
@@ -654,7 +654,7 @@ body {
654654
<server>
655655
set nonFavNamespaces = []
656656
set selectedNamespaces = []
657-
do ##class(SourceControl.Git.Utils).GetFavoriteNamespaces(.selectedNamespaces,.nonFavNamespaces)
657+
do ##class(%zpkg.isc.sc.git.Favorites).GetFavoriteNamespaces(.selectedNamespaces,.nonFavNamespaces)
658658
set iterator = selectedNamespaces.%GetIterator()
659659
while iterator.%GetNext(.key, .value) {
660660
&html<<option selected value=#(value)#>#(value)#</option>>

docs/baselining.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Baselining Source Code
2+
Baselining source code is the first step to enabling source control on an existing system. Baselining synchronizes the Git repository with a source of truth, usually the current state of the production environment. This establishes a clean starting point so that any future changes can be tracked.
3+
4+
Git-source-control includes an API method `BaselineExport` that may be run in an IRIS terminal to export items in a namespace to the configured Git repository.
5+
6+
A baselining workflow will commonly include these steps:
7+
- Create a new remote repository on your Git platform of choice.
8+
- Use `do ##class(SourceControl.Git.API).Configure()` to configure Git on the production environment (or a copy of the production environment). Clone the new remote repository.
9+
- Use the Settings page in the Source Control menu to customize the mapping configuration.
10+
- Use the Source Control menu to check out a new branch for the baseline export.
11+
- Use the `BaselineExport` method to export all items to the Git repository, commit, and push to the remote: `do ##class(SourceControl.Git.API).BaselineExport("initial baseline commit","origin")`
12+
- Create a merge or pull request on your remote Git platform from the baseline branch to the main branch. Review the code to ensure it includes all required items. If needed, modify the mapping configuration and redo the baseline export. When the baseline is satisfactory, merge it into the main branch.
13+
- Use the Source Control menu to switch back to the main branch on the production environment.
14+
- For each other environment, configure Git to clone that same remote repository. From the Source Control menu, run Import All (Force) to load all items from the baseline.

docs/hcc.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,22 @@ Use the link in the output of the sync in order to create a merge request in the
3636

3737
Suppose you begin working on a larger project in one branch, and then need to shift to something else. The proper approach to this in git-source-control is to commit your in-progress work on the first interface, and then to switch to a new branch. This branch will be based on the development branch and may be missing components from the first project, but that's OK. You can always switch back to the first interface branch to continue work there.
3838

39+
## Configuring Git on a New Namespace
40+
41+
When creating a new namespace on the Health Connect instance, you will need to ensure that the Git configuration matches that in other namespaces. The steps to do so are:
42+
43+
- Configure the mappings in the settings. From the Settings page in the source control menu, view the Mappings configuration and confirm it matches the other namespaces. Below is a sample of a common mapping configuration.
44+
45+
![Mappings Configuration](images/hcc/configuremappings.png)
46+
47+
- Configure the default merge branch. From the Settings page in the source control menu, the "Default merge branch" input should match that configured for other namespaces.
48+
49+
![Default merge branch](images/hcc/configuremergebranch.png)
50+
51+
- Run "Import All (Force)" from the source control menu. This will initially populate the namespace with items from the Git repository.
52+
53+
![Import All (Force)](images/hcc/importallforce.png)
54+
3955
## Deploying Changes to the Main Dev Namespace
4056

4157
If you are using a CI/CD pipeline in GitLab, simply merging the feature branch to development is enough; your change will be deployed to the main development namespace automatically.

docs/images/hcc/configuremappings.png

40.1 KB
Loading

0 commit comments

Comments
 (0)