@@ -42,34 +42,31 @@ declare function api:get-status($request as map(*)) {
42
42
};
43
43
44
44
declare function api:repo-xml ($info as map (*)) as element (repo) {
45
- <repo type = "{$info?type } " url = "{$info?url} "
46
- ref = "{$info?ref} " collection = "{$info?collection} "
47
- message = "{$info?message} " status = "{$info?status} " />
45
+ element repo {
46
+ map:for-each ($info, function ($name as xs:string, $value) as attribute () {
47
+ attribute { $attribute } { $value }
48
+ })
49
+ }
48
50
};
49
51
50
52
declare function api:collection-info ($collection as xs:string) as map (*) {
51
53
let $collection-config := api:get-collection-config ($collection)
52
- let $actions := vcs:get-actions ($collection-config?vcs)
53
- let $deployed-commit-hash := doc ($collection-config?path || "/gitsha.xml" )/hash/value /string ()
54
- let $info := map {
55
- 'deployed' : $deployed-commit-hash,
56
- 'type' : $collection-config?vcs,
57
- 'ref' : $collection-config?ref,
58
- 'collection' : $collection-config?collection
59
- }
54
+ (: hide passwords and tokens :)
55
+ let $masked := map:remove ($collection-config, ("hookpasswd" , "token" ))
60
56
61
57
return
62
58
try {
59
+ let $actions := vcs:get-actions ($collection-config?type )
63
60
let $url := $actions?get-url ($collection-config)
64
61
let $last-remote-commit := $actions?get-last-commit ($collection-config)
65
62
let $remote-short-sha := app:shorten-sha ($last-remote-commit?sha)
66
63
67
64
let $status :=
68
- if ($last- remote-commit? sha = "" )
65
+ if ($remote-short- sha = "" )
69
66
then "error"
70
- else if (empty ($deployed-commit-hash ))
67
+ else if (empty ($collection-config?deployed ))
71
68
then "new"
72
- else if ($deployed-commit-hash = $remote-short-sha)
69
+ else if ($collection-config?deployed = $remote-short-sha)
73
70
then "uptodate"
74
71
else "behind"
75
72
@@ -78,15 +75,15 @@ declare function api:collection-info ($collection as xs:string) as map(*) {
78
75
then "no commit on remote"
79
76
else "remote found"
80
77
81
- return map:merge (( $info , map {
78
+ return map:merge (( $masked , map {
82
79
'url' : $url,
83
80
'remote' : $remote-short-sha,
84
81
'message' : $message,
85
82
'status' : $status
86
83
}))
87
84
}
88
85
catch * {
89
- map:merge (( $info , map {
86
+ map:merge (( $masked , map {
90
87
'message' : $err:description,
91
88
'status' : 'error'
92
89
}))
@@ -99,14 +96,14 @@ declare function api:collection-info ($collection as xs:string) as map(*) {
99
96
declare function api:get-hash ($request as map (*)) as map (*) {
100
97
try {
101
98
let $collection-config := api:get-collection-config ($request?parameters?collection)
102
- let $actions := vcs:get-actions ($collection-config?vcs )
99
+ let $actions := vcs:get-actions ($collection-config?type )
103
100
let $collection-staging := $collection-config?path || config:suffix () || "/gitsha.xml"
104
101
105
102
let $last-remote-commit := $actions?get-last-commit ($collection-config)
106
103
107
104
return map {
108
105
"remote-hash" : $last-remote-commit?sha,
109
- "local-hash" : app:production-sha ( $collection-config?collection) ,
106
+ "local-hash" : $collection-config?deployed ,
110
107
"local-staging-hash" : doc ($collection-staging)/hash/value /text ()
111
108
}
112
109
}
@@ -172,7 +169,7 @@ declare function api:git-pull($request as map(*)) {
172
169
map { "message" : doc ($lockfile)/task/value /text () || " in progress" }
173
170
)
174
171
else (
175
- let $actions := vcs:get-actions ($config?vcs )
172
+ let $actions := vcs:get-actions ($config?type )
176
173
let $write-lock := app:lock-write ($collection-destination, "git-pull" )
177
174
let $commit :=
178
175
if ($request?parameters?hash) then (
@@ -206,7 +203,7 @@ declare function api:git-pull-default($request as map(*)) {
206
203
map { "message" : doc ($lockfile)/task/value /text () || " in progress" }
207
204
)
208
205
else (
209
- let $actions := vcs:get-actions ($config?vcs )
206
+ let $actions := vcs:get-actions ($config?type )
210
207
let $write-lock := app:lock-write ($collection-destination, "git-pull" )
211
208
let $commit :=
212
209
if ($request?parameters?hash)
@@ -261,8 +258,8 @@ declare function api:git-deploy($request as map(*)) {
261
258
let $set-permissions := app:set-permission ($config?collection)
262
259
return
263
260
map {
264
- "sha" : app:production -sha ($config?collection ),
265
- "message" : "success"
261
+ "sha" : config:deployed -sha ($config?path ),
262
+ "message" : "success"
266
263
}
267
264
)
268
265
else (
@@ -285,8 +282,8 @@ declare function api:git-deploy($request as map(*)) {
285
282
let $install := repo:install-and-deploy-from-db (concat ($collection-staging-uri, "/pkg.xar" ))
286
283
return
287
284
map {
288
- "sha" : app:production -sha ($config?collection ),
289
- "message" : "success"
285
+ "sha" : config:deployed -sha ($config?path ),
286
+ "message" : "success"
290
287
}
291
288
)
292
289
let $remove-staging := xmldb:remove ($collection-staging-uri)
@@ -309,9 +306,11 @@ declare function api:git-deploy($request as map(*)) {
309
306
declare function api:get-commits ($request as map (*)) as map (*) {
310
307
try {
311
308
let $config := api:get-collection-config ($request?parameters?collection)
312
- let $actions := vcs:get-actions ($config?vcs )
309
+ let $actions := vcs:get-actions ($config?type )
313
310
314
- return $actions?get-commits ($config, $request?parameters?count )
311
+ return map {
312
+ 'commits' : $actions?get-commits ($config, $request?parameters?count )
313
+ }
315
314
}
316
315
catch * {
317
316
map {
@@ -329,7 +328,7 @@ declare function api:get-commits($request as map(*)) as map(*) {
329
328
declare function api:get-commits-default ($request as map (*)) as map (*) {
330
329
try {
331
330
let $config := api:get-default-collection-config ()
332
- let $actions := vcs:get-actions ($config?vcs )
331
+ let $actions := vcs:get-actions ($config?type )
333
332
334
333
return map {
335
334
'commits' : $actions?get-commits ($config, $request?parameters?count )
@@ -355,7 +354,7 @@ declare function api:incremental($request as map(*)) as map(*) {
355
354
let $collection-path := $config?path
356
355
let $lockfile := $collection-path || "/" || config:lock ()
357
356
let $collection-destination-sha := $collection-path || "/gitsha.xml"
358
- let $actions := vcs:get-actions ($config?vcs )
357
+ let $actions := vcs:get-actions ($config?type )
359
358
360
359
return
361
360
if (not (xmldb:collection-available ($collection-path))) then (
@@ -366,21 +365,21 @@ declare function api:incremental($request as map(*)) as map(*) {
366
365
)
367
366
else if (exists ($drymode) and $drymode) then
368
367
map {
369
- "changes" : $actions?incremental-dry ($config, $config?collection ),
368
+ "changes" : $actions?incremental-dry ($config),
370
369
"message" : "success"
371
370
}
372
371
else if (doc-available ($lockfile)) then (
373
372
map { "message" : doc ($lockfile)/task/value /text () || " in progress" }
374
373
)
375
374
else (
376
375
let $write-lock := app:lock-write ($collection-path, "incremental" )
377
- let $incremental := $actions?incremental ($config, $config?collection )
376
+ let $incremental := $actions?incremental ($config)
378
377
let $remove-lock := app:lock-remove ($collection-path)
379
378
380
379
return
381
380
map {
382
- "sha" : app:production -sha ($config?collection ),
383
- "message" : "success"
381
+ "sha" : config:deployed -sha ($config?path ),
382
+ "message" : "success"
384
383
}
385
384
)
386
385
}
@@ -434,14 +433,14 @@ declare function api:hook($request as map(*)) {
434
433
let $login := xmldb:login ($config?path, $config?hookuser, $config?hookpasswd)
435
434
let $write-lock := app:lock-write ($config?path, "hook" )
436
435
437
- let $incremental := $actions?incremental ($config, $config?collection )
436
+ let $incremental := $actions?incremental ($config)
438
437
439
438
let $remove-lock := app:lock-remove ($collection-path)
440
439
441
- return
440
+ return
442
441
map {
443
- "sha" : app:production -sha ($config?collection ),
444
- "message" : "success"
442
+ "sha" : config:deployed -sha ($config?path ),
443
+ "message" : "success"
445
444
}
446
445
)
447
446
}
0 commit comments