index.js 949 B

12345678910111213141516171819202122232425262728293031
  1. module.exports = authenticationPlugin;
  2. const { Deprecation } = require("deprecation");
  3. const once = require("once");
  4. const deprecateAuthenticate = once((log, deprecation) => log.warn(deprecation));
  5. const authenticate = require("./authenticate");
  6. const beforeRequest = require("./before-request");
  7. const requestError = require("./request-error");
  8. function authenticationPlugin(octokit, options) {
  9. if (options.auth) {
  10. octokit.authenticate = () => {
  11. deprecateAuthenticate(
  12. octokit.log,
  13. new Deprecation(
  14. '[@octokit/rest] octokit.authenticate() is deprecated and has no effect when "auth" option is set on Octokit constructor'
  15. )
  16. );
  17. };
  18. return;
  19. }
  20. const state = {
  21. octokit,
  22. auth: false
  23. };
  24. octokit.authenticate = authenticate.bind(null, state);
  25. octokit.hook.before("request", beforeRequest.bind(null, state));
  26. octokit.hook.error("request", requestError.bind(null, state));
  27. }