Skip to content

Commit

Permalink
Reformat code: yarn run format
Browse files Browse the repository at this point in the history
  • Loading branch information
06393993 committed Aug 15, 2024
1 parent 6bf1ac5 commit 9ca8f32
Show file tree
Hide file tree
Showing 6 changed files with 127 additions and 104 deletions.
32 changes: 22 additions & 10 deletions dist/main.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -109246,11 +109246,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.
Expand Down Expand Up @@ -109314,7 +109320,7 @@ function getStatement(file) {
const { branches, functions, lines } = file;

return [branches, functions, lines].reduce(
function (acc, curr) {
function(acc, curr) {
if (!curr) {
return acc
}
Expand All @@ -109340,7 +109346,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))
}
Expand Down Expand Up @@ -109370,7 +109376,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}`
Expand All @@ -109391,7 +109397,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
Expand Down Expand Up @@ -109548,8 +109554,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";
Expand All @@ -109576,7 +109585,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;
Expand Down
12 changes: 9 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand Down
8 changes: 4 additions & 4 deletions src/tabulate.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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))
}
Expand Down Expand Up @@ -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}`
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/tabulate_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down
16 changes: 11 additions & 5 deletions src/util.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import path from 'path'
import path from "path"

export function normalisePath(file) {
return file.replace(/\\/g, "/")
Expand All @@ -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
};
}
filename,
}
}
159 changes: 79 additions & 80 deletions src/util_test.js
Original file line number Diff line number Diff line change
@@ -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",
})
})
})

0 comments on commit 9ca8f32

Please sign in to comment.