From f06bb2d55c6a4c1d0141897453c8fcbf2f3aa04c Mon Sep 17 00:00:00 2001 From: "s.pirohov" Date: Wed, 3 Aug 2022 15:16:08 +0300 Subject: [PATCH 01/39] change build stats api --- .github/workflows/main.yml | 5 +++-- action.yml | 11 +++++++---- index.js | 28 +++++++++++++--------------- 3 files changed, 23 insertions(+), 21 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index bae2535..2da00bc 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -10,5 +10,6 @@ jobs: - name: Reqover action step uses: ./ with: - build-id: 'td0wsmc2xlet' - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + projectToken: 'td0wsmc2xlet' + buildName: PR-1 + githubToken: ${{ secrets.GITHUB_TOKEN }} diff --git a/action.yml b/action.yml index 59f2937..c73a8ba 100644 --- a/action.yml +++ b/action.yml @@ -1,14 +1,17 @@ name: 'Reqover' description: 'Publish reqover results' inputs: - server-url: + serverUrl: description: 'Reqover server url' required: false default: 'https://reqover-io.herokuapp.com' - build-id: - description: 'Build id' + projectToken: + description: 'Reqover project id' required: true - GITHUB_TOKEN: + buildName: + description: 'Reqover build name for selected project' + required: true + githubToken: description: 'Github token of the repository (automatically created by Github)' required: true runs: diff --git a/index.js b/index.js index 83d479e..7323c26 100644 --- a/index.js +++ b/index.js @@ -4,9 +4,10 @@ const axios = require('axios').default; async function run() { try { - const serverUrl = core.getInput('server-url'); - const buildId = core.getInput('build-id'); - const github_token = core.getInput('GITHUB_TOKEN'); + const serverUrl = core.getInput('serverUrl'); + const projectToken = core.getInput('projectToken'); + const buildName = core.getInput('buildName'); + const github_token = core.getInput('githubToken'); const pr_number = core.getInput('pr_number'); const context = github.context; @@ -14,35 +15,32 @@ async function run() { const pull_number = parseInt(pr_number) || context.payload.pull_request?.number; if (!pull_number) { - core.setFailed('No pull request in input neither in current context.'); return; } - console.log(`Issue number: ${pull_number}`); - console.log(`About to get information for build: ${buildId}!`); + console.log(`About to get information for build: ${buildName}!`); if(!github_token){ - console.log(`TOKEN is not set`) + core.setFailed('`Github TOKEN is not set'); + return; } - const response = await axios.get(`${serverUrl}/builds/${buildId}`); + const response = await axios.get(`${serverUrl}/${projectToken}/stats?name=${buildName}`); const summary = response.data.report.result.summary console.log(JSON.stringify(summary, null, 2)); const octokit = new github.getOctokit(github_token); - const { data: comment } = await octokit.rest.issues.createComment({ + await octokit.rest.issues.createComment({ ...context.repo, issue_number: pull_number, body: `#### Reqover report -- Full: ${summary.operations.full} -- Missing: ${summary.operations.missing} -- Partial: ${summary.operations.partial} -- Skipped: ${summary.operations.skipped} +Full: ${summary.operations.full} +Missing: ${summary.operations.missing} +Partial: ${summary.operations.partial} +Skipped: ${summary.operations.skipped} `, }); - - console.log(`Comment ${comment.id} was added`) } catch (error) { core.setFailed(error.message); } From 9ff8a456ae8380df0c1e23d8b25cca3dd66bc478 Mon Sep 17 00:00:00 2001 From: "s.pirohov" Date: Wed, 3 Aug 2022 15:18:26 +0300 Subject: [PATCH 02/39] fix projectToken value --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 2da00bc..8e493b0 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -10,6 +10,6 @@ jobs: - name: Reqover action step uses: ./ with: - projectToken: 'td0wsmc2xlet' + projectToken: 4zjud4ttejxk buildName: PR-1 githubToken: ${{ secrets.GITHUB_TOKEN }} From 46fed8ace42eed1320addb599418623b4d6a6135 Mon Sep 17 00:00:00 2001 From: "s.pirohov" Date: Wed, 3 Aug 2022 15:19:42 +0300 Subject: [PATCH 03/39] fix --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 7323c26..8d4cbd2 100644 --- a/index.js +++ b/index.js @@ -18,7 +18,7 @@ async function run() { return; } - console.log(`About to get information for build: ${buildName}!`); + console.log(`About to get information for build: ${buildName}`); if(!github_token){ core.setFailed('`Github TOKEN is not set'); return; From ad8294ba973bdae5c4e7a2085236184fc2b81845 Mon Sep 17 00:00:00 2001 From: "s.pirohov" Date: Wed, 3 Aug 2022 15:20:32 +0300 Subject: [PATCH 04/39] fix operations --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 8d4cbd2..f85735a 100644 --- a/index.js +++ b/index.js @@ -26,7 +26,7 @@ async function run() { const response = await axios.get(`${serverUrl}/${projectToken}/stats?name=${buildName}`); - const summary = response.data.report.result.summary + const summary = response.operations; console.log(JSON.stringify(summary, null, 2)); const octokit = new github.getOctokit(github_token); From fe2b5440a6953d0713bf17783664aa5dae388fe5 Mon Sep 17 00:00:00 2001 From: "s.pirohov" Date: Wed, 3 Aug 2022 15:24:35 +0300 Subject: [PATCH 05/39] fix --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index f85735a..c29d504 100644 --- a/index.js +++ b/index.js @@ -26,7 +26,7 @@ async function run() { const response = await axios.get(`${serverUrl}/${projectToken}/stats?name=${buildName}`); - const summary = response.operations; + const summary = response.data.operations; console.log(JSON.stringify(summary, null, 2)); const octokit = new github.getOctokit(github_token); From 204944013d2c94e3d3434dbd78257f1c99af5541 Mon Sep 17 00:00:00 2001 From: "s.pirohov" Date: Wed, 3 Aug 2022 15:25:41 +0300 Subject: [PATCH 06/39] fix --- index.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index c29d504..07abf39 100644 --- a/index.js +++ b/index.js @@ -35,10 +35,10 @@ async function run() { ...context.repo, issue_number: pull_number, body: `#### Reqover report -Full: ${summary.operations.full} -Missing: ${summary.operations.missing} -Partial: ${summary.operations.partial} -Skipped: ${summary.operations.skipped} +Full: ${summary.full} +Missing: ${summary.missing} +Partial: ${summary.partial} +Skipped: ${summary.skipped} `, }); } catch (error) { From 755bfcb481dc636e9ffc8589e24a73beba959087 Mon Sep 17 00:00:00 2001 From: "s.pirohov" Date: Wed, 3 Aug 2022 15:30:23 +0300 Subject: [PATCH 07/39] add log --- index.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/index.js b/index.js index 07abf39..33e911a 100644 --- a/index.js +++ b/index.js @@ -27,7 +27,7 @@ async function run() { const response = await axios.get(`${serverUrl}/${projectToken}/stats?name=${buildName}`); const summary = response.data.operations; - console.log(JSON.stringify(summary, null, 2)); + console.log(`Result:\n ${JSON.stringify(summary, null, 2)}`); const octokit = new github.getOctokit(github_token); @@ -35,10 +35,10 @@ async function run() { ...context.repo, issue_number: pull_number, body: `#### Reqover report -Full: ${summary.full} -Missing: ${summary.missing} -Partial: ${summary.partial} -Skipped: ${summary.skipped} + Full: ${summary.full} + Missing: ${summary.missing} + Partial: ${summary.partial} + Skipped: ${summary.skipped} `, }); } catch (error) { From cb2cb2be34b35bf4af896d3a053e2dd7a6a895b4 Mon Sep 17 00:00:00 2001 From: "s.pirohov" Date: Wed, 3 Aug 2022 15:31:01 +0300 Subject: [PATCH 08/39] add % --- index.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index 33e911a..d329b2b 100644 --- a/index.js +++ b/index.js @@ -35,10 +35,10 @@ async function run() { ...context.repo, issue_number: pull_number, body: `#### Reqover report - Full: ${summary.full} - Missing: ${summary.missing} - Partial: ${summary.partial} - Skipped: ${summary.skipped} + Full: ${summary.full}% + Missing: ${summary.missing}% + Partial: ${summary.partial}% + Skipped: ${summary.skipped}% `, }); } catch (error) { From 218b0b389fe15bb78340ae5fc6aa9498cab2be5d Mon Sep 17 00:00:00 2001 From: "s.pirohov" Date: Wed, 3 Aug 2022 15:32:39 +0300 Subject: [PATCH 09/39] fix text --- index.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index d329b2b..2c9320b 100644 --- a/index.js +++ b/index.js @@ -35,10 +35,13 @@ async function run() { ...context.repo, issue_number: pull_number, body: `#### Reqover report - Full: ${summary.full}% - Missing: ${summary.missing}% - Partial: ${summary.partial}% - Skipped: ${summary.skipped}% + + Operations coverage result(%): + + Full: ${summary.full} + Missing: ${summary.missing} + Partial: ${summary.partial} + Skipped: ${summary.skipped} `, }); } catch (error) { From 0ee74531f5df08117c3f133606b96debb0917805 Mon Sep 17 00:00:00 2001 From: "s.pirohov" Date: Wed, 3 Aug 2022 15:39:30 +0300 Subject: [PATCH 10/39] add readme --- README.md | 7 +++++++ action.yml | 4 ++-- 2 files changed, 9 insertions(+), 2 deletions(-) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..4e2b3cf --- /dev/null +++ b/README.md @@ -0,0 +1,7 @@ +### Reqover Github action + +Reports coverage results as a comment to pull request + +Usage: + +See example workflow in .github/workflows \ No newline at end of file diff --git a/action.yml b/action.yml index c73a8ba..845db0f 100644 --- a/action.yml +++ b/action.yml @@ -6,10 +6,10 @@ inputs: required: false default: 'https://reqover-io.herokuapp.com' projectToken: - description: 'Reqover project id' + description: 'Reqover project token' required: true buildName: - description: 'Reqover build name for selected project' + description: 'Reqover build name for target project' required: true githubToken: description: 'Github token of the repository (automatically created by Github)' From ea985bac1c5016aaff793bb95209c9c3d3dca96b Mon Sep 17 00:00:00 2001 From: "s.pirohov" Date: Wed, 3 Aug 2022 15:40:20 +0300 Subject: [PATCH 11/39] fix text --- index.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/index.js b/index.js index 2c9320b..816c3e4 100644 --- a/index.js +++ b/index.js @@ -37,11 +37,10 @@ async function run() { body: `#### Reqover report Operations coverage result(%): - - Full: ${summary.full} - Missing: ${summary.missing} - Partial: ${summary.partial} - Skipped: ${summary.skipped} + Full: ${summary.full} + Missing: ${summary.missing} + Partial: ${summary.partial} + Skipped: ${summary.skipped} `, }); } catch (error) { From 769154423ec6bf6b4e71f3cc458ce248e1907e18 Mon Sep 17 00:00:00 2001 From: "s.pirohov" Date: Wed, 3 Aug 2022 15:43:20 +0300 Subject: [PATCH 12/39] fix text --- index.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/index.js b/index.js index 816c3e4..b420c4b 100644 --- a/index.js +++ b/index.js @@ -36,11 +36,11 @@ async function run() { issue_number: pull_number, body: `#### Reqover report - Operations coverage result(%): - Full: ${summary.full} - Missing: ${summary.missing} - Partial: ${summary.partial} - Skipped: ${summary.skipped} +Operations coverage result(%): +- Full: ${summary.full} +- Missing: ${summary.missing} +- Partial: ${summary.partial} +- Skipped: ${summary.skipped} `, }); } catch (error) { From 5c04f03e3e3afd051f8d3dade9a98627c45b1686 Mon Sep 17 00:00:00 2001 From: "s.pirohov" Date: Wed, 3 Aug 2022 15:47:36 +0300 Subject: [PATCH 13/39] add text --- index.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index b420c4b..c917090 100644 --- a/index.js +++ b/index.js @@ -36,11 +36,13 @@ async function run() { issue_number: pull_number, body: `#### Reqover report -Operations coverage result(%): +Operations coverage result: - Full: ${summary.full} - Missing: ${summary.missing} - Partial: ${summary.partial} - Skipped: ${summary.skipped} + +**_values are represented in %_ `, }); } catch (error) { From feeae5219db7daedb99dd5f233057dae6f3a3462 Mon Sep 17 00:00:00 2001 From: "s.pirohov" Date: Wed, 3 Aug 2022 17:04:39 +0300 Subject: [PATCH 14/39] add branch --- index.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/index.js b/index.js index c917090..f937598 100644 --- a/index.js +++ b/index.js @@ -13,6 +13,9 @@ async function run() { const context = github.context; const pull_number = parseInt(pr_number) || context.payload.pull_request?.number; + const branch = parseInt(pr_number) || context.ref; + + console.log(branch); if (!pull_number) { return; From e01b53a46104d56023f8f25c149ba1ead843976c Mon Sep 17 00:00:00 2001 From: "s.pirohov" Date: Mon, 15 Aug 2022 16:53:49 +0300 Subject: [PATCH 15/39] add action wait for build to be completed --- index.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index f937598..0721e85 100644 --- a/index.js +++ b/index.js @@ -27,7 +27,10 @@ async function run() { return; } - const response = await axios.get(`${serverUrl}/${projectToken}/stats?name=${buildName}`); + let response = await getBuildInfo(serverUrl, projectToken, buildName); + while(!response.data.isFinished) { + response = await getBuildInfo(serverUrl, projectToken, buildName); + } const summary = response.data.operations; console.log(`Result:\n ${JSON.stringify(summary, null, 2)}`); @@ -53,4 +56,8 @@ Operations coverage result: } } +async function getBuildInfo (serverUrl, projectToken, buildName) { + return axios.get(`${serverUrl}/${projectToken}/stats?name=${buildName}`); +} + run() \ No newline at end of file From 11eec2090d08a2b17f664adc5643af3125271fa2 Mon Sep 17 00:00:00 2001 From: "s.pirohov" Date: Mon, 15 Aug 2022 16:55:37 +0300 Subject: [PATCH 16/39] fix workflow --- .github/workflows/main.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 8e493b0..e6b4390 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -10,6 +10,6 @@ jobs: - name: Reqover action step uses: ./ with: - projectToken: 4zjud4ttejxk - buildName: PR-1 + projectToken: cpkoaj8qiwsw + buildName: Master githubToken: ${{ secrets.GITHUB_TOKEN }} From 8508d7bd88f2d7e94186978ecf611548adeffb5e Mon Sep 17 00:00:00 2001 From: "s.pirohov" Date: Mon, 15 Aug 2022 17:00:26 +0300 Subject: [PATCH 17/39] add logs --- index.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 0721e85..009372f 100644 --- a/index.js +++ b/index.js @@ -15,7 +15,8 @@ async function run() { const pull_number = parseInt(pr_number) || context.payload.pull_request?.number; const branch = parseInt(pr_number) || context.ref; - console.log(branch); + console.log(`Project: ${projectToken}`); + console.log(`Branch: ${branch}`); if (!pull_number) { return; From c26a144a860bff1e383d36c2f4118c76e1ff1b1d Mon Sep 17 00:00:00 2001 From: "s.pirohov" Date: Mon, 15 Aug 2022 18:52:04 +0300 Subject: [PATCH 18/39] fix --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 009372f..2c089cb 100644 --- a/index.js +++ b/index.js @@ -16,7 +16,7 @@ async function run() { const branch = parseInt(pr_number) || context.ref; console.log(`Project: ${projectToken}`); - console.log(`Branch: ${branch}`); + console.log(`Branch: ${buildName}`); if (!pull_number) { return; From d6382293012f93387a3f03fa3524499575cc3e94 Mon Sep 17 00:00:00 2001 From: "s.pirohov" Date: Mon, 15 Aug 2022 18:53:48 +0300 Subject: [PATCH 19/39] fix --- index.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/index.js b/index.js index 2c089cb..9edcc86 100644 --- a/index.js +++ b/index.js @@ -16,8 +16,7 @@ async function run() { const branch = parseInt(pr_number) || context.ref; console.log(`Project: ${projectToken}`); - console.log(`Branch: ${buildName}`); - + if (!pull_number) { return; } From 2e2a2ffc3d3b9f3f81bbe954ec537a0725886153 Mon Sep 17 00:00:00 2001 From: "s.pirohov" Date: Mon, 15 Aug 2022 19:17:44 +0300 Subject: [PATCH 20/39] fix buildName --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index e6b4390..94a8e5a 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -11,5 +11,5 @@ jobs: uses: ./ with: projectToken: cpkoaj8qiwsw - buildName: Master + buildName: master githubToken: ${{ secrets.GITHUB_TOKEN }} From 3cfb19bdced74ba57bcea1d307c67503d9655d4a Mon Sep 17 00:00:00 2001 From: "s.pirohov" Date: Mon, 15 Aug 2022 19:21:12 +0300 Subject: [PATCH 21/39] add log --- index.js | 1 + 1 file changed, 1 insertion(+) diff --git a/index.js b/index.js index 9edcc86..937bc5d 100644 --- a/index.js +++ b/index.js @@ -29,6 +29,7 @@ async function run() { let response = await getBuildInfo(serverUrl, projectToken, buildName); while(!response.data.isFinished) { + console.log("Wait for build to be completed") response = await getBuildInfo(serverUrl, projectToken, buildName); } From debadb7420481f4396649de2036a67dceae5e6fc Mon Sep 17 00:00:00 2001 From: "s.pirohov" Date: Mon, 15 Aug 2022 19:22:34 +0300 Subject: [PATCH 22/39] add log --- index.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 937bc5d..3204dd1 100644 --- a/index.js +++ b/index.js @@ -29,7 +29,8 @@ async function run() { let response = await getBuildInfo(serverUrl, projectToken, buildName); while(!response.data.isFinished) { - console.log("Wait for build to be completed") + const isFinished = response.data.isFinished + console.log(`Wait for build to be completed. Current status: ${isFinished}`) response = await getBuildInfo(serverUrl, projectToken, buildName); } From 4a52fe2cebbfb32ffd137ccdd9f86f7d4854a8fa Mon Sep 17 00:00:00 2001 From: "s.pirohov" Date: Mon, 15 Aug 2022 19:42:48 +0300 Subject: [PATCH 23/39] fix --- index.js | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 3204dd1..2503e3f 100644 --- a/index.js +++ b/index.js @@ -28,8 +28,9 @@ async function run() { } let response = await getBuildInfo(serverUrl, projectToken, buildName); - while(!response.data.isFinished) { - const isFinished = response.data.isFinished + let isFinished = response.data.isFinished; + while(!isFinished) { + isFinished = response.data.isFinished; console.log(`Wait for build to be completed. Current status: ${isFinished}`) response = await getBuildInfo(serverUrl, projectToken, buildName); } @@ -62,4 +63,21 @@ async function getBuildInfo (serverUrl, projectToken, buildName) { return axios.get(`${serverUrl}/${projectToken}/stats?name=${buildName}`); } +const sleepUntil = async (f, timeoutMs) => { + return new Promise((resolve, reject) => { + const timeWas = new Date(); + const wait = setInterval(function() { + if (f()) { + console.log("resolved after", new Date() - timeWas, "ms"); + clearInterval(wait); + resolve(); + } else if (new Date() - timeWas > timeoutMs) { // Timeout + console.log("rejected after", new Date() - timeWas, "ms"); + clearInterval(wait); + reject(); + } + }, 20); + }); +} + run() \ No newline at end of file From e715d1de4d44cca595b39ac4577a0df20f2ef00c Mon Sep 17 00:00:00 2001 From: "s.pirohov" Date: Mon, 15 Aug 2022 19:44:17 +0300 Subject: [PATCH 24/39] fix --- index.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 2503e3f..6375a59 100644 --- a/index.js +++ b/index.js @@ -28,10 +28,10 @@ async function run() { } let response = await getBuildInfo(serverUrl, projectToken, buildName); - let isFinished = response.data.isFinished; + let completed = response.data.completed; while(!isFinished) { - isFinished = response.data.isFinished; - console.log(`Wait for build to be completed. Current status: ${isFinished}`) + completed = response.data.completed; + console.log(`Wait for build to be completed. Current status: ${completed}`) response = await getBuildInfo(serverUrl, projectToken, buildName); } From 2f40b7fda689c1a8eb075c7d516deed166bc9bd9 Mon Sep 17 00:00:00 2001 From: "s.pirohov" Date: Mon, 15 Aug 2022 20:17:43 +0300 Subject: [PATCH 25/39] fix --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 6375a59..d5b784f 100644 --- a/index.js +++ b/index.js @@ -29,7 +29,7 @@ async function run() { let response = await getBuildInfo(serverUrl, projectToken, buildName); let completed = response.data.completed; - while(!isFinished) { + while(!completed) { completed = response.data.completed; console.log(`Wait for build to be completed. Current status: ${completed}`) response = await getBuildInfo(serverUrl, projectToken, buildName); From 8e4c013f4e214d9e2031abeb735d3c4ee8f2ace6 Mon Sep 17 00:00:00 2001 From: "s.pirohov" Date: Tue, 16 Aug 2022 09:53:01 +0300 Subject: [PATCH 26/39] add wait for build --- index.js | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/index.js b/index.js index d5b784f..8c38f41 100644 --- a/index.js +++ b/index.js @@ -27,7 +27,8 @@ async function run() { return; } - let response = await getBuildInfo(serverUrl, projectToken, buildName); + const response = await waitForBuildCompleted(getBuildInfo(serverUrl, projectToken, buildName)); + let completed = response.data.completed; while(!completed) { completed = response.data.completed; @@ -63,21 +64,20 @@ async function getBuildInfo (serverUrl, projectToken, buildName) { return axios.get(`${serverUrl}/${projectToken}/stats?name=${buildName}`); } -const sleepUntil = async (f, timeoutMs) => { - return new Promise((resolve, reject) => { - const timeWas = new Date(); - const wait = setInterval(function() { - if (f()) { - console.log("resolved after", new Date() - timeWas, "ms"); - clearInterval(wait); - resolve(); - } else if (new Date() - timeWas > timeoutMs) { // Timeout - console.log("rejected after", new Date() - timeWas, "ms"); - clearInterval(wait); - reject(); - } - }, 20); - }); +const waitForBuildCompleted = async (f, timeoutMs) => { + const timeWas = new Date(); + let response = await f(); + let completed = response.data.completed; + while(!completed) { + if(new Date() - timeWas > timeoutMs){ + throw new Error(`Timeout of ${timeoutMs} ms is exceeded`) + } + completed = response.data.completed; + console.log(`Wait for build to be completed. Current status: ${completed}`) + response = await f(); + } + + return response; } run() \ No newline at end of file From ccff36da6580314d705aed264b57946f0fca592e Mon Sep 17 00:00:00 2001 From: "s.pirohov" Date: Tue, 16 Aug 2022 09:56:43 +0300 Subject: [PATCH 27/39] fix --- index.js | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/index.js b/index.js index 8c38f41..d2acbbf 100644 --- a/index.js +++ b/index.js @@ -27,14 +27,7 @@ async function run() { return; } - const response = await waitForBuildCompleted(getBuildInfo(serverUrl, projectToken, buildName)); - - let completed = response.data.completed; - while(!completed) { - completed = response.data.completed; - console.log(`Wait for build to be completed. Current status: ${completed}`) - response = await getBuildInfo(serverUrl, projectToken, buildName); - } + const response = await waitForBuildCompleted(serverUrl, projectToken, buildName, 5000); const summary = response.data.operations; console.log(`Result:\n ${JSON.stringify(summary, null, 2)}`); @@ -64,9 +57,9 @@ async function getBuildInfo (serverUrl, projectToken, buildName) { return axios.get(`${serverUrl}/${projectToken}/stats?name=${buildName}`); } -const waitForBuildCompleted = async (f, timeoutMs) => { +const waitForBuildCompleted = async (serverUrl, projectToken, buildName, timeoutMs) => { const timeWas = new Date(); - let response = await f(); + let response = await getBuildInfo(serverUrl, projectToken, buildName); let completed = response.data.completed; while(!completed) { if(new Date() - timeWas > timeoutMs){ @@ -74,7 +67,7 @@ const waitForBuildCompleted = async (f, timeoutMs) => { } completed = response.data.completed; console.log(`Wait for build to be completed. Current status: ${completed}`) - response = await f(); + response = await getBuildInfo(serverUrl, projectToken, buildName); } return response; From 737b7ed72188f266db71b92a4f38e87b4d3ded92 Mon Sep 17 00:00:00 2001 From: "s.pirohov" Date: Sat, 26 Nov 2022 12:17:32 +0200 Subject: [PATCH 28/39] refactor --- action.yml | 12 +++--------- index.js | 39 ++++----------------------------------- 2 files changed, 7 insertions(+), 44 deletions(-) diff --git a/action.yml b/action.yml index 02eeb1e..29175ea 100644 --- a/action.yml +++ b/action.yml @@ -4,16 +4,10 @@ branding: icon: 'award' color: 'green' inputs: - serverUrl: - description: 'Reqover server url' + filePath: + description: 'coverage.json file path' required: false - default: 'https://reqover-io.herokuapp.com' - projectToken: - description: 'Reqover project token' - required: true - buildName: - description: 'Reqover build name for target project' - required: true + default: './coverage.json' githubToken: description: 'Github token of the repository (automatically created by Github)' required: true diff --git a/index.js b/index.js index d2acbbf..aea6c86 100644 --- a/index.js +++ b/index.js @@ -1,35 +1,24 @@ const core = require('@actions/core'); const github = require('@actions/github'); const axios = require('axios').default; +const fs = require('fs'); async function run() { try { - const serverUrl = core.getInput('serverUrl'); - const projectToken = core.getInput('projectToken'); - const buildName = core.getInput('buildName'); + const filePath = core.getInput('filePath'); const github_token = core.getInput('githubToken'); const pr_number = core.getInput('pr_number'); const context = github.context; - const pull_number = parseInt(pr_number) || context.payload.pull_request?.number; - const branch = parseInt(pr_number) || context.ref; - console.log(`Project: ${projectToken}`); - if (!pull_number) { return; } - console.log(`About to get information for build: ${buildName}`); - if(!github_token){ - core.setFailed('`Github TOKEN is not set'); - return; - } - - const response = await waitForBuildCompleted(serverUrl, projectToken, buildName, 5000); + const rawData = fs.readFileSync(filePath) - const summary = response.data.operations; + const summary = JSON.parse(rawData); console.log(`Result:\n ${JSON.stringify(summary, null, 2)}`); const octokit = new github.getOctokit(github_token); @@ -53,24 +42,4 @@ Operations coverage result: } } -async function getBuildInfo (serverUrl, projectToken, buildName) { - return axios.get(`${serverUrl}/${projectToken}/stats?name=${buildName}`); -} - -const waitForBuildCompleted = async (serverUrl, projectToken, buildName, timeoutMs) => { - const timeWas = new Date(); - let response = await getBuildInfo(serverUrl, projectToken, buildName); - let completed = response.data.completed; - while(!completed) { - if(new Date() - timeWas > timeoutMs){ - throw new Error(`Timeout of ${timeoutMs} ms is exceeded`) - } - completed = response.data.completed; - console.log(`Wait for build to be completed. Current status: ${completed}`) - response = await getBuildInfo(serverUrl, projectToken, buildName); - } - - return response; -} - run() \ No newline at end of file From 8a7b0acbd7a147904e980a0131459c3dc01c0cc6 Mon Sep 17 00:00:00 2001 From: "s.pirohov" Date: Sat, 26 Nov 2022 12:26:47 +0200 Subject: [PATCH 29/39] refactor --- index.js | 1 - 1 file changed, 1 deletion(-) diff --git a/index.js b/index.js index aea6c86..11a03b8 100644 --- a/index.js +++ b/index.js @@ -1,6 +1,5 @@ const core = require('@actions/core'); const github = require('@actions/github'); -const axios = require('axios').default; const fs = require('fs'); async function run() { From a55ea97546a87735d5f2bea6a3eab13d88297ecb Mon Sep 17 00:00:00 2001 From: SergeyPirogov Date: Fri, 24 Mar 2023 11:00:55 +0200 Subject: [PATCH 30/39] fix --- index.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 94a6c91..6c899fa 100644 --- a/index.js +++ b/index.js @@ -20,10 +20,10 @@ async function run() { return; } - const rawData = fs.readFileSync(filePath); - const coverage = JSON.parse(rawData); + // const rawData = fs.readFileSync(filePath); + // const coverage = JSON.parse(rawData); - console.log(`Result:\n ${JSON.stringify(coverage, null, 2)}`); + // console.log(`Result:\n ${JSON.stringify(coverage, null, 2)}`); const octokit = new github.getOctokit(github_token); From b1f73bf83e8264677c67c72e06bac282a7e7568c Mon Sep 17 00:00:00 2001 From: SergeyPirogov Date: Fri, 24 Mar 2023 11:02:05 +0200 Subject: [PATCH 31/39] fix --- index.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/index.js b/index.js index 6c899fa..730492b 100644 --- a/index.js +++ b/index.js @@ -27,11 +27,11 @@ async function run() { const octokit = new github.getOctokit(github_token); - await octokit.rest.issues.createComment({ - ...context.repo, - issue_number: pull_number, - body: getBody(coverage), - }); + // await octokit.rest.issues.createComment({ + // ...context.repo, + // issue_number: pull_number, + // body: getBody(coverage), + // }); const GITHUB_REPOSITORY = process.env.GITHUB_REPOSITORY; const run_id = process.env.GITHUB_RUN_ID; From 13acd5779c1595b83dc98f3e71b56f700634ba2e Mon Sep 17 00:00:00 2001 From: SergeyPirogov Date: Fri, 24 Mar 2023 11:03:17 +0200 Subject: [PATCH 32/39] fix --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 730492b..1e99adf 100644 --- a/index.js +++ b/index.js @@ -39,7 +39,7 @@ async function run() { const repo = GITHUB_REPOSITORY.split("/")[1]; const owner = GITHUB_REPOSITORY.split("/")[0]; - const runUsage = await octokit.rest.actions.getWorkflowRunUsage({ + const runUsage = await octokit.rest.actions.getWorkflowRun({ owner, repo, run_id, From 3b32c5c098e4c53dad833a0d152944f9851974a1 Mon Sep 17 00:00:00 2001 From: SergeyPirogov Date: Fri, 24 Mar 2023 11:32:55 +0200 Subject: [PATCH 33/39] add sleep --- .github/workflows/main.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 873b4a4..05d9891 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -3,10 +3,13 @@ on: [pull_request] jobs: hello_world_job: runs-on: ubuntu-latest - name: Test Reqover action + name: Test Reqover action steps: - name: Checkout uses: actions/checkout@v1 + - uses: jakejarvis/wait-action@master + with: + time: "30s" - name: Reqover action step uses: ./ with: From 04d57b774859f87eeda59204c8c990bf0fc3e5ee Mon Sep 17 00:00:00 2001 From: SergeyPirogov Date: Fri, 24 Mar 2023 11:42:54 +0200 Subject: [PATCH 34/39] add diff --- index.js | 52 +++++++++++++++++++++++++++++++--------------------- 1 file changed, 31 insertions(+), 21 deletions(-) diff --git a/index.js b/index.js index 1e99adf..bc128dc 100644 --- a/index.js +++ b/index.js @@ -1,22 +1,22 @@ -const core = require('@actions/core'); -const github = require('@actions/github'); -const fs = require('fs'); +const core = require("@actions/core"); +const github = require("@actions/github"); +const fs = require("fs"); async function run() { try { - const filePath = core.getInput('filePath'); - const github_token = core.getInput('githubToken'); - const pr_number = core.getInput('pr_number'); + const filePath = core.getInput("filePath"); + const github_token = core.getInput("githubToken"); + const pr_number = core.getInput("pr_number"); const context = github.context; - const pull_number = parseInt(pr_number) || context.payload.pull_request?.number; + const pull_number = + parseInt(pr_number) || context.payload.pull_request?.number; if (!pull_number) { return; } - - if(!github_token){ - core.setFailed('`Github TOKEN is not set'); + if (!github_token) { + core.setFailed("`Github TOKEN is not set"); return; } @@ -24,7 +24,7 @@ async function run() { // const coverage = JSON.parse(rawData); // console.log(`Result:\n ${JSON.stringify(coverage, null, 2)}`); - + const octokit = new github.getOctokit(github_token); // await octokit.rest.issues.createComment({ @@ -39,26 +39,36 @@ async function run() { const repo = GITHUB_REPOSITORY.split("/")[1]; const owner = GITHUB_REPOSITORY.split("/")[0]; - const runUsage = await octokit.rest.actions.getWorkflowRun({ + const runInfo = await octokit.rest.actions.getWorkflowRun({ owner, repo, run_id, }); - console.log(JSON.stringify(runUsage, null, 2)) - + console.log(JSON.stringify(runUsage, null, 2)); + + const run_started_at = runInfo.data.run_started_at; + + const date = new Date(run_started_at); + + const now = new Date(); + const diffInMilliseconds = now.getTime() - date.getTime(); + const diffInSeconds = Math.floor(diffInMilliseconds / 1000); + const diffInMinutes = Math.floor(diffInSeconds / 60); + console.log(`The difference between now and ${dateString} is:`); + console.log( + `${diffInMinutes % 60} minutes, and ${diffInSeconds % 60} seconds` + ); } catch (error) { core.setFailed(error.message); } } - function getBody(coverage) { - let missingText = ""; - for(const [key, value] of Object.entries(coverage.missing.items)) { - for(const item of value){ - missingText += `- ${item.method} ${item.path}\n` + for (const [key, value] of Object.entries(coverage.missing.items)) { + for (const item of value) { + missingText += `- ${item.method} ${item.path}\n`; } } @@ -71,7 +81,7 @@ function getBody(coverage) { ##### Missing: ${missingText} - ` + `; } -run() \ No newline at end of file +run(); From abae812460f43fa09d8a35455e33869e356a3638 Mon Sep 17 00:00:00 2001 From: SergeyPirogov Date: Fri, 24 Mar 2023 11:45:02 +0200 Subject: [PATCH 35/39] fix --- index.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index bc128dc..355e373 100644 --- a/index.js +++ b/index.js @@ -45,7 +45,7 @@ async function run() { run_id, }); - console.log(JSON.stringify(runUsage, null, 2)); + //console.log(JSON.stringify(runInfo, null, 2)); const run_started_at = runInfo.data.run_started_at; @@ -59,6 +59,7 @@ async function run() { console.log( `${diffInMinutes % 60} minutes, and ${diffInSeconds % 60} seconds` ); + } catch (error) { core.setFailed(error.message); } From 64275e0f36d3bf7843790ce402f43eafb764f105 Mon Sep 17 00:00:00 2001 From: SergeyPirogov Date: Fri, 24 Mar 2023 11:59:12 +0200 Subject: [PATCH 36/39] fix --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 355e373..4f28209 100644 --- a/index.js +++ b/index.js @@ -55,7 +55,7 @@ async function run() { const diffInMilliseconds = now.getTime() - date.getTime(); const diffInSeconds = Math.floor(diffInMilliseconds / 1000); const diffInMinutes = Math.floor(diffInSeconds / 60); - console.log(`The difference between now and ${dateString} is:`); + console.log( `${diffInMinutes % 60} minutes, and ${diffInSeconds % 60} seconds` ); From 0be0e72d0ec01a34cbb2734310a278c2e8ae3eb2 Mon Sep 17 00:00:00 2001 From: SergeyPirogov Date: Fri, 24 Mar 2023 12:05:39 +0200 Subject: [PATCH 37/39] fix --- index.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 4f28209..a901dab 100644 --- a/index.js +++ b/index.js @@ -55,9 +55,10 @@ async function run() { const diffInMilliseconds = now.getTime() - date.getTime(); const diffInSeconds = Math.floor(diffInMilliseconds / 1000); const diffInMinutes = Math.floor(diffInSeconds / 60); + const diffInHours = Math.floor(diffInMinutes / 60); console.log( - `${diffInMinutes % 60} minutes, and ${diffInSeconds % 60} seconds` + `${diffInHours % 24} hours, ${diffInMinutes % 60} minutes, and ${diffInSeconds % 60} seconds` ); } catch (error) { From 28458363cc8d616b1707c0fd9982fa289dcba6d0 Mon Sep 17 00:00:00 2001 From: SergeyPirogov Date: Fri, 24 Mar 2023 12:08:12 +0200 Subject: [PATCH 38/39] fix --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index a901dab..24cbff4 100644 --- a/index.js +++ b/index.js @@ -45,7 +45,7 @@ async function run() { run_id, }); - //console.log(JSON.stringify(runInfo, null, 2)); + console.log(JSON.stringify(runInfo, null, 2)); const run_started_at = runInfo.data.run_started_at; From d567d91420c4d5ffb0a30289c864c7800ee6318a Mon Sep 17 00:00:00 2001 From: SergeyPirogov Date: Fri, 24 Mar 2023 12:10:41 +0200 Subject: [PATCH 39/39] updated_at --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 24cbff4..d39b407 100644 --- a/index.js +++ b/index.js @@ -47,7 +47,7 @@ async function run() { console.log(JSON.stringify(runInfo, null, 2)); - const run_started_at = runInfo.data.run_started_at; + const run_started_at = runInfo.data.updated_at; const date = new Date(run_started_at);