Skip to content

Commit

Permalink
fix lint and run build/test/lint on PRs
Browse files Browse the repository at this point in the history
  • Loading branch information
hipstersmoothie committed Dec 17, 2020
1 parent ba1bdee commit 45b6a9f
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 23 deletions.
4 changes: 0 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@ node_js:
- "12"
- "13"

branches:
only:
- master

script:
- yarn lint
- yarn test
Expand Down
29 changes: 20 additions & 9 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { execFile, execFileSync, ExecSyncOptions, ExecException } from "child_process";
import {
execFile,
execFileSync,
ExecSyncOptions,
ExecException,
} from "child_process";
import { existsSync } from "fs";
import createDebugger from "debug";

Expand Down Expand Up @@ -140,7 +145,7 @@ function addOptionalArguments<Field extends string = DefaultField>(
"committer",
] as const;

for (let i = cmdOptional.length; i--;) {
for (let i = cmdOptional.length; i--; ) {
if (options[cmdOptional[i]]) {
commandWithOptions.push(`--${cmdOptional[i]}=${options[cmdOptional[i]]}`);
}
Expand Down Expand Up @@ -234,9 +239,9 @@ const parseCommits = <T extends string>(
};

/** Run "git log" and return the result as JSON */
function createCommandArguments<T extends CommitField | DefaultField = DefaultField>(
options: GitlogOptions<T>
) {
function createCommandArguments<
T extends CommitField | DefaultField = DefaultField
>(options: GitlogOptions<T>) {
// Start constructing command
let command: string[] = ["log", "-l0"];

Expand All @@ -257,7 +262,7 @@ function createCommandArguments<T extends CommitField | DefaultField = DefaultFi
command = addOptionalArguments(command, options);

// Start of custom format
let prettyArgument: string = '--pretty=@begin@';
let prettyArgument: string = "--pretty=@begin@";

// Iterating through the fields and adding them to the custom format
if (options.fields) {
Expand All @@ -271,7 +276,7 @@ function createCommandArguments<T extends CommitField | DefaultField = DefaultFi
}

// Close custom format
prettyArgument += '@end@';
prettyArgument += "@end@";
command.push(prettyArgument);

// Append branch (revision range) if specified
Expand All @@ -285,7 +290,9 @@ function createCommandArguments<T extends CommitField | DefaultField = DefaultFi
}

if (options.fileLineRange) {
command.push(`-L ${options.fileLineRange.startLine},${options.fileLineRange.endLine}:${options.fileLineRange.file}`);
command.push(
`-L ${options.fileLineRange.startLine},${options.fileLineRange.endLine}:${options.fileLineRange.file}`
);
}

if (options.file) {
Expand Down Expand Up @@ -347,7 +354,11 @@ function gitlog<Field extends CommitField = DefaultField>(
const commandArguments = createCommandArguments(options);

if (!cb) {
const stdout = execFileSync("git", commandArguments, execOptions).toString();
const stdout = execFileSync(
"git",
commandArguments,
execOptions
).toString();
const commits = stdout.split("@begin@");

if (commits[0] === "") {
Expand Down
23 changes: 13 additions & 10 deletions test/gitlog.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -322,17 +322,20 @@ describe("gitlog", () => {
});

it("should not execute shell commands", (done) => {
gitlog({
repo: testRepoLocation,
branch: "$(touch ../exploit)"
}, () => {
const exists = fs.existsSync("./test/exploit");
expect(exists).toBe(false);
if (exists) {
fs.unlinkSync("./test/exploit");
gitlog(
{
repo: testRepoLocation,
branch: "$(touch ../exploit)",
},
() => {
const exists = fs.existsSync("./test/exploit");
expect(exists).toBe(false);
if (exists) {
fs.unlinkSync("./test/exploit");
}
done();
}
done();
});
);
});

afterAll(() => {
Expand Down

0 comments on commit 45b6a9f

Please sign in to comment.