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
23 changes: 18 additions & 5 deletions backend/src/services/integrationService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,11 @@ export default class IntegrationService {
async destroyAll(ids) {
const toRemoveRepo = new Set<string>()
let segmentId
// Collect GitLab webhook info before opening the transaction so external HTTP calls
// don't hold the DB connection idle long enough to trigger a connection timeout.
const gitlabWebhookRemovals: Array<{ token: string; projectIds: number[]; hookIds: number[] }> =
Comment thread
joanagmaia marked this conversation as resolved.
[]

const transaction = await SequelizeRepository.createTransaction(this.options)

try {
Expand Down Expand Up @@ -446,11 +451,11 @@ export default class IntegrationService {
}

if (integration.platform === PlatformType.GITLAB && integration.settings.webhooks) {
await removeGitlabWebhooks(
integration.token,
integration.settings.webhooks.map((hook) => hook.projectId),
integration.settings.webhooks.map((hook) => hook.hookId),
)
gitlabWebhookRemovals.push({
token: integration.token,
projectIds: integration.settings.webhooks.map((hook) => hook.projectId),
hookIds: integration.settings.webhooks.map((hook) => hook.hookId),
})
}

if (integration.platform === PlatformType.GIT) {
Expand Down Expand Up @@ -495,6 +500,14 @@ export default class IntegrationService {
await SequelizeRepository.rollbackTransaction(transaction)
throw error
}

// Remove GitLab webhooks after the transaction commits — these are external HTTP calls
// and must not hold a DB connection open.
await Promise.all(
gitlabWebhookRemovals.map(({ token, projectIds, hookIds }) =>
removeGitlabWebhooks(token, projectIds, hookIds),
),
)
Comment thread
joanagmaia marked this conversation as resolved.
}

async findById(id) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,11 @@ SQL >
argMin(
updatedAt,
if(
type IN ('pull_request-reviewed', 'merge_request-review-changes-requested')
type IN (
'pull_request-reviewed',
'merge_request-review-changes-requested',
'merge_request-review-approved'
)
Comment thread
joanagmaia marked this conversation as resolved.
OR (
type = 'patchset_approval-created'
AND splitByChar('-', sourceParentId)[1] = prSourceId
Expand All @@ -126,7 +130,11 @@ SQL >
) AS reviewedUpdatedAt,
min(
if(
type IN ('pull_request-reviewed', 'merge_request-review-changes-requested')
type IN (
'pull_request-reviewed',
'merge_request-review-changes-requested',
'merge_request-review-approved'
)
OR (
type = 'patchset_approval-created'
AND splitByChar('-', sourceParentId)[1] = prSourceId
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ SQL >
and (
type = 'pull_request-reviewed'
OR type = 'merge_request-review-changes-requested'
OR type = 'merge_request-review-approved'
OR type = 'patchset_approval-created'
)
{% if defined(bucket_id) %}
Expand Down
Loading