@graphql-inspector/action
Version:
GraphQL Inspector functionality for GitHub Actions
148 lines (147 loc) • 5.35 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const diagnostics_js_1 = require("./helpers/diagnostics.js");
const loaders_js_1 = require("./helpers/loaders.js");
const schema_change_notifications_js_1 = require("./schema-change-notifications.js");
const schema_diff_js_1 = require("./schema-diff.js");
const allowedCheckActions = ['rerequested'];
function handleProbot(app) {
const { onError, release } = (0, diagnostics_js_1.getDiagnostics)(app);
function wrap(runner) {
return (ctx) => tslib_1.__awaiter(this, void 0, void 0, function* () {
try {
yield runner(ctx);
}
catch (error) {
onError(error);
throw error;
}
});
}
app.on('check_run', wrap((context) => tslib_1.__awaiter(this, void 0, void 0, function* () {
const ref = context.payload.check_run.head_sha;
const { owner, repo } = context.repo();
const action = context.payload.action;
const pullRequests = context.payload.check_run.pull_requests;
const before = context.payload.check_run.check_suite.before;
const fullAction = 'check_run.' + action;
if (allowedCheckActions.includes(action) === false) {
return;
}
const loadFile = (0, loaders_js_1.createFileLoader)({
context,
owner,
repo,
release,
action: fullAction,
});
const loadConfig = (0, loaders_js_1.createConfigLoader)({ context, owner, repo, ref, release, action: fullAction }, loadFile);
yield (0, schema_diff_js_1.handleSchemaDiff)({
release,
action: fullAction,
context,
ref,
repo,
owner,
loadFile,
loadConfig,
before,
pullRequests,
onError,
});
})));
app.on('check_suite', wrap((context) => tslib_1.__awaiter(this, void 0, void 0, function* () {
const ref = context.payload.check_suite.head_sha;
const { owner, repo } = context.repo();
const action = context.payload.action;
const pullRequests = context.payload.check_suite.pull_requests;
const before = context.payload.check_suite.before;
const fullAction = 'check_suite.' + action;
if (allowedCheckActions.includes(action) === false) {
return;
}
const loadFile = (0, loaders_js_1.createFileLoader)({
context,
owner,
repo,
release,
action: fullAction,
});
const loadConfig = (0, loaders_js_1.createConfigLoader)({ context, owner, repo, ref, release, action: fullAction }, loadFile);
yield (0, schema_diff_js_1.handleSchemaDiff)({
release,
action: fullAction,
context,
ref,
repo,
owner,
loadFile,
loadConfig,
before,
pullRequests,
onError,
});
})));
app.on('pull_request', wrap((context) => tslib_1.__awaiter(this, void 0, void 0, function* () {
const ref = context.payload.pull_request.head.sha;
const pullRequestNumber = context.payload.pull_request.number;
const { owner, repo } = context.repo();
const action = context.payload.action;
const pullRequests = [context.payload.pull_request];
const before = context.payload.pull_request.base.sha;
const fullAction = 'pull_request.' + action;
if (['opened', 'synchronize', 'edited', 'labeled', 'unlabeled'].includes(action) === false) {
return;
}
const loadFile = (0, loaders_js_1.createFileLoader)({
context,
owner,
repo,
release,
action: fullAction,
});
const loadConfig = (0, loaders_js_1.createConfigLoader)({ context, owner, repo, ref, release, action: fullAction }, loadFile);
yield (0, schema_diff_js_1.handleSchemaDiff)({
release,
action: fullAction,
context,
ref,
repo,
owner,
loadFile,
loadConfig,
before,
pullRequests,
pullRequestNumber,
onError,
});
})));
app.on('push', wrap((context) => tslib_1.__awaiter(this, void 0, void 0, function* () {
const ref = context.payload.ref;
const { owner, repo } = context.repo();
const before = context.payload.before;
const action = 'push';
const loadFile = (0, loaders_js_1.createFileLoader)({
context,
owner,
repo,
release,
action,
});
const loadConfig = (0, loaders_js_1.createConfigLoader)({ context, owner, repo, ref, release, action }, loadFile);
yield (0, schema_change_notifications_js_1.handleSchemaChangeNotifications)({
action,
release,
context,
ref,
before,
repo,
owner,
loadFile,
loadConfig,
onError,
});
})));
}
exports.default = handleProbot;