-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
57 lines (49 loc) · 1.55 KB
/
index.js
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
const axios = require('axios');
const core = require('@actions/core');
(async () => {
const bpToken = core.getInput('buildPulse-api-token');
core.debug(`BuildPulse-Token: ${bpToken}`);
if (!bpToken) core.setFailed('Missing BuildPulse API token');
const discordWebhook = core.getInput('discord-webhook');
core.debug(`Discrod Webhook: ${discordWebhook}`);
if (!discordWebhook) core.setFailed('Missing Discord webhook');
const repo = core.getInput('repository') || process.env.GITHUB_REPOSITORY;
let bpData;
try {
bpData = (await axios(
{
url: `https://buildpulse.io/api/repos/${repo}/tests`,
headers: {
Authorization: `token ${bpToken}`
}
}
)).data;
} catch (e) {
core.setFailed(`Failed to communicate with BuildPulse: ${e}`);
}
const tests = bpData.tests;
tests.sort((a, b) => {
return b.disruptiveness - a.disruptiveness;
});
let content = '__**The most flaky tests the last 14 days**__\n```';
if (tests.length > 0) {
for (let i = 0; i < 3 && i < tests.length; i++) {
const test = tests[i];
content += `Disruptiveness: ${test.disruptiveness} - ${test.name}\n`;
}
} else {
content += 'No flaky tests found!';
}
content += '```';
try {
await axios({
method: 'POST',
url: discordWebhook,
data: {
content: content
}
});
} catch (e) {
core.setFailed(`Failed to communicate with Discord: ${e}`);
}
})();