UNPKG

probot

Version:

A framework for building GitHub Apps to automate and improve your workflow

111 lines 5.63 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); // Usage: probot receive -e push -p path/to/payload app.js const node_fs_1 = __importDefault(require("node:fs")); const node_path_1 = __importDefault(require("node:path")); const node_crypto_1 = require("node:crypto"); const express_1 = __importStar(require("express")); const dotenv_1 = require("dotenv"); (0, dotenv_1.config)(); const commander_1 = require("commander"); const get_private_key_1 = require("@probot/get-private-key"); const get_log_js_1 = require("../helpers/get-log.js"); const index_js_1 = require("../index.js"); const resolve_app_function_js_1 = require("../helpers/resolve-app-function.js"); async function main() { commander_1.program .usage("[options] [path/to/app.js...]") .option("-e, --event <event-name>", "Event name", process.env.GITHUB_EVENT_NAME) .option("-p, --payload-path <payload-path>", "Path to the event payload", process.env.GITHUB_EVENT_PATH) .option("-t, --token <access-token>", "Access token", process.env.GITHUB_TOKEN) .option("-a, --app <id>", "ID of the GitHub App", process.env.APP_ID) .option("-P, --private-key <file>", "Path to private key file (.pem) for the GitHub App", process.env.PRIVATE_KEY_PATH) .option("-L, --log-level <level>", 'One of: "trace" | "debug" | "info" | "warn" | "error" | "fatal"', process.env.LOG_LEVEL) .option("--log-format <format>", 'One of: "pretty", "json"', process.env.LOG_LEVEL || "pretty") .option("--log-level-in-string", "Set to log levels (trace, debug, info, ...) as words instead of numbers (10, 20, 30, ...)", process.env.LOG_LEVEL_IN_STRING === "true") .option("--log-message-key", "Set to the string key for the 'message' in the log JSON object", process.env.LOG_MESSAGE_KEY || "msg") .option("--sentry-dsn <dsn>", 'Set to your Sentry DSN, e.g. "https://1234abcd@sentry.io/12345"', process.env.SENTRY_DSN) .option("--base-url <url>", 'GitHub API base URL. If you use GitHub Enterprise Server, and your hostname is "https://github.acme-inc.com", then the root URL is "https://github.acme-inc.com/api/v3"', process.env.GHE_HOST ? `${process.env.GHE_PROTOCOL || "https"}://${process.env.GHE_HOST}/api/v3` : "https://api.github.com") .parse(process.argv); const { app: appId, baseUrl, token: githubToken, event, payloadPath, logLevel, logFormat, logLevelInString, logMessageKey, sentryDsn, } = commander_1.program.opts(); if (!event || !payloadPath) { commander_1.program.help(); } const privateKey = (0, get_private_key_1.getPrivateKey)(); if (!githubToken && (!appId || !privateKey)) { console.warn("No token specified and no certificate found, which means you will not be able to do authenticated requests to GitHub"); } const payload = JSON.parse(node_fs_1.default.readFileSync(node_path_1.default.resolve(payloadPath), "utf8")); const log = (0, get_log_js_1.getLog)({ level: logLevel, logFormat, logLevelInString, logMessageKey, sentryDsn, }); const probot = new index_js_1.Probot({ appId, privateKey: String(privateKey), githubToken: githubToken, log, baseUrl: baseUrl, }); const expressApp = (0, express_1.default)(); const options = { getRouter: (path = "/") => { const newRouter = (0, express_1.Router)(); expressApp.use(path, newRouter); return newRouter; }, }; const appFn = await (0, resolve_app_function_js_1.resolveAppFunction)(node_path_1.default.resolve(process.cwd(), commander_1.program.args[0])); await probot.load(appFn, options); probot.log.debug("Receiving event", event); probot.receive({ name: event, payload, id: (0, node_crypto_1.randomUUID)() }).catch(() => { // Process must exist non-zero to indicate that the action failed to run process.exit(1); }); } main().catch((error) => { console.error(error); process.exit(1); }); //# sourceMappingURL=probot-receive.js.map