Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
18 changes: 18 additions & 0 deletions src/github/github-webhooks.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,23 @@ describe('GithubWebhooksService', () => {
expect(bountiesService.markMergedAndRelease).not.toHaveBeenCalled();
});

it.each(['push', 'ping', 'unknown_event'])(
'ignores a verified %s event when no handler is registered',
async (eventType) => {
const event = await service.handleEvent(
eventType,
'delivery-unhandled',
{},
true,
);

expect(event.status).toBe(WebhookEventStatus.IGNORED);
expect(event.processedAt).toBeUndefined();
expect(syncService.findRepositoryByGithubId).not.toHaveBeenCalled();
expect(bountiesService.markMergedAndRelease).not.toHaveBeenCalled();
},
);

it('processes a merged pull_request event and releases the linked bounty', async () => {
issueRepo.findOne.mockResolvedValue({
id: 'issue-1',
Expand Down Expand Up @@ -279,6 +296,7 @@ describe('GithubWebhooksService', () => {
payload.issue,
);
expect(event.status).toBe(WebhookEventStatus.PROCESSED);
expect(event.processedAt).toBeInstanceOf(Date);
});

it('ignores events for a repository this app is not tracking, without erroring', async () => {
Expand Down
12 changes: 6 additions & 6 deletions src/github/github-webhooks.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,14 @@ export class GithubWebhooksService {
payload as unknown as GithubPullRequestPayload,
);
this.applyPullRequestOutcomes(event, outcomes);
} else {
if (eventType === 'issues') {
await this.handleIssueEvent(
payload as unknown as GithubIssuesEventPayload,
);
}
} else if (eventType === 'issues') {
await this.handleIssueEvent(
payload as unknown as GithubIssuesEventPayload,
);
event.status = WebhookEventStatus.PROCESSED;
event.processedAt = new Date();
} else {
event.status = WebhookEventStatus.IGNORED;
}
} catch (err) {
event.status = WebhookEventStatus.FAILED;
Expand Down