diff --git a/services/webhooks2tasks/src/handlers/bitbucketPullRequestUpdated.ts b/services/webhooks2tasks/src/handlers/bitbucketPullRequestUpdated.ts index 5ca5c901ab..7c67143f0d 100644 --- a/services/webhooks2tasks/src/handlers/bitbucketPullRequestUpdated.ts +++ b/services/webhooks2tasks/src/handlers/bitbucketPullRequestUpdated.ts @@ -69,6 +69,8 @@ export async function bitbucketPullRequestUpdated(webhook: WebhookRequestData, p buildName: buildName, sourceUser: sourceUser, sourceType: "WEBHOOK", + bulkId: webhook.bulkId, + bulkName: webhook.bulkName, } try { diff --git a/services/webhooks2tasks/src/handlers/bitbucketPush.ts b/services/webhooks2tasks/src/handlers/bitbucketPush.ts index 25c9e18e48..d6ef2d7eea 100644 --- a/services/webhooks2tasks/src/handlers/bitbucketPush.ts +++ b/services/webhooks2tasks/src/handlers/bitbucketPush.ts @@ -56,6 +56,8 @@ export async function bitbucketPush(webhook: WebhookRequestData, project: Projec buildName: buildName, sourceUser: sourceUser, sourceType: "WEBHOOK", + bulkId: webhook.bulkId, + bulkName: webhook.bulkName, } let logMessage = `\`<${body.push.changes[0].new.links.html.href}>\`` diff --git a/services/webhooks2tasks/src/handlers/giteaPullRequestOpened.ts b/services/webhooks2tasks/src/handlers/giteaPullRequestOpened.ts index db53277d9d..430729d716 100644 --- a/services/webhooks2tasks/src/handlers/giteaPullRequestOpened.ts +++ b/services/webhooks2tasks/src/handlers/giteaPullRequestOpened.ts @@ -70,6 +70,8 @@ export async function giteaPullRequestOpened(webhook: WebhookRequestData, projec buildName: buildName, sourceUser: sourceUser, sourceType: "WEBHOOK", + bulkId: webhook.bulkId, + bulkName: webhook.bulkName, } try { diff --git a/services/webhooks2tasks/src/handlers/giteaPullRequestSynchronize.ts b/services/webhooks2tasks/src/handlers/giteaPullRequestSynchronize.ts index 63f7cefffe..f5cb14c489 100644 --- a/services/webhooks2tasks/src/handlers/giteaPullRequestSynchronize.ts +++ b/services/webhooks2tasks/src/handlers/giteaPullRequestSynchronize.ts @@ -88,6 +88,8 @@ export async function giteaPullRequestSynchronize(webhook: WebhookRequestData, p buildName: buildName, sourceUser: sourceUser, sourceType: "WEBHOOK", + bulkId: webhook.bulkId, + bulkName: webhook.bulkName, } try { diff --git a/services/webhooks2tasks/src/handlers/giteaPush.ts b/services/webhooks2tasks/src/handlers/giteaPush.ts index 5a91e6d29b..474e222332 100644 --- a/services/webhooks2tasks/src/handlers/giteaPush.ts +++ b/services/webhooks2tasks/src/handlers/giteaPush.ts @@ -57,6 +57,8 @@ export async function giteaPush(webhook: WebhookRequestData, project: Project) { buildName: buildName, sourceUser: sourceUser, sourceType: "WEBHOOK", + bulkId: webhook.bulkId, + bulkName: webhook.bulkName, } let logMessage = `\`<${body.repository.html_url}/tree/${meta.branch}|${meta.branch}>\`` diff --git a/services/webhooks2tasks/src/handlers/githubPullRequestOpened.ts b/services/webhooks2tasks/src/handlers/githubPullRequestOpened.ts index 3e1d962d5f..8c9d51b32a 100644 --- a/services/webhooks2tasks/src/handlers/githubPullRequestOpened.ts +++ b/services/webhooks2tasks/src/handlers/githubPullRequestOpened.ts @@ -70,6 +70,8 @@ export async function githubPullRequestOpened(webhook: WebhookRequestData, proje buildName: buildName, sourceUser: sourceUser, sourceType: "WEBHOOK", + bulkId: webhook.bulkId, + bulkName: webhook.bulkName, } try { diff --git a/services/webhooks2tasks/src/handlers/githubPullRequestSynchronize.ts b/services/webhooks2tasks/src/handlers/githubPullRequestSynchronize.ts index 3990d4e900..c990656f6f 100644 --- a/services/webhooks2tasks/src/handlers/githubPullRequestSynchronize.ts +++ b/services/webhooks2tasks/src/handlers/githubPullRequestSynchronize.ts @@ -88,6 +88,8 @@ export async function githubPullRequestSynchronize(webhook: WebhookRequestData, buildName: buildName, sourceUser: sourceUser, sourceType: "WEBHOOK", + bulkId: webhook.bulkId, + bulkName: webhook.bulkName, } try { diff --git a/services/webhooks2tasks/src/handlers/githubPush.ts b/services/webhooks2tasks/src/handlers/githubPush.ts index b23522805e..890ce1f235 100644 --- a/services/webhooks2tasks/src/handlers/githubPush.ts +++ b/services/webhooks2tasks/src/handlers/githubPush.ts @@ -56,6 +56,8 @@ export async function githubPush(webhook: WebhookRequestData, project: Project) buildName: buildName, sourceUser: sourceUser, sourceType: "WEBHOOK", + bulkId: webhook.bulkId, + bulkName: webhook.bulkName, } let logMessage = `\`<${body.repository.html_url}/tree/${meta.branch}|${meta.branch}>\`` diff --git a/services/webhooks2tasks/src/handlers/gitlabPullRequestOpened.ts b/services/webhooks2tasks/src/handlers/gitlabPullRequestOpened.ts index 9064da0aeb..5fe1c371e2 100644 --- a/services/webhooks2tasks/src/handlers/gitlabPullRequestOpened.ts +++ b/services/webhooks2tasks/src/handlers/gitlabPullRequestOpened.ts @@ -70,6 +70,8 @@ export async function gitlabPullRequestOpened(webhook: WebhookRequestData, proje buildName: buildName, sourceUser: sourceUser, sourceType: "WEBHOOK", + bulkId: webhook.bulkId, + bulkName: webhook.bulkName, } try { diff --git a/services/webhooks2tasks/src/handlers/gitlabPullRequestUpdated.ts b/services/webhooks2tasks/src/handlers/gitlabPullRequestUpdated.ts index 05be8daeda..7f11c82511 100644 --- a/services/webhooks2tasks/src/handlers/gitlabPullRequestUpdated.ts +++ b/services/webhooks2tasks/src/handlers/gitlabPullRequestUpdated.ts @@ -70,6 +70,8 @@ export async function gitlabPullRequestUpdated(webhook: WebhookRequestData, proj buildName: buildName, sourceUser: sourceUser, sourceType: "WEBHOOK", + bulkId: webhook.bulkId, + bulkName: webhook.bulkName, } try { diff --git a/services/webhooks2tasks/src/handlers/gitlabPush.ts b/services/webhooks2tasks/src/handlers/gitlabPush.ts index d24648a9dd..793a282277 100644 --- a/services/webhooks2tasks/src/handlers/gitlabPush.ts +++ b/services/webhooks2tasks/src/handlers/gitlabPush.ts @@ -57,6 +57,8 @@ export async function gitlabPush(webhook: WebhookRequestData, project: Project) buildName: buildName, sourceUser: sourceUser, sourceType: "WEBHOOK", + bulkId: webhook.bulkId, + bulkName: webhook.bulkName, } let logMessage = `\`<${body.project.http_url}/tree/${meta.branch}|${meta.branch}>\`` diff --git a/services/webhooks2tasks/src/types.ts b/services/webhooks2tasks/src/types.ts index e256118da9..72b7ac86b4 100644 --- a/services/webhooks2tasks/src/types.ts +++ b/services/webhooks2tasks/src/types.ts @@ -17,22 +17,23 @@ export interface removeData { } export interface deployData { - baseBranchName?: string; - baseSha?: string; - branchName: string; - buildName?: string; - buildPriority?: string; - buildVariables?: any; - bulkId?: string; - headBranchName?: string; - headSha?: string; - projectName: string; - pullrequestNumber?: number; - pullrequestTitle?: string; - pullrequestUrl?: string; - repoName?: string; - repoUrl?: string; - sha?: string; + baseBranchName?: string, + baseSha?: string, + branchName: string, + buildName?: string, + buildPriority?: string, + buildVariables?: any, + bulkId?: string, + bulkName?: string, + headBranchName?: string, + headSha?: string, + projectName: string, + pullrequestNumber?: number, + pullrequestTitle?: string, + pullrequestUrl?: string, + repoName?: string, + repoUrl?: string, + sha?: string, sourceType?: string, sourceUser?: string, type?: string; @@ -40,13 +41,15 @@ export interface deployData { export interface WebhookRequestData { body?: any; + bulkId?: string, + bulkName?: string, event: string; giturl: string; sender?: any; user?: any; uuid?: string; webhooktype: string; -} +}; export type Project = Pick< LagoonProject, diff --git a/services/webhooks2tasks/src/webhooks/projects.ts b/services/webhooks2tasks/src/webhooks/projects.ts index 959cfc0d0f..59ee82b8ad 100644 --- a/services/webhooks2tasks/src/webhooks/projects.ts +++ b/services/webhooks2tasks/src/webhooks/projects.ts @@ -22,6 +22,7 @@ import { gitlabBranchDeleted } from '../handlers/gitlabBranchDeleted'; import { gitlabPullRequestClosed } from '../handlers/gitlabPullRequestClosed'; import { gitlabPullRequestOpened } from '../handlers/gitlabPullRequestOpened'; import { gitlabPullRequestUpdated } from '../handlers/gitlabPullRequestUpdated'; +import crypto from 'crypto'; import { WebhookRequestData, @@ -140,6 +141,15 @@ export async function processProjects( return; } + // if there are more than 1 projects returned, it is probably a polysite deployment + if (projects.length > 1) { + // label them as a bulk or grouped deployment + // assign a random uuid + webhook.bulkId = crypto.randomUUID() + // and then add the name as polysite indicating what type of event started it + webhook.bulkName = `Polysite - ${webhooktype}:${event} - ${new Date().toISOString()}` + } + projects.forEach(async project => { switch (`${webhooktype}:${event}`) { case 'github:pull_request':