Skip to content

Commit 5e37cd9

Browse files
author
Uroš Marolt
committed
Merge branch 'hotfix/github-webhook-fix'
2 parents a292ecd + 66dffea commit 5e37cd9

2 files changed

Lines changed: 43 additions & 12 deletions

File tree

backend/src/bin/scripts/process-integration.ts

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { createServiceLogger } from '../../utils/logging'
66
import SequelizeRepository from '../../database/repositories/sequelizeRepository'
77
import { sendNodeWorkerMessage } from '../../serverless/utils/nodeWorkerSQS'
88
import { NodeWorkerIntegrationProcessMessage } from '../../types/mq/nodeWorkerIntegrationProcessMessage'
9+
import IntegrationRepository from '../../database/repositories/integrationRepository'
910

1011
const banner = fs.readFileSync(path.join(__dirname, 'banner.txt'), 'utf8')
1112

@@ -27,6 +28,11 @@ const options = [
2728
type: Boolean,
2829
defaultValue: false,
2930
},
31+
{
32+
name: 'platform',
33+
alias: 'p',
34+
description: 'The platform for which we should run all integrations.',
35+
},
3036
{
3137
name: 'help',
3238
alias: 'h',
@@ -52,24 +58,18 @@ const sections = [
5258
const usage = commandLineUsage(sections)
5359
const parameters = commandLineArgs(options)
5460

55-
if (parameters.help || !parameters.integration) {
61+
if (parameters.help || (!parameters.integration && !parameters.platform)) {
5662
console.log(usage)
5763
} else {
5864
setImmediate(async () => {
59-
const integrationIds = parameters.integration.split(',')
6065
const onboarding = parameters.onboarding
6166
const options = await SequelizeRepository.getDefaultIRepositoryOptions()
6267

63-
for (const integrationId of integrationIds) {
64-
const integration = await options.database.integration.findOne({
65-
where: { id: integrationId },
66-
})
67-
68-
if (!integration) {
69-
log.error({ integrationId }, 'Integration not found!')
70-
process.exit(1)
71-
} else {
72-
log.info({ integrationId, onboarding }, 'Integration found - triggering SQS message!')
68+
if (parameters.platform) {
69+
const integrations = await IntegrationRepository.findAllActive(parameters.platform)
70+
for (const i of integrations) {
71+
const integration = i as any
72+
log.info({ integrationId: integration.id, onboarding }, 'Triggering SQS message!')
7373
await sendNodeWorkerMessage(
7474
integration.tenantId,
7575
new NodeWorkerIntegrationProcessMessage(
@@ -80,7 +80,31 @@ if (parameters.help || !parameters.integration) {
8080
),
8181
)
8282
}
83+
} else {
84+
const integrationIds = parameters.integration.split(',')
85+
for (const integrationId of integrationIds) {
86+
const integration = await options.database.integration.findOne({
87+
where: { id: integrationId },
88+
})
89+
90+
if (!integration) {
91+
log.error({ integrationId }, 'Integration not found!')
92+
process.exit(1)
93+
} else {
94+
log.info({ integrationId, onboarding }, 'Integration found - triggering SQS message!')
95+
await sendNodeWorkerMessage(
96+
integration.tenantId,
97+
new NodeWorkerIntegrationProcessMessage(
98+
integration.platform,
99+
integration.tenantId,
100+
onboarding,
101+
integration.id,
102+
),
103+
)
104+
}
105+
}
83106
}
107+
84108
process.exit(0)
85109
})
86110
}

backend/src/serverless/integrations/services/integrations/githubIntegrationService.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,13 @@ export class GithubIntegrationService extends IntegrationServiceBase {
298298
const event = webhook.payload.event
299299
const payload = webhook.payload.data
300300

301+
const redis = await createRedisClient(true)
302+
const emailCache = new RedisCache('github-emails', redis)
303+
304+
context.pipelineData = {
305+
emailCache,
306+
}
307+
301308
switch (event) {
302309
case 'issues': {
303310
record = await GithubIntegrationService.parseWebhookIssue(payload, context)

0 commit comments

Comments
 (0)