diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index bae2535..8e493b0 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: 4zjud4ttejxk + buildName: PR-1 + githubToken: ${{ secrets.GITHUB_TOKEN }} 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 59f2937..845db0f 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 token' required: true - GITHUB_TOKEN: + buildName: + description: 'Reqover build name for target 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..c917090 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,36 @@ 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 summary = response.data.operations; + console.log(`Result:\n ${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} + +Operations coverage result: +- Full: ${summary.full} +- Missing: ${summary.missing} +- Partial: ${summary.partial} +- Skipped: ${summary.skipped} + +**_values are represented in %_ `, }); - - console.log(`Comment ${comment.id} was added`) } catch (error) { core.setFailed(error.message); }