Skip to content

Commit

Permalink
refactor: clean up code formatting and remove unnecessary whitespace …
Browse files Browse the repository at this point in the history
…in various files
  • Loading branch information
simlarsen committed Feb 14, 2025
1 parent 3bc89a8 commit 1d7a25f
Show file tree
Hide file tree
Showing 9 changed files with 110 additions and 70 deletions.
Original file line number Diff line number Diff line change
@@ -1,30 +1,65 @@
import { MigrationInterface, QueryRunner } from "typeorm";

export class MigrationName1739569321582 implements MigrationInterface {
public name = 'MigrationName1739569321582'
public name = "MigrationName1739569321582";

public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE "Incident" RENAME COLUMN "postUpdatesToWorkspaceChannelName" TO "postUpdatesToWorkspaceChannels"`);
await queryRunner.query(`ALTER TABLE "Alert" RENAME COLUMN "postUpdatesToWorkspaceChannelName" TO "postUpdatesToWorkspaceChannels"`);
await queryRunner.query(`ALTER TABLE "ScheduledMaintenance" RENAME COLUMN "postUpdatesToWorkspaceChannelName" TO "postUpdatesToWorkspaceChannels"`);
await queryRunner.query(`ALTER TABLE "Incident" DROP COLUMN "postUpdatesToWorkspaceChannels"`);
await queryRunner.query(`ALTER TABLE "Incident" ADD "postUpdatesToWorkspaceChannels" jsonb`);
await queryRunner.query(`ALTER TABLE "Alert" DROP COLUMN "postUpdatesToWorkspaceChannels"`);
await queryRunner.query(`ALTER TABLE "Alert" ADD "postUpdatesToWorkspaceChannels" jsonb`);
await queryRunner.query(`ALTER TABLE "ScheduledMaintenance" DROP COLUMN "postUpdatesToWorkspaceChannels"`);
await queryRunner.query(`ALTER TABLE "ScheduledMaintenance" ADD "postUpdatesToWorkspaceChannels" jsonb`);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE "ScheduledMaintenance" DROP COLUMN "postUpdatesToWorkspaceChannels"`);
await queryRunner.query(`ALTER TABLE "ScheduledMaintenance" ADD "postUpdatesToWorkspaceChannels" character varying(100)`);
await queryRunner.query(`ALTER TABLE "Alert" DROP COLUMN "postUpdatesToWorkspaceChannels"`);
await queryRunner.query(`ALTER TABLE "Alert" ADD "postUpdatesToWorkspaceChannels" character varying(100)`);
await queryRunner.query(`ALTER TABLE "Incident" DROP COLUMN "postUpdatesToWorkspaceChannels"`);
await queryRunner.query(`ALTER TABLE "Incident" ADD "postUpdatesToWorkspaceChannels" character varying(100)`);
await queryRunner.query(`ALTER TABLE "ScheduledMaintenance" RENAME COLUMN "postUpdatesToWorkspaceChannels" TO "postUpdatesToWorkspaceChannelName"`);
await queryRunner.query(`ALTER TABLE "Alert" RENAME COLUMN "postUpdatesToWorkspaceChannels" TO "postUpdatesToWorkspaceChannelName"`);
await queryRunner.query(`ALTER TABLE "Incident" RENAME COLUMN "postUpdatesToWorkspaceChannels" TO "postUpdatesToWorkspaceChannelName"`);
}
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "Incident" RENAME COLUMN "postUpdatesToWorkspaceChannelName" TO "postUpdatesToWorkspaceChannels"`,
);
await queryRunner.query(
`ALTER TABLE "Alert" RENAME COLUMN "postUpdatesToWorkspaceChannelName" TO "postUpdatesToWorkspaceChannels"`,
);
await queryRunner.query(
`ALTER TABLE "ScheduledMaintenance" RENAME COLUMN "postUpdatesToWorkspaceChannelName" TO "postUpdatesToWorkspaceChannels"`,
);
await queryRunner.query(
`ALTER TABLE "Incident" DROP COLUMN "postUpdatesToWorkspaceChannels"`,
);
await queryRunner.query(
`ALTER TABLE "Incident" ADD "postUpdatesToWorkspaceChannels" jsonb`,
);
await queryRunner.query(
`ALTER TABLE "Alert" DROP COLUMN "postUpdatesToWorkspaceChannels"`,
);
await queryRunner.query(
`ALTER TABLE "Alert" ADD "postUpdatesToWorkspaceChannels" jsonb`,
);
await queryRunner.query(
`ALTER TABLE "ScheduledMaintenance" DROP COLUMN "postUpdatesToWorkspaceChannels"`,
);
await queryRunner.query(
`ALTER TABLE "ScheduledMaintenance" ADD "postUpdatesToWorkspaceChannels" jsonb`,
);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "ScheduledMaintenance" DROP COLUMN "postUpdatesToWorkspaceChannels"`,
);
await queryRunner.query(
`ALTER TABLE "ScheduledMaintenance" ADD "postUpdatesToWorkspaceChannels" character varying(100)`,
);
await queryRunner.query(
`ALTER TABLE "Alert" DROP COLUMN "postUpdatesToWorkspaceChannels"`,
);
await queryRunner.query(
`ALTER TABLE "Alert" ADD "postUpdatesToWorkspaceChannels" character varying(100)`,
);
await queryRunner.query(
`ALTER TABLE "Incident" DROP COLUMN "postUpdatesToWorkspaceChannels"`,
);
await queryRunner.query(
`ALTER TABLE "Incident" ADD "postUpdatesToWorkspaceChannels" character varying(100)`,
);
await queryRunner.query(
`ALTER TABLE "ScheduledMaintenance" RENAME COLUMN "postUpdatesToWorkspaceChannels" TO "postUpdatesToWorkspaceChannelName"`,
);
await queryRunner.query(
`ALTER TABLE "Alert" RENAME COLUMN "postUpdatesToWorkspaceChannels" TO "postUpdatesToWorkspaceChannelName"`,
);
await queryRunner.query(
`ALTER TABLE "Incident" RENAME COLUMN "postUpdatesToWorkspaceChannels" TO "postUpdatesToWorkspaceChannelName"`,
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -213,5 +213,5 @@ export default [
MigrationName1739217257089,
MigrationName1739282331053,
MigrationName1739374537088,
MigrationName1739569321582
MigrationName1739569321582,
];
60 changes: 30 additions & 30 deletions Common/Server/Services/IncidentService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,16 +238,16 @@ export class Service extends DatabaseService<Model> {

logger.debug(
"Mutex acquired - IncidentService.incident-create " +
projectId.toString() +
" at " +
OneUptimeDate.getCurrentDateAsFormattedString(),
projectId.toString() +
" at " +
OneUptimeDate.getCurrentDateAsFormattedString(),
);
} catch (err) {
logger.debug(
"Mutex acquire failed - IncidentService.incident-create " +
projectId.toString() +
" at " +
OneUptimeDate.getCurrentDateAsFormattedString(),
projectId.toString() +
" at " +
OneUptimeDate.getCurrentDateAsFormattedString(),
);
logger.error(err);
}
Expand Down Expand Up @@ -325,16 +325,16 @@ export class Service extends DatabaseService<Model> {
await Semaphore.release(mutex);
logger.debug(
"Mutex released - IncidentService.incident-create " +
projectId.toString() +
" at " +
OneUptimeDate.getCurrentDateAsFormattedString(),
projectId.toString() +
" at " +
OneUptimeDate.getCurrentDateAsFormattedString(),
);
} catch (err) {
logger.debug(
"Mutex release failed - IncidentService.incident-create " +
projectId.toString() +
" at " +
OneUptimeDate.getCurrentDateAsFormattedString(),
projectId.toString() +
" at " +
OneUptimeDate.getCurrentDateAsFormattedString(),
);
logger.error(err);
}
Expand Down Expand Up @@ -376,9 +376,9 @@ ${createdItem.description || "No description provided."}
createdItem.changeMonitorStatusToId,
true, // notifyMonitorOwners
createdItem.rootCause ||
"Status was changed because incident " +
createdItem.id.toString() +
" was created.",
"Status was changed because incident " +
createdItem.id.toString() +
" was created.",
createdItem.createdStateLog,
onCreate.createBy.props,
);
Expand Down Expand Up @@ -433,9 +433,9 @@ ${createdItem.remediationNotes || "No remediation notes provided."}`,
createdItem.projectId,
createdItem.id,
(onCreate.createBy.miscDataProps["ownerUsers"] as Array<ObjectID>) ||
[],
[],
(onCreate.createBy.miscDataProps["ownerTeams"] as Array<ObjectID>) ||
[],
[],
false,
onCreate.createBy.props,
);
Expand Down Expand Up @@ -475,7 +475,6 @@ ${createdItem.remediationNotes || "No remediation notes provided."}`,
}
}


