Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
PrevPrevious commit
Azure Function: avoid errors about context.done()
An Azure Function is supposed to either return a `Promise` or call `context.done()`, otherwise the following error will be shown: [Error] Error: Choose either to return a promise or call 'done'. Do not use both in your script. Learn more: https://go.microsoft.com/fwlink/?linkid=2097909 Since we do prefer to return a `Promise`, let's just skip the call to `context.done()`. To be sure, these error messages are only shown in the Azure Portal, when a developer deigns to turn on and look at the logs. Anyway, this _is_ an error, so let's do fix it. Signed-off-by: Johannes Schindelin <[email protected]>
  • Loading branch information
@dscho
dscho committed Sep 2, 2025
commit f8cfc51eb7a15a2d7dcbbfb1a015e8b2fe8fe86b
4 changes: 0 additions & 4 deletions GitGitGadget/index.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -21,7 +21,6 @@ module.exports = async (context, req) =>{
status: 403,
body: 'Not a valid GitHub webhook: ' + e,
};
context.done();
return;
}

Expand DownExpand Up@@ -112,7 +111,6 @@ module.exports = async (context, req) =>{
context.res ={
body: `Not a command: '${comment.body}'`,
};
context.done();
return;
}

Expand All@@ -137,6 +135,4 @@ module.exports = async (context, req) =>{
body: `Caught an error: ${e.message || JSON.stringify(e, null, 2)}`,
};
}

context.done();
};
12 changes: 6 additions & 6 deletions __tests__/index.test.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -49,7 +49,7 @@ test('reject requests other than webhook payloads', async () =>{
body: `Not a valid GitHub webhook: Error: ${message}`,
status: 403
})
expect(context.done).toHaveBeenCalledTimes(1)
expect(context.done).not.toHaveBeenCalled()
}

await expectInvalidWebhook('Unexpected content type: text/plain')
Expand DownExpand Up@@ -142,7 +142,7 @@ const testIssueComment = (comment, repoOwner, fn) =>{
try{
expect(await index(context, context.req)).toBeUndefined()
await fn(context)
expect(context.done).toHaveBeenCalledTimes(1)
expect(context.done).not.toHaveBeenCalled()
} catch (e){
context.log.mock.calls.forEach(e => console.log(e[0]))
throw e;
Expand All@@ -151,7 +151,7 @@ const testIssueComment = (comment, repoOwner, fn) =>{
}

testIssueComment('/test', async (context) =>{
expect(context.done).toHaveBeenCalledTimes(1)
expect(context.done).not.toHaveBeenCalled()
expect(context.res).toEqual({
body: 'Okay, triggered <the URL to the workflow handle-pr-comment.yml run on main with inputs{"pr-comment-url":"https://github.com/gitgitgadget/git/pull/1886743660"}>!'
})
Expand All@@ -160,7 +160,7 @@ testIssueComment('/test', async (context) =>{
})

testIssueComment('/verify-repository', 'nope', (context) =>{
expect(context.done).toHaveBeenCalledTimes(1)
expect(context.done).not.toHaveBeenCalled()
expect(context.res).toEqual({
body: 'Refusing to work on a repository other than gitgitgadget/git or git/git',
'status': 403,
Expand All@@ -178,7 +178,7 @@ const testWebhookPayload = (testLabel, gitHubEvent, payload, fn) =>{
try{
expect(await index(context, context.req)).toBeUndefined()
await fn(context)
expect(context.done).toHaveBeenCalledTimes(1)
expect(context.done).not.toHaveBeenCalled()
} catch (e){
context.log.mock.calls.forEach(e => console.log(e[0]))
throw e;
Expand DownExpand Up@@ -305,4 +305,4 @@ testWebhookPayload('react to PR push', 'pull_request',{
'pr-url': 'https://github.com/gitgitgadget/git/pull/1956',
}
])
})
})