forked from mirrors/probot
fix: do not overwrite `options.throttle` passed to `{Octokit: ProbotOctokit.defaults(options)} (#1373)
This commit is contained in:
parent
f537204987
commit
9483546c74
|
@ -39,37 +39,41 @@ export function getProbotOctokitWithDefaults(options: Options) {
|
||||||
},
|
},
|
||||||
authStrategy: createAppAuth,
|
authStrategy: createAppAuth,
|
||||||
};
|
};
|
||||||
const defaultOptions = {
|
|
||||||
|
const octokitThrottleOptions = getOctokitThrottleOptions({
|
||||||
|
log: options.log,
|
||||||
|
redisConfig: options.redisConfig,
|
||||||
|
});
|
||||||
|
|
||||||
|
const defaultOptions: any = {
|
||||||
baseUrl:
|
baseUrl:
|
||||||
process.env.GHE_HOST &&
|
process.env.GHE_HOST &&
|
||||||
`${process.env.GHE_PROTOCOL || "https"}://${process.env.GHE_HOST}/api/v3`,
|
`${process.env.GHE_PROTOCOL || "https"}://${process.env.GHE_HOST}/api/v3`,
|
||||||
throttle: Object.assign(
|
|
||||||
{},
|
|
||||||
options.throttleOptions,
|
|
||||||
getOctokitThrottleOptions({
|
|
||||||
log: options.log,
|
|
||||||
redisConfig: options.redisConfig,
|
|
||||||
})
|
|
||||||
),
|
|
||||||
...authOptions,
|
...authOptions,
|
||||||
};
|
};
|
||||||
|
|
||||||
return options.Octokit.defaults((instanceOptions: any) => {
|
if (options.throttleOptions || octokitThrottleOptions) {
|
||||||
const options = Object.assign(
|
defaultOptions.throttle = Object.assign(
|
||||||
{},
|
{},
|
||||||
defaultOptions,
|
options.throttleOptions,
|
||||||
instanceOptions,
|
octokitThrottleOptions
|
||||||
{
|
|
||||||
auth: instanceOptions.auth
|
|
||||||
? Object.assign({}, defaultOptions.auth, instanceOptions.auth)
|
|
||||||
: defaultOptions.auth,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
throttle: instanceOptions.throttle
|
|
||||||
? Object.assign({}, defaultOptions.throttle, instanceOptions.throttle)
|
|
||||||
: defaultOptions.throttle,
|
|
||||||
}
|
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return options.Octokit.defaults((instanceOptions: any) => {
|
||||||
|
const options = Object.assign({}, defaultOptions, instanceOptions, {
|
||||||
|
auth: instanceOptions.auth
|
||||||
|
? Object.assign({}, defaultOptions.auth, instanceOptions.auth)
|
||||||
|
: defaultOptions.auth,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (instanceOptions.throttle) {
|
||||||
|
options.throttle = Object.assign(
|
||||||
|
{},
|
||||||
|
defaultOptions.throttle,
|
||||||
|
instanceOptions.throttle
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return options;
|
return options;
|
||||||
});
|
});
|
||||||
|
|
|
@ -4,8 +4,7 @@ import { NextFunction, Request, Response } from "express";
|
||||||
import request = require("supertest");
|
import request = require("supertest");
|
||||||
import nock from "nock";
|
import nock from "nock";
|
||||||
|
|
||||||
import { Application, Probot } from "../src";
|
import { Application, Probot, ProbotOctokit } from "../src";
|
||||||
import { ProbotOctokit } from "../src/octokit/probot-octokit";
|
|
||||||
|
|
||||||
import path = require("path");
|
import path = require("path");
|
||||||
|
|
||||||
|
@ -40,12 +39,29 @@ describe("Probot", () => {
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
it("constructor", () => {
|
describe("constructor", () => {
|
||||||
// probot with token. Should not throw
|
it('{ githubToken: "faketoken" }', () => {
|
||||||
new Probot({ githubToken: "faketoken" });
|
// probot with token. Should not throw
|
||||||
|
new Probot({ githubToken: "faketoken" });
|
||||||
|
});
|
||||||
|
it('{ id, privateKey" }', () => {
|
||||||
|
// probot with id/privateKey
|
||||||
|
new Probot({ id, privateKey });
|
||||||
|
});
|
||||||
|
|
||||||
// probot with id/privateKey
|
it.only("shouldn't overwrite `options.throttle` passed to `{Octokit: ProbotOctokit.defaults(optiosn)}`", () => {
|
||||||
new Probot({ id, privateKey });
|
expect.assertions(1);
|
||||||
|
|
||||||
|
const MyOctokit = ProbotOctokit.plugin((octokit, options) => {
|
||||||
|
expect(options.throttle.enabled).toEqual(false);
|
||||||
|
}).defaults({
|
||||||
|
throttle: {
|
||||||
|
enabled: false,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
new Probot({ Octokit: MyOctokit });
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("run", () => {
|
describe("run", () => {
|
||||||
|
|
Loading…
Reference in New Issue