Skip to content

Feature/validate #34

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

Merged
merged 11 commits into from
Jun 13, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
cherry-pick init commits
Signed-off-by: shmck <shawn.j.mckay@gmail.com>
  • Loading branch information
ShMcK committed Jun 13, 2020
commit 55c4dcbaedd562bcf6f6979118424c71c6e990bd
29 changes: 29 additions & 0 deletions src/utils/cherryPick.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { exec as cpExec } from "child_process";
import { promisify } from "util";

const asyncExec = promisify(cpExec);

export const exec = (
command: string,
cwd: string
): Promise<{ stdout: string; stderr: string }> | never => {
return asyncExec(command, { cwd });
};

export function gitPCherryPick(cwd: string) {
return async function cherryPick(commits: string[]): Promise<void> {
for (const commit of commits) {
try {
const { stdout } = await exec(
`git cherry-pick -X theirs ${commit}`,
cwd
);
if (!stdout) {
console.warn(`No cherry-pick output for ${commit}`);
}
} catch (e) {
console.warn(`Cherry-pick failed for ${commit}`);
}
}
};
}
11 changes: 10 additions & 1 deletion src/validate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as fs from "fs-extra";
import * as yamlParser from "js-yaml";
import { getArg } from "./utils/args";
import gitP, { SimpleGit } from "simple-git/promise";
import { gitPCherryPick } from "./utils/cherryPick";
import { getCommits, CommitLogObject } from "./utils/commits";

async function validate(args: string[]) {
Expand Down Expand Up @@ -46,10 +47,18 @@ async function validate(args: string[]) {
await fs.emptyDir(tmpDir);
}
const tempGit: SimpleGit = gitP(tmpDir);

console.log(Object.keys(gitP));

await tempGit.init();
await tempGit.addRemote("origin", skeleton.config.repo.uri);
await tempGit.fetch("origin", skeleton.config.repo.branch);
// no js cherry pick implementation
const cherryPick = gitPCherryPick(tmpDir);

// VALIDATE TUTORIAL TESTS
if (commits.INIT) {
cherryPick(commits.INIT);
}

// run test runner setup command(s)
Expand All @@ -71,7 +80,7 @@ async function validate(args: string[]) {
console.error(e.message);
} finally {
// cleanup
await fs.emptyDir(tmpDir);
// await fs.emptyDir(tmpDir);
}
}

Expand Down