-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnotify-slack.js
More file actions
98 lines (90 loc) · 2.23 KB
/
notify-slack.js
File metadata and controls
98 lines (90 loc) · 2.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
// notify-slack.js
require("dotenv").config();
const fs = require("fs");
const axios = require("axios");
const WEBHOOK_URL = process.env.SLACK_WEBHOOK_URL;
const RESULTS_FILE = "test-results/results.json";
const REPORT_URL = "https://jurrego1771.github.io/api_test_flow/";
if (!WEBHOOK_URL) {
console.error("❌ No se encontró SLACK_WEBHOOK_URL en el archivo .env");
process.exit(1);
}
if (!fs.existsSync(RESULTS_FILE)) {
console.error("❌ No se encontró el archivo de resultados:", RESULTS_FILE);
process.exit(1);
}
const results = JSON.parse(fs.readFileSync(RESULTS_FILE, "utf8"));
const { stats } = results;
const total = stats.expected;
const passed = total - (stats.unexpected + stats.flaky);
const failed = stats.unexpected;
const duration = (stats.duration / 1000).toFixed(2);
const color = failed > 0 ? "#E01E5A" : "#2EB67D";
const emoji = failed > 0 ? "❌" : "✅";
const statusText =
failed > 0 ? "Algunas pruebas fallaron" : "Todas las pruebas pasaron";
const message = {
blocks: [
{
type: "section",
text: {
type: "mrkdwn",
text: `*:shield: Resultados de Pruebas*`,
},
},
{
type: "divider",
},
{
type: "section",
fields: [
{
type: "mrkdwn",
text: `*Estado:*\n${statusText} ${emoji}`,
},
{
type: "mrkdwn",
text: `*Duración:*\n${duration}s`,
},
{
type: "mrkdwn",
text: `*Total:*\n${total}`,
},
{
type: "mrkdwn",
text: `*Exitosas:*\n${passed}`,
},
{
type: "mrkdwn",
text: `*Fallidas:*\n${failed}`,
},
],
},
{
type: "actions",
elements: [
{
type: "button",
text: {
type: "plain_text",
emoji: true,
text: "🔗 Ver Reporte Completo",
},
style: failed > 0 ? "danger" : "primary",
url: REPORT_URL,
},
],
},
],
attachments: [
{
color: color,
},
],
};
axios
.post(WEBHOOK_URL, message)
.then(() => console.log("✅ Notificación enviada a Slack"))
.catch((err) =>
console.error("❌ Error al enviar notificación a Slack:", err)
);