Skip to content

Commit 14d758c

Browse files
authored
Merge pull request #6 from gitgitgadget/some-fixes
Various fixes
2 parents 3940c47 + f8cfc51 commit 14d758c

File tree

2 files changed

+8
-12
lines changed

2 files changed

+8
-12
lines changed

GitGitGadget/index.js

Lines changed: 2 additions & 6 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

@@ -131,12 +129,10 @@ module.exports = async (context, req) => {
131129
};
132130
}
133131
} catch (e) {
134-
context.log('Caught exception ' + e);
132+
context.log('Caught exception ', e);
135133
context.res = {
136134
status: 500,
137-
body: 'Caught an error: ' + e,
135+
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)