Skip to content

Commit f62b1ee

Browse files
committed
feat: deprecate octokit.gitdata.*, octokit.pullRequests.*
1 parent 78bc983 commit f62b1ee

File tree

1 file changed

+21
-9
lines changed

1 file changed

+21
-9
lines changed

src/index.ts

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Octokit } from "@octokit/core";
2+
import { Deprecation } from "deprecation";
23

34
import endpointsByScope from "./generated/endpoints";
45
import { VERSION } from "./version";
@@ -19,17 +20,28 @@ export function restEndpointMethods(octokit: Octokit): Api {
1920
// @ts-ignore
2021
octokit.registerEndpoints = registerEndpoints.bind(null, octokit);
2122

23+
registerEndpoints(octokit, endpointsByScope);
24+
2225
// Aliasing scopes for backward compatibility
2326
// See https://github.com/octokit/rest.js/pull/1134
24-
// @ts-ignore
25-
registerEndpoints(
26-
octokit,
27-
Object.assign(endpointsByScope, {
28-
gitdata: endpointsByScope.git,
29-
authorization: endpointsByScope.oauthAuthorizations,
30-
pullRequests: endpointsByScope.pulls
31-
})
32-
);
27+
[
28+
["gitdata", "git"],
29+
["authorization", "oauthAuthorizations"],
30+
["pullRequests", "pulls"]
31+
].forEach(([deprecatedScope, scope]) => {
32+
Object.defineProperty(octokit, deprecatedScope, {
33+
get() {
34+
octokit.log.warn(
35+
// @ts-ignore
36+
new Deprecation(
37+
`[@octokit/plugin-rest-endpoint-methods] "octokit.${deprecatedScope}.*" methods are deprecated, use "octokit.${scope}.*" instead`
38+
)
39+
);
40+
// @ts-ignore
41+
return octokit[scope];
42+
}
43+
});
44+
});
3345

3446
return {} as Api;
3547
}

0 commit comments

Comments
 (0)