Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Validate yaml#28

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
ShMcK merged 9 commits intomasterfromvalidate-yaml
Jun 7, 2020
Merged
Show file tree
Hide file tree
Changes from1 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
NextNext commit
validate yaml setup
Signed-off-by: shmck <shawn.j.mckay@gmail.com>
  • Loading branch information
@ShMcK
ShMcK committedJun 7, 2020
commitc0e7cd0c6c63e2608a936e101840c5df91551073
4 changes: 4 additions & 0 deletionssrc/build.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -74,6 +74,10 @@ async function build(args: string[]) {
let config;
try {
config = yamlParser.load(_yaml);
// TODO: validate yaml
if (!config || !config.length) {
throw new Error("Invalid yaml file contents");
}
} catch (e) {
console.error("Error parsing yaml");
console.error(e.message);
Expand Down
2 changes: 1 addition & 1 deletionsrc/utils/commits.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -2,7 +2,7 @@ import * as fs from "fs";
import util from "util";
import * as path from "path";
import gitP, { SimpleGit } from "simple-git/promise";
import {addToCommitOrder,validateCommitOrder } from "./commitOrder";
import { validateCommitOrder } from "./validateCommits";

const mkdir = util.promisify(fs.mkdir);
const exists = util.promisify(fs.exists);
Expand Down
1 change: 0 additions & 1 deletionsrc/utils/parse.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -106,7 +106,6 @@ export function parse(params: ParseParams): any {

// add init commits
if (params.commits.INIT && params.commits.INIT.length) {
console.log(JSON.stringify(parsed.config?.testRunner));
// @ts-ignore
parsed.config.testRunner.setup = {
...(parsed.config?.testRunner?.setup || {}),
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
// should flag commits that are out of order based on the previous commit
// position is a string like 'INIT', 'L1', 'L1S1'
export function addToCommitOrder(position: string) {
// add position to list
}

export function validateCommitOrder(positions: string[]): boolean {
// loop over positions
const errors: number[] = [];
Expand All@@ -12,7 +8,6 @@ export function validateCommitOrder(positions: string[]): boolean {
positions.forEach((position: string, index: number) => {
if (position === "INIT") {
if (previous.level !== 0 && previous.step !== 0) {
console.log("ERROR HERE");
errors.push(index);
}
current = { level: 0, step: 0 };
Expand DownExpand Up@@ -46,7 +41,7 @@ export function validateCommitOrder(positions: string[]): boolean {
previous = current;
});

if (errors.length) {
if (errors.length && process.env.NODE_ENV !== "test") {
console.warn("Found commit positions out of order");
positions.forEach((position, index) => {
if (errors.includes(index)) {
Expand Down
3 changes: 3 additions & 0 deletionssrc/utils/validateYaml.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
export function validateYaml(yaml: string) {
return true;
}
31 changes: 27 additions & 4 deletionssrc/validate.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,46 @@
import * as path from "path";
import * as fs from "fs";
import util from "util";
import * as yamlParser from "js-yaml";
import { getArg } from "./utils/args";
import gitP, { SimpleGit } from "simple-git/promise";
import { getCommits, CommitLogObject } from "./utils/commits";

const mkdir = util.promisify(fs.mkdir);
const exists = util.promisify(fs.exists);
const rmdir = util.promisify(fs.rmdir);
const read = util.promisify(fs.readFile);

async function validate(args: string[]) {
// dir - default .
const dir = !args.length || args[0].match(/^-/) ? "." : args[0];
console.warn("Not yet implemented. Coming soon");

const localDir = path.join(process.cwd(), dir);
const codeBranch = "";

const commits = getCommits({ localDir, codeBranch });
// -y --yaml - default coderoad-config.yml
const options = {
yaml: getArg(args, { name: "yaml", alias: "y" }) || "coderoad.yaml";
}

const _yaml = await read(path.join(localDir, options.yaml), "utf8");

// parse yaml config
let config;
try {
config = yamlParser.load(_yaml)
// TODO: validate yaml
if (!config || !config.length) {
throw new Error('Invalid yaml file contents')
}
} catch (e) {
console.error("Error parsing yaml");
console.error(e.message);
}

const codeBranch: string = config.config.repo.branch;

// VALIDATE SKELETON WITH COMMITS
const commits = getCommits({ localDir, codeBranch });

// parse tutorial skeleton for order and commands

// on error, warn missing level/step
Expand Down
2 changes: 1 addition & 1 deletiontests/commitOrder.test.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
import { validateCommitOrder } from "../src/utils/commitOrder";
import { validateCommitOrder } from "../src/utils/validateCommits";

describe("commitOrder", () => {
it("should return true if order is valid", () => {
Expand Down
3 changes: 3 additions & 0 deletionstests/yaml.test.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
describe("yaml", () => {
it.todo("should parse a valid yaml file");
});

[8]ページ先頭

©2009-2025 Movatter.jp