Skip to content

Commit 2ec1604

Browse files
authored
Merge pull request #44 from eeditiones/520-compat
improvements and fixes
2 parents 8bbe9fd + c018bba commit 2ec1604

File tree

7 files changed

+67
-39
lines changed

7 files changed

+67
-39
lines changed

.github/workflows/node.js.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ jobs:
2323
include:
2424
- exist-version: latest
2525
experimental: true
26-
26+
- exist-version: 5.2.0
27+
experimental: true
2728
services:
2829
# Label used to access the service container
2930
exist:

package.json

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
{
22
"name": "tuttle",
3-
"version": "1.2.0",
3+
"version": "2.0.0",
44
"description": "tuttle - a Git-integration for eXist-db",
55
"scripts": {
66
"start": "gulp",
77
"test": "gulp install && mocha --exit",
88
"test:watch": "mocha --watch",
9-
"test:build": "gulp test:install",
10-
"build": "gulp build",
11-
"build:all": "gulp build && gulp test:build",
9+
"build": "gulp xar",
1210
"deploy": "gulp install",
1311
"copy": "gulp copyStatic"
1412
},

src/api.json

+14-14
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
},
2020
"cookieAuth": {
2121
"type": "apiKey",
22-
"name": "eeditiones.org.login",
22+
"name": "org.exist.login",
2323
"in": "cookie"
2424
}
2525
}
@@ -29,7 +29,7 @@
2929
"get": {
3030
"summary": "Fetch git repo to staging collection",
3131
"x-constraints": {
32-
"user": "admin"
32+
"groups": ["dba"]
3333
},
3434
"operationId": "api:git-pull",
3535
"parameters": [
@@ -71,7 +71,7 @@
7171
"post": {
7272
"summary": "Deploy repo to final collection",
7373
"x-constraints": {
74-
"user": "admin"
74+
"groups": ["dba"]
7575
},
7676
"operationId": "api:git-deploy",
7777
"parameters": [
@@ -107,7 +107,7 @@
107107
"get": {
108108
"summary": "Fetch git repo to staging collection",
109109
"x-constraints": {
110-
"user": "admin"
110+
"groups": ["dba"]
111111
},
112112
"operationId": "api:git-pull-default",
113113
"parameters": [
@@ -141,7 +141,7 @@
141141
"post": {
142142
"summary": "Deploy repo to final collection",
143143
"x-constraints": {
144-
"user": "admin"
144+
"groups": ["dba"]
145145
},
146146
"operationId": "api:git-deploy",
147147
"responses": {
@@ -167,7 +167,7 @@
167167
"post": {
168168
"summary": "Trigger incremental update",
169169
"x-constraints": {
170-
"user": "admin"
170+
"groups": ["dba"]
171171
},
172172
"operationId": "api:incremental",
173173
"parameters": [
@@ -215,7 +215,7 @@
215215
"post": {
216216
"summary": "Trigger incremental update",
217217
"x-constraints": {
218-
"user": "admin"
218+
"groups": ["dba"]
219219
},
220220
"operationId": "api:incremental",
221221
"parameters": [
@@ -255,7 +255,7 @@
255255
"get": {
256256
"summary": "Get remote and local hash",
257257
"x-constraints": {
258-
"user": "admin"
258+
"groups": ["dba"]
259259
},
260260
"operationId": "api:get-hash",
261261
"parameters": [
@@ -299,7 +299,7 @@
299299
"get": {
300300
"summary": "Get remote and local hash",
301301
"x-constraints": {
302-
"user": "admin"
302+
"groups": ["dba"]
303303
},
304304
"operationId": "api:get-hash",
305305
"responses": {
@@ -333,7 +333,7 @@
333333
"get": {
334334
"summary": "Get commits",
335335
"x-constraints": {
336-
"user": "admin"
336+
"groups": ["dba"]
337337
},
338338
"operationId": "api:get-commits",
339339
"parameters": [
@@ -373,7 +373,7 @@
373373
"get": {
374374
"summary": "Get commits",
375375
"x-constraints": {
376-
"user": "admin"
376+
"groups": ["dba"]
377377
},
378378
"operationId": "api:get-commits-default",
379379
"parameters": [
@@ -461,7 +461,7 @@
461461
"get": {
462462
"summary": "Generate API-Webhook-Keys",
463463
"x-constraints": {
464-
"user": "admin"
464+
"groups": ["dba"]
465465
},
466466
"operationId": "api:api-keygen",
467467
"parameters": [
@@ -497,7 +497,7 @@
497497
"get": {
498498
"summary": "Generate API-Webhook-Keys",
499499
"x-constraints": {
500-
"user": "admin"
500+
"groups": ["dba"]
501501
},
502502
"operationId": "api:api-keygen",
503503
"responses": {
@@ -523,7 +523,7 @@
523523
"get": {
524524
"summary": "Get Tuttle configuration",
525525
"x-constraints": {
526-
"user": "admin"
526+
"groups": ["dba"]
527527
},
528528
"operationId": "api:get-status",
529529
"responses": {

src/expath-pkg.xml

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<package xmlns="http://expath.org/ns/pkg" spec="1.0"
33
name="http://e-editiones.org/tuttle" abbrev="tuttle" version="2.0.0">
44
<title>Tuttle - Git for eXist-db</title>
5-
<dependency processor="http://exist-db.org" semver-min="5.5.1" semver-max="6" />
5+
<dependency processor="http://exist-db.org" semver-min="5.2.0" semver-max="6" />
66
<dependency package="http://e-editiones.org/roaster" semver-min="1.0.0"/>
7-
<dependency package="http://expath.org/ns/crypto" semver-min="5.0.0"/>
7+
<dependency package="http://expath.org/ns/crypto" semver-min="1.0.0"/>
88
</package>

src/modules/api.xql

+19-11
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,23 @@ declare variable $api:definitions := ("api.json");
2525
:)
2626
declare function api:get-status($request as map(*)) {
2727
if (contains(request:get-header('Accept'), 'application/json'))
28-
then map {
29-
'default': config:default-collection(),
30-
'repos': array {
31-
config:list-collections() ! api:collection-info(.)
28+
then
29+
map {
30+
'default': config:default-collection(),
31+
'repos': array {
32+
for $collection-info in config:list-collections()
33+
return
34+
api:collection-info($collection-info)
35+
}
3236
}
33-
}
3437
else
3538
<tuttle>
3639
<default>{config:default-collection()}</default>
3740
<repos>{
38-
config:list-collections()
39-
! api:collection-info(.)
40-
! api:repo-xml(.)
41+
for $collection-info in config:list-collections()
42+
return
43+
api:repo-xml(
44+
api:collection-info($collection-info))
4145
}</repos>
4246
</tuttle>
4347
};
@@ -53,7 +57,9 @@ declare function api:repo-xml ($info as map(*)) as element(repo) {
5357
declare function api:collection-info ($collection as xs:string) as map(*) {
5458
let $collection-config := api:get-collection-config($collection)
5559
(: hide passwords and tokens :)
56-
let $masked := map:remove($collection-config, ("hookpasswd", "token"))
60+
let $masked :=
61+
map:remove(
62+
map:remove($collection-config, "hookpasswd"), "token")
5763

5864
return
5965
try {
@@ -103,7 +109,7 @@ declare function api:get-hash($request as map(*)) as map(*) {
103109
let $last-remote-commit := $actions?get-last-commit($collection-config)
104110

105111
return map {
106-
"remote-hash": $last-remote-commit?sha,
112+
"remote-hash": app:shorten-sha($last-remote-commit?sha),
107113
"local-hash": $collection-config?deployed,
108114
"local-staging-hash": doc($collection-staging)/hash/value/text()
109115
}
@@ -413,6 +419,8 @@ declare function api:hook($request as map(*)) as map(*) {
413419
let $config := api:get-collection-config($request?parameters?collection)
414420
let $apikey := doc(config:apikeys())//apikeys/collection[name = $config?collection]/key/string()
415421
let $lockfile := $config?path || "/" || config:lock()
422+
let $actions := vcs:get-actions($config?type)
423+
416424
return
417425
if (empty($apikey)) then (
418426
map { "message": "apikey does not exist" }
@@ -430,7 +438,7 @@ declare function api:hook($request as map(*)) as map(*) {
430438

431439
let $incremental := $actions?incremental($config)
432440

433-
let $remove-lock := app:lock-remove($collection-path)
441+
let $remove-lock := app:lock-remove($config?path)
434442

435443
return
436444
map {

src/modules/app.xql

+4-1
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,10 @@ declare function app:set-permission($collection as xs:string) {
151151
};
152152

153153
declare function app:get-permissions ($collection as xs:string) {
154-
if (doc-available($collection || "/repo.xml")) then (
154+
if (
155+
doc-available($collection || "/repo.xml") and
156+
exists(doc($collection || "/repo.xml")//repo:permissions)
157+
) then (
155158
let $repo := doc($collection || "/repo.xml")//repo:permissions
156159
return map {
157160
"user": $repo/@user/string(),

src/modules/github.xql

+24-6
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,21 @@ declare function github:get-changes ($collection-config as map(*)) as map(*) {
120120
return github:get-commit-files($collection-config, $sha)?*
121121

122122
(: aggregate file changes :)
123-
return fold-left($changes, map{}, github:aggregate-filechanges#2)
124-
123+
let $aggregated := fold-left($changes, map{}, github:aggregate-filechanges#2)
124+
let $filtered := fold-left($aggregated?new, map{}, function($res, $next) {
125+
if (
126+
$next = ("build.xml", "repo.xml", "expath-pkg.xml")
127+
or starts-with($next, ".git")
128+
or ends-with($next, ".xconf")
129+
)
130+
then map:put($res, 'ignored', ($res?ignored, $next))
131+
else map:put($res, 'new', ($res?new, $next))
132+
})
133+
return map {
134+
"del": $aggregated?del,
135+
"new": $filtered?new,
136+
"ignored": $filtered?ignored
137+
}
125138
};
126139

127140
(:~
@@ -137,14 +150,18 @@ declare function github:remove-or-ignore ($changes as map(*), $filename as xs:st
137150
else map:put($changes, "del", ($changes?del, $filename)) (: add document to be removed :)
138151
};
139152

153+
(: unhandled cases: "copied", "changed", "unchanged" :)
140154
declare function github:aggregate-filechanges ($changes as map(*), $next as map(*)) as map(*) {
141155
switch ($next?status)
142156
case "added" (: fall-through :)
143157
case "modified" return
144-
map:put($changes, "new", ($changes?new, $next?filename))
158+
if ($next?filename = $changes?new) (: file already in new list :)
159+
then $changes
160+
else map:put($changes, "new", ($changes?new, $next?filename))
145161
case "renamed" return
146-
github:remove-or-ignore($changes, $next?previous_filename)
147-
=> map:put("new", ($changes?new, $next?filename))
162+
github:remove-or-ignore(
163+
map:put($changes, "new", ($changes?new, $next?filename)),
164+
$next?previous_filename)
148165
case "removed" return
149166
github:remove-or-ignore($changes, $next?filename)
150167
default return
@@ -158,7 +175,8 @@ declare function github:incremental-dry($config as map(*)) {
158175
let $changes := github:get-changes($config)
159176
return map {
160177
'new': array{ $changes?new },
161-
'del': array{ $changes?del }
178+
'del': array{ $changes?del },
179+
'ignored': array{ $changes?ignored }
162180
}
163181
};
164182

0 commit comments

Comments
 (0)