Skip to content

Commit

Permalink
Merge pull request #3 from Rabatta-ApS/2-handle-failure
Browse files Browse the repository at this point in the history
2 handle failure
Benjadahl authored Jan 19, 2022
2 parents 74f6430 + 9e9adc7 commit 18b571a
Showing 2 changed files with 56 additions and 21 deletions.
19 changes: 19 additions & 0 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: CI

on:
push:
pull_request:

jobs:
test-action:
runs-on: ubuntu-latest
name: Test that the BuildPulse-Discord action WAI
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Send Digest
uses: ./
with:
buildPulse-api-token: ${{ secrets.BUILDPULSE_API_TOKEN }}
discord-webhook: ${{ secrets.DISCORD_BUILDPULSE_WEBHOOK }}
repository: rabatta-aps/rabatta
58 changes: 37 additions & 21 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,27 @@
const axios = require('axios');
const core = require('@actions/core');

try {
(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;
const bpData = (await axios(
{
url: `https://buildpulse.io/api/repos/${repo}/tests`,
headers: {
Authorization: `token ${core.getInput('buildPulse-api-token')}`
let bpData;
try {
bpData = (await axios(
{
url: `https://buildpulse.io/api/repos/${repo}/tests`,
headers: {
Authorization: `token ${bpToken}`
}
}
}
)).data;
)).data;
} catch (e) {
core.setFailed(`Failed to communicate with BuildPulse: ${e}`);
}

const tests = bpData.tests;

@@ -21,21 +31,27 @@ try {

let content = '__**The most flaky tests the last 14 days**__\n```';

for (let i = 0; i < 3 && i < tests.length; i++) {
const test = tests[i];
content += `Disruptiveness: ${test.disruptiveness} - ${test.name}\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 += '```';

axios({
method: 'POST',
url: core.getInput('discord-webhook'),
data: {
content: content
}
});
try {
await axios({
method: 'POST',
url: discordWebhook,
data: {
content: content
}
});
} catch (e) {
core.setFailed(`Failed to communicate with Discord: ${e}`);
}
})();
} catch (e) {
core.setFailed(e);
}

0 comments on commit 18b571a

Please sign in to comment.