Skip to content

Commit

Permalink
Merge branch 'MartinFechner-add-compatibility-for-non-expath-repos'
Browse files Browse the repository at this point in the history
  • Loading branch information
dominik kuehne committed Sep 28, 2022
2 parents 511af71 + f1e1c0b commit 232afc3
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 5 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ Synchronizes your data collection with GitHub and GitLab.

- [node](https://nodejs.org/en/): `v12+`
- [exist-db](https://www.exist-db.org): `v5.3.0+` (works with Version [GITSHA: 4a8124](https://github.com/eXist-db/exist#4a8124))
- the data xar containing the target collection must be installed prior to using Tuttle
- Authtoken for git repository to use

## Building and Installation
Expand Down Expand Up @@ -117,7 +116,9 @@ With incremental update only the changes to the database collection are applied.
2) click on 'full' to trigger a full deployment from git to existdb
3) now you can update your collection with a click on 'incremental'

**REMARK: A valid expath-pkg.xml and repo.xml must be present**
Repositories from which a valid XAR (existing expath-pkg.xml and repo.xml) package can be generated are installed as a package, all others are created purely on the DB.

**REMARK: Note that there may be index problems if a collection is not installed as a package.**

**REMARK: Only use it with data collections**

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "tuttle",
"version": "1.1.2",
"version": "1.1.3",
"description": "tuttle - a Git-integration for eXist-db",
"scripts": {
"test": "gulp install && mocha --exit",
Expand Down
2 changes: 1 addition & 1 deletion src/expath-pkg.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<package
xmlns="http://expath.org/ns/pkg"
name="http://e-editiones.org/tuttle"
abbrev="tuttle" version="1.1.2" spec="1.0">
abbrev="tuttle" version="1.1.3" spec="1.0">
<title>Tuttle - Git for eXist-db</title>
<dependency processor="http://exist-db.org" semver-min="5.3.0"/>
<dependency package="http://e-editiones.org/roaster" semver-min="1.0.0"/>
Expand Down
9 changes: 8 additions & 1 deletion src/modules/api.xql
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,15 @@ declare function api:git-deploy($request as map(*)) {
let $write-lock := app:lock-write($collection-destination, "deploy")
let $xar-list := xmldb:get-child-resources($collection-staging-uri)
let $xar-check := if (not($xar-list = "expath-pkg.xml" and $xar-list = "repo.xml")) then (
let $cleanup-col := app:cleanup-collection($git-collection, config:prefix())
let $cleanup-res := app:cleanup-resources($git-collection, config:prefix())
let $move-col := app:move-collections($collection-staging, $git-collection, config:prefix())
let $move-res := app:move-resources($collection-staging, $git-collection, config:prefix())
let $set-permissions := app:set-permission($git-collection)
return
map {
"message" : "no expath-pkg.xml or repo.xml in repo"
"sha" : app:production-sha($git-collection),
"message" : "success"
}
)
else (
Expand Down
57 changes: 57 additions & 0 deletions src/modules/app.xql
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,63 @@ declare function app:unzip-filter($path as xs:string, $data-type as xs:string, $
true()
};

(:~
: Move staging collection to final collection
:)
declare function app:move-collections($collection-source as xs:string, $collection-target as xs:string, $prefix as xs:string) {
let $fullpath-collection-source := $prefix || "/" || $collection-source
let $fullpath-collection-target := $prefix || "/" || $collection-target

return
for $child in xmldb:get-child-collections($fullpath-collection-source)
let $fullpath-child-source := $fullpath-collection-source || "/" || $child
let $fullpath-child-target := $fullpath-collection-target || "/"
return
xmldb:move($fullpath-child-source, $fullpath-child-target)
};

(:~
: Move staging collection to final collection
:)
declare function app:move-resources($collection-source as xs:string, $collection-target as xs:string, $prefix as xs:string) {
let $fullpath-collection-source := $prefix || "/" || $collection-source
let $fullpath-collection-target := $prefix || "/" || $collection-target

return
for $child in xmldb:get-child-resources($fullpath-collection-source)
return
xmldb:move($fullpath-collection-source, $fullpath-collection-target, $child)
};

(:~
: Cleanup destination collection - delete collections from target collection
:)
declare function app:cleanup-collection($collection as xs:string, $prefix as xs:string) {
let $blacklist := [config:blacklist(), config:lock()]
let $fullpath-collection := $prefix || "/" || $collection

return
for $child in xmldb:get-child-collections($fullpath-collection)
where not(contains($child, $blacklist))
let $fullpath-child := $fullpath-collection || "/" || $child
return
xmldb:remove($fullpath-child)
};

(:~
: Cleanup destination collection - delete resources from target collection
:)
declare function app:cleanup-resources($collection as xs:string, $prefix as xs:string) {
let $blacklist := config:blacklist()
let $fullpath-collection := $prefix || "/" || $collection

return
for $child in xmldb:get-child-resources($fullpath-collection)
where not(contains($child, $blacklist))
return
xmldb:remove($fullpath-collection, $child)
};

(:~
: Random apikey generator
:)
Expand Down

0 comments on commit 232afc3

Please sign in to comment.