Skip to content

Commit c4326bb

Browse files
authored
Merge pull request #190 from git-for-windows/make-reproducing-webhook-failures-easier
Make reproducing webhook failures easier
2 parents 6df40d5 + 289b3f6 commit c4326bb

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

GitForWindowsHelper/https-request.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,17 @@ const httpsRequest = async (context, hostname, method, requestPath, body, header
1818
path: requestPath,
1919
headers
2020
}
21+
if (process.env.LOG_HTTPS_REQUESTS === 'true') {
22+
const quote = s => !s.match(/[\][.?*\\^_"'`{}()<>@~&+:;$%"; // \t\r\n]/) ? s : `'${s.replace(/'/g, "'\\''")}'`
23+
const commandLine = [
24+
'curl',
25+
options.method === 'GET' ? '' : `-X ${options.method}`,
26+
...Object.entries(options.headers).map(([key, value]) => `-H ${quote(`${key}: ${value}`)}`),
27+
body ? `-d ${quote(body)}` : '',
28+
`https://${options.hostname}${options.path}`,
29+
].filter(e => e).join(' ')
30+
;(context.error || console.error)(commandLine)
31+
}
2132
return new Promise((resolve, reject) => {
2233
try {
2334
const https = require('https')

get-webhook-event-payload.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,14 +101,14 @@
101101
let cursor = Math.floor(answer.oldest.id - rate * (answer.oldest.epoch - until))
102102
for (;;) {
103103
answer = await getAtCursor(cursor)
104-
console.log(`got answer ${JSON.stringify(answer)} for cursor ${cursor}`)
104+
console.error(`got answer ${JSON.stringify(answer)} for cursor ${cursor}`)
105105
if (answer.newest) break
106106
rate /= 2
107107
const newCursor = Math.floor(previousAnswer.oldest.id - rate * (previousAnswer.oldest.epoch - until))
108108
if (newCursor === cursor) break
109109
cursor = newCursor
110110
}
111-
console.log(`got final answer ${JSON.stringify(answer)} for cursor ${cursor}`)
111+
console.error(`got final answer ${JSON.stringify(answer)} for cursor ${cursor}`)
112112
}
113113

114114
while (answer.newest?.epoch && answer.newest.epoch < until) {
@@ -144,4 +144,7 @@
144144
const fullEvent = await gitHubRequestAsApp(console, 'GET', `/app/hook/deliveries/${e.id}`)
145145
console.log(`id: ${e.id}\naction: ${e.action}\nevent: ${JSON.stringify(fullEvent, null, 2)}`)
146146
}
147-
})().catch(console.log)
147+
})().catch(e => {
148+
console.error(e)
149+
process.exitCode = 1
150+
})

0 commit comments

Comments
 (0)