Skip to content

Commit 494d7d6

Browse files
committed
Initial commit
1 parent d1c2ee9 commit 494d7d6

File tree

5 files changed

+535
-0
lines changed

5 files changed

+535
-0
lines changed

isc/git/Diff.cls.xml

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<Export generator="Cache" version="25">
3+
<Class name="isc.git.Diff">
4+
<Super>isc.util.OSUtils</Super>
5+
<TimeCreated>64700,69295.723984</TimeCreated>
6+
7+
<Method name="buildDiff">
8+
<Description>
9+
Get diff between two points in repository
10+
repo - repository root directory
11+
sha1, commitEnd - poins of history in repository
12+
modified - list of modified files
13+
added - list of added files
14+
deleted - list of deleted files
15+
16+
Internal diff statuses:
17+
M modified - File has been modified
18+
C copy-edit - File has been copied and modified //3-arg form
19+
R rename-edit - File has been renamed and modified //3-arg form
20+
A added - File has been added
21+
D deleted - File has been deleted
22+
U unmerged - File has conflicts after a merge
23+
24+
do ##class(isc.git.Diff).buildDiff("C:\\temp\GitLab\", "HEAD~10", "HEAD", .modified, .added, .deleted)</Description>
25+
<ClassMethod>1</ClassMethod>
26+
<FormalSpec>repo:%String,commitBegin:%String,commitEnd:%String,*modified:%List,*added:%List,*deleted:%List</FormalSpec>
27+
<Implementation><![CDATA[
28+
#include %occCPTJSgen
29+
set (modified, added, deleted) = ""
30+
$$$TOE(sc, ..createFile(.tempFile))
31+
do $system.Process.CurrentDirectory(repo)
32+
$$$TOE(sc, ..execute($$$FormatText("git diff --name-status %1 %2 > %3 2>&1", commitBegin, commitEnd, tempFile)))
33+
$$$TOE(sc, ..fileToString(tempFile, .diffRaw))
34+
for i=1:1:$length(diffRaw, $c(10)) {
35+
set element = $piece(diffRaw, $c(10), i)
36+
set status = $e($piece(element, $$$TAB))
37+
set file = $piece(element, $$$TAB, 2)
38+
39+
if ((element="") || ('..isRelevantFile(repo, file))) {
40+
continue
41+
} elseif ($length(element, $$$TAB)=2) {
42+
if ((status="M") || (status="U")) {
43+
set modified = modified _ $lb(file)
44+
} elseif (status="A") {
45+
set added = added _ $lb(file)
46+
} elseif (status="D") {
47+
set deleted = deleted _ $lb(file)
48+
} else {
49+
throw ##class(%Exception.General).%New("INVALID DIFF STATUS: " _ status)
50+
}
51+
} elseif ($length(element, $$$TAB)=3) {
52+
set newFile = $piece(element, $c(9), 3)
53+
if (status="C") {
54+
set added = added _ $lb(newFile)
55+
} elseif (status="R") {
56+
set added = added _ $lb(newFile)
57+
set deleted = deleted _ $lb(file)
58+
} else {
59+
throw ##class(%Exception.General).%New("INVALID DIFF STATUS: " _ status)
60+
}
61+
} else {
62+
throw ##class(%Exception.General).%New("INVALID DIFF LINE: " _ element)
63+
}
64+
}
65+
]]></Implementation>
66+
</Method>
67+
68+
<Method name="isRelevantFile">
69+
<Description>
70+
Determine if the file is neede for git diff </Description>
71+
<ClassMethod>1</ClassMethod>
72+
<FormalSpec>dir:%String,file:%String</FormalSpec>
73+
<ReturnType>%Boolean</ReturnType>
74+
<Implementation><![CDATA[
75+
set ext = $select($length(file, ".")=1:"", 1:$piece(file, ".", *))
76+
quit $lf(##class(isc.git.Settings).getSetting("ext"), ext)>0
77+
]]></Implementation>
78+
</Method>
79+
</Class>
80+
</Export>

isc/git/GitLab.cls.xml

Lines changed: 265 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,265 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<Export generator="Cache" version="25">
3+
<Class name="isc.git.GitLab">
4+
<TimeCreated>64700,73518.498808</TimeCreated>
5+
6+
<Method name="getDir">
7+
<ClassMethod>1</ClassMethod>
8+
<CodeMode>expression</CodeMode>
9+
<Implementation><![CDATA[##class(%File).NormalizeDirectory($system.Util.GetEnviron("CI_PROJECT_DIR"))
10+
]]></Implementation>
11+
</Method>
12+
13+
<Method name="getCommit">
14+
<Description>
15+
For CI build - get current commit</Description>
16+
<ClassMethod>1</ClassMethod>
17+
<CodeMode>expression</CodeMode>
18+
<Implementation><![CDATA[$system.Util.GetEnviron("CI_COMMIT_SHA")
19+
]]></Implementation>
20+
</Method>
21+
22+
<Method name="load">
23+
<Description>
24+
Do a full load
25+
do ##class(isc.git.GitLab).load()</Description>
26+
<ClassMethod>1</ClassMethod>
27+
<Implementation><![CDATA[
28+
try {
29+
set dir = ..getDir()
30+
do ..log("Importing dir " _ dir)
31+
do $system.OBJ.ImportDir(dir, ..getExtWildcard(), "c", .errors, 1)
32+
throw:$get(errors,0)'=0 ##class(%Exception.General).%New("Load error")
33+
34+
do ..init()
35+
36+
$$$TOE(sc, ##class(isc.git.Settings).setSetting("commit", ..getCommit()))
37+
38+
halt
39+
} catch ex {
40+
write !,$System.Status.GetErrorText(ex.AsStatus()),!
41+
do $system.Process.Terminate(, 1)
42+
}
43+
]]></Implementation>
44+
</Method>
45+
46+
<Method name="loadDiff">
47+
<Description>
48+
Do a diff load
49+
do ##class(isc.git.GitLab).loadDiff()</Description>
50+
<ClassMethod>1</ClassMethod>
51+
<Implementation><![CDATA[
52+
try {
53+
#dim sc,sc1 As %Status = $$$OK
54+
set oldCommit = ##class(isc.git.Settings).getSetting("commit")
55+
if (oldCommit="") {
56+
do ..log("Previous commit not found. Doing full load.")
57+
do ..load()
58+
halt
59+
} else {
60+
set dir = ..getDir()
61+
set newCommit = ..getCommit()
62+
do ..log("Importing dir " _ dir)
63+
do ..log($$$FormatText("Loading diff between %1 and %2", oldCommit, newCommit))
64+
}
65+
66+
do ##class(isc.git.Diff).buildDiff(dir, oldCommit, newCommit, .modified, .added, .deleted)
67+
68+
set modified = modified _ added
69+
do ..logVar(modified, "modified")
70+
set items = ""
71+
72+
for i=1:1:$ll(modified) {
73+
set file = dir _ $lg(modified, i)
74+
set sc = $$$ADDSC(sc, $system.OBJ.Load(file,"", .errors, .item,,,,"UTF8"))
75+
merge items = item
76+
}
77+
78+
do ..logVar(.items, "items")
79+
set sc = $$$ADDSC(sc, $system.OBJ.CompileList(.items, "cuk /checkuptodate=expandedonly", .errors))
80+
81+
// To-Do delete
82+
set deleteCode = ##class(isc.git.Settings).getSetting("delete")
83+
if (($ll(deleted)>0) && (deleteCode '="")) {
84+
do $classmethod($p(deleteCode, ":"), $p(deleteCode, ":", 2))
85+
}
86+
87+
throw:$$$ISERR(sc) ##class(%Exception.StatusException).CreateFromStatus(sc)
88+
throw:$get(errors,0)'=0 ##class(%Exception.General).%New("Load error")
89+
90+
do ..init()
91+
92+
$$$TOE(sc, ##class(isc.git.Settings).setSetting("commit", ..getCommit()))
93+
94+
$$$TOE(sc, $system.OBJ.Export(.items, dir _ "diff.xml"))
95+
96+
halt
97+
} catch ex {
98+
do ..logException(ex)
99+
do $system.Process.Terminate(, 1)
100+
}
101+
]]></Implementation>
102+
</Method>
103+
104+
<Method name="init">
105+
<ClassMethod>1</ClassMethod>
106+
<Implementation><![CDATA[
107+
set init = ##class(isc.git.Settings).getSetting("init")
108+
if (init'="") {
109+
do ..log("Running init code: " _ init)
110+
do $classmethod($p(init, ":"), $p(init, ":", 2))
111+
} else {
112+
do ..log("No init code")
113+
}
114+
]]></Implementation>
115+
</Method>
116+
117+
<Method name="test">
118+
<Description>
119+
do ##class(isc.git.GitLab).test()</Description>
120+
<ClassMethod>1</ClassMethod>
121+
<Implementation><![CDATA[
122+
try {
123+
set tests = ##class(isc.git.Settings).getSetting("tests")
124+
if (tests'="") {
125+
set dir = ..getDir()
126+
set ^UnitTestRoot = dir
127+
128+
$$$TOE(sc, ##class(%UnitTest.Manager).RunTest(tests, "/nodelete"))
129+
$$$TOE(sc, ..writeTestHTML())
130+
throw:'..isLastTestOk() ##class(%Exception.General).%New("Tests error")
131+
}
132+
halt
133+
} catch ex {
134+
do ..logException(ex)
135+
do $system.Process.Terminate(, 1)
136+
}
137+
]]></Implementation>
138+
</Method>
139+
140+
<Method name="package">
141+
<Description>
142+
do ##class(GitLab.Main).package()</Description>
143+
<ClassMethod>1</ClassMethod>
144+
<Implementation><![CDATA[
145+
try {
146+
set dir = ..getDir()
147+
// TODO
148+
do $system.OBJ.ExportAllClasses(dir _ "full.xml", , .errors)
149+
throw:$g(errors,0)'=0 ##class(%Exception.General).%New("Package error")
150+
halt
151+
} catch ex {
152+
do ..logException(ex)
153+
do $system.Process.Terminate(, 1)
154+
}
155+
]]></Implementation>
156+
</Method>
157+
158+
<Method name="writeTestHTML">
159+
<ClassMethod>1</ClassMethod>
160+
<Implementation><![CDATA[
161+
set text = ##class(%Dictionary.XDataDefinition).IDKEYOpen($classname(), "html").Data.Read()
162+
set text = $replace(text, "!!!", ..getURL())
163+
164+
set file = ##class(%Stream.FileCharacter).%New()
165+
set name = ..getDir() _ "tests.html"
166+
do file.LinkToFile(name)
167+
do file.Write(text)
168+
quit file.%Save()
169+
]]></Implementation>
170+
</Method>
171+
172+
<Method name="getURL">
173+
<ClassMethod>1</ClassMethod>
174+
<Implementation><![CDATA[
175+
set url = ##class(isc.git.Settings).getSetting("url")
176+
set url = url _ $system.CSP.GetDefaultApp("%SYS")
177+
set url = url_"/%25UnitTest.Portal.Indices.cls?Index="_ $g(^UnitTest.Result, 1) _ "&$NAMESPACE=" _ $zconvert($namespace,"O","URL")
178+
quit url
179+
]]></Implementation>
180+
</Method>
181+
182+
<Method name="getExtWildcard">
183+
<Description>
184+
Get extensions as wildcard for import</Description>
185+
<ClassMethod>1</ClassMethod>
186+
<ReturnType>%String</ReturnType>
187+
<Implementation><![CDATA[
188+
set extList = ##class(isc.git.Settings).getSetting("ext")
189+
set ext = "*." _ $lts(##class(isc.git.Settings).getSetting("ext"), ";*.")
190+
quit ext
191+
]]></Implementation>
192+
</Method>
193+
194+
<Method name="isLastTestOk">
195+
<Description>
196+
w ##class(GitLab.Main).isLastTestOk()</Description>
197+
<ClassMethod>1</ClassMethod>
198+
<ReturnType>%Boolean</ReturnType>
199+
<Implementation><![CDATA[
200+
set in = ##class(%UnitTest.Result.TestInstance).%OpenId(^UnitTest.Result)
201+
for i=1:1:in.TestSuites.Count() {
202+
#dim suite As %UnitTest.Result.TestSuite
203+
set suite = in.TestSuites.GetAt(i)
204+
return:suite.Status=0 $$$NO
205+
}
206+
quit $$$YES
207+
]]></Implementation>
208+
</Method>
209+
210+
<XData name="html">
211+
<Data><![CDATA[
212+
<html lang="en-US">
213+
<head>
214+
<meta charset="UTF-8"/>
215+
<meta http-equiv="refresh" content="0; url=!!!"/>
216+
<script type="text/javascript">
217+
window.location.href = "!!!"
218+
</script>
219+
</head>
220+
<body>
221+
If you are not redirected automatically, follow this <a href='!!!'>link to tests</a>.
222+
</body>
223+
</html>
224+
]]></Data>
225+
</XData>
226+
227+
<Method name="logVar">
228+
<ClassMethod>1</ClassMethod>
229+
<FormalSpec>var="",name:%String=""</FormalSpec>
230+
<ReturnType>%String</ReturnType>
231+
<Implementation><![CDATA[
232+
do ..log("Variable " _ name)
233+
zw var
234+
/*if $isObject(var) {
235+
zw var
236+
} elseif $listValid(var) {
237+
write $lts(var, ", ")
238+
} else {
239+
write var
240+
}*/
241+
]]></Implementation>
242+
</Method>
243+
244+
<Method name="logException">
245+
<ClassMethod>1</ClassMethod>
246+
<FormalSpec>ex:%Exception.AbstractException</FormalSpec>
247+
<Implementation><![CDATA[ do ..logStatus(ex.AsStatus())
248+
]]></Implementation>
249+
</Method>
250+
251+
<Method name="logStatus">
252+
<ClassMethod>1</ClassMethod>
253+
<FormalSpec>sc:%Status</FormalSpec>
254+
<Implementation><![CDATA[ do ..log($System.Status.GetErrorText(sc))
255+
]]></Implementation>
256+
</Method>
257+
258+
<Method name="log">
259+
<ClassMethod>1</ClassMethod>
260+
<FormalSpec>msg:%String</FormalSpec>
261+
<Implementation><![CDATA[ write !, $$$FormatText("[%1] %2", $zdatetime($ztimestamp, 3, 1, 3), msg), !
262+
]]></Implementation>
263+
</Method>
264+
</Class>
265+
</Export>

0 commit comments

Comments
 (0)