// send message to workspaces - slack, teams, etc.
const createdChannels: {
channelsCreated: Array<WorkspaceChannel>;
Expand All @@ -485,9 +484,12 @@ ${createdItem.remediationNotes || "No remediation notes provided."}`,
incidentNumber: createdItem.incidentNumber!,
});


if (createdChannels && createdChannels.channelsCreated && createdChannels.channelsCreated.length > 0) {
// update incident with these channels.
if (
createdChannels &&
createdChannels.channelsCreated &&
createdChannels.channelsCreated.length > 0
) {
// update incident with these channels.
await this.updateOneById({
id: createdItem.id!,
data: {
Expand Down Expand Up @@ -760,10 +762,10 @@ ${onUpdate.updateBy.data.remediationNotes || "No remediation notes provided."}
feedInfoInMarkdown += `\n\n**Labels**:
${labels
.map((label: Label) => {
return `- ${label.name}`;
})
.join("\n")}
.map((label: Label) => {
return `- ${label.name}`;
})
.join("\n")}
`;

shouldAddIncidentFeed = true;
Expand Down Expand Up @@ -918,7 +920,7 @@ ${incidentSeverity.name}
if (
latestState &&
latestState.monitorStatusId?.toString() ===
resolvedMonitorState.id!.toString()
resolvedMonitorState.id!.toString()
) {
// already on this state. Skip.
continue;
Expand Down Expand Up @@ -1031,7 +1033,7 @@ ${incidentSeverity.name}
lastIncidentStatusTimeline &&
lastIncidentStatusTimeline.incidentStateId &&
lastIncidentStatusTimeline.incidentStateId.toString() ===
incidentStateId.toString()
incidentStateId.toString()
) {
return;
}
Expand Down Expand Up @@ -1249,7 +1251,7 @@ ${incidentSeverity.name}
timeToResolveMetric.description = "Time taken to resolve the incident";
timeToResolveMetric.value = OneUptimeDate.getDifferenceInSeconds(
resolvedIncidentStateTimeline?.startsAt ||
OneUptimeDate.getCurrentDate(),
OneUptimeDate.getCurrentDate(),
incidentStartsAt,
);
timeToResolveMetric.unit = "seconds";
Expand Down Expand Up @@ -1353,9 +1355,7 @@ ${incidentSeverity.name}
}): Promise<{
channelsCreated: WorkspaceChannel[];
} | null> {

try {

// we will notify the workspace about the incident creation with the bot tokken which is in WorkspaceProjectAuth Table.
return await WorkspaceNotificationRuleService.createInviteAndPostToChannelsBasedOnRules(
{
Expand Down
5 changes: 3 additions & 2 deletions Common/Server/Services/WorkspaceNotificationRuleService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ export class Service extends DatabaseService<Model> {
}): Promise<{
channelsCreated: Array<WorkspaceChannel>;
} | null> {

const channelsCreated: Array<WorkspaceChannel> = [];

const projectAuths: Array<WorkspaceProjectAuthToken> =
Expand Down Expand Up @@ -370,7 +369,9 @@ export class Service extends DatabaseService<Model> {
workspaceRules.shouldCreateNewChannel &&
workspaceRules.newChannelTemplateName
) {
const newChannelName: string = workspaceRules.newChannelTemplateName || `oneuptime-${data.notificationEventType.toLowerCase()}-`;
const newChannelName: string =
workspaceRules.newChannelTemplateName ||
`oneuptime-${data.notificationEventType.toLowerCase()}-`;

// add suffix and then check if it is already added or not.
const channelName: string = newChannelName + data.channelNameSiffix;
Expand Down
6 changes: 3 additions & 3 deletions Common/Server/Utils/Workspace/Slack/Slack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ export default class SlackUtil extends WorkspaceBase {
"name"
] as string,
id: data.channelId,
workspaceType: WorkspaceType.Slack
workspaceType: WorkspaceType.Slack,
};
}

Expand Down Expand Up @@ -146,7 +146,7 @@ export default class SlackUtil extends WorkspaceBase {
channels[channel["name"].toString()] = {
id: channel["id"] as string,
name: channel["name"] as string,
workspaceType: WorkspaceType.Slack
workspaceType: WorkspaceType.Slack,
};
}

Expand Down Expand Up @@ -259,7 +259,7 @@ export default class SlackUtil extends WorkspaceBase {
name: ((response.jsonData as JSONObject)["channel"] as JSONObject)[
"name"
] as string,
workspaceType: WorkspaceType.Slack
workspaceType: WorkspaceType.Slack,
};
}

Expand Down
2 changes: 1 addition & 1 deletion Common/Server/Utils/Workspace/WorkspaceBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import URL from "Common/Types/API/URL";
export interface WorkspaceChannel {
id: string;
name: string;
workspaceType: WorkspaceType;
workspaceType: WorkspaceType;
}

export default class WorkspaceBase {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,22 @@ export class NotificationRuleConditionUtil {
}
}

if (eventType === NotificationRuleEventType.Incident || eventType === NotificationRuleEventType.Alert || eventType === NotificationRuleEventType.ScheduledMaintenance) {
if (
eventType === NotificationRuleEventType.Incident ||
eventType === NotificationRuleEventType.Alert ||
eventType === NotificationRuleEventType.ScheduledMaintenance
) {
// either create slack channel or select existing one should be active.


if (
!notificationRule.shouldCreateNewChannel &&
!notificationRule.shouldPostToExistingChannel
) {
return "Please select either create slack channel or post to existing " + workspaceType + " channel";
return (
"Please select either create slack channel or post to existing " +
workspaceType +
" channel"
);
}

if (notificationRule.shouldPostToExistingChannel) {
Expand All @@ -100,12 +107,11 @@ export class NotificationRuleConditionUtil {
}
}

if(notificationRule.shouldCreateNewChannel) {
if (notificationRule.shouldCreateNewChannel) {
if (!notificationRule.newChannelTemplateName?.trim()) {
return "New " + workspaceType + " channel name is required";
}
}

}

return null;
Expand Down Expand Up @@ -221,7 +227,7 @@ export class NotificationRuleConditionUtil {
data.checkOn === NotificationRuleConditionCheckOn.IncidentLabels ||
data.checkOn === NotificationRuleConditionCheckOn.AlertLabels ||
data.checkOn ===
NotificationRuleConditionCheckOn.ScheduledMaintenanceLabels
NotificationRuleConditionCheckOn.ScheduledMaintenanceLabels
) {
return data.labels.map((label: Label) => {
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ const NotificationRuleForm: FunctionComponent<ComponentProps> = (
},
},
{

field: {
shouldPostToExistingChannel: true,
},
Expand Down Expand Up @@ -153,7 +152,6 @@ const NotificationRuleForm: FunctionComponent<ComponentProps> = (
{
field: {
newChannelTemplateName: true,

},
title: `New ${props.workspaceType} Channel Name`,
showIf: (formValue: FormValues<NotificationRulesType>) => {
Expand Down
2 changes: 1 addition & 1 deletion Dashboard/src/Pages/Settings/SideMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const DashboardSideMenu: () => JSX.Element = (): ReactElement => {
icon={IconProp.Label}
/>
</SideMenuSection>

<SideMenuSection title="Workspace Connections">
<SideMenuItem
link={{
Expand Down

0 comments on commit 1d7a25f

Please sign in to comment.