You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
: Get commits in full, going over pages until we find the commit with the correct hash
118
+
:)
119
+
declarefunctiongithub:get-raw-commits (
120
+
$config asmap(*),
121
+
$count as xs:integer,
122
+
$stop-at-commit-id as xs:string?
123
+
) asarray(*)? {
124
+
let $stop-condition := if (empty($stop-at-commit-id)) then
125
+
function ($_) {
126
+
(: We are not looking for any SHA. Prevent going over all of the commits in a possibly big repo :)
127
+
true()
128
+
}
129
+
else
130
+
function ($results-on-page) {
131
+
(: We can stop searching once we have all the commits between 'now' and the commit we looked for :)
132
+
let $found-commits := $results-on-page?*?sha
133
+
return $found-commits = $stop-at-commit-id
134
+
}
135
+
136
+
let $results := github:request-json-all-pages(
137
+
github:commit-ref-url($config, $count),
138
+
$config?token,
139
+
$stop-condition
140
+
)
141
+
returnarray { $results?* }
112
142
};
113
143
114
144
(:~
115
145
: Get diff between production collection and github-newest
116
146
:)
117
147
declarefunctiongithub:get-newest-commits($config asmap(*)) as xs:string* {
118
148
let $deployed := $config?deployed
119
-
let $commits := github:get-raw-commits($config, 100)
149
+
let $commits := github:get-raw-commits($config, $github:max-page-size, $deployed)
120
150
let $sha := $commits?*?sha
121
151
let $how-many := index-of($sha, $deployed) - 1
122
152
return
123
153
if (empty($how-many)) then (
124
154
error(
125
155
xs:QName("github:commit-not-found"),
126
-
'The deployed commit hash ' || $deployed || ' was not found in the list of commits on the remote.')
156
+
'The deployed commit hash ' || $deployed || ' was not found in the list of commits on the remote. Tuttle can only process incremental upgrades of ' || $github:max-total-result-size || '.')
127
157
) else (
128
158
reverse(subsequence($sha, 1, $how-many))
129
159
)
@@ -218,7 +248,7 @@ declare function github:incremental($config as map(*)) {
218
248
:)
219
249
declarefunctiongithub:get-commit-files($config asmap(*), $sha as xs:string) asarray(*) {
220
250
let $url := github:repo-url($config) || "/commits/" || $sha
221
-
let $commit := github:request-json-all-pages($url, $config?token, ())
251
+
let $commit := github:request-json-all-pages($url, $config?token)
222
252
223
253
returnarray { $commit?files?* }
224
254
};
@@ -361,7 +391,32 @@ declare %private function github:request-json($url as xs:string, $token as xs:st
361
391
)
362
392
};
363
393
364
-
declare %private functiongithub:request-json-all-pages($url as xs:string, $token as xs:string?, $acc) {
394
+
(:~
395
+
: Get all pages of a specified URL. Github has some paginated endpoints, This function traverses all of
396
+
: those and joins the results.
397
+
:)
398
+
declare %private functiongithub:request-json-all-pages($url as xs:string, $token as xs:string?) {
399
+
github:request-json-all-pages($url, $token, function ($_) { (: Traverse all pages :)false() }, ())
400
+
};
401
+
402
+
(:~
403
+
: Overload, adds the $stop-condition callback which is given the contents of the current page
404
+
: return `true()` to indicate there are sufficient results and we can stop
0 commit comments