Skip to content

Commit

Permalink
XML -> UDL
Browse files Browse the repository at this point in the history
  • Loading branch information
eduard93 committed Mar 26, 2018
1 parent 8babd6d commit 234b1af
Show file tree
Hide file tree
Showing 6 changed files with 239 additions and 332 deletions.
67 changes: 28 additions & 39 deletions isc/git/Diff.cls.xml → isc/git/Diff.cls
Original file line number Diff line number Diff line change
@@ -1,30 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<Export generator="Cache" version="25">
<Class name="isc.git.Diff">
<Super>isc.util.OSUtils</Super>
<TimeCreated>64700,69295.723984</TimeCreated>
Class isc.git.Diff Extends isc.util.OSUtils
{

<Method name="buildDiff">
<Description>
Get diff between two points in repository
repo - repository root directory
sha1, commitEnd - poins of history in repository
modified - list of modified files
added - list of added files
deleted - list of deleted files

Internal diff statuses:
M modified - File has been modified
C copy-edit - File has been copied and modified //3-arg form
R rename-edit - File has been renamed and modified //3-arg form
A added - File has been added
D deleted - File has been deleted
U unmerged - File has conflicts after a merge

do ##class(isc.git.Diff).buildDiff("C:\\temp\GitLab\", "HEAD~10", "HEAD", .modified, .added, .deleted)</Description>
<ClassMethod>1</ClassMethod>
<FormalSpec>repo:%String,commitBegin:%String,commitEnd:%String,*modified:%List,*added:%List,*deleted:%List</FormalSpec>
<Implementation><![CDATA[
/// Get diff between two points in repository
/// repo - repository root directory
/// sha1, commitEnd - poins of history in repository
/// modified - list of modified files
/// added - list of added files
/// deleted - list of deleted files
///
/// Internal diff statuses:
/// M modified - File has been modified
/// C copy-edit - File has been copied and modified //3-arg form
/// R rename-edit - File has been renamed and modified //3-arg form
/// A added - File has been added
/// D deleted - File has been deleted
/// U unmerged - File has conflicts after a merge
///
/// do ##class(isc.git.Diff).buildDiff("C:\\temp\GitLab\", "HEAD~10", "HEAD", .modified, .added, .deleted)
ClassMethod buildDiff(repo As %String, commitBegin As %String, commitEnd As %String, Output modified As %List, Output added As %List, Output deleted As %List)
{
#include %occCPTJSgen
set (modified, added, deleted) = ""
$$$TOE(sc, ..createFile(.tempFile))
Expand Down Expand Up @@ -62,19 +56,14 @@ do ##class(isc.git.Diff).buildDiff("C:\\temp\GitLab\", "HEAD~10", "HEAD", .modif
throw ##class(%Exception.General).%New("INVALID DIFF LINE: " _ element)
}
}
]]></Implementation>
</Method>
}

<Method name="isRelevantFile">
<Description>
Determine if the file is neede for git diff </Description>
<ClassMethod>1</ClassMethod>
<FormalSpec>dir:%String,file:%String</FormalSpec>
<ReturnType>%Boolean</ReturnType>
<Implementation><![CDATA[
/// Determine if the file is neede for git diff
ClassMethod isRelevantFile(dir As %String, file As %String) As %Boolean
{
set ext = $select($length(file, ".")=1:"", 1:$piece(file, ".", *))
quit $lf(##class(isc.git.Settings).getSetting("ext"), ext)>0
]]></Implementation>
</Method>
</Class>
</Export>
}

}

183 changes: 70 additions & 113 deletions isc/git/GitLab.cls.xml → isc/git/GitLab.cls
Original file line number Diff line number Diff line change
@@ -1,30 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<Export generator="Cache" version="25">
<Class name="isc.git.GitLab">
<TimeCreated>64700,73518.498808</TimeCreated>

<Method name="getDir">
<ClassMethod>1</ClassMethod>
<CodeMode>expression</CodeMode>
<Implementation><![CDATA[##class(%File).NormalizeDirectory($system.Util.GetEnviron("CI_PROJECT_DIR"))
]]></Implementation>
</Method>

<Method name="getCommit">
<Description>
For CI build - get current commit</Description>
<ClassMethod>1</ClassMethod>
<CodeMode>expression</CodeMode>
<Implementation><![CDATA[$system.Util.GetEnviron("CI_COMMIT_SHA")
]]></Implementation>
</Method>

