Skip to content

Commit

Permalink
feat: v6 (#592)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: Drop support for NodeJS v14, v16
BREAKING CHANGE: remove deprecated `options.throttle.minimalSecondaryRateRetryAfter`
BREAKING CHANGE: remove deprecated `options.throttle.onAbuseLimit`

Co-authored-by: Gregor Martynus <39992+gr2m@users.noreply.github.com>
  • Loading branch information
wolfy1339 and gr2m authored May 22, 2023
1 parent 5335870 commit 32b598d
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 187 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@ jobs:
strategy:
matrix:
node_version:
- 14
- 16
- 18
- 20
steps:
- uses: actions/checkout@v3
- name: Test with Node.js ${{ matrix.node_version }}
Expand Down
76 changes: 38 additions & 38 deletions package-lock.json

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

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
[
"@pika/plugin-build-node",
{
"minNodeVersion": "14"
"minNodeVersion": 18
}
],
[
Expand Down Expand Up @@ -105,6 +105,6 @@
]
},
"engines": {
"node": ">= 14"
"node": ">= 18"
}
}
23 changes: 0 additions & 23 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,29 +59,6 @@ export function throttling(octokit: Octokit, octokitOptions: OctokitOptions) {
createGroups(Bottleneck, common);
}

if (
octokitOptions.throttle &&
octokitOptions.throttle.minimalSecondaryRateRetryAfter
) {
octokit.log.warn(
"[@octokit/plugin-throttling] `options.throttle.minimalSecondaryRateRetryAfter` is deprecated, please use `options.throttle.fallbackSecondaryRateRetryAfter` instead"
);
octokitOptions.throttle.fallbackSecondaryRateRetryAfter =
octokitOptions.throttle.minimalSecondaryRateRetryAfter;
delete octokitOptions.throttle.minimalSecondaryRateRetryAfter;
}

if (octokitOptions.throttle && octokitOptions.throttle.onAbuseLimit) {
octokit.log.warn(
"[@octokit/plugin-throttling] `onAbuseLimit()` is deprecated and will be removed in a future release of `@octokit/plugin-throttling`, please use the `onSecondaryRateLimit` handler instead"
);
// @ts-ignore types don't allow for both properties to be set
octokitOptions.throttle.onSecondaryRateLimit =
octokitOptions.throttle.onAbuseLimit;
// @ts-ignore
delete octokitOptions.throttle.onAbuseLimit;
}

const state = Object.assign(
{
clustering: connection != null,
Expand Down
20 changes: 4 additions & 16 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,7 @@ type LimitHandler = (
retryCount: number
) => void;

export type AbuseLimitHandler = {
/**
* @deprecated "[@octokit/plugin-throttling] `onAbuseLimit()` is deprecated and will be removed in a future release of `@octokit/plugin-throttling`, please use the `onSecondaryRateLimit` handler instead"
*/
onAbuseLimit: LimitHandler;
onSecondaryRateLimit?: never;
};

export type SecondaryLimitHandler = {
/**
* @deprecated "[@octokit/plugin-throttling] `onAbuseLimit()` is deprecated and will be removed in a future release of `@octokit/plugin-throttling`, please use the `onSecondaryRateLimit` handler instead"
*/
onAbuseLimit?: never;
onSecondaryRateLimit: LimitHandler;
};

Expand All @@ -43,10 +31,10 @@ export type ThrottlingOptionsBase = {
};

export type ThrottlingOptions =
| (ThrottlingOptionsBase & (AbuseLimitHandler | SecondaryLimitHandler))
| (Partial<
ThrottlingOptionsBase & (AbuseLimitHandler | SecondaryLimitHandler)
> & { enabled: false });
| (ThrottlingOptionsBase & SecondaryLimitHandler)
| (Partial<ThrottlingOptionsBase & SecondaryLimitHandler> & {
enabled: false;
});

export type Groups = {
global?: Bottleneck.Group;
Expand Down
42 changes: 2 additions & 40 deletions test/deprecations.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,44 +3,6 @@ import { throttling } from "../src";

const TestOctokit = Octokit.plugin(throttling);

describe("deprecations", () => {
it("throttle.minimalSecondaryRateRetryAfter option", () => {
const log = {
warn: jest.fn(),
};
new TestOctokit({
// @ts-expect-error
log,
throttle: {
minimalSecondaryRateRetryAfter: 1,
onSecondaryRateLimit: () => 1,
onRateLimit: () => 1,
},
});

expect(log.warn).toHaveBeenCalledWith(
"[@octokit/plugin-throttling] `options.throttle.minimalSecondaryRateRetryAfter` is deprecated, please use `options.throttle.fallbackSecondaryRateRetryAfter` instead"
);
});

describe("throttle.onAbuseLimit", function () {
it("Should detect SecondaryRate limit and broadcast event", async function () {
const log = {
warn: jest.fn(),
};

new TestOctokit({
// @ts-expect-error
log,
throttle: {
onAbuseLimit: () => 1,
onRateLimit: () => 1,
},
});

expect(log.warn).toHaveBeenCalledWith(
"[@octokit/plugin-throttling] `onAbuseLimit()` is deprecated and will be removed in a future release of `@octokit/plugin-throttling`, please use the `onSecondaryRateLimit` handler instead"
);
});
});
describe.skip("deprecations", () => {
it("No deprecations", () => {});
});
47 changes: 0 additions & 47 deletions test/events.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,53 +121,6 @@ describe("Events", function () {
expect(error.status).toEqual(403);
}

expect(eventCount).toEqual(1);
});
});
describe("with 'onSecondaryRateLimit'", function () {
it("Should detect SecondaryRate limit and broadcast event", async function () {
let eventCount = 0;

const octokit = new TestOctokit({
throttle: {
onSecondaryRateLimit: (retryAfter, options, octokitFromOptions) => {
expect(octokit).toBe(octokitFromOptions);
expect(retryAfter).toEqual(60);
expect(options).toMatchObject({
method: "GET",
url: "/route2",
request: { retryCount: 0 },
});
eventCount++;
},
onRateLimit: () => 1,
},
});

await octokit.request("GET /route1", {
request: {
responses: [{ status: 201, headers: {}, data: {} }],
},
});
try {
await octokit.request("GET /route2", {
request: {
responses: [
{
status: 403,
headers: { "retry-after": "60" },
data: {
message: "You have exceeded a secondary rate limit",
},
},
],
},
});
throw new Error("Should not reach this point");
} catch (error: any) {
expect(error.status).toEqual(403);
}

expect(eventCount).toEqual(1);
});
});
Expand Down
Loading

0 comments on commit 32b598d

Please sign in to comment.