forked from mirrors/probot
Compare commits
12 Commits
| Author | SHA1 | Date |
|---|---|---|
|
|
60d44430be | |
|
|
491b157cd9 | |
|
|
b155a5cbea | |
|
|
fade527f28 | |
|
|
6e4f1bb269 | |
|
|
bc130a1068 | |
|
|
04fc220210 | |
|
|
fe811eb08f | |
|
|
8e525624c1 | |
|
|
9eb24bd8ed | |
|
|
af58050ed6 | |
|
|
e5bb535c8f |
|
|
@ -1,3 +1,3 @@
|
|||
#!/usr/bin/env node
|
||||
|
||||
require("../lib/bin/probot-receive");
|
||||
import "../lib/bin/probot-receive.js";
|
||||
|
|
|
|||
|
|
@ -1,3 +1,3 @@
|
|||
#!/usr/bin/env node
|
||||
|
||||
require("../lib/bin/probot-run");
|
||||
import "../lib/bin/probot-run.js";
|
||||
|
|
|
|||
|
|
@ -1,3 +1,3 @@
|
|||
#!/usr/bin/env node
|
||||
|
||||
require("../lib/bin/probot");
|
||||
import "../lib/bin/probot.js";
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load Diff
31
package.json
31
package.json
|
|
@ -36,17 +36,17 @@
|
|||
"author": "Brandon Keepers",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"@octokit/core": "^5.0.2",
|
||||
"@octokit/plugin-enterprise-compatibility": "^4.0.1",
|
||||
"@octokit/plugin-paginate-rest": "^9.1.4",
|
||||
"@octokit/plugin-rest-endpoint-methods": "^10.1.5",
|
||||
"@octokit/plugin-retry": "^6.0.1",
|
||||
"@octokit/plugin-throttling": "^8.1.3",
|
||||
"@octokit/request": "^8.1.6",
|
||||
"@octokit/types": "^12.3.0",
|
||||
"@octokit/webhooks": "^12.0.10",
|
||||
"@octokit/core": "^6.1.2",
|
||||
"@octokit/plugin-enterprise-compatibility": "^5.0.0",
|
||||
"@octokit/plugin-paginate-rest": "^11.3.0",
|
||||
"@octokit/plugin-rest-endpoint-methods": "^13.2.1",
|
||||
"@octokit/plugin-retry": "^7.1.1",
|
||||
"@octokit/plugin-throttling": "^9.3.0",
|
||||
"@octokit/request": "^9.1.1",
|
||||
"@octokit/types": "^13.5.0",
|
||||
"@octokit/webhooks": "^13.2.6",
|
||||
"@probot/get-private-key": "^1.1.2",
|
||||
"@probot/octokit-plugin-config": "^2.0.1",
|
||||
"@probot/octokit-plugin-config": "^3.0.2",
|
||||
"@probot/pino": "^2.3.5",
|
||||
"@types/express": "^4.17.21",
|
||||
"bottleneck": "^2.19.5",
|
||||
|
|
@ -61,15 +61,15 @@
|
|||
"octokit-auth-probot": "^2.0.0",
|
||||
"pino": "^8.16.1",
|
||||
"pino-http": "^9.0.0",
|
||||
"pkg-conf": "^3.1.0",
|
||||
"pkg-conf": "^5.0.0",
|
||||
"resolve": "^1.22.8",
|
||||
"update-dotenv": "^1.1.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@octokit/openapi-webhooks-types": "^8.2.1",
|
||||
"@octokit/tsconfig": "^3.0.0",
|
||||
"@octokit/webhooks-examples": "^7.3.1",
|
||||
"@octokit/webhooks-methods": "^4.0.0",
|
||||
"@octokit/webhooks-types": "^7.3.1",
|
||||
"@octokit/webhooks-methods": "^5.1.0",
|
||||
"@types/eventsource": "^1.1.15",
|
||||
"@types/js-yaml": "^4.0.9",
|
||||
"@types/node": "^20.0.0",
|
||||
|
|
@ -78,9 +78,9 @@
|
|||
"@vitest/coverage-v8": "^1.0.0",
|
||||
"@vitest/ui": "^1.0.0",
|
||||
"connect-sse": "^1.2.0",
|
||||
"execa": "^5.0.0",
|
||||
"execa": "^8.0.1",
|
||||
"fetch-mock": "npm:@gr2m/fetch-mock@9.11.0-pull-request-644.1",
|
||||
"get-port": "^5.1.1",
|
||||
"get-port": "^7.0.0",
|
||||
"prettier": "^3.0.3",
|
||||
"rimraf": "^5.0.5",
|
||||
"semantic-release": "^23.0.0",
|
||||
|
|
@ -112,6 +112,7 @@
|
|||
]
|
||||
]
|
||||
},
|
||||
"type": "module",
|
||||
"publishConfig": {
|
||||
"provenance": true
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,16 +1,14 @@
|
|||
import { resolve } from "node:path";
|
||||
import { resolve, dirname } from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
|
||||
import { program } from "commander";
|
||||
import { config as dotenvConfig } from "dotenv";
|
||||
import { isSupportedNodeVersion } from "../helpers/is-supported-node-version.js";
|
||||
import { loadPackageJson } from "../helpers/load-package-json.js";
|
||||
|
||||
/*import { dirname } from 'path';
|
||||
import { fileURLToPath } from 'url';*/
|
||||
|
||||
dotenvConfig();
|
||||
|
||||
//const __dirname = dirname(fileURLToPath(import.meta.url));
|
||||
const __dirname = dirname(fileURLToPath(import.meta.url));
|
||||
const pkg = loadPackageJson(resolve(__dirname, "package.json"));
|
||||
|
||||
if (!isSupportedNodeVersion()) {
|
||||
|
|
|
|||
|
|
@ -223,17 +223,16 @@ export class Context<E extends WebhookEvents = WebhookEvents> {
|
|||
): Promise<T | null> {
|
||||
const params = this.repo({
|
||||
path: path.posix.join(".github", fileName),
|
||||
defaults(configs: object[]) {
|
||||
defaults(configs: Record<string, unknown>[]) {
|
||||
const result = merge.all(
|
||||
[defaultConfig || {}, ...configs],
|
||||
deepMergeOptions,
|
||||
);
|
||||
|
||||
return result;
|
||||
return result as Record<string, unknown>;
|
||||
},
|
||||
});
|
||||
|
||||
// @ts-expect-error
|
||||
const { config, files } = await this.octokit.config.get(params);
|
||||
|
||||
// if no default config is set, and no config files are found, return null
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ import type {
|
|||
export function getErrorHandler(log: Logger) {
|
||||
return (error: Error & { event?: WebhookEvent }) => {
|
||||
const errors = (
|
||||
error.name === "AggregateError" ? error : [error]
|
||||
error instanceof AggregateError ? error.errors : [error]
|
||||
) as WebhookError[];
|
||||
|
||||
const event = error.event;
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@
|
|||
import { pino } from "pino";
|
||||
import type { Logger, LoggerOptions } from "pino";
|
||||
import { getTransformStream, type Options, type LogLevel } from "@probot/pino";
|
||||
import { rebindLog } from "./rebind-log";
|
||||
import { rebindLog } from "./rebind-log.js";
|
||||
|
||||
export type GetLogOptions = {
|
||||
level?: LogLevel;
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ type FactoryOptions = {
|
|||
export async function getAuthenticatedOctokit(
|
||||
state: State,
|
||||
installationId?: number,
|
||||
) {
|
||||
): Promise<ProbotOctokit> {
|
||||
const { log, octokit } = state;
|
||||
|
||||
if (!installationId) return octokit;
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ type Options = {
|
|||
redisConfig?: RedisOptions | string;
|
||||
};
|
||||
|
||||
export function getOctokitThrottleOptions(options: Options) {
|
||||
export function getOctokitThrottleOptions(options: Options): ThrottlingOptions {
|
||||
let { log, redisConfig } = options;
|
||||
|
||||
const throttlingOptions: ThrottlingOptions = {
|
||||
|
|
|
|||
|
|
@ -32,7 +32,9 @@ type Options = {
|
|||
* Besides the authentication, the Octokit's baseUrl is set as well when run
|
||||
* against a GitHub Enterprise Server with a custom domain.
|
||||
*/
|
||||
export function getProbotOctokitWithDefaults(options: Options) {
|
||||
export function getProbotOctokitWithDefaults(
|
||||
options: Options,
|
||||
): typeof ProbotOctokit {
|
||||
const authOptions = options.githubToken
|
||||
? {
|
||||
token: options.githubToken,
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ import { createProbotAuth } from "octokit-auth-probot";
|
|||
|
||||
import { probotRequestLogging } from "./octokit-plugin-probot-request-logging.js";
|
||||
import { VERSION } from "../version.js";
|
||||
import type { Constructor } from "../probot.js";
|
||||
|
||||
const defaultOptions = {
|
||||
authStrategy: createProbotAuth,
|
||||
|
|
@ -38,8 +39,13 @@ const defaultOptions = {
|
|||
},
|
||||
userAgent: `probot/${VERSION}`,
|
||||
};
|
||||
|
||||
export const ProbotOctokit = Octokit.plugin(
|
||||
export const ProbotOctokit: typeof Octokit &
|
||||
Constructor<
|
||||
ReturnType<typeof retry> &
|
||||
ReturnType<typeof paginateRest> &
|
||||
ReturnType<typeof legacyRestEndpointMethods> &
|
||||
ReturnType<typeof config>
|
||||
> = Octokit.plugin(
|
||||
throttling,
|
||||
retry,
|
||||
paginateRest,
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import pkgConf from "pkg-conf";
|
||||
import { packageConfig } from "pkg-conf";
|
||||
|
||||
import type { ApplicationFunction, Options, ServerOptions } from "./types.js";
|
||||
import { Logger, Probot, ProbotOctokit } from "./index.js";
|
||||
|
|
@ -122,7 +122,7 @@ export async function run(
|
|||
}
|
||||
|
||||
if (Array.isArray(appFnOrArgv)) {
|
||||
const pkg = await pkgConf("probot");
|
||||
const pkg = await packageConfig("probot");
|
||||
|
||||
const combinedApps: ApplicationFunction = async (_app) => {
|
||||
await server.load(defaultApp);
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import type { Server as HttpServer } from "node:http";
|
||||
import { join } from "node:path";
|
||||
import { join, dirname } from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
|
||||
import express, { Router, type Application } from "express";
|
||||
import type { Logger } from "pino";
|
||||
|
|
@ -16,6 +17,8 @@ import { rebindLog } from "../helpers/rebind-log.js";
|
|||
// the default path as defined in @octokit/webhooks
|
||||
export const defaultWebhooksPath = "/api/github/webhooks";
|
||||
|
||||
const __dirname = dirname(fileURLToPath(import.meta.url));
|
||||
|
||||
type State = {
|
||||
cwd?: string;
|
||||
httpServer?: HttpServer;
|
||||
|
|
|
|||
|
|
@ -1,4 +1,6 @@
|
|||
import Stream from "node:stream";
|
||||
import { dirname } from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
|
||||
import { pino } from "pino";
|
||||
import request from "supertest";
|
||||
|
|
@ -7,6 +9,8 @@ import { describe, expect, it } from "vitest";
|
|||
import { Probot, Server } from "../../src/index.js";
|
||||
import { defaultApp } from "../../src/apps/default.js";
|
||||
|
||||
const __dirname = dirname(fileURLToPath(import.meta.url));
|
||||
|
||||
describe("default app", () => {
|
||||
let output = [];
|
||||
|
||||
|
|
|
|||
|
|
@ -1,30 +1,63 @@
|
|||
import fs from "node:fs";
|
||||
import path from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
|
||||
import type { EmitterWebhookEvent as WebhookEvent } from "@octokit/webhooks";
|
||||
import type {
|
||||
EmitterWebhookEvent as WebhookEvent,
|
||||
EmitterWebhookEventName,
|
||||
} from "@octokit/webhooks";
|
||||
import WebhookExamples from "@octokit/webhooks-examples";
|
||||
import type { WebhookDefinition } from "@octokit/webhooks-examples";
|
||||
import fetchMock from "fetch-mock";
|
||||
import { describe, expect, test, beforeEach, it, vi } from "vitest";
|
||||
|
||||
import { Context } from "../src/index.js";
|
||||
import { ProbotOctokit } from "../src/octokit/probot-octokit.js";
|
||||
import type { PushEvent } from "@octokit/webhooks-types";
|
||||
|
||||
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
||||
|
||||
type GetWebhookEventPayload<T extends EmitterWebhookEventName> =
|
||||
WebhookEvent<T>["payload"];
|
||||
|
||||
type WebhookDefinition<
|
||||
TName extends EmitterWebhookEventName = EmitterWebhookEventName,
|
||||
> = {
|
||||
name: TName;
|
||||
actions: string[];
|
||||
description: string;
|
||||
examples: GetWebhookEventPayload<TName>[];
|
||||
properties: Record<
|
||||
string,
|
||||
{
|
||||
description: string;
|
||||
type:
|
||||
| "string"
|
||||
| "number"
|
||||
| "boolean"
|
||||
| "object"
|
||||
| "integer"
|
||||
| "array"
|
||||
| "null";
|
||||
}
|
||||
>;
|
||||
};
|
||||
|
||||
type PushEvent = GetWebhookEventPayload<"push">;
|
||||
|
||||
const webhookExamples = WebhookExamples as unknown as WebhookDefinition[];
|
||||
const pushEventPayload = (
|
||||
(WebhookExamples as unknown as WebhookDefinition[]).filter(
|
||||
webhookExamples.filter(
|
||||
(event) => event.name === "push",
|
||||
)[0] as WebhookDefinition<"push">
|
||||
)[0] as unknown as WebhookDefinition<"push">
|
||||
).examples[0];
|
||||
const issuesEventPayload = (
|
||||
(WebhookExamples as unknown as WebhookDefinition[]).filter(
|
||||
webhookExamples.filter(
|
||||
(event) => event.name === "issues",
|
||||
)[0] as WebhookDefinition<"issues">
|
||||
)[0] as unknown as WebhookDefinition<"issues">
|
||||
).examples[0];
|
||||
const pullRequestEventPayload = (
|
||||
(WebhookExamples as unknown as WebhookDefinition[]).filter(
|
||||
webhookExamples.filter(
|
||||
(event) => event.name === "pull_request",
|
||||
)[0] as WebhookDefinition<"pull_request">
|
||||
)[0] as unknown as WebhookDefinition<"pull_request">
|
||||
).examples[0] as WebhookEvent<"pull_request">["payload"];
|
||||
|
||||
describe("Context", () => {
|
||||
|
|
@ -292,14 +325,14 @@ describe("Context", () => {
|
|||
|
||||
describe("isBot", () => {
|
||||
test("returns true if sender is a bot", () => {
|
||||
event.payload.sender.type = "Bot";
|
||||
event.payload.sender!.type = "Bot";
|
||||
context = new Context(event, {} as any, {} as any);
|
||||
|
||||
expect(context.isBot).toBe(true);
|
||||
});
|
||||
|
||||
test("returns false if sender is not a bot", () => {
|
||||
event.payload.sender.type = "User";
|
||||
event.payload.sender!.type = "User";
|
||||
context = new Context(event, {} as any, {} as any);
|
||||
|
||||
expect(context.isBot).toBe(false);
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import execa from "execa";
|
||||
import { execa, ExecaChildProcess } from "execa";
|
||||
import getPort from "get-port";
|
||||
|
||||
import { sign } from "@octokit/webhooks-methods";
|
||||
|
|
@ -15,7 +15,7 @@ import { describe, expect, it, vi, beforeEach, afterEach } from "vitest";
|
|||
*/
|
||||
describe("end-to-end-tests", () => {
|
||||
let server: any;
|
||||
let probotProcess: execa.ExecaChildProcess<string> | null;
|
||||
let probotProcess: ExecaChildProcess<string> | null;
|
||||
let probotPort: number;
|
||||
let mockServerPort: number;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
import Stream from "node:stream";
|
||||
|
||||
import type {
|
||||
EmitterWebhookEvent,
|
||||
EmitterWebhookEvent as WebhookEvent,
|
||||
EmitterWebhookEventName,
|
||||
} from "@octokit/webhooks";
|
||||
import Bottleneck from "bottleneck";
|
||||
import fetchMock from "fetch-mock";
|
||||
|
|
@ -14,7 +14,6 @@ import { Probot, ProbotOctokit, Context } from "../src/index.js";
|
|||
import webhookExamples, {
|
||||
type WebhookDefinition,
|
||||
} from "@octokit/webhooks-examples";
|
||||
import type { EmitterWebhookEventName } from "@octokit/webhooks/dist-types/types.js";
|
||||
|
||||
const appId = 1;
|
||||
const privateKey = `-----BEGIN RSA PRIVATE KEY-----
|
||||
|
|
@ -50,7 +49,7 @@ const getPayloadExamples = <TName extends EmitterWebhookEventName>(
|
|||
) => {
|
||||
return (webhookExamples as unknown as WebhookDefinition[]).filter(
|
||||
(event) => event.name === name.split(".")[0],
|
||||
)[0].examples as EmitterWebhookEvent<TName>["payload"][];
|
||||
)[0].examples as WebhookEvent<TName>["payload"][];
|
||||
};
|
||||
const getPayloadExample = <TName extends EmitterWebhookEventName>(
|
||||
name: TName,
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
import path from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
|
||||
import request from "supertest";
|
||||
import { sign } from "@octokit/webhooks-methods";
|
||||
|
|
@ -11,6 +12,8 @@ import WebhookExamples, {
|
|||
type WebhookDefinition,
|
||||
} from "@octokit/webhooks-examples";
|
||||
|
||||
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
||||
|
||||
describe("run", () => {
|
||||
let server: Server;
|
||||
let env: NodeJS.ProcessEnv;
|
||||
|
|
|
|||
|
|
@ -9,7 +9,6 @@
|
|||
"outDir": "./lib",
|
||||
"skipLibCheck": true,
|
||||
"noImplicitAny": true,
|
||||
"esModuleInterop": true,
|
||||
"declaration": true,
|
||||
"allowJs": true,
|
||||
"lib": ["es2023", "dom"]
|
||||
|
|
|
|||
Loading…
Reference in New Issue