Skip to content

Commit

Permalink
Merge pull request #1 from reqover/test
Browse files Browse the repository at this point in the history
delete comment
  • Loading branch information
SergeyPirogov authored Aug 3, 2022
2 parents bc333f6 + 85b6b31 commit 3b79d32
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 41 deletions.
12 changes: 5 additions & 7 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
on: [push, pull_request]
on: [pull_request]

jobs:
hello_world_job:
runs-on: ubuntu-latest
name: Test Reqover action
steps:
- name: Checkout
uses: actions/checkout@v1
- name: Reqover action step
id: hello
uses: reqover/reqover-action@master
uses: ./
with:
build-id: 'td0wsmc2xlet'
github-token: ${{secrets.GITHUB_TOKEN}}
# Use the output from the `hello` step
#- name: Get the output time
# run: echo "The time was ${{ steps.hello.outputs.time }}"
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
7 changes: 2 additions & 5 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,9 @@ inputs:
build-id:
description: 'Build id'
required: true
github-token:
description: 'Github token'
GITHUB_TOKEN:
description: 'Github token of the repository (automatically created by Github)'
required: true
outputs:
time: # id of output
description: 'The time we greeted you'
runs:
using: 'node16'
main: 'index.js'
76 changes: 47 additions & 29 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,50 @@ const core = require('@actions/core');
const github = require('@actions/github');
const axios = require('axios').default;

try {
const serverUrl = core.getInput('server-url');
const buildId = core.getInput('build-id');
const ghToken = core.getInput('github-token');

const issueNumber = github.context.issue.number;
console.log(`Issue number ${issueNumber}`);
console.log(`About to get information for ${buildId}!`);

axios.get(`${serverUrl}/builds/${buildId}`)
.then(function (response) {
console.log(JSON.stringify(response.data.report.result.summary, null, 2));
github.issues.createComment({
issue_number: github.context.issue.number,
owner: github.context.repo.owner,
repo: github.context.repo.repo,
body: '👋 Thanks for reporting!'
})
})
.catch(function (error) {
console.log(error);
});

// Get the JSON webhook payload for the event that triggered the workflow
// const payload = JSON.stringify(github.context.payload, undefined, 2)
// console.log(`The event payload: ${payload}`);
} catch (error) {
core.setFailed(error.message);
}
async function run() {
try {
const serverUrl = core.getInput('server-url');
const buildId = core.getInput('build-id');
const github_token = core.getInput('GITHUB_TOKEN');
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}!`);
if(!github_token){
console.log(`TOKEN is not set`)
}

const response = await axios.get(`${serverUrl}/builds/${buildId}`);

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({
...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}
`,
});

console.log(`Comment ${comment.id} was added`)
} catch (error) {
core.setFailed(error.message);
}
}

run()

0 comments on commit 3b79d32

Please sign in to comment.