Skip to content

Commit b5128cc

Browse files
authored
Fix CSP file mappings (#202)
* Fix CSP file mappings Fixes #201 * Update README.md * Update module.xml
1 parent 6558422 commit b5128cc

File tree

7 files changed

+65
-8
lines changed

7 files changed

+65
-8
lines changed

CHANGELOG.md

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# git-source-control
2+
3+
All notable changes to this project will be documented in this file.
4+
5+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7+
8+
## [2.0.2] - 2022-08-09
9+
10+
### Fixed
11+
- #201: fix behavior with CSP files
12+
13+
## [2.0.1] - 2022-06-02
14+
- Last released version before CHANGELOG existed.
15+

README.md

+10
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,16 @@ The same right click menus as in Studio live under "Server Source Control..." wh
3939
4040
## Notes
4141
42+
### Mapping Configuration
43+
To specify where files should go relative to your repository root, add mappings via the "Settings" menu item. A mapping has three parts:
44+
* The file extension to use: e.g., CLS, MAC. As a special case for web application files, use "/CSP/" as the mapping.
45+
* A filter on the files of that type (e.g., a package name or web application folder)
46+
* The folder relative to the repo root that contains the item. This controls behavior for import and export.
47+
48+
This might look like:
49+
50+
![Example of mapping configuration](docs/images/settings.PNG "Example of mapping configuration")
51+
4252
### Security
4353
If you want to interact with remotes from VSCode/Studio directly (e.g., to push/pull), you must use ssh (rather than https), create a public/private key pair to identify the instance (not yourself), configure the private key file for use in Settings, and configure the public key as a deploy key in the remote(s).
4454

cls/SourceControl/Git/Utils.cls

+13-4
Original file line numberDiff line numberDiff line change
@@ -450,8 +450,11 @@ ClassMethod AddToSourceControl(InternalName As %String) As %Status
450450
if 'sc {
451451
set ec = $$$ADDSC(ec, sc)
452452
}
453-
for i=1:1:filenames{
453+
for i=1:1:$Get(filenames) {
454454
set FileInternalName = ##class(SourceControl.Git.Utils).NormalizeExtension(##class(SourceControl.Git.Utils).NameToInternalName(filenames(i), 0,,1))
455+
if (FileInternalName = "") {
456+
continue
457+
}
455458
set FileType = ##class(SourceControl.Git.Utils).Type(FileInternalName)
456459

457460
set @..#Storage@("items", FileInternalName) = ""
@@ -1566,22 +1569,28 @@ ClassMethod NameToInternalName(Name, IgnorePercent = 1, IgnoreNonexistent = 1, V
15661569
set currScore = 0
15671570
while (queryary'="")&&(mappingsSubscript="mappings") {
15681571
set nam = $extract(name, $length(dir)+1, *)
1569-
if ($zconvert(subscript, "U") = $zconvert($piece(name, ".", *), "U")){
1572+
if ($zconvert(subscript, "U") = $zconvert($piece(name, ".", *), "U")) {
1573+
set extScore = 1
1574+
} elseif (subscript = "/CSP/") {
15701575
set extScore = 1
15711576
} else {
15721577
set extScore = 0
15731578
}
15741579

1575-
if ((dir["/")&&(dir=$extract(name, 1, $length(dir)))){
1580+
if ((dir["/")&&(dir=$extract(name, 1, $length(dir)))) {
15761581
set pathScore = 1
15771582
} else {
15781583
set pathScore = 0
15791584
}
15801585

1581-
if (coverage = "*"){
1586+
if (coverage = "*") {
15821587
set covScore = 1
15831588
} elseif ($extract($translate(nam, "/", "."), 1, ($length(coverage)+1)) = (coverage_".")) {
15841589
set covScore = 2
1590+
} elseif (subscript = "/CSP/") {
1591+
// Normalize coverage to start/end with slash
1592+
set coverage = $case($extract(coverage),"/":"",:"/")_coverage_$case($extract(coverage,*),"/":"",:"/")
1593+
set covScore = pathScore
15851594
} else {
15861595
set covScore = 0
15871596
}

csp/gitprojectsettings.csp

+7-3
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,12 @@ body {
160160
<label for="privateKeyFile" class="col-sm-3 col-form-label" data-toggle="tooltip" data-placement="top" title="Absolute path to your private SSH key file">SSH Private Key File</label>
161161
<div class="col-sm-7">
162162
<server>
163-
Set fileExists=##class(%File).Exists(settings.privateKeyFile)
164-
if (fileExists) {
163+
Set fileExists = ##class(%File).Exists(settings.privateKeyFile)
164+
if (settings.privateKeyFile = "") {
165+
set class = "form-control"
166+
set divClass = "neutral-feedback"
167+
set feedbackText = "You must configure an SSH private key to be able to work with remotes. This should be set up as a deploy key / equivalent, authenticating the server, not a specific user."
168+
} elseif (fileExists) {
165169
set class = "form-control is-valid"
166170
set divClass = ""
167171
set feedbackText = ""
@@ -200,7 +204,7 @@ body {
200204
<div class="form-group row mb-3 mapping-input-group">
201205
<div class="col-sm-1"></div>
202206
<div class="col-sm-3">
203-
<label for="MappingsPath" class="col-form-label" data-toggle="tooltip" data-placement="top" title="Relative paths mapping the files in your project">Mappings</label>
207+
<label for="MappingsPath" class="col-form-label" data-toggle="tooltip" data-placement="top" title="Relative paths mapping the files in your project. For web application files, use the extension: /CSP/">Mappings</label>
204208
<button type="button" class="btn btn-default btn-add" >
205209
<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" fill="#198754" class="bi bi-plus-circle-fill" viewBox="0 0 16 16">
206210
<path d="M16 8A8 8 0 1 1 0 8a8 8 0 0 1 16 0zM8.5 4.5a.5.5 0 0 0-1 0v3h-3a.5.5 0 0 0 0 1h3v3a.5.5 0 0 0 1 0v-3h3a.5.5 0 0 0 0-1h-3v-3z"></path>

docs/images/settings.PNG

28.3 KB
Loading

module.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<Document name="git-source-control.ZPM">
44
<Module>
55
<Name>git-source-control</Name>
6-
<Version>2.0.1</Version>
6+
<Version>2.0.2</Version>
77
<Description>Server-side source control extension for use of Git on InterSystems platforms</Description>
88
<Keywords>git source control studio vscode</Keywords>
99
<Packaging>module</Packaging>

test/UnitTest/SourceControl/Git/NameToInternalNameTest.cls

+19
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,21 @@ Method TestStaticFileNames()
5555
do $$$AssertEquals(##class(SourceControl.Git.Utils).NameToInternalName("git-webui\src\js\git-webui.js", 1, 0, 1),"")
5656
}
5757

58+
Method TestWebFileNames()
59+
{
60+
// Get namespace-default web application and create a fake CSP file there
61+
set app = $System.CSP.GetDefaultApp($Namespace)
62+
if (app '= "") {
63+
set filename = app_"/unittest.csp"
64+
set routine = ##class(%CSP.Routine).%New(filename)
65+
do routine.Write("<html><head><title>Unit Test</title></head><body>It's a unit test page!</body></html>")
66+
do $$$AssertStatusOK(routine.%Save())
67+
do $$$AssertStatusOK(##class(SourceControl.Git.Utils).AddToSourceControl(filename))
68+
do $$$AssertEquals(##class(SourceControl.Git.Utils).NameToInternalName("csp\unittest.csp"),filename)
69+
do $$$AssertStatusOK(##class(SourceControl.Git.Utils).RemoveFromSourceControl(filename))
70+
}
71+
}
72+
5873
Method TestNegative()
5974
{
6075
// Based on composite scores
@@ -82,6 +97,10 @@ Method OnBeforeAllTests() As %Status
8297
$$$ThrowOnError(settings.%Save())
8398
merge ..Mappings = @##class(SourceControl.Git.Utils).MappingsNode()
8499
kill @##class(SourceControl.Git.Utils).MappingsNode()
100+
Set app = $System.CSP.GetDefaultApp($Namespace)
101+
If (app '= "") {
102+
set $$$SourceMapping("/CSP/", app) = "csp/"
103+
}
85104
set $$$SourceMapping("CLS", "*") = "cls/"
86105
set $$$SourceMapping("CLS", "UnitTest") = "test/"
87106
set $$$SourceMapping("CLS", "UnitTest.Foo") = "foo/"

0 commit comments

Comments
 (0)