MCPcopy Index your code
hub / github.com/coderoad/coderoad-vscode / callWebhookEndpoint

Function callWebhookEndpoint

src/services/hooks/webhooks.ts:32–58  ·  view source on GitHub ↗
(bodyObject: B)

Source from the content-addressed store, hash-verified

30}
31
32const callWebhookEndpoint = async <B>(bodyObject: B): Promise<void> => {
33 if (!WEBHOOK_URI) {
34 return
35 }
36
37 const headers = { 'Content-Type': 'application/json' }
38 // if the webhook token is specified as env var, sends a token with the request
39 if (WEBHOOK_TOKEN) {
40 headers['CodeRoad-User-Token'] = WEBHOOK_TOKEN
41 }
42
43 const body = JSON.stringify(bodyObject)
44
45 try {
46 const sendEvent = await fetch(WEBHOOK_URI, {
47 method: 'POST',
48 headers,
49 body,
50 })
51 if (!sendEvent.ok) {
52 throw new Error('Error sending event')
53 }
54 logger(`Called webhook endpoint ${WEBHOOK_URI} with body ${JSON.stringify(body)}`)
55 } catch (err: unknown) {
56 logger(`Failed to call webhook endpoint ${WEBHOOK_URI} with body ${JSON.stringify(body)}`)
57 }
58}
59
60type WebhookEventInit = {
61 tutorialId: string

Callers 6

onInitFunction · 0.85
onResetFunction · 0.85
onContinueFunction · 0.85
onStepCompleteFunction · 0.85
onLevelCompleteFunction · 0.85
onTutorialCompleteFunction · 0.85

Calls 1

loggerFunction · 0.50

Tested by

no test coverage detected