diff --git a/dist/main.cjs b/dist/main.cjs index c9e662b1..ca0a46eb 100644 --- a/dist/main.cjs +++ b/dist/main.cjs @@ -110675,11 +110675,17 @@ function createHref(options, file) { const relative = file.file.replace(options.prefix, ""); const parts = relative.split("/"); const filename = parts[parts.length - 1]; - const url = path$1.join(options.repository, 'blob', options.commit, options.workingDir || './', relative); + const url = path$1.join( + options.repository, + "blob", + options.commit, + options.workingDir || "./", + relative, + ); return { href: `https://github.com/${url}`, - filename - }; + filename, + } } // Tabulate the lcov data in a HTML table. @@ -110743,7 +110749,7 @@ function getStatement(file) { const { branches, functions, lines } = file; return [branches, functions, lines].reduce( - function (acc, curr) { + function(acc, curr) { if (!curr) { return acc } @@ -110769,7 +110775,7 @@ function toRow(file, indent, options) { } function filename(file, indent, options) { - const {href, filename} = createHref(options, file); + const { href, filename } = createHref(options, file); const space = indent ? "   " : ""; return fragment(space, a({ href }, filename)) } @@ -110799,7 +110805,7 @@ function uncovered(file, options) { const all = ranges([...branches, ...lines]); return all - .map(function (range) { + .map(function(range) { const fragment = range.start === range.end ? `L${range.start}` @@ -110820,7 +110826,7 @@ function ranges(linenos) { let last = null; - linenos.sort().forEach(function (lineno) { + linenos.sort().forEach(function(lineno) { if (last === null) { last = { start: lineno, end: lineno }; return @@ -110977,8 +110983,11 @@ async function main() { const token = core.getInput("github-token"); const octokit = getOctokit_1(token); const githubClient = octokit.rest; - const workingDir = core.getInput('working-directory') || './'; - const lcovFile = path$1.join(workingDir, core.getInput("lcov-file") || "./coverage/lcov.info"); + const workingDir = core.getInput("working-directory") || "./"; + const lcovFile = path$1.join( + workingDir, + core.getInput("lcov-file") || "./coverage/lcov.info", + ); const baseFile = core.getInput("lcov-base"); const shouldFilterChangedFiles = core.getInput("filter-changed-files").toLowerCase() === "true"; @@ -111005,7 +111014,10 @@ async function main() { workingDir, }; - if (context.eventName === "pull_request" || context.eventName === "pull_request_target") { + if ( + context.eventName === "pull_request" || + context.eventName === "pull_request_target" + ) { options.commit = context.payload.pull_request.head.sha; options.baseCommit = context.payload.pull_request.base.sha; options.head = context.payload.pull_request.head.ref; diff --git a/src/index.js b/src/index.js index 76997cc3..dbf4a60e 100644 --- a/src/index.js +++ b/src/index.js @@ -15,8 +15,11 @@ async function main() { const token = core.getInput("github-token") const octokit = getOctokit(token) const githubClient = octokit.rest - const workingDir = core.getInput('working-directory') || './'; - const lcovFile = path.join(workingDir, core.getInput("lcov-file") || "./coverage/lcov.info") + const workingDir = core.getInput("working-directory") || "./" + const lcovFile = path.join( + workingDir, + core.getInput("lcov-file") || "./coverage/lcov.info", + ) const baseFile = core.getInput("lcov-base") const shouldFilterChangedFiles = core.getInput("filter-changed-files").toLowerCase() === "true" @@ -43,7 +46,10 @@ async function main() { workingDir, } - if (context.eventName === "pull_request" || context.eventName === "pull_request_target") { + if ( + context.eventName === "pull_request" || + context.eventName === "pull_request_target" + ) { options.commit = context.payload.pull_request.head.sha options.baseCommit = context.payload.pull_request.base.sha options.head = context.payload.pull_request.head.ref diff --git a/src/tabulate.js b/src/tabulate.js index db51aa93..e8c61959 100644 --- a/src/tabulate.js +++ b/src/tabulate.js @@ -62,7 +62,7 @@ function getStatement(file) { const { branches, functions, lines } = file return [branches, functions, lines].reduce( - function (acc, curr) { + function(acc, curr) { if (!curr) { return acc } @@ -88,7 +88,7 @@ function toRow(file, indent, options) { } function filename(file, indent, options) { - const {href, filename} = createHref(options, file); + const { href, filename } = createHref(options, file) const space = indent ? "   " : "" return fragment(space, a({ href }, filename)) } @@ -118,7 +118,7 @@ function uncovered(file, options) { const all = ranges([...branches, ...lines]) return all - .map(function (range) { + .map(function(range) { const fragment = range.start === range.end ? `L${range.start}` @@ -139,7 +139,7 @@ function ranges(linenos) { let last = null - linenos.sort().forEach(function (lineno) { + linenos.sort().forEach(function(lineno) { if (last === null) { last = { start: lineno, end: lineno } return diff --git a/src/tabulate_test.js b/src/tabulate_test.js index b0610b69..1a5325d8 100644 --- a/src/tabulate_test.js +++ b/src/tabulate_test.js @@ -119,7 +119,7 @@ test("tabulate should generate a correct table", function() { repository: "example/foo", commit: "2e15bee6fe0df5003389aa5ec894ec0fea2d874a", prefix: "/files/project/", - workingDir: 'frontend' + workingDir: "frontend", } const html = table( @@ -489,7 +489,7 @@ test("filtered tabulate should fix backwards slashes in filenames", function() { shouldFilterChangedFiles: true, changedFiles: ["src/foo.js"], } - + const html = table( tbody( tr( diff --git a/src/util.js b/src/util.js index 71a319f6..bf4e218b 100644 --- a/src/util.js +++ b/src/util.js @@ -1,4 +1,4 @@ -import path from 'path' +import path from "path" export function normalisePath(file) { return file.replace(/\\/g, "/") @@ -8,9 +8,15 @@ export function createHref(options, file) { const relative = file.file.replace(options.prefix, "") const parts = relative.split("/") const filename = parts[parts.length - 1] - const url = path.join(options.repository, 'blob', options.commit, options.workingDir || './', relative) + const url = path.join( + options.repository, + "blob", + options.commit, + options.workingDir || "./", + relative, + ) return { href: `https://github.com/${url}`, - filename - }; -} \ No newline at end of file + filename, + } +} diff --git a/src/util_test.js b/src/util_test.js index 9ce9e197..71116daf 100644 --- a/src/util_test.js +++ b/src/util_test.js @@ -1,87 +1,86 @@ import { createHref } from "./util" -test('create simple url to file', () => { - const options = { - repository: "example/foo", - commit: "2e15bee6fe0df5003389aa5ec894ec0fea2d874a", - prefix: "/files/project/", - } - const file = { - file: "/files/project/index.js", - functions: { - found: 0, - hit: 0, - details: [], - }, - } - expect(createHref(options, file)).toEqual({ - href: `https://github.com/${options.repository}/blob/${options.commit}/index.js`, - filename: 'index.js' - }) +test("create simple url to file", () => { + const options = { + repository: "example/foo", + commit: "2e15bee6fe0df5003389aa5ec894ec0fea2d874a", + prefix: "/files/project/", + } + const file = { + file: "/files/project/index.js", + functions: { + found: 0, + hit: 0, + details: [], + }, + } + expect(createHref(options, file)).toEqual({ + href: `https://github.com/${options.repository}/blob/${options.commit}/index.js`, + filename: "index.js", + }) }) -describe('has working directory', () => { - test('create url to file with simple working dir path', () => { - const options = { - repository: "example/foo", - commit: "2e15bee6fe0df5003389aa5ec894ec0fea2d874a", - prefix: "/files/project/", - workingDir: 'frontend' - } - const file = { - file: "/files/project/index.js", - functions: { - found: 0, - hit: 0, - details: [], - }, - } - expect(createHref(options, file)).toEqual({ - href: `https://github.com/${options.repository}/blob/${options.commit}/frontend/index.js`, - filename: 'index.js' - }) - }) +describe("has working directory", () => { + test("create url to file with simple working dir path", () => { + const options = { + repository: "example/foo", + commit: "2e15bee6fe0df5003389aa5ec894ec0fea2d874a", + prefix: "/files/project/", + workingDir: "frontend", + } + const file = { + file: "/files/project/index.js", + functions: { + found: 0, + hit: 0, + details: [], + }, + } + expect(createHref(options, file)).toEqual({ + href: `https://github.com/${options.repository}/blob/${options.commit}/frontend/index.js`, + filename: "index.js", + }) + }) - test('working dir relative path', () => { - const options = { - repository: "example/foo", - commit: "2e15bee6fe0df5003389aa5ec894ec0fea2d874a", - prefix: "/files/project/", - workingDir: './frontend/' - } - const file = { - file: "/files/project/index.js", - functions: { - found: 0, - hit: 0, - details: [], - }, - } - expect(createHref(options, file)).toEqual({ - href: `https://github.com/${options.repository}/blob/${options.commit}/frontend/index.js`, - filename: 'index.js' - }) - }) - - test('working dir path with leading and trailing slashed', () => { - const options = { - repository: "example/foo", - commit: "2e15bee6fe0df5003389aa5ec894ec0fea2d874a", - prefix: "/files/project/", - workingDir: '/frontend/' - } - const file = { - file: "/files/project/src/foo.js", - functions: { - found: 0, - hit: 0, - details: [], - }, - } - expect(createHref(options, file)).toEqual({ - href: `https://github.com/${options.repository}/blob/${options.commit}/frontend/src/foo.js`, - filename: 'foo.js' - }) - }) + test("working dir relative path", () => { + const options = { + repository: "example/foo", + commit: "2e15bee6fe0df5003389aa5ec894ec0fea2d874a", + prefix: "/files/project/", + workingDir: "./frontend/", + } + const file = { + file: "/files/project/index.js", + functions: { + found: 0, + hit: 0, + details: [], + }, + } + expect(createHref(options, file)).toEqual({ + href: `https://github.com/${options.repository}/blob/${options.commit}/frontend/index.js`, + filename: "index.js", + }) + }) + test("working dir path with leading and trailing slashed", () => { + const options = { + repository: "example/foo", + commit: "2e15bee6fe0df5003389aa5ec894ec0fea2d874a", + prefix: "/files/project/", + workingDir: "/frontend/", + } + const file = { + file: "/files/project/src/foo.js", + functions: { + found: 0, + hit: 0, + details: [], + }, + } + expect(createHref(options, file)).toEqual({ + href: `https://github.com/${options.repository}/blob/${options.commit}/frontend/src/foo.js`, + filename: "foo.js", + }) + }) })