Skip to content

Commit

Permalink
feat: group polysite deployments under bulk label
Browse files Browse the repository at this point in the history
  • Loading branch information
shreddedbacon committed Mar 27, 2024
1 parent 1ef8e57 commit 39e400d
Show file tree
Hide file tree
Showing 13 changed files with 52 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ export async function bitbucketPullRequestUpdated(webhook: WebhookRequestData, p
buildName: buildName,
sourceUser: sourceUser,
sourceType: "WEBHOOK",
bulkId: webhook.bulkId,
bulkName: webhook.bulkName,
}

try {
Expand Down
2 changes: 2 additions & 0 deletions services/webhooks2tasks/src/handlers/bitbucketPush.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}>\``
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ export async function giteaPullRequestOpened(webhook: WebhookRequestData, projec
buildName: buildName,
sourceUser: sourceUser,
sourceType: "WEBHOOK",
bulkId: webhook.bulkId,
bulkName: webhook.bulkName,
}

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ export async function giteaPullRequestSynchronize(webhook: WebhookRequestData, p
buildName: buildName,
sourceUser: sourceUser,
sourceType: "WEBHOOK",
bulkId: webhook.bulkId,
bulkName: webhook.bulkName,
}

try {
Expand Down
2 changes: 2 additions & 0 deletions services/webhooks2tasks/src/handlers/giteaPush.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}>\``
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ export async function githubPullRequestOpened(webhook: WebhookRequestData, proje
buildName: buildName,
sourceUser: sourceUser,
sourceType: "WEBHOOK",
bulkId: webhook.bulkId,
bulkName: webhook.bulkName,
}

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ export async function githubPullRequestSynchronize(webhook: WebhookRequestData,
buildName: buildName,
sourceUser: sourceUser,
sourceType: "WEBHOOK",
bulkId: webhook.bulkId,
bulkName: webhook.bulkName,
}

try {
Expand Down
2 changes: 2 additions & 0 deletions services/webhooks2tasks/src/handlers/githubPush.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}>\``
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ export async function gitlabPullRequestOpened(webhook: WebhookRequestData, proje
buildName: buildName,
sourceUser: sourceUser,
sourceType: "WEBHOOK",
bulkId: webhook.bulkId,
bulkName: webhook.bulkName,
}

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ export async function gitlabPullRequestUpdated(webhook: WebhookRequestData, proj
buildName: buildName,
sourceUser: sourceUser,
sourceType: "WEBHOOK",
bulkId: webhook.bulkId,
bulkName: webhook.bulkName,
}

try {
Expand Down
2 changes: 2 additions & 0 deletions services/webhooks2tasks/src/handlers/gitlabPush.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}>\``
Expand Down
37 changes: 20 additions & 17 deletions services/webhooks2tasks/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,36 +17,39 @@ 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;
}

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,
Expand Down
10 changes: 10 additions & 0 deletions services/webhooks2tasks/src/webhooks/projects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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':
Expand Down

0 comments on commit 39e400d

Please sign in to comment.