<Method name="load">
<Description>
Do a full load
do ##class(isc.git.GitLab).load()</Description>
<ClassMethod>1</ClassMethod>
<Implementation><![CDATA[
Class isc.git.GitLab
{

ClassMethod getDir() [ CodeMode = expression ]
{
##class(%File).NormalizeDirectory($system.Util.GetEnviron("CI_PROJECT_DIR"))
}

/// For CI build - get current commit
ClassMethod getCommit() [ CodeMode = expression ]
{
$system.Util.GetEnviron("CI_COMMIT_SHA")
}

/// Do a full load
/// do ##class(isc.git.GitLab).load()
ClassMethod load()
{
try {
set dir = ..getDir()
do ..log("Importing dir " _ dir)
Expand All @@ -40,15 +31,12 @@ do ##class(isc.git.GitLab).load()</Description>
write !,$System.Status.GetErrorText(ex.AsStatus()),!
do $system.Process.Terminate(, 1)
}
]]></Implementation>
</Method>
}

<Method name="loadDiff">
<Description>
Do a diff load
do ##class(isc.git.GitLab).loadDiff()</Description>
<ClassMethod>1</ClassMethod>
<Implementation><![CDATA[
/// Do a diff load
/// do ##class(isc.git.GitLab).loadDiff()
ClassMethod loadDiff()
{
try {
#dim sc,sc1 As %Status = $$$OK
set oldCommit = ##class(isc.git.Settings).getSetting("commit")
Expand Down Expand Up @@ -98,27 +86,22 @@ do ##class(isc.git.GitLab).loadDiff()</Description>
do ..logException(ex)
do $system.Process.Terminate(, 1)
}
]]></Implementation>
</Method>
}

<Method name="init">
<ClassMethod>1</ClassMethod>
<Implementation><![CDATA[
ClassMethod init()
{
set init = ##class(isc.git.Settings).getSetting("init")
if (init'="") {
do ..log("Running init code: " _ init)
do $classmethod($p(init, ":"), $p(init, ":", 2))
} else {
do ..log("No init code")
}
]]></Implementation>
</Method>
}

<Method name="test">
<Description>
do ##class(isc.git.GitLab).test()</Description>
<ClassMethod>1</ClassMethod>
<Implementation><![CDATA[
/// do ##class(isc.git.GitLab).test()
ClassMethod test()
{
try {
set tests = ##class(isc.git.Settings).getSetting("tests")
if (tests'="") {
Expand All @@ -134,14 +117,11 @@ do ##class(isc.git.GitLab).test()</Description>
do ..logException(ex)
do $system.Process.Terminate(, 1)
}
]]></Implementation>
</Method>
}

<Method name="package">
<Description>
do ##class(GitLab.Main).package()</Description>
<ClassMethod>1</ClassMethod>
<Implementation><![CDATA[
/// do ##class(GitLab.Main).package()
ClassMethod package()
{
try {
set dir = ..getDir()
// TODO
Expand All @@ -152,12 +132,10 @@ do ##class(GitLab.Main).package()</Description>
do ..logException(ex)
do $system.Process.Terminate(, 1)
}
]]></Implementation>
</Method>
}

<Method name="writeTestHTML">
<ClassMethod>1</ClassMethod>
<Implementation><![CDATA[
ClassMethod writeTestHTML()
{
set text = ##class(%Dictionary.XDataDefinition).IDKEYOpen($classname(), "html").Data.Read()
set text = $replace(text, "!!!", ..getURL())

Expand All @@ -166,49 +144,38 @@ do ##class(GitLab.Main).package()</Description>
do file.LinkToFile(name)
do file.Write(text)
quit file.%Save()
]]></Implementation>
</Method>
}

<Method name="getURL">
<ClassMethod>1</ClassMethod>
<Implementation><![CDATA[
ClassMethod getURL()
{
set url = ##class(isc.git.Settings).getSetting("url")
set url = url _ $system.CSP.GetDefaultApp("%SYS")
set url = url_"/%25UnitTest.Portal.Indices.cls?Index="_ $g(^UnitTest.Result, 1) _ "&$NAMESPACE=" _ $zconvert($namespace,"O","URL")
quit url
]]></Implementation>
</Method>
}

<Method name="getExtWildcard">
<Description>
Get extensions as wildcard for import</Description>
<ClassMethod>1</ClassMethod>
<ReturnType>%String</ReturnType>
<Implementation><![CDATA[
/// Get extensions as wildcard for import
ClassMethod getExtWildcard() As %String
{
set extList = ##class(isc.git.Settings).getSetting("ext")
set ext = "*." _ $lts(##class(isc.git.Settings).getSetting("ext"), ";*.")
quit ext
]]></Implementation>
</Method>
}

<Method name="isLastTestOk">
<Description>
w ##class(GitLab.Main).isLastTestOk()</Description>
<ClassMethod>1</ClassMethod>
<ReturnType>%Boolean</ReturnType>
<Implementation><![CDATA[
/// w ##class(GitLab.Main).isLastTestOk()
ClassMethod isLastTestOk() As %Boolean
{
set in = ##class(%UnitTest.Result.TestInstance).%OpenId(^UnitTest.Result)
for i=1:1:in.TestSuites.Count() {
#dim suite As %UnitTest.Result.TestSuite
set suite = in.TestSuites.GetAt(i)
return:suite.Status=0 $$$NO
}
quit $$$YES
]]></Implementation>
</Method>
}

<XData name="html">
<Data><![CDATA[
XData html
{
<html lang="en-US">
<head>
<meta charset="UTF-8"/>
Expand All @@ -221,14 +188,10 @@ window.location.href = "!!!"
If you are not redirected automatically, follow this <a href='!!!'>link to tests</a>.
</body>
</html>
]]></Data>
</XData>
}

<Method name="logVar">
<ClassMethod>1</ClassMethod>
<FormalSpec>var="",name:%String=""</FormalSpec>
<ReturnType>%String</ReturnType>
<Implementation><![CDATA[
ClassMethod logVar(var = "", name As %String = "") As %String
{
do ..log("Variable " _ name)
zw var
/*if $isObject(var) {
Expand All @@ -238,28 +201,22 @@ If you are not redirected automatically, follow this <a href='!!!'>link to tests
} else {
write var
}*/
]]></Implementation>
</Method>
}

ClassMethod logException(ex As %Exception.AbstractException)
{
do ..logStatus(ex.AsStatus())
}

ClassMethod logStatus(sc As %Status)
{
do ..log($System.Status.GetErrorText(sc))
}

<Method name="logException">
<ClassMethod>1</ClassMethod>
<FormalSpec>ex:%Exception.AbstractException</FormalSpec>
<Implementation><![CDATA[ do ..logStatus(ex.AsStatus())
]]></Implementation>
</Method>
ClassMethod log(msg As %String)
{
write !, $$$FormatText("[%1] %2", $zdatetime($ztimestamp, 3, 1, 3), msg), !
}

<Method name="logStatus">
<ClassMethod>1</ClassMethod>
<FormalSpec>sc:%Status</FormalSpec>
<Implementation><![CDATA[ do ..log($System.Status.GetErrorText(sc))
]]></Implementation>
</Method>
}

<Method name="log">
<ClassMethod>1</ClassMethod>
<FormalSpec>msg:%String</FormalSpec>
<Implementation><![CDATA[ write !, $$$FormatText("[%1] %2", $zdatetime($ztimestamp, 3, 1, 3), msg), !
]]></Implementation>
</Method>
</Class>
</Export>
50 changes: 50 additions & 0 deletions isc/git/Settings.cls
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
Include %syPrompt

Class isc.git.Settings
{

/// List of extensions relevant to code load
Parameter EXT As List = {$lb("xml", "cls", "csp", "csr", "mac", "int", "bas", "inc", "gbl", "prj", "obj", "pkg", "gof", "dfi", "pivot", "dashboard")};

Parameter URL = "http://127.0.0.1:57772";

Parameter GLVN = "^isc.git.Settings";

/// Get setting
/// Получить настойку
/// write ##class(isc.git.Settings).getSetting("ext")
ClassMethod getSetting(name As %String) As %String [ CodeMode = expression ]
{
$get(@..#GLVN@($zcvt(name, "l")), $parameter(,$zcvt(name, "U")))
}

/// Get setting
/// Установить настройку
/// write ##class(isc.git.Settings).setSetting("ext")
ClassMethod setSetting(name As %String = "", value As %String = "") As %Status
{
#dim sc As %Status = $$$OK

if name = "tests" {
// Path relative from the repo root to test suite
} elseif name = "ext" {
set:'$listValid(value) sc = $$$ERROR($$$GeneralError, "Extension list should be in $lb format.")
} elseif name = "commit" {
// TO-DO commit validation.
} elseif name = "init" {
set:$length(value, ":")'=2 sc = $$$ERROR($$$GeneralError, "Init should be in a format: 'class:method'")
} elseif name = "delete" {
set:$length(value, ":")'=2 sc = $$$ERROR($$$GeneralError, "Delete should be in a format: 'class:method'")
} elseif name = "url" {
// TO-DO url validation.
// "http://127.0.0.1:57772"
} else {
set sc = $$$ERROR($$$GeneralError, $$$FormatText("Setting '%1' does not exist", name))
}

set:$$$ISOK(sc) @..#GLVN@($zcvt(name, "l")) = value
return sc
}

}

Loading

0 comments on commit 234b1af

Please sign in to comment.