UNPKG

@graphql-inspector/action

Version:

GraphQL Inspector functionality for GitHub Actions

55 lines (54 loc) 1.59 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.batch = batch; exports.castToBoolean = castToBoolean; exports.getInputAsArray = getInputAsArray; exports.resolveRule = resolveRule; const tslib_1 = require("tslib"); const fs_1 = require("fs"); const core = tslib_1.__importStar(require("@actions/core")); const commands_1 = require("@graphql-inspector/commands"); const core_1 = require("@graphql-inspector/core"); function batch(items, limit) { const batches = []; const batchesNum = Math.ceil(items.length / limit); // We still want to update check-run and send empty annotations if (batchesNum === 0) { return [[]]; } for (let i = 0; i < batchesNum; i++) { const start = i * limit; const end = start + limit; batches.push(items.slice(start, end)); } return batches; } /** * Treats non-falsy value as true */ function castToBoolean(value, defaultValue) { if (typeof value === 'boolean') { return value; } if (value === 'true' || value === 'false') { return value === 'true'; } if (typeof defaultValue === 'boolean') { return defaultValue; } return true; } function getInputAsArray(name, options) { return core .getInput(name, options) .split('\n') .map(s => s.trim()) .filter(x => x !== ''); } function resolveRule(name) { const filepath = (0, commands_1.ensureAbsolute)(name); if ((0, fs_1.existsSync)(filepath)) { return require(filepath); } return core_1.DiffRule[name]; }