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: diff --git a/index.js b/index.js index cf91483..d39b407 100644 --- a/index.js +++ b/index.js @@ -1,38 +1,37 @@ -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; } - 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); - 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; @@ -40,25 +39,38 @@ async function run() { const repo = GITHUB_REPOSITORY.split("/")[1]; const owner = GITHUB_REPOSITORY.split("/")[0]; - const runUsage = await octokit.rest.actions.getWorkflowRunUsage({ + const runInfo = await octokit.rest.actions.getWorkflowRun({ owner, repo, run_id, }); - console.log(JSON.stringify(runUsage, null, 2)) + console.log(JSON.stringify(runInfo, null, 2)); + + const run_started_at = runInfo.data.updated_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); + const diffInHours = Math.floor(diffInMinutes / 60); + console.log( + `${diffInHours % 24} hours, ${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 +83,7 @@ function getBody(coverage) { ##### Missing: ${missingText} - ` + `; } -run() \ No newline at end of file +run();