mirror of
https://github.com/OneUptime/oneuptime.git
synced 2026-04-06 00:32:12 +02:00
feat: Add null handling for on-call policy cards in MicrosoftTeamsAlertActions and MicrosoftTeamsIncidentActions
This commit is contained in:
11
.github/instructions/instructions.md
vendored
Normal file
11
.github/instructions/instructions.md
vendored
Normal 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.
|
||||
@@ -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",
|
||||
|
||||
@@ -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",
|
||||
|
||||
Reference in New Issue
Block a user