fix: throttleOption defaults and REDIS_URL configuration (#1313)

This commit is contained in:
Gregor Martynus 2020-08-20 12:29:02 -07:00
parent ad3216497c
commit c43910364f
7 changed files with 126 additions and 57 deletions

3
.codesandbox/ci.json Normal file
View File

@ -0,0 +1,3 @@
{
"sandboxes": ["new", "vanilla"]
}

69
package-lock.json generated
View File

@ -13032,16 +13032,16 @@
"dev": true
},
"smee-client": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/smee-client/-/smee-client-1.1.0.tgz",
"integrity": "sha512-5NM7K2qQnglGSIN7A6ndk/ku1Vocnz1k2EzD7IPeE2UTWBufl7vWk/AMP4oKMya5W2c6M8NC3DNHs1Wce9fWUg==",
"version": "1.2.2",
"resolved": "https://registry.npmjs.org/smee-client/-/smee-client-1.2.2.tgz",
"integrity": "sha512-RFV54aJOgj0jeBGFR5hBZ/QqxYO4Vuz7GmceJyAYnT5eigkBe5DiZUx9t9izpKHMXYk3TEiyKVW1Aa8eeKsIvQ==",
"dev": true,
"requires": {
"commander": "^2.12.2",
"eventsource": "^1.0.5",
"morgan": "^1.9.0",
"superagent": "^3.8.3",
"validator": "^10.4.0"
"commander": "^2.19.0",
"eventsource": "^1.0.7",
"morgan": "^1.9.1",
"superagent": "^5.0.2",
"validator": "^10.11.0"
},
"dependencies": {
"commander": {
@ -13049,6 +13049,59 @@
"resolved": "https://registry.npmjs.org/commander/-/commander-2.20.3.tgz",
"integrity": "sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ==",
"dev": true
},
"form-data": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/form-data/-/form-data-3.0.0.tgz",
"integrity": "sha512-CKMFDglpbMi6PyN+brwB9Q/GOw0eAnsrEZDgcsH5Krhz5Od/haKHAX0NmQfha2zPPz0JpWzA7GJHGSnvCRLWsg==",
"dev": true,
"requires": {
"asynckit": "^0.4.0",
"combined-stream": "^1.0.8",
"mime-types": "^2.1.12"
}
},
"mime": {
"version": "2.4.6",
"resolved": "https://registry.npmjs.org/mime/-/mime-2.4.6.tgz",
"integrity": "sha512-RZKhC3EmpBchfTGBVb8fb+RL2cWyw/32lshnsETttkBAyAUXSGHxbEJWWRXc751DrIxG1q04b8QwMbAwkRPpUA==",
"dev": true
},
"qs": {
"version": "6.9.4",
"resolved": "https://registry.npmjs.org/qs/-/qs-6.9.4.tgz",
"integrity": "sha512-A1kFqHekCTM7cz0udomYUoYNWjBebHm/5wzU/XqrBRBNWectVH0QIiN+NEcZ0Dte5hvzHwbr8+XQmguPhJ6WdQ==",
"dev": true
},
"readable-stream": {
"version": "3.6.0",
"resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.0.tgz",
"integrity": "sha512-BViHy7LKeTz4oNnkcLJ+lVSL6vpiFeX6/d3oSH8zCW7UxP2onchk+vTGB143xuFjHS3deTgkKoXXymXqymiIdA==",
"dev": true,
"requires": {
"inherits": "^2.0.3",
"string_decoder": "^1.1.1",
"util-deprecate": "^1.0.1"
}
},
"superagent": {
"version": "5.3.1",
"resolved": "https://registry.npmjs.org/superagent/-/superagent-5.3.1.tgz",
"integrity": "sha512-wjJ/MoTid2/RuGCOFtlacyGNxN9QLMgcpYLDQlWFIhhdJ93kNscFonGvrpAHSCVjRVj++DGCglocF7Aej1KHvQ==",
"dev": true,
"requires": {
"component-emitter": "^1.3.0",
"cookiejar": "^2.1.2",
"debug": "^4.1.1",
"fast-safe-stringify": "^2.0.7",
"form-data": "^3.0.0",
"formidable": "^1.2.2",
"methods": "^1.1.2",
"mime": "^2.4.6",
"qs": "^6.9.4",
"readable-stream": "^3.6.0",
"semver": "^7.3.2"
}
}
}
},

View File

@ -107,7 +107,7 @@
"rimraf": "^3.0.2",
"semantic-release": "^17.0.0",
"semantic-release-plugin-update-version-in-files": "^1.1.0",
"smee-client": "^1.0.1",
"smee-client": "^1.2.2",
"supertest": "^4.0.2",
"ts-jest": "^26.1.1",
"typedoc": "^0.17.0",

