Skip to content

Commit

Permalink
feat: deprecate octokit.gitdata.*, octokit.pullRequests.*
Browse files Browse the repository at this point in the history
  • Loading branch information
gr2m committed Feb 3, 2020
1 parent 78bc983 commit f62b1ee
Showing 1 changed file with 21 additions and 9 deletions.
30 changes: 21 additions & 9 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Octokit } from "@octokit/core";
import { Deprecation } from "deprecation";

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

registerEndpoints(octokit, endpointsByScope);

// Aliasing scopes for backward compatibility
// See https://github.com/octokit/rest.js/pull/1134
// @ts-ignore
registerEndpoints(
octokit,
Object.assign(endpointsByScope, {
gitdata: endpointsByScope.git,
authorization: endpointsByScope.oauthAuthorizations,
pullRequests: endpointsByScope.pulls
})
);
[
["gitdata", "git"],
["authorization", "oauthAuthorizations"],
["pullRequests", "pulls"]
].forEach(([deprecatedScope, scope]) => {
Object.defineProperty(octokit, deprecatedScope, {
get() {
octokit.log.warn(
// @ts-ignore
new Deprecation(
`[@octokit/plugin-rest-endpoint-methods] "octokit.${deprecatedScope}.*" methods are deprecated, use "octokit.${scope}.*" instead`
)
);
// @ts-ignore
return octokit[scope];
}
});
});

return {} as Api;
}
Expand Down

0 comments on commit f62b1ee

Please sign in to comment.