@graphql-inspector/action
Version:
GraphQL Inspector functionality for GitHub Actions
60 lines (59 loc) • 1.83 kB
JavaScript
import { CheckStatus } from './types.js';
import { batch } from './utils.js';
export async function start({ context, owner, repo, sha, logger, }) {
try {
const result = await 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 async function annotate({ context, owner, repo, checkRunId, annotations, title, summary, logger, }) {
const batches = batch(annotations, 50);
context.log.info(`annotations to be sent: ${annotations.length}`);
context.log.info(`title: ${title}`);
try {
await Promise.all(batches.map(async (chunk) => {
await 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 async function complete({ context, owner, repo, checkRunId, conclusion, logger, }) {
try {
await 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;
}
}