View File

@ -1,22 +0,0 @@
declare module "smee-client" {
import EventSource = require("eventsource");
type Severity = "info" | "error";
interface Options {
source?: string;
target: string;
logger?: Pick<Console, Severity>;
}
class Client {
constructor({ source, target, logger }: Options);
public onmessage(msg: any): void;
public onopen(): void;
public onerror(error: any): void;
public start(): EventSource;
public static createChannel(): Promise<string>;
}
export = Client;
}

View File

@ -10,14 +10,7 @@ import { throttling } from "@octokit/plugin-throttling";
import { probotRequestLogging } from "./octokit-plugin-probot-request-logging";
import { VERSION } from "../version";
export const ProbotOctokit = Octokit.plugin(
throttling,
retry,
paginateRest,
restEndpointMethods,
enterpriseCompatibility,
probotRequestLogging
).defaults({
const defaultOptions = {
throttle: {
onAbuseLimit: (
retryAfter: number,
@ -41,4 +34,22 @@ export const ProbotOctokit = Octokit.plugin(
},
},
userAgent: `probot/${VERSION}`,
};
export const ProbotOctokit = Octokit.plugin(
throttling,
retry,
paginateRest,
restEndpointMethods,
enterpriseCompatibility,
probotRequestLogging
).defaults((instanceOptions: any) => {
// merge throttle options deeply
const options = Object.assign({}, defaultOptions, instanceOptions, {
throttle: instanceOptions.throttle
? Object.assign({}, defaultOptions.throttle, instanceOptions.throttle)
: defaultOptions.throttle,
});
return options;
});

View File

@ -7,7 +7,7 @@ exports[`Probot ghe support with http throws if the GHE host includes a protocol
exports[`Probot run runs with a function as argument 1`] = `
Object {
"id": 1,
"port": 3003,
"port": 3000,
"privateKey": "-----BEGIN RSA PRIVATE KEY-----
MIIJKAIBAAKCAgEAu0E+tR6wfOAJZ4lASzRUmvorCgbI5nQyvZl3WLu6ko2pcEnq
1t1/W/Yaovt9W8eMFVfoFXKhsHOAM5dFlktxOlcaUQiRYSO7fBbZYVNYoawnCRqD
@ -69,7 +69,7 @@ wB98bfAGtcuCZWzgjgL67CS0pcNxadFA/TFo/NnynLBC4qRXSfFslKVE+Og=
exports[`Probot run runs with an array of strings 1`] = `
Object {
"id": "1",
"port": "3003",
"port": 3000,
"privateKey": "-----BEGIN RSA PRIVATE KEY-----
MIIJKAIBAAKCAgEAu0E+tR6wfOAJZ4lASzRUmvorCgbI5nQyvZl3WLu6ko2pcEnq
1t1/W/Yaovt9W8eMFVfoFXKhsHOAM5dFlktxOlcaUQiRYSO7fBbZYVNYoawnCRqD

View File

@ -65,32 +65,56 @@ describe("Probot", () => {
process.env = env;
});
it("runs with a function as argument", async () => {
process.env.PORT = "3003";
it("runs with a function as argument", () => {
let initialized = false;
probot = await Probot.run((app) => {
initialized = true;
return new Promise(async (resolve) => {
probot = await Probot.run((app) => {
initialized = true;
});
expect(probot.options).toMatchSnapshot();
expect(initialized).toBeTruthy();
probot.stop();
resolve();
});
expect(probot.options).toMatchSnapshot();
expect(initialized).toBeTruthy();
probot.stop();
});
it("runs with an array of strings", async () => {
probot = await Probot.run(["run", "file.js"]);
expect(probot.options).toMatchSnapshot();
probot.stop();
it("runs with an array of strings", () => {
return new Promise(async (resolve) => {
probot = await Probot.run(["run", "file.js"]);
expect(probot.options).toMatchSnapshot();
probot.stop();
resolve();
});
});
it("works with REDIS_URL configuration", () => {
process.env.REDIS_URL = "redis://test:test@localhost:6379";
return new Promise(async (resolve, reject) => {
const probot = await Probot.run((app) => {
app.auth(1).then(resolve, reject);
});
probot.stop();
});
});
it("runs without config and loads the setup app", async () => {
let initialized = false;
delete process.env.PRIVATE_KEY_PATH;
probot = await Probot.run((app) => {
initialized = true;
process.env.PORT = "3003";
return new Promise(async (resolve) => {
probot = await Probot.run((app) => {
initialized = true;
});
expect(probot.options).toMatchSnapshot();
expect(initialized).toBeFalsy();
probot.stop();
resolve();
});
expect(probot.options).toMatchSnapshot();
expect(initialized).toBeFalsy();
probot.stop();
});
});