UNPKG

@graphql-inspector/action

Version:

GraphQL Inspector functionality for GitHub Actions

73 lines (72 loc) 2.56 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.complete = exports.annotate = exports.start = void 0; const tslib_1 = require("tslib"); const types_js_1 = require("./types.js"); const utils_js_1 = require("./utils.js"); function start({ context, owner, repo, sha, logger, }) { return tslib_1.__awaiter(this, void 0, void 0, function* () { try { const result = yield context.octokit.checks.create({ owner, repo, name: 'graphql-inspector', head_sha: sha, status: types_js_1.CheckStatus.InProgress, }); logger.info(`check started`); return result.data.id; } catch (error) { logger.error(`failed to start a check`, error); throw error; } }); } exports.start = start; function annotate({ context, owner, repo, checkRunId, annotations, title, summary, logger, }) { return tslib_1.__awaiter(this, void 0, void 0, function* () { const batches = (0, utils_js_1.batch)(annotations, 50); context.log.info(`annotations to be sent: ${annotations.length}`); context.log.info(`title: ${title}`); try { yield Promise.all(batches.map((chunk) => tslib_1.__awaiter(this, void 0, void 0, function* () { yield context.octokit.checks.update({ owner, repo, check_run_id: checkRunId, output: { annotations: chunk, title, summary, }, }); logger.info(`annotations sent (${chunk.length})`); }))); } catch (error) { logger.error(`failed to send annotations`, error); throw error; } }); } exports.annotate = annotate; function complete({ context, owner, repo, checkRunId, conclusion, logger, }) { return tslib_1.__awaiter(this, void 0, void 0, function* () { try { yield context.octokit.checks.update({ owner, repo, check_run_id: checkRunId, conclusion, status: types_js_1.CheckStatus.Completed, }); logger.info(`check completed`); } catch (error) { logger.error(`failed to complete a check`, error); throw error; } }); } exports.complete = complete;