Skip to content

Fix CSP file mappings #202

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 3 commits into from
Aug 9, 2022
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
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# git-source-control

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [2.0.2] - 2022-08-09

### Fixed
- #201: fix behavior with CSP files

## [2.0.1] - 2022-06-02
- Last released version before CHANGELOG existed.

10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,16 @@ The same right click menus as in Studio live under "Server Source Control..." wh

## Notes

### Mapping Configuration
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.

This might look like:

![Example of mapping configuration](docs/images/settings.PNG "Example of mapping configuration")

### Security
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).

Expand Down
17 changes: 13 additions & 4 deletions cls/SourceControl/Git/Utils.cls
Original file line number Diff line number Diff line change
Expand Up @@ -450,8 +450,11 @@ ClassMethod AddToSourceControl(InternalName As %String) As %Status
if 'sc {
set ec = $$$ADDSC(ec, sc)
}
for i=1:1:filenames{
for i=1:1:$Get(filenames) {
set FileInternalName = ##class(SourceControl.Git.Utils).NormalizeExtension(##class(SourceControl.Git.Utils).NameToInternalName(filenames(i), 0,,1))
if (FileInternalName = "") {
continue
}
set FileType = ##class(SourceControl.Git.Utils).Type(FileInternalName)

set @..#Storage@("items", FileInternalName) = ""
Expand Down Expand Up @@ -1566,22 +1569,28 @@ ClassMethod NameToInternalName(Name, IgnorePercent = 1, IgnoreNonexistent = 1, V
set currScore = 0
while (queryary'="")&&(mappingsSubscript="mappings") {
set nam = $extract(name, $length(dir)+1, *)
if ($zconvert(subscript, "U") = $zconvert($piece(name, ".", *), "U")){
if ($zconvert(subscript, "U") = $zconvert($piece(name, ".", *), "U")) {
set extScore = 1
} elseif (subscript = "/CSP/") {
set extScore = 1
} else {
set extScore = 0
}

if ((dir["/")&&(dir=$extract(name, 1, $length(dir)))){
if ((dir["/")&&(dir=$extract(name, 1, $length(dir)))) {
set pathScore = 1
} else {
set pathScore = 0
}

if (coverage = "*"){
if (coverage = "*") {
set covScore = 1
} elseif ($extract($translate(nam, "/", "."), 1, ($length(coverage)+1)) = (coverage_".")) {
set covScore = 2
} elseif (subscript = "/CSP/") {
// Normalize coverage to start/end with slash
set coverage = $case($extract(coverage),"/":"",:"/")_coverage_$case($extract(coverage,*),"/":"",:"/")
set covScore = pathScore
} else {
set covScore = 0
}
Expand Down
10 changes: 7 additions & 3 deletions csp/gitprojectsettings.csp
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,12 @@ body {
<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>
<div class="col-sm-7">
<server>
Set fileExists=##class(%File).Exists(settings.privateKeyFile)
if (fileExists) {
Set fileExists = ##class(%File).Exists(settings.privateKeyFile)
if (settings.privateKeyFile = "") {
set class = "form-control"
set divClass = "neutral-feedback"
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."
} elseif (fileExists) {
set class = "form-control is-valid"
set divClass = ""
set feedbackText = ""
Expand Down Expand Up @@ -200,7 +204,7 @@ body {
<div class="form-group row mb-3 mapping-input-group">
<div class="col-sm-1"></div>
<div class="col-sm-3">
<label for="MappingsPath" class="col-form-label" data-toggle="tooltip" data-placement="top" title="Relative paths mapping the files in your project">Mappings</label>
<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>
<button type="button" class="btn btn-default btn-add" >
<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">
<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>
Expand Down
Binary file added docs/images/settings.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion module.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<Document name="git-source-control.ZPM">
<Module>
<Name>git-source-control</Name>
<Version>2.0.1</Version>
<Version>2.0.2</Version>
<Description>Server-side source control extension for use of Git on InterSystems platforms</Description>
<Keywords>git source control studio vscode</Keywords>
<Packaging>module</Packaging>
Expand Down
19 changes: 19 additions & 0 deletions test/UnitTest/SourceControl/Git/NameToInternalNameTest.cls
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,21 @@ Method TestStaticFileNames()
do $$$AssertEquals(##class(SourceControl.Git.Utils).NameToInternalName("git-webui\src\js\git-webui.js", 1, 0, 1),"")
}

Method TestWebFileNames()
{
// Get namespace-default web application and create a fake CSP file there
set app = $System.CSP.GetDefaultApp($Namespace)
if (app '= "") {
set filename = app_"/unittest.csp"
set routine = ##class(%CSP.Routine).%New(filename)
do routine.Write("<html><head><title>Unit Test</title></head><body>It's a unit test page!</body></html>")
do $$$AssertStatusOK(routine.%Save())
do $$$AssertStatusOK(##class(SourceControl.Git.Utils).AddToSourceControl(filename))
do $$$AssertEquals(##class(SourceControl.Git.Utils).NameToInternalName("csp\unittest.csp"),filename)
do $$$AssertStatusOK(##class(SourceControl.Git.Utils).RemoveFromSourceControl(filename))
}
}

Method TestNegative()
{
// Based on composite scores
Expand Down Expand Up @@ -82,6 +97,10 @@ Method OnBeforeAllTests() As %Status
$$$ThrowOnError(settings.%Save())
merge ..Mappings = @##class(SourceControl.Git.Utils).MappingsNode()
kill @##class(SourceControl.Git.Utils).MappingsNode()
Set app = $System.CSP.GetDefaultApp($Namespace)
If (app '= "") {
set $$$SourceMapping("/CSP/", app) = "csp/"
}
set $$$SourceMapping("CLS", "*") = "cls/"
set $$$SourceMapping("CLS", "UnitTest") = "test/"
set $$$SourceMapping("CLS", "UnitTest.Foo") = "foo/"
Expand Down