Skip to content

Commit

Permalink
fallback to sha if not on pr (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
jmisur authored May 22, 2020
1 parent 449a761 commit dec13d8
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 8 deletions.
7 changes: 4 additions & 3 deletions action.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@ const action = async () => {
: 'No test results found!';
core.info(`Result: ${title}`);

const prLink = github.context.payload.pull_request.html_url;
const pullRequest = github.context.payload.pull_request;
const link = pullRequest && pullRequest.html_url || github.context.ref;
const conclusion = foundResults && annotations.length === 0 ? 'success' : 'failure';
const status = 'completed';
const head_sha = github.context.payload.pull_request.head.sha;
const head_sha = pullRequest && pullRequest.head.sha || github.context.sha;
core.info(
`Posting status '${status}' with conclusion '${conclusion}' to ${prLink} (sha: ${head_sha})`
`Posting status '${status}' with conclusion '${conclusion}' to ${link} (sha: ${head_sha})`
);

const createCheckRequest = {
Expand Down
14 changes: 13 additions & 1 deletion action.test.fixtures.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,18 @@ const finishedSuccess = {
}
};

const masterSuccess = {
name: 'Test Report',
head_sha: 'masterSha123',
status: 'completed',
conclusion: 'success',
output: {
title: '1 tests run, 0 skipped, 0 failed.',
summary: '',
annotations: []
}
};

const nothingFound = {
name: 'Test Report',
head_sha: 'sha123',
Expand All @@ -178,4 +190,4 @@ const nothingFound = {
}
};

module.exports = { finishedWithFailures, finishedSuccess, nothingFound };
module.exports = { finishedWithFailures, finishedSuccess, nothingFound, masterSuccess };
26 changes: 25 additions & 1 deletion action.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@ const core = require('@actions/core');
const github = require('@actions/github');
const nock = require('nock');
const action = require('./action');
const { finishedWithFailures, finishedSuccess, nothingFound } = require('./action.test.fixtures');
const {
finishedWithFailures,
finishedSuccess,
nothingFound,
masterSuccess
} = require('./action.test.fixtures');

jest.setTimeout(20000);

Expand Down Expand Up @@ -89,4 +94,23 @@ describe('action should work', () => {

expect(request).toStrictEqual(nothingFound);
});

it('should send reports to sha if no pr detected', async () => {
inputs.report_paths = '**/surefire-reports/TEST-*AllOkTest.xml';
github.context.payload.pull_request = undefined;
github.context.sha = 'masterSha123';
github.context.ref = 'refs/heads/master';

let request = null;
const scope = nock('https://api.github.com')
.post('/repos/scacap/action-surefire-report/check-runs', body => {
request = body;
return body;
})
.reply(200, {});
await action();
scope.done();

expect(request).toStrictEqual(masterSuccess);
});
});
7 changes: 4 additions & 3 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29747,12 +29747,13 @@ const action = async () => {
: 'No test results found!';
core.info(`Result: ${title}`);

const prLink = github.context.payload.pull_request.html_url;
const pullRequest = github.context.payload.pull_request;
const link = pullRequest && pullRequest.html_url || github.context.ref;
const conclusion = foundResults && annotations.length === 0 ? 'success' : 'failure';
const status = 'completed';
const head_sha = github.context.payload.pull_request.head.sha;
const head_sha = pullRequest && pullRequest.head.sha || github.context.sha;
core.info(
`Posting status '${status}' with conclusion '${conclusion}' to ${prLink} (sha: ${head_sha})`
`Posting status '${status}' with conclusion '${conclusion}' to ${link} (sha: ${head_sha})`
);

const createCheckRequest = {
Expand Down

0 comments on commit dec13d8

Please # to comment.