Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: send metrics without created PR #156

Merged
merged 6 commits into from
Mar 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13321,7 +13321,6 @@ module.exports = {
/***/ 8383:
/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {

/* eslint-disable no-console */
const github = __nccwpck_require__(5438);
const { githubApi } = __nccwpck_require__(4044);

Expand Down Expand Up @@ -13433,9 +13432,13 @@ const { githubApi } = __nccwpck_require__(4044);
const { getPullRequestContext, getOctokit } = __nccwpck_require__(8383);

const getChangedFilesCoverage = async (coverage) => {
const { repo, owner, pullNumber } = getPullRequestContext();
const pullRequestContext = getPullRequestContext();

if (!pullRequestContext) return coverage.data;

const octokit = await getOctokit();

const { repo, owner, pullNumber } = pullRequestContext;
const changedFiles = await githubApi.getChangedFiles(octokit, {
repo,
owner,
Expand Down
1 change: 0 additions & 1 deletion src/lib/github.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable no-console */
const github = require("@actions/github");
const { githubApi } = require("barecheck");

Expand Down
6 changes: 5 additions & 1 deletion src/services/changedFilesCoverage.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@ const { githubApi } = require("barecheck");
const { getPullRequestContext, getOctokit } = require("../lib/github");

const getChangedFilesCoverage = async (coverage) => {
const { repo, owner, pullNumber } = getPullRequestContext();
const pullRequestContext = getPullRequestContext();

if (!pullRequestContext) return coverage.data;

const octokit = await getOctokit();

const { repo, owner, pullNumber } = pullRequestContext;
const changedFiles = await githubApi.getChangedFiles(octokit, {
repo,
owner,
Expand Down
35 changes: 35 additions & 0 deletions test/services/changedFilesCoverage.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,39 @@ describe("services/changedFilesCoverage", () => {
}
]);
});

it("show return coverage data when there is not Pull Request context", async () => {
const pullRequestContext = false;
const coverage = {
data: [
{
file: "changed1.js",
lines: [1, 2]
},
{
file: "not changed 3.js",
lines: [1, 2]
}
]
};

const getChangedFiles = sinon.spy();

const getPullRequestContext = sinon.stub().returns(pullRequestContext);
const getOctokit = sinon.spy();
const githubApi = {
getChangedFiles
};

const getChangedFilesCoverage = getChangedFilesCoverageMock({
getPullRequestContext,
getOctokit,
githubApi
});
const res = await getChangedFilesCoverage(coverage);

assert.deepEqual(res, coverage.data);
assert.isFalse(getChangedFiles.calledOnce);
assert.isFalse(getOctokit.calledOnce);
});
});