2023-10-26 04:27:07 +08:00
|
|
|
"use strict";
|
|
|
|
var __defProp = Object.defineProperty;
|
|
|
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
|
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
|
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
|
|
var __export = (target, all) => {
|
|
|
|
for (var name in all)
|
|
|
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
|
|
};
|
|
|
|
var __copyProps = (to, from, except, desc) => {
|
|
|
|
if (from && typeof from === "object" || typeof from === "function") {
|
|
|
|
for (let key of __getOwnPropNames(from))
|
|
|
|
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
|
|
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
2022-11-04 00:55:07 +08:00
|
|
|
}
|
2023-10-26 04:27:07 +08:00
|
|
|
return to;
|
|
|
|
};
|
|
|
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
|
|
|
|
|
|
// pkg/dist-src/index.js
|
|
|
|
var dist_src_exports = {};
|
|
|
|
__export(dist_src_exports, {
|
|
|
|
Octokit: () => Octokit
|
|
|
|
});
|
|
|
|
module.exports = __toCommonJS(dist_src_exports);
|
|
|
|
var import_universal_user_agent = require("universal-user-agent");
|
|
|
|
var import_before_after_hook = require("before-after-hook");
|
|
|
|
var import_request = require("@octokit/request");
|
|
|
|
var import_graphql = require("@octokit/graphql");
|
|
|
|
var import_auth_token = require("@octokit/auth-token");
|
|
|
|
|
|
|
|
// pkg/dist-src/version.js
|
|
|
|
var VERSION = "5.0.1";
|
|
|
|
|
|
|
|
// pkg/dist-src/index.js
|
|
|
|
var Octokit = class {
|
|
|
|
static {
|
|
|
|
this.VERSION = VERSION;
|
2022-11-04 00:55:07 +08:00
|
|
|
}
|
2023-10-26 04:27:07 +08:00
|
|
|
static defaults(defaults) {
|
|
|
|
const OctokitWithDefaults = class extends this {
|
|
|
|
constructor(...args) {
|
|
|
|
const options = args[0] || {};
|
|
|
|
if (typeof defaults === "function") {
|
|
|
|
super(defaults(options));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
super(
|
|
|
|
Object.assign(
|
|
|
|
{},
|
|
|
|
defaults,
|
|
|
|
options,
|
|
|
|
options.userAgent && defaults.userAgent ? {
|
|
|
|
userAgent: `${options.userAgent} ${defaults.userAgent}`
|
|
|
|
} : null
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
return OctokitWithDefaults;
|
|
|
|
}
|
|
|
|
static {
|
|
|
|
this.plugins = [];
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* Attach a plugin (or many) to your Octokit instance.
|
|
|
|
*
|
|
|
|
* @example
|
|
|
|
* const API = Octokit.plugin(plugin1, plugin2, plugin3, ...)
|
|
|
|
*/
|
|
|
|
static plugin(...newPlugins) {
|
|
|
|
const currentPlugins = this.plugins;
|
|
|
|
const NewOctokit = class extends this {
|
|
|
|
static {
|
|
|
|
this.plugins = currentPlugins.concat(
|
|
|
|
newPlugins.filter((plugin) => !currentPlugins.includes(plugin))
|
|
|
|
);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
return NewOctokit;
|
2022-11-04 00:55:07 +08:00
|
|
|
}
|
|
|
|
constructor(options = {}) {
|
2023-10-26 04:27:07 +08:00
|
|
|
const hook = new import_before_after_hook.Collection();
|
2022-11-04 00:55:07 +08:00
|
|
|
const requestDefaults = {
|
2023-10-26 04:27:07 +08:00
|
|
|
baseUrl: import_request.request.endpoint.DEFAULTS.baseUrl,
|
2022-11-04 00:55:07 +08:00
|
|
|
headers: {},
|
|
|
|
request: Object.assign({}, options.request, {
|
2023-10-26 04:27:07 +08:00
|
|
|
// @ts-ignore internal usage only, no need to type
|
2022-11-04 00:55:07 +08:00
|
|
|
hook: hook.bind(null, "request")
|
|
|
|
}),
|
|
|
|
mediaType: {
|
|
|
|
previews: [],
|
|
|
|
format: ""
|
|
|
|
}
|
2023-10-26 04:27:07 +08:00
|
|
|
};
|
|
|
|
requestDefaults.headers["user-agent"] = [
|
|
|
|
options.userAgent,
|
|
|
|
`octokit-core.js/${VERSION} ${(0, import_universal_user_agent.getUserAgent)()}`
|
|
|
|
].filter(Boolean).join(" ");
|
2022-11-04 00:55:07 +08:00
|
|
|
if (options.baseUrl) {
|
|
|
|
requestDefaults.baseUrl = options.baseUrl;
|
|
|
|
}
|
|
|
|
if (options.previews) {
|
|
|
|
requestDefaults.mediaType.previews = options.previews;
|
|
|
|
}
|
|
|
|
if (options.timeZone) {
|
|
|
|
requestDefaults.headers["time-zone"] = options.timeZone;
|
|
|
|
}
|
2023-10-26 04:27:07 +08:00
|
|
|
this.request = import_request.request.defaults(requestDefaults);
|
|
|
|
this.graphql = (0, import_graphql.withCustomRequest)(this.request).defaults(requestDefaults);
|
|
|
|
this.log = Object.assign(
|
|
|
|
{
|
|
|
|
debug: () => {
|
|
|
|
},
|
|
|
|
info: () => {
|
|
|
|
},
|
|
|
|
warn: console.warn.bind(console),
|
|
|
|
error: console.error.bind(console)
|
|
|
|
},
|
|
|
|
options.log
|
|
|
|
);
|
|
|
|
this.hook = hook;
|
2022-11-04 00:55:07 +08:00
|
|
|
if (!options.authStrategy) {
|
|
|
|
if (!options.auth) {
|
|
|
|
this.auth = async () => ({
|
|
|
|
type: "unauthenticated"
|
|
|
|
});
|
|
|
|
} else {
|
2023-10-26 04:27:07 +08:00
|
|
|
const auth = (0, import_auth_token.createTokenAuth)(options.auth);
|
2022-11-04 00:55:07 +08:00
|
|
|
hook.wrap("request", auth.hook);
|
|
|
|
this.auth = auth;
|
|
|
|
}
|
|
|
|
} else {
|
2023-10-26 04:27:07 +08:00
|
|
|
const { authStrategy, ...otherOptions } = options;
|
|
|
|
const auth = authStrategy(
|
|
|
|
Object.assign(
|
|
|
|
{
|
|
|
|
request: this.request,
|
|
|
|
log: this.log,
|
|
|
|
// we pass the current octokit instance as well as its constructor options
|
|
|
|
// to allow for authentication strategies that return a new octokit instance
|
|
|
|
// that shares the same internal state as the current one. The original
|
|
|
|
// requirement for this was the "event-octokit" authentication strategy
|
|
|
|
// of https://github.com/probot/octokit-auth-probot.
|
|
|
|
octokit: this,
|
|
|
|
octokitOptions: otherOptions
|
|
|
|
},
|
|
|
|
options.auth
|
|
|
|
)
|
|
|
|
);
|
2022-11-04 00:55:07 +08:00
|
|
|
hook.wrap("request", auth.hook);
|
|
|
|
this.auth = auth;
|
2023-10-26 04:27:07 +08:00
|
|
|
}
|
2022-11-04 00:55:07 +08:00
|
|
|
const classConstructor = this.constructor;
|
2023-10-26 04:27:07 +08:00
|
|
|
classConstructor.plugins.forEach((plugin) => {
|
2022-11-04 00:55:07 +08:00
|
|
|
Object.assign(this, plugin(this, options));
|
|
|
|
});
|
|
|
|
}
|
2023-10-26 04:27:07 +08:00
|
|
|
};
|
|
|
|
// Annotate the CommonJS export names for ESM import in node:
|
|
|
|
0 && (module.exports = {
|
|
|
|
Octokit
|
|
|
|
});
|