Skip to content

Commit 9405cb6

Browse files
committed
get-webhook-event-payload: be careful not to overshoot the date range
GitHub has a pretty low limit of how many events it retains. That means we can easily overshoot if we are asking for an even that is a couple of days old. Avoid ending the search prematurely in such instances. Signed-off-by: Johannes Schindelin <[email protected]>
1 parent 200552b commit 9405cb6

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

get-webhook-event-payload.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,19 @@
9696
while (answer.oldest?.epoch && answer.oldest.epoch > until) {
9797
tooNew = answer.oldest
9898

99-
const rate = (answer.newest.id - answer.oldest.id) / (answer.newest.epoch - answer.oldest.epoch)
99+
const previousAnswer = answer
100+
let rate = (answer.newest.id - answer.oldest.id) / (answer.newest.epoch - answer.oldest.epoch)
100101
let cursor = Math.floor(answer.oldest.id - rate * (answer.oldest.epoch - until))
101-
answer = await getAtCursor(cursor)
102+
for (;;) {
103+
answer = await getAtCursor(cursor)
104+
console.log(`got answer ${JSON.stringify(answer)} for cursor ${cursor}`)
105+
if (answer.newest) break
106+
rate /= 2
107+
const newCursor = Math.floor(previousAnswer.oldest.id - rate * (previousAnswer.oldest.epoch - until))
108+
if (newCursor === cursor) break
109+
cursor = newCursor
110+
}
111+
console.log(`got final answer ${JSON.stringify(answer)} for cursor ${cursor}`)
102112
}
103113

104114
while (answer.newest?.epoch && answer.newest.epoch < until) {

0 commit comments

Comments
 (0)