Skip to content

Commit

Permalink
fix: throttleOption defaults and REDIS_URL configuration (probot#1313)
Browse files Browse the repository at this point in the history
  • Loading branch information
gr2m committed Sep 1, 2020
1 parent ad32164 commit c439103
Show file tree
Hide file tree
Showing 7 changed files with 126 additions and 57 deletions.
3 changes: 3 additions & 0 deletions .codesandbox/ci.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"sandboxes": ["new", "vanilla"]
}
69 changes: 61 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
22 changes: 0 additions & 22 deletions src/@types/smee-client/index.d.ts

This file was deleted.

27 changes: 19 additions & 8 deletions src/octokit/probot-octokit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;
});
4 changes: 2 additions & 2 deletions test/__snapshots__/index.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
56 changes: 40 additions & 16 deletions test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});

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();
});
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("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();
});
});

Expand Down

0 comments on commit c439103

Please sign in to comment.