@graphql-inspector/action
Version:
GraphQL Inspector functionality for GitHub Actions
67 lines (66 loc) • 2.29 kB
JavaScript
import { __awaiter } from "tslib";
import { CheckStatus } from './types.js';
import { batch } from './utils.js';
export function start({ context, owner, repo, sha, logger, }) {
return __awaiter(this, void 0, void 0, function* () {
try {
const result = yield context.octokit.checks.create({
owner,
repo,
name: 'graphql-inspector',
head_sha: sha,
status: CheckStatus.InProgress,
});
logger.info(`check started`);
return result.data.id;
}
catch (error) {
logger.error(`failed to start a check`, error);
throw error;
}
});
}
export function annotate({ context, owner, repo, checkRunId, annotations, title, summary, logger, }) {
return __awaiter(this, void 0, void 0, function* () {
const batches = batch(annotations, 50);
context.log.info(`annotations to be sent: ${annotations.length}`);
context.log.info(`title: ${title}`);
try {
yield Promise.all(batches.map((chunk) => __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;
}
});
}
export function complete({ context, owner, repo, checkRunId, conclusion, logger, }) {
return __awaiter(this, void 0, void 0, function* () {
try {
yield context.octokit.checks.update({
owner,
repo,
check_run_id: checkRunId,
conclusion,
status: CheckStatus.Completed,
});
logger.info(`check completed`);
}
catch (error) {
logger.error(`failed to complete a check`, error);
throw error;
}
});
}