Skip to content

Commit

Permalink
sync: merge main
Browse files Browse the repository at this point in the history
  • Loading branch information
gireesh-naidu committed May 20, 2024
2 parents c9d5897 + ef86ad8 commit 7d450ab
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 36 deletions.
38 changes: 19 additions & 19 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"@types/request": "^2.48.1",
"body-parser": "^1.20.2",
"axios": "1.6.8",
"express": "^4.16.4",
"express": "^4.19.2",
"js-yaml": "^3.13.1",
"json-rules-engine": "^2.3.6",
"moment-timezone": "^0.5.31",
Expand Down
62 changes: 49 additions & 13 deletions src/common/mustacheHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,14 @@ export class MustacheHelper {
return parsedScoopNotification
}

parseEvent(event: Event, isSlackNotification?: boolean): ParsedCIEvent | ParsedCDEvent | ParseApprovalEvent | ParseConfigApprovalEvent | ParsedScoopNotification{
parseEvent(event: Event, isSlackNotification?: boolean): ParsedCIEvent | ParsedCDEvent | ParseApprovalEvent | ParseConfigApprovalEvent | ParseArtifactPromotionEvent | ParsedScoopNotification{
if(event.eventTypeId===EVENT_TYPE.ScoopNotification){
return this.parseScoopNotification(event)
}
let baseURL = event.baseUrl;
let material = event.payload.material;
let ciMaterials;
if (event.eventTypeId!==EVENT_TYPE.Approval && event.eventTypeId!==EVENT_TYPE.ConfigApproval){
if (event.eventTypeId!==EVENT_TYPE.Approval && event.eventTypeId!==EVENT_TYPE.ConfigApproval && event.eventTypeId!=EVENT_TYPE.ImagePromotion){
ciMaterials = material.ciMaterials ? material.ciMaterials.map((ci) => {
if (material && material.gitTriggers && material.gitTriggers[ci.id]) {
let trigger = material.gitTriggers[ci.id];
Expand Down Expand Up @@ -128,7 +128,7 @@ export class MustacheHelper {
if (event.payload.dockerImageUrl) index = event.payload.dockerImageUrl.indexOf(":");
if (baseURL && event.payload.appDetailLink) appDetailsLink = `${baseURL}${event.payload.appDetailLink}`;
if (baseURL && event.payload.deploymentHistoryLink) deploymentHistoryLink = `${baseURL}${event.payload.deploymentHistoryLink}`;

return {
eventTime: timestamp,
triggeredBy: event.payload.triggeredBy || "NA",
Expand Down Expand Up @@ -189,7 +189,30 @@ export class MustacheHelper {
protectConfigLink:protectConfigLink,
approvalLink:approvalLink,
}

}
else if (event.eventTypeId === EVENT_TYPE.ImagePromotion ){

let artifactPromotionRequestViewLink : string = `${baseURL}${event.payload?.artifactPromotionRequestViewLink}`
let artifactPromotionApprovalLink = `${baseURL}${event.payload?.artifactPromotionApprovalLink}`
let imageTagNames = event.payload?.imageTagNames
let imageComment = event.payload?.imageComment
let imagePromotionSource = event.payload?.promotionArtifactSource
let envName = event.payload?.envName
let index = -1;
if (event.payload.dockerImageUrl) index = event.payload.dockerImageUrl.lastIndexOf(":");

return {
eventTime: timestamp,
triggeredBy: event.payload.triggeredBy || "NA",
appName: event.payload.appName || "NA",
envName: event.payload.envName || envName,
imageTag: index >= 0 ? event.payload.dockerImageUrl.substring(index + 1) : "NA",
tags: imageTagNames,
comment: imageComment,
promotionArtifactSource: imagePromotionSource,
artifactPromotionRequestViewLink:artifactPromotionRequestViewLink,
artifactPromotionApprovalLink:artifactPromotionApprovalLink,
}

}
}
Expand Down Expand Up @@ -273,8 +296,8 @@ export class MustacheHelper {
scannedBy:event.payload.imageScanExecutionInfo?.scannedBy,
buildHistoryLink: buildHistoryLink,
appDetailsLink: appDetailsLink,



};
}
Expand All @@ -284,7 +307,7 @@ export class MustacheHelper {
high: imageScanExecutionInfo.severityCount.high,
moderate: imageScanExecutionInfo.severityCount.moderate,
low: imageScanExecutionInfo.severityCount.low,
}
}
} else{
return {};
}
Expand Down Expand Up @@ -312,7 +335,7 @@ export class MustacheHelper {
return array.map(item => JSON.stringify(item));
}
});

array.forEach((item, index) => {
Object.defineProperty(item, 'isLastIndex', {
get: function() {
Expand All @@ -323,18 +346,18 @@ export class MustacheHelper {
}
defineObjectProperties<T>(object: T): void {
if (typeof object!=="object"){
return

return
}
Object.defineProperty(object, 'getAll', {
get: function() {
return JSON.stringify(object);
}
});


}


modifyWebhookData (webhookDataMap: any, gitUrl : string, isMergedTypeWebhook : boolean) : any {

Expand Down Expand Up @@ -374,4 +397,17 @@ export class MustacheHelper {
export class WebhookData {
mergedType : boolean; // merged/non-merged
data: Map<string, string>;
}

interface ParseArtifactPromotionEvent {
eventTime: number | string;
triggeredBy: string;
appName: string;
envName: string;
tags?:string[];
comment?:string;
artifactPromotionRequestViewLink?: string;
artifactPromotionApprovalLink?: string;
promotionArtifactSource?: string;
imageTag: string;
}
6 changes: 4 additions & 2 deletions src/destination/destinationHandlers/sesHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {NotificationTemplates} from "../../entities/notificationTemplates";
import {SESConfigRepository} from "../../repository/sesConfigRepository";
import {UsersRepository} from "../../repository/usersRepository";
import { MustacheHelper } from '../../common/mustacheHelper';
import {EVENT_TYPE} from "../../common/types";

//https://github.com/notifme/notifme-sdk/blob/master/src/models/notification-request.js#L132

Expand Down Expand Up @@ -161,14 +162,15 @@ export class SESService implements Handler {
parsedEvent['fromEmail'] = event.payload['fromEmail'];
parsedEvent['toEmail'] = event.payload['toEmail'];
let json: string
if(event.eventTypeId===4){
if(event.eventTypeId===4 || event.eventTypeId === EVENT_TYPE.ImagePromotion){
let commentDisplayStyle = (event.payload.imageComment === "") ? 'none' : 'inline';
let tagDisplayStyle = (event.payload.imageTagNames === null) ? 'none' : 'inline';
json = Mustache.render(template, { ...parsedEvent, commentDisplayStyle ,tagDisplayStyle});
}else if(event.eventTypeId===5){
let commentDisplayStyle = (event.payload.protectConfigComment === "") ? 'none' : 'inline';
json = Mustache.render(template, { ...parsedEvent, commentDisplayStyle });
}else{
}
else{
json = Mustache.render(template, parsedEvent)
}

Expand Down
2 changes: 1 addition & 1 deletion src/entities/notificationTemplates.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Entity, Column, PrimaryGeneratedColumn} from "typeorm";
import {Entity, Column, PrimaryGeneratedColumn} from "typeorm";

@Entity("notification_templates")
export class NotificationTemplates {
Expand Down

0 comments on commit 7d450ab

Please sign in to comment.