CodeCommitsIssuesPull requestsActionsInsightsSecurity
62f2d4762afc5abc190b8a01a52c44278143e9df

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

.script/yamlFileValidator.ts

26lines · modepreview

import { runCheckOverChangedFiles } from "./utils/changedFilesValidator";
import { ExitCode } from "./utils/exitCode";
import yaml from "js-yaml";
import fs from "fs";
import * as logger from "./utils/logger";

export async function IsValidYamlFile(filePath: string): Promise<ExitCode> {
  yaml.safeLoad(fs.readFileSync(filePath, "utf8"));
  return ExitCode.SUCCESS;
}

let fileTypeSuffixes = ["yaml", "yml"];
let fileKinds = ["Added", "Modified"];
let CheckOptions = {
  onCheckFile: (filePath: string) => {
    return IsValidYamlFile(filePath);
  },
  onExecError: async (e: any, filePath: string) => {
    console.log(`Incorrect yaml file. File path: ${filePath}. Error message: ${e.message}`);
  },
  onFinalFailed: async () => {
    logger.logError("An error occurred, please open an issue");
  }
};

runCheckOverChangedFiles(CheckOptions, fileKinds, fileTypeSuffixes);