-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreplaceModifiedFiles.xq
66 lines (58 loc) · 3 KB
/
replaceModifiedFiles.xq
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
(: to do this could be modified to allow changing of individual files that have been added or are modified:)
declare function local:files($before, $after, $owner, $repo, $access_token){
let $url := "https://api.github.com/repos/" || $owner ||"/" || $repo || "/compare/" || $before ||"..." || $after || "?access_token=" || $access_token
let $request := <http:request method="GET" href="{$url}" timeout="30"/>
let $response := http:send-request($request)
let $shortid := $repo
let $top_level_collection := local:topLevelCollectionQuery($shortid)
let $save-path := if ($top_level_collection = $repo) then
let $result := "/db/apps/scta-data/" || $repo || "/"
return $result
else
let $result := "/db/apps/scta-data/" || $top_level_collection || "/" || $repo || "/"
return $result
let $files := if ($response[1]/@status = "200") then
let $json := parse-json(util:binary-to-string($response[2]))
return $json?files?*
else
let $json := parse-json(util:binary-to-string($response[2]))
return $json
for $file in $files
let $new-save-path := if (contains($file?filename, "/")) then
let $additional-path := tokenize($file?filename, "/")[1]
let $result := $save-path || $additional-path || "/"
return $result
else
let $result := $save-path
return $result
let $new-file-name := if (contains($file?filename, "/")) then
let $result := tokenize($file?filename, "/")[2]
return $result
else
let $result := $file?filename
return $result
return
if ($file?status = 'added' or $file?status = 'modified') then
let $url := $file?contents_url || "&access_token=" || $access_token
(: let $url := "https://api.github.com/repos/" || $owner ||"/" || $repo || "/contents/" || $file?filename || "?ref=" || $after || "&access_token=" || $access_token :)
let $request := <http:request method="GET" href="{$url}" timeout="30"/>
let $response := http:send-request($request)
let $new-content := util:base64-decode(parse-json(util:binary-to-string($response[2]))?content)
return
if (xmldb:collection-available($new-save-path)) then(
<p>{$file?status}: {xmldb:store($new-save-path, $new-file-name, $new-content)}</p>
(: <p>{$new-save-path} {$new-file-name} {$url}</p> :)
)
else(
<div>
(: <p>{xmldb:create-collection("/db/apps/scta-data/" || $top_level_collection, $new-save-path)}</p> :)
(: <p>{$file?status}: {xmldb:store($new-save-path, $new-file-name, $new-content)}</p> :)
<p>Collection not available: {$new-save-path} {$new-file-name}</p>
</div>
)
else if ($file?status = 'removed') then
<p>{$file?status}: {xmldb:remove($new-save-path, $new-file-name)}</p>
else(
<p>No files created, modified, or deleted</ p>
)
};