index.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. import { Deprecation } from "deprecation";
  2. import endpointsByScope from "./generated/endpoints";
  3. import { VERSION } from "./version";
  4. import { registerEndpoints } from "./register-endpoints";
  5. /**
  6. * This plugin is a 1:1 copy of internal @octokit/rest plugins. The primary
  7. * goal is to rebuild @octokit/rest on top of @octokit/core. Once that is
  8. * done, we will remove the registerEndpoints methods and return the methods
  9. * directly as with the other plugins. At that point we will also remove the
  10. * legacy workarounds and deprecations.
  11. *
  12. * See the plan at
  13. * https://github.com/octokit/plugin-rest-endpoint-methods.js/pull/1
  14. */
  15. export function restEndpointMethods(octokit) {
  16. // @ts-ignore
  17. octokit.registerEndpoints = registerEndpoints.bind(null, octokit);
  18. registerEndpoints(octokit, endpointsByScope);
  19. // Aliasing scopes for backward compatibility
  20. // See https://github.com/octokit/rest.js/pull/1134
  21. [
  22. ["gitdata", "git"],
  23. ["authorization", "oauthAuthorizations"],
  24. ["pullRequests", "pulls"]
  25. ].forEach(([deprecatedScope, scope]) => {
  26. Object.defineProperty(octokit, deprecatedScope, {
  27. get() {
  28. octokit.log.warn(
  29. // @ts-ignore
  30. new Deprecation(`[@octokit/plugin-rest-endpoint-methods] "octokit.${deprecatedScope}.*" methods are deprecated, use "octokit.${scope}.*" instead`));
  31. // @ts-ignore
  32. return octokit[scope];
  33. }
  34. });
  35. });
  36. return {};
  37. }
  38. restEndpointMethods.VERSION = VERSION;