From b4a7858a0482143e67bc6d338d62bf8e46179c99 Mon Sep 17 00:00:00 2001 From: benjadahl Date: Wed, 19 Jan 2022 15:55:00 +0100 Subject: [PATCH 01/17] Add CI workflow --- .github/workflows/CI.yml | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 .github/workflows/CI.yml diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml new file mode 100644 index 0000000..fc74045 --- /dev/null +++ b/.github/workflows/CI.yml @@ -0,0 +1,18 @@ +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: Rabatta-ApS/BuildPulse-Discord@v2.0.0 + with: + buildPulse-api-token: ${{ secrets.BUILDPULSE_API_TOKEN }} + discord-webhook: ${{ secrets.DISCORD_BUILDPULSE_WEBHOOK }} \ No newline at end of file From addf22f8f14bcd51a9c13ccbae8f0d6535dc377d Mon Sep 17 00:00:00 2001 From: benjadahl Date: Wed, 19 Jan 2022 15:56:23 +0100 Subject: [PATCH 02/17] Add test repo to CI --- .github/workflows/CI.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index fc74045..a1c3eb4 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -15,4 +15,5 @@ jobs: uses: Rabatta-ApS/BuildPulse-Discord@v2.0.0 with: buildPulse-api-token: ${{ secrets.BUILDPULSE_API_TOKEN }} - discord-webhook: ${{ secrets.DISCORD_BUILDPULSE_WEBHOOK }} \ No newline at end of file + discord-webhook: ${{ secrets.DISCORD_BUILDPULSE_WEBHOOK }} + repository: rabatta-aps/rabatta \ No newline at end of file From a002f88761dc4688c2dd3a87365f9c7d704e1663 Mon Sep 17 00:00:00 2001 From: benjadahl Date: Wed, 19 Jan 2022 16:05:47 +0100 Subject: [PATCH 03/17] Handle no tests found --- .github/workflows/CI.yml | 2 +- index.js | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index a1c3eb4..45ff711 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -16,4 +16,4 @@ jobs: with: buildPulse-api-token: ${{ secrets.BUILDPULSE_API_TOKEN }} discord-webhook: ${{ secrets.DISCORD_BUILDPULSE_WEBHOOK }} - repository: rabatta-aps/rabatta \ No newline at end of file + #repository: rabatta-aps/rabatta \ No newline at end of file diff --git a/index.js b/index.js index fb4d158..6356b53 100644 --- a/index.js +++ b/index.js @@ -21,9 +21,13 @@ 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 (test.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 += '```'; From 3a42bd099aa564de04a859f7e7b45c4efeef4f3d Mon Sep 17 00:00:00 2001 From: benjadahl Date: Wed, 19 Jan 2022 16:06:30 +0100 Subject: [PATCH 04/17] Use local action --- .github/workflows/CI.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 45ff711..6c0dfdc 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -12,7 +12,7 @@ jobs: - name: Checkout uses: actions/checkout@v2 - name: Send Digest - uses: Rabatta-ApS/BuildPulse-Discord@v2.0.0 + uses: ./ with: buildPulse-api-token: ${{ secrets.BUILDPULSE_API_TOKEN }} discord-webhook: ${{ secrets.DISCORD_BUILDPULSE_WEBHOOK }} From 155c79bfff2c23e8fa3d74e6b96db0452721dec3 Mon Sep 17 00:00:00 2001 From: benjadahl Date: Wed, 19 Jan 2022 16:07:32 +0100 Subject: [PATCH 05/17] Correct var --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 6356b53..9ba5eb7 100644 --- a/index.js +++ b/index.js @@ -21,7 +21,7 @@ try { let content = '__**The most flaky tests the last 14 days**__\n```'; - if (test.length > 0) { + 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`; From ba13e58992e91026ad99564f7efe6a1cf38f8daf Mon Sep 17 00:00:00 2001 From: benjadahl Date: Wed, 19 Jan 2022 16:10:26 +0100 Subject: [PATCH 06/17] Add checks for inputs --- .github/workflows/CI.yml | 4 ++-- index.js | 8 ++++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 6c0dfdc..af25c9f 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -15,5 +15,5 @@ jobs: uses: ./ with: buildPulse-api-token: ${{ secrets.BUILDPULSE_API_TOKEN }} - discord-webhook: ${{ secrets.DISCORD_BUILDPULSE_WEBHOOK }} - #repository: rabatta-aps/rabatta \ No newline at end of file + #discord-webhook: ${{ secrets.DISCORD_BUILDPULSE_WEBHOOK }} + repository: rabatta-aps/rabatta \ No newline at end of file diff --git a/index.js b/index.js index 9ba5eb7..4676a49 100644 --- a/index.js +++ b/index.js @@ -3,12 +3,16 @@ const core = require('@actions/core'); try { (async () => { + const bpToken = core.getInput('buildPulse-api-token'); + if (bpToken == null) core.setFailed('Missing BuildPulse API token'); + const discordWebhook = core.getInput('discord-webhook'); + if (discordWebhook == null) 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')}` + Authorization: `token ${bpToken}` } } )).data; @@ -34,7 +38,7 @@ try { axios({ method: 'POST', - url: core.getInput('discord-webhook'), + url: discordWebhook, data: { content: content } From 0a29e3c51de9cf8b1b04ce79c46c4c4d32d99046 Mon Sep 17 00:00:00 2001 From: benjadahl Date: Wed, 19 Jan 2022 16:11:32 +0100 Subject: [PATCH 07/17] Add logs --- index.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/index.js b/index.js index 4676a49..bb56258 100644 --- a/index.js +++ b/index.js @@ -4,8 +4,10 @@ const core = require('@actions/core'); try { (async () => { const bpToken = core.getInput('buildPulse-api-token'); + console.log(bpToken); if (bpToken == null) core.setFailed('Missing BuildPulse API token'); const discordWebhook = core.getInput('discord-webhook'); + console.log(discordWebhook); if (discordWebhook == null) core.setFailed('Missing Discord webhook'); const repo = core.getInput('repository') || process.env.GITHUB_REPOSITORY; const bpData = (await axios( From 63c77c1845b4f568ea0b41d245bfc18c7e727c50 Mon Sep 17 00:00:00 2001 From: benjadahl Date: Wed, 19 Jan 2022 16:12:58 +0100 Subject: [PATCH 08/17] Comment out calls --- index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index bb56258..8e656b3 100644 --- a/index.js +++ b/index.js @@ -10,7 +10,7 @@ try { console.log(discordWebhook); if (discordWebhook == null) core.setFailed('Missing Discord webhook'); const repo = core.getInput('repository') || process.env.GITHUB_REPOSITORY; - const bpData = (await axios( + /*const bpData = (await axios( { url: `https://buildpulse.io/api/repos/${repo}/tests`, headers: { @@ -44,7 +44,7 @@ try { data: { content: content } - }); + });*/ })(); } catch (e) { core.setFailed(e); From bf22ac83f4efb533c24bffc93ca99c83c4bf2586 Mon Sep 17 00:00:00 2001 From: benjadahl Date: Wed, 19 Jan 2022 16:15:07 +0100 Subject: [PATCH 09/17] Change to console info --- index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 8e656b3..68b079c 100644 --- a/index.js +++ b/index.js @@ -4,10 +4,10 @@ const core = require('@actions/core'); try { (async () => { const bpToken = core.getInput('buildPulse-api-token'); - console.log(bpToken); + console.info(bpToken); if (bpToken == null) core.setFailed('Missing BuildPulse API token'); const discordWebhook = core.getInput('discord-webhook'); - console.log(discordWebhook); + console.info(discordWebhook); if (discordWebhook == null) core.setFailed('Missing Discord webhook'); const repo = core.getInput('repository') || process.env.GITHUB_REPOSITORY; /*const bpData = (await axios( From a1eef635e52f5c82d1e5d06c55064b5c1d49263a Mon Sep 17 00:00:00 2001 From: benjadahl Date: Wed, 19 Jan 2022 16:18:52 +0100 Subject: [PATCH 10/17] Use core logging --- index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 68b079c..326e32c 100644 --- a/index.js +++ b/index.js @@ -4,10 +4,10 @@ const core = require('@actions/core'); try { (async () => { const bpToken = core.getInput('buildPulse-api-token'); - console.info(bpToken); + core.debug(bpToken); if (bpToken == null) core.setFailed('Missing BuildPulse API token'); const discordWebhook = core.getInput('discord-webhook'); - console.info(discordWebhook); + core.debug(discordWebhook); if (discordWebhook == null) core.setFailed('Missing Discord webhook'); const repo = core.getInput('repository') || process.env.GITHUB_REPOSITORY; /*const bpData = (await axios( From 5091dda73da9753854e8f9441aeb6cf19851b7bd Mon Sep 17 00:00:00 2001 From: benjadahl Date: Wed, 19 Jan 2022 16:20:22 +0100 Subject: [PATCH 11/17] Changed conditionals for throwing input error --- index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 326e32c..310c27d 100644 --- a/index.js +++ b/index.js @@ -5,10 +5,10 @@ try { (async () => { const bpToken = core.getInput('buildPulse-api-token'); core.debug(bpToken); - if (bpToken == null) core.setFailed('Missing BuildPulse API token'); + if (bpToken) core.setFailed('Missing BuildPulse API token'); const discordWebhook = core.getInput('discord-webhook'); core.debug(discordWebhook); - if (discordWebhook == null) core.setFailed('Missing Discord webhook'); + if (discordWebhook) core.setFailed('Missing Discord webhook'); const repo = core.getInput('repository') || process.env.GITHUB_REPOSITORY; /*const bpData = (await axios( { From f97b62a8cf5e4ffaac804bfafb101bd7a01d175c Mon Sep 17 00:00:00 2001 From: benjadahl Date: Wed, 19 Jan 2022 16:24:22 +0100 Subject: [PATCH 12/17] Invert conditions --- index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 310c27d..472e799 100644 --- a/index.js +++ b/index.js @@ -5,10 +5,10 @@ try { (async () => { const bpToken = core.getInput('buildPulse-api-token'); core.debug(bpToken); - if (bpToken) core.setFailed('Missing BuildPulse API token'); + if (!bpToken) core.setFailed('Missing BuildPulse API token'); const discordWebhook = core.getInput('discord-webhook'); core.debug(discordWebhook); - if (discordWebhook) core.setFailed('Missing Discord webhook'); + if (!discordWebhook) core.setFailed('Missing Discord webhook'); const repo = core.getInput('repository') || process.env.GITHUB_REPOSITORY; /*const bpData = (await axios( { From f531c318b754f8479d878d91483a6ba3a214e839 Mon Sep 17 00:00:00 2001 From: benjadahl Date: Wed, 19 Jan 2022 16:49:15 +0100 Subject: [PATCH 13/17] Set error messages for fetching --- index.js | 46 ++++++++++++++++++++++++++-------------------- 1 file changed, 26 insertions(+), 20 deletions(-) diff --git a/index.js b/index.js index 472e799..28c45ee 100644 --- a/index.js +++ b/index.js @@ -1,23 +1,27 @@ const axios = require('axios'); const core = require('@actions/core'); -try { (async () => { const bpToken = core.getInput('buildPulse-api-token'); core.debug(bpToken); - if (!bpToken) core.setFailed('Missing BuildPulse API token'); + //if (!bpToken) core.setFailed('Missing BuildPulse API token'); const discordWebhook = core.getInput('discord-webhook'); core.debug(discordWebhook); - if (!discordWebhook) core.setFailed('Missing Discord webhook'); + //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 ${bpToken}` + 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; @@ -38,14 +42,16 @@ try { content += '```'; - axios({ - method: 'POST', - url: discordWebhook, - data: { - content: content - } - });*/ + try { + axios({ + method: 'POST', + url: discordWebhook, + data: { + content: content + } + }); + } catch (e) { + core.setFailed(`Failed to communicate with Discord: ${e}`); + } })(); -} catch (e) { - core.setFailed(e); -} + From 55a75238a862d29848fb1c4a6e9427e53410969a Mon Sep 17 00:00:00 2001 From: benjadahl Date: Wed, 19 Jan 2022 16:51:58 +0100 Subject: [PATCH 14/17] Added missing await --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 28c45ee..2c75e83 100644 --- a/index.js +++ b/index.js @@ -43,7 +43,7 @@ const core = require('@actions/core'); content += '```'; try { - axios({ + await axios({ method: 'POST', url: discordWebhook, data: { From 558d9e875e98fcd85253057d6317a10256f51e10 Mon Sep 17 00:00:00 2001 From: benjadahl Date: Wed, 19 Jan 2022 16:54:36 +0100 Subject: [PATCH 15/17] Readded error msgs --- index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 2c75e83..e51aeb9 100644 --- a/index.js +++ b/index.js @@ -4,10 +4,10 @@ const core = require('@actions/core'); (async () => { const bpToken = core.getInput('buildPulse-api-token'); core.debug(bpToken); - //if (!bpToken) core.setFailed('Missing BuildPulse API token'); + if (!bpToken) core.setFailed('Missing BuildPulse API token'); const discordWebhook = core.getInput('discord-webhook'); core.debug(discordWebhook); - //if (!discordWebhook) core.setFailed('Missing Discord webhook'); + if (!discordWebhook) core.setFailed('Missing Discord webhook'); const repo = core.getInput('repository') || process.env.GITHUB_REPOSITORY; let bpData; try { From 1b34d8cc38961a18ee108d077a0cf2c0104a9bd3 Mon Sep 17 00:00:00 2001 From: benjadahl Date: Wed, 19 Jan 2022 16:56:29 +0100 Subject: [PATCH 16/17] Readded discord webhook --- .github/workflows/CI.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index af25c9f..77731b4 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -15,5 +15,5 @@ jobs: uses: ./ with: buildPulse-api-token: ${{ secrets.BUILDPULSE_API_TOKEN }} - #discord-webhook: ${{ secrets.DISCORD_BUILDPULSE_WEBHOOK }} + discord-webhook: ${{ secrets.DISCORD_BUILDPULSE_WEBHOOK }} repository: rabatta-aps/rabatta \ No newline at end of file From 9e9adc7fa47414b3a65398074ad781fdbdea752f Mon Sep 17 00:00:00 2001 From: benjadahl Date: Wed, 19 Jan 2022 16:57:30 +0100 Subject: [PATCH 17/17] Add debug info --- index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index e51aeb9..2425d51 100644 --- a/index.js +++ b/index.js @@ -3,10 +3,10 @@ const core = require('@actions/core'); (async () => { const bpToken = core.getInput('buildPulse-api-token'); - core.debug(bpToken); + core.debug(`BuildPulse-Token: ${bpToken}`); if (!bpToken) core.setFailed('Missing BuildPulse API token'); const discordWebhook = core.getInput('discord-webhook'); - core.debug(discordWebhook); + core.debug(`Discrod Webhook: ${discordWebhook}`); if (!discordWebhook) core.setFailed('Missing Discord webhook'); const repo = core.getInput('repository') || process.env.GITHUB_REPOSITORY; let bpData;