feat: Add null handling for on-call policy cards in MicrosoftTeamsAlertActions and MicrosoftTeamsIncidentActions

This commit is contained in:
Simon Larsen
2025-09-29 10:42:12 +01:00
parent 703b525310
commit e7599c2202
3 changed files with 29 additions and 2 deletions

11
.github/instructions/instructions.md vendored Normal file
View File

@@ -0,0 +1,11 @@
---
applyTo: '**'
---
If you would like to compile or build any project. Please cd into the directory and run the following command:
```
npm run compile
```
Ths will make sure there are no type / syntax errors.

View File

@@ -321,6 +321,10 @@ export default class MicrosoftTeamsAlertActions {
// Send the input card
const card = await this.buildExecuteAlertOnCallPolicyCard(actionValue, projectId);
if (!card) {
await turnContext.sendActivity("No on-call policies found in the project");
return;
}
await turnContext.sendActivity({ attachments: [{ contentType: "application/vnd.microsoft.card.adaptive", content: card }] });
return;
}
@@ -431,7 +435,7 @@ export default class MicrosoftTeamsAlertActions {
};
}
private static async buildExecuteAlertOnCallPolicyCard(alertId: string, projectId: ObjectID): Promise<JSONObject> {
private static async buildExecuteAlertOnCallPolicyCard(alertId: string, projectId: ObjectID): Promise<JSONObject | null> {
const onCallPolicies = await OnCallDutyPolicyService.findBy({
query: {
projectId: projectId,
@@ -452,6 +456,10 @@ export default class MicrosoftTeamsAlertActions {
value: policy._id?.toString() || "",
})).filter(choice => choice.title && choice.value);
if (choices.length === 0) {
return null;
}
return {
type: "AdaptiveCard",
$schema: "http://adaptivecards.io/schemas/adaptive-card.json",

View File

@@ -343,6 +343,10 @@ export default class MicrosoftTeamsIncidentActions {
// Send the input card
const card = await this.buildExecuteOnCallPolicyCard(actionValue, projectId);
if (!card) {
await turnContext.sendActivity("No on-call policies found in the project");
return;
}
await turnContext.sendActivity({ attachments: [{ contentType: "application/vnd.microsoft.card.adaptive", content: card }] });
return;
}
@@ -470,7 +474,7 @@ export default class MicrosoftTeamsIncidentActions {
};
}
private static async buildExecuteOnCallPolicyCard(incidentId: string, projectId: ObjectID): Promise<JSONObject> {
private static async buildExecuteOnCallPolicyCard(incidentId: string, projectId: ObjectID): Promise<JSONObject | null> {
const onCallPolicies = await OnCallDutyPolicyService.findBy({
query: {
projectId: projectId,
@@ -491,6 +495,10 @@ export default class MicrosoftTeamsIncidentActions {
value: policy._id?.toString() || "",
})).filter(choice => choice.title && choice.value);
if (choices.length === 0) {
return null;
}
return {
type: "AdaptiveCard",
$schema: "http://adaptivecards.io/schemas/adaptive-card.json",