github.com/jfrog/frogbot@v1.1.1-0.20231221090046-821a26f50338/action/node_modules/@octokit/core/dist-node/index.js (about) 1 'use strict'; 2 3 Object.defineProperty(exports, '__esModule', { value: true }); 4 5 var universalUserAgent = require('universal-user-agent'); 6 var beforeAfterHook = require('before-after-hook'); 7 var request = require('@octokit/request'); 8 var graphql = require('@octokit/graphql'); 9 var authToken = require('@octokit/auth-token'); 10 11 function _objectWithoutPropertiesLoose(source, excluded) { 12 if (source == null) return {}; 13 var target = {}; 14 var sourceKeys = Object.keys(source); 15 var key, i; 16 17 for (i = 0; i < sourceKeys.length; i++) { 18 key = sourceKeys[i]; 19 if (excluded.indexOf(key) >= 0) continue; 20 target[key] = source[key]; 21 } 22 23 return target; 24 } 25 26 function _objectWithoutProperties(source, excluded) { 27 if (source == null) return {}; 28 29 var target = _objectWithoutPropertiesLoose(source, excluded); 30 31 var key, i; 32 33 if (Object.getOwnPropertySymbols) { 34 var sourceSymbolKeys = Object.getOwnPropertySymbols(source); 35 36 for (i = 0; i < sourceSymbolKeys.length; i++) { 37 key = sourceSymbolKeys[i]; 38 if (excluded.indexOf(key) >= 0) continue; 39 if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; 40 target[key] = source[key]; 41 } 42 } 43 44 return target; 45 } 46 47 const VERSION = "3.6.0"; 48 49 const _excluded = ["authStrategy"]; 50 class Octokit { 51 constructor(options = {}) { 52 const hook = new beforeAfterHook.Collection(); 53 const requestDefaults = { 54 baseUrl: request.request.endpoint.DEFAULTS.baseUrl, 55 headers: {}, 56 request: Object.assign({}, options.request, { 57 // @ts-ignore internal usage only, no need to type 58 hook: hook.bind(null, "request") 59 }), 60 mediaType: { 61 previews: [], 62 format: "" 63 } 64 }; // prepend default user agent with `options.userAgent` if set 65 66 requestDefaults.headers["user-agent"] = [options.userAgent, `octokit-core.js/${VERSION} ${universalUserAgent.getUserAgent()}`].filter(Boolean).join(" "); 67 68 if (options.baseUrl) { 69 requestDefaults.baseUrl = options.baseUrl; 70 } 71 72 if (options.previews) { 73 requestDefaults.mediaType.previews = options.previews; 74 } 75 76 if (options.timeZone) { 77 requestDefaults.headers["time-zone"] = options.timeZone; 78 } 79 80 this.request = request.request.defaults(requestDefaults); 81 this.graphql = graphql.withCustomRequest(this.request).defaults(requestDefaults); 82 this.log = Object.assign({ 83 debug: () => {}, 84 info: () => {}, 85 warn: console.warn.bind(console), 86 error: console.error.bind(console) 87 }, options.log); 88 this.hook = hook; // (1) If neither `options.authStrategy` nor `options.auth` are set, the `octokit` instance 89 // is unauthenticated. The `this.auth()` method is a no-op and no request hook is registered. 90 // (2) If only `options.auth` is set, use the default token authentication strategy. 91 // (3) If `options.authStrategy` is set then use it and pass in `options.auth`. Always pass own request as many strategies accept a custom request instance. 92 // TODO: type `options.auth` based on `options.authStrategy`. 93 94 if (!options.authStrategy) { 95 if (!options.auth) { 96 // (1) 97 this.auth = async () => ({ 98 type: "unauthenticated" 99 }); 100 } else { 101 // (2) 102 const auth = authToken.createTokenAuth(options.auth); // @ts-ignore ¯\_(ツ)_/¯ 103 104 hook.wrap("request", auth.hook); 105 this.auth = auth; 106 } 107 } else { 108 const { 109 authStrategy 110 } = options, 111 otherOptions = _objectWithoutProperties(options, _excluded); 112 113 const auth = authStrategy(Object.assign({ 114 request: this.request, 115 log: this.log, 116 // we pass the current octokit instance as well as its constructor options 117 // to allow for authentication strategies that return a new octokit instance 118 // that shares the same internal state as the current one. The original 119 // requirement for this was the "event-octokit" authentication strategy 120 // of https://github.com/probot/octokit-auth-probot. 121 octokit: this, 122 octokitOptions: otherOptions 123 }, options.auth)); // @ts-ignore ¯\_(ツ)_/¯ 124 125 hook.wrap("request", auth.hook); 126 this.auth = auth; 127 } // apply plugins 128 // https://stackoverflow.com/a/16345172 129 130 131 const classConstructor = this.constructor; 132 classConstructor.plugins.forEach(plugin => { 133 Object.assign(this, plugin(this, options)); 134 }); 135 } 136 137 static defaults(defaults) { 138 const OctokitWithDefaults = class extends this { 139 constructor(...args) { 140 const options = args[0] || {}; 141 142 if (typeof defaults === "function") { 143 super(defaults(options)); 144 return; 145 } 146 147 super(Object.assign({}, defaults, options, options.userAgent && defaults.userAgent ? { 148 userAgent: `${options.userAgent} ${defaults.userAgent}` 149 } : null)); 150 } 151 152 }; 153 return OctokitWithDefaults; 154 } 155 /** 156 * Attach a plugin (or many) to your Octokit instance. 157 * 158 * @example 159 * const API = Octokit.plugin(plugin1, plugin2, plugin3, ...) 160 */ 161 162 163 static plugin(...newPlugins) { 164 var _a; 165 166 const currentPlugins = this.plugins; 167 const NewOctokit = (_a = class extends this {}, _a.plugins = currentPlugins.concat(newPlugins.filter(plugin => !currentPlugins.includes(plugin))), _a); 168 return NewOctokit; 169 } 170 171 } 172 Octokit.VERSION = VERSION; 173 Octokit.plugins = []; 174 175 exports.Octokit = Octokit; 176 //# sourceMappingURL=index.js.map