Compare commits

..

12 Commits

Author SHA1 Message Date
wolfy1339 60d44430be
style: prettier 2024-04-30 23:12:25 -04:00
wolfy1339 491b157cd9
build: lockfile update 2024-04-30 23:09:09 -04:00
wolfy1339 b155a5cbea
Merge branch 'master' into full-esm 2024-04-30 22:51:39 -04:00
wolfy1339 fade527f28
test: adapt for latest @octokit/webhooks 2024-04-30 22:50:20 -04:00
wolfy1339 6e4f1bb269
fix: adapt for latest version of aggreagate-error 2024-04-30 22:50:00 -04:00
wolfy1339 bc130a1068
fix: update octokit deps 2024-04-30 22:32:31 -04:00
Aaron Dewes 04fc220210 Update `@probot/octokit-plugin-config` again 2024-03-10 23:47:06 +01:00
Aaron Dewes fe811eb08f Update `@probot/octokit-plugin-config` 2024-03-10 23:24:27 +01:00
Aaron Dewes 8e525624c1 Merge remote-tracking branch 'origin/master' into full-esm 2024-03-10 23:23:53 +01:00
Aaron Dewes 9eb24bd8ed Run the linter 2024-01-26 19:56:35 +01:00
Aaron Dewes af58050ed6 Update various dependencies to their latest, ESM-only versions
This updates pkg-conf at runtime, and get-port and execa in development
2024-01-26 19:54:51 +01:00
Aaron Dewes e5bb535c8f feat!: Full ESM
This makes Probot entirely esm-only.
2024-01-26 19:51:18 +01:00
21 changed files with 851 additions and 1539 deletions

View File

@ -1,3 +1,3 @@
#!/usr/bin/env node
require("../lib/bin/probot-receive");
import "../lib/bin/probot-receive.js";

View File

@ -1,3 +1,3 @@
#!/usr/bin/env node
require("../lib/bin/probot-run");
import "../lib/bin/probot-run.js";

View File

@ -1,3 +1,3 @@
#!/usr/bin/env node
require("../lib/bin/probot");
import "../lib/bin/probot.js";

2233
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -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",
@ -59,17 +59,17 @@
"js-yaml": "^4.1.0",
"lru-cache": "^10.0.3",
"octokit-auth-probot": "^2.0.0",
"pino": "^9.0.0",
"pino-http": "^10.0.0",
"pkg-conf": "^3.1.0",
"pino": "^8.16.1",
"pino-http": "^9.0.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
}

View File

@ -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()) {

View File

@ -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

View File

@ -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;

View File

@ -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;

View File

@ -12,7 +12,7 @@ type FactoryOptions = {
export async function getAuthenticatedOctokit(
state: State,
installationId?: number,
) {
): Promise<ProbotOctokit> {
const { log, octokit } = state;
if (!installationId) return octokit;

View File

@ -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 = {

View File

@ -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,

View File

@ -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,

View File

@ -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);

View File

@ -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;

View File

@ -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 = [];

View File

@ -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);

View File

@ -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;

View File

@ -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,

View File

@ -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;

View File

@ -9,7 +9,6 @@
"outDir": "./lib",
"skipLibCheck": true,
"noImplicitAny": true,
"esModuleInterop": true,
"declaration": true,
"allowJs": true,
"lib": ["es2023", "dom"]