Skip to content

Commit

Permalink
change build stats api (#2)
Browse files Browse the repository at this point in the history
* change build stats api


Co-authored-by: s.pirohov <[email protected]>
  • Loading branch information
SergeyPirogov and s.pirohov authored Aug 3, 2022
1 parent 3b79d32 commit 054996c
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 23 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
### Reqover Github action

Reports coverage results as a comment to pull request

Usage:

See example workflow in .github/workflows
11 changes: 7 additions & 4 deletions action.yml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
36 changes: 19 additions & 17 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,45 +4,47 @@ 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;

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

0 comments on commit 054996c

Please sign in to comment.