Skip to content

Commit f8cfc51

Browse files
committed
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]>
1 parent ccd0025 commit f8cfc51

File tree

2 files changed

+6
-10
lines changed

2 files changed

+6
-10
lines changed

GitGitGadget/index.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ module.exports = async (context, req) => {
2121
status: 403,
2222
body: 'Not a valid GitHub webhook: ' + e,
2323
};
24-
context.done();
2524
return;
2625
}
2726

@@ -112,7 +111,6 @@ module.exports = async (context, req) => {
112111
context.res = {
113112
body: `Not a command: '${comment.body}'`,
114113
};
115-
context.done();
116114
return;
117115
}
118116

@@ -137,6 +135,4 @@ module.exports = async (context, req) => {
137135
body: `Caught an error: ${e.message || JSON.stringify(e, null, 2)}`,
138136
};
139137
}
140-
141-
context.done();
142138
};

__tests__/index.test.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ test('reject requests other than webhook payloads', async () => {
4949
body: `Not a valid GitHub webhook: Error: ${message}`,
5050
status: 403
5151
})
52-
expect(context.done).toHaveBeenCalledTimes(1)
52+
expect(context.done).not.toHaveBeenCalled()
5353
}
5454

5555
await expectInvalidWebhook('Unexpected content type: text/plain')
@@ -142,7 +142,7 @@ const testIssueComment = (comment, repoOwner, fn) => {
142142
try {
143143
expect(await index(context, context.req)).toBeUndefined()
144144
await fn(context)
145-
expect(context.done).toHaveBeenCalledTimes(1)
145+
expect(context.done).not.toHaveBeenCalled()
146146
} catch (e) {
147147
context.log.mock.calls.forEach(e => console.log(e[0]))
148148
throw e;
@@ -151,7 +151,7 @@ const testIssueComment = (comment, repoOwner, fn) => {
151151
}
152152

153153
testIssueComment('/test', async (context) => {
154-
expect(context.done).toHaveBeenCalledTimes(1)
154+
expect(context.done).not.toHaveBeenCalled()
155155
expect(context.res).toEqual({
156156
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"}>!'
157157
})
@@ -160,7 +160,7 @@ testIssueComment('/test', async (context) => {
160160
})
161161

162162
testIssueComment('/verify-repository', 'nope', (context) => {
163-
expect(context.done).toHaveBeenCalledTimes(1)
163+
expect(context.done).not.toHaveBeenCalled()
164164
expect(context.res).toEqual({
165165
body: 'Refusing to work on a repository other than gitgitgadget/git or git/git',
166166
'status': 403,
@@ -178,7 +178,7 @@ const testWebhookPayload = (testLabel, gitHubEvent, payload, fn) => {
178178
try {
179179
expect(await index(context, context.req)).toBeUndefined()
180180
await fn(context)
181-
expect(context.done).toHaveBeenCalledTimes(1)
181+
expect(context.done).not.toHaveBeenCalled()
182182
} catch (e) {
183183
context.log.mock.calls.forEach(e => console.log(e[0]))
184184
throw e;
@@ -305,4 +305,4 @@ testWebhookPayload('react to PR push', 'pull_request', {
305305
'pr-url': 'https://github.com/gitgitgadget/git/pull/1956',
306306
}
307307
])
308-
})
308+
})

0 commit comments

Comments
 (0)