Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2 handle failure #3

Merged
merged 17 commits into from
Jan 19, 2022
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;

Expand All @@ -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);
}