Upgrade octokit to v4.1.2
This commit is contained in:
parent
dbbcbe019d
commit
c1745a9831
1214 changed files with 160765 additions and 0 deletions
39
node_modules/@octokit/app/dist-src/each-installation.js
generated
vendored
Normal file
39
node_modules/@octokit/app/dist-src/each-installation.js
generated
vendored
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
import { composePaginateRest } from "@octokit/plugin-paginate-rest";
|
||||
import { getInstallationOctokit } from "./get-installation-octokit.js";
|
||||
function eachInstallationFactory(app) {
|
||||
return Object.assign(eachInstallation.bind(null, app), {
|
||||
iterator: eachInstallationIterator.bind(null, app)
|
||||
});
|
||||
}
|
||||
async function eachInstallation(app, callback) {
|
||||
const i = eachInstallationIterator(app)[Symbol.asyncIterator]();
|
||||
let result = await i.next();
|
||||
while (!result.done) {
|
||||
await callback(result.value);
|
||||
result = await i.next();
|
||||
}
|
||||
}
|
||||
function eachInstallationIterator(app) {
|
||||
return {
|
||||
async *[Symbol.asyncIterator]() {
|
||||
const iterator = composePaginateRest.iterator(
|
||||
app.octokit,
|
||||
"GET /app/installations"
|
||||
);
|
||||
for await (const { data: installations } of iterator) {
|
||||
for (const installation of installations) {
|
||||
const installationOctokit = await getInstallationOctokit(
|
||||
app,
|
||||
installation.id
|
||||
);
|
||||
yield { octokit: installationOctokit, installation };
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
export {
|
||||
eachInstallation,
|
||||
eachInstallationFactory,
|
||||
eachInstallationIterator
|
||||
};
|
||||
53
node_modules/@octokit/app/dist-src/each-repository.js
generated
vendored
Normal file
53
node_modules/@octokit/app/dist-src/each-repository.js
generated
vendored
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
import { composePaginateRest } from "@octokit/plugin-paginate-rest";
|
||||
function eachRepositoryFactory(app) {
|
||||
return Object.assign(eachRepository.bind(null, app), {
|
||||
iterator: eachRepositoryIterator.bind(null, app)
|
||||
});
|
||||
}
|
||||
async function eachRepository(app, queryOrCallback, callback) {
|
||||
const i = eachRepositoryIterator(
|
||||
app,
|
||||
callback ? queryOrCallback : void 0
|
||||
)[Symbol.asyncIterator]();
|
||||
let result = await i.next();
|
||||
while (!result.done) {
|
||||
if (callback) {
|
||||
await callback(result.value);
|
||||
} else {
|
||||
await queryOrCallback(result.value);
|
||||
}
|
||||
result = await i.next();
|
||||
}
|
||||
}
|
||||
function singleInstallationIterator(app, installationId) {
|
||||
return {
|
||||
async *[Symbol.asyncIterator]() {
|
||||
yield {
|
||||
octokit: await app.getInstallationOctokit(installationId)
|
||||
};
|
||||
}
|
||||
};
|
||||
}
|
||||
function eachRepositoryIterator(app, query) {
|
||||
return {
|
||||
async *[Symbol.asyncIterator]() {
|
||||
const iterator = query ? singleInstallationIterator(app, query.installationId) : app.eachInstallation.iterator();
|
||||
for await (const { octokit } of iterator) {
|
||||
const repositoriesIterator = composePaginateRest.iterator(
|
||||
octokit,
|
||||
"GET /installation/repositories"
|
||||
);
|
||||
for await (const { data: repositories } of repositoriesIterator) {
|
||||
for (const repository of repositories) {
|
||||
yield { octokit, repository };
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
export {
|
||||
eachRepository,
|
||||
eachRepositoryFactory,
|
||||
eachRepositoryIterator
|
||||
};
|
||||
18
node_modules/@octokit/app/dist-src/get-installation-octokit.js
generated
vendored
Normal file
18
node_modules/@octokit/app/dist-src/get-installation-octokit.js
generated
vendored
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
import { createAppAuth } from "@octokit/auth-app";
|
||||
async function getInstallationOctokit(app, installationId) {
|
||||
return app.octokit.auth({
|
||||
type: "installation",
|
||||
installationId,
|
||||
factory(auth) {
|
||||
const options = {
|
||||
...auth.octokitOptions,
|
||||
authStrategy: createAppAuth,
|
||||
...{ auth: { ...auth, installationId } }
|
||||
};
|
||||
return new auth.octokit.constructor(options);
|
||||
}
|
||||
});
|
||||
}
|
||||
export {
|
||||
getInstallationOctokit
|
||||
};
|
||||
31
node_modules/@octokit/app/dist-src/get-installation-url.js
generated
vendored
Normal file
31
node_modules/@octokit/app/dist-src/get-installation-url.js
generated
vendored
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
function getInstallationUrlFactory(app) {
|
||||
let installationUrlBasePromise;
|
||||
return async function getInstallationUrl(options = {}) {
|
||||
if (!installationUrlBasePromise) {
|
||||
installationUrlBasePromise = getInstallationUrlBase(app);
|
||||
}
|
||||
const installationUrlBase = await installationUrlBasePromise;
|
||||
const installationUrl = new URL(installationUrlBase);
|
||||
if (options.target_id !== void 0) {
|
||||
installationUrl.pathname += "/permissions";
|
||||
installationUrl.searchParams.append(
|
||||
"target_id",
|
||||
options.target_id.toFixed()
|
||||
);
|
||||
}
|
||||
if (options.state !== void 0) {
|
||||
installationUrl.searchParams.append("state", options.state);
|
||||
}
|
||||
return installationUrl.href;
|
||||
};
|
||||
}
|
||||
async function getInstallationUrlBase(app) {
|
||||
const { data: appInfo } = await app.octokit.request("GET /app");
|
||||
if (!appInfo) {
|
||||
throw new Error("[@octokit/app] unable to fetch metadata for app");
|
||||
}
|
||||
return `${appInfo.html_url}/installations/new`;
|
||||
}
|
||||
export {
|
||||
getInstallationUrlFactory
|
||||
};
|
||||
105
node_modules/@octokit/app/dist-src/index.js
generated
vendored
Normal file
105
node_modules/@octokit/app/dist-src/index.js
generated
vendored
Normal file
|
|
@ -0,0 +1,105 @@
|
|||
import { Octokit as OctokitCore } from "@octokit/core";
|
||||
import { createAppAuth } from "@octokit/auth-app";
|
||||
import { OAuthApp } from "@octokit/oauth-app";
|
||||
import { VERSION } from "./version.js";
|
||||
import { webhooks } from "./webhooks.js";
|
||||
import { eachInstallationFactory } from "./each-installation.js";
|
||||
import { eachRepositoryFactory } from "./each-repository.js";
|
||||
import { getInstallationOctokit } from "./get-installation-octokit.js";
|
||||
import { getInstallationUrlFactory } from "./get-installation-url.js";
|
||||
class App {
|
||||
static VERSION = VERSION;
|
||||
static defaults(defaults) {
|
||||
const AppWithDefaults = class extends this {
|
||||
constructor(...args) {
|
||||
super({
|
||||
...defaults,
|
||||
...args[0]
|
||||
});
|
||||
}
|
||||
};
|
||||
return AppWithDefaults;
|
||||
}
|
||||
octokit;
|
||||
// @ts-ignore calling app.webhooks will throw a helpful error when options.webhooks is not set
|
||||
webhooks;
|
||||
// @ts-ignore calling app.oauth will throw a helpful error when options.oauth is not set
|
||||
oauth;
|
||||
getInstallationOctokit;
|
||||
eachInstallation;
|
||||
eachRepository;
|
||||
getInstallationUrl;
|
||||
log;
|
||||
constructor(options) {
|
||||
const Octokit = options.Octokit || OctokitCore;
|
||||
const authOptions = Object.assign(
|
||||
{
|
||||
appId: options.appId,
|
||||
privateKey: options.privateKey
|
||||
},
|
||||
options.oauth ? {
|
||||
clientId: options.oauth.clientId,
|
||||
clientSecret: options.oauth.clientSecret
|
||||
} : {}
|
||||
);
|
||||
const octokitOptions = {
|
||||
authStrategy: createAppAuth,
|
||||
auth: authOptions
|
||||
};
|
||||
if ("log" in options && typeof options.log !== "undefined") {
|
||||
octokitOptions.log = options.log;
|
||||
}
|
||||
this.octokit = new Octokit(octokitOptions);
|
||||
this.log = Object.assign(
|
||||
{
|
||||
debug: () => {
|
||||
},
|
||||
info: () => {
|
||||
},
|
||||
warn: console.warn.bind(console),
|
||||
error: console.error.bind(console)
|
||||
},
|
||||
options.log
|
||||
);
|
||||
if (options.webhooks) {
|
||||
this.webhooks = webhooks(this.octokit, options.webhooks);
|
||||
} else {
|
||||
Object.defineProperty(this, "webhooks", {
|
||||
get() {
|
||||
throw new Error("[@octokit/app] webhooks option not set");
|
||||
}
|
||||
});
|
||||
}
|
||||
if (options.oauth) {
|
||||
this.oauth = new OAuthApp({
|
||||
...options.oauth,
|
||||
clientType: "github-app",
|
||||
Octokit
|
||||
});
|
||||
} else {
|
||||
Object.defineProperty(this, "oauth", {
|
||||
get() {
|
||||
throw new Error(
|
||||
"[@octokit/app] oauth.clientId / oauth.clientSecret options are not set"
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
this.getInstallationOctokit = getInstallationOctokit.bind(
|
||||
null,
|
||||
this
|
||||
);
|
||||
this.eachInstallation = eachInstallationFactory(
|
||||
this
|
||||
);
|
||||
this.eachRepository = eachRepositoryFactory(
|
||||
this
|
||||
);
|
||||
this.getInstallationUrl = getInstallationUrlFactory(this);
|
||||
}
|
||||
}
|
||||
import { createNodeMiddleware } from "./middleware/node/index.js";
|
||||
export {
|
||||
App,
|
||||
createNodeMiddleware
|
||||
};
|
||||
57
node_modules/@octokit/app/dist-src/middleware/node/index.js
generated
vendored
Normal file
57
node_modules/@octokit/app/dist-src/middleware/node/index.js
generated
vendored
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
import {
|
||||
createNodeMiddleware as oauthNodeMiddleware,
|
||||
sendNodeResponse,
|
||||
unknownRouteResponse
|
||||
} from "@octokit/oauth-app";
|
||||
import { createNodeMiddleware as webhooksNodeMiddleware } from "@octokit/webhooks";
|
||||
function noop() {
|
||||
}
|
||||
function createNodeMiddleware(app, options = {}) {
|
||||
const log = Object.assign(
|
||||
{
|
||||
debug: noop,
|
||||
info: noop,
|
||||
warn: console.warn.bind(console),
|
||||
error: console.error.bind(console)
|
||||
},
|
||||
options.log
|
||||
);
|
||||
const optionsWithDefaults = {
|
||||
pathPrefix: "/api/github",
|
||||
...options,
|
||||
log
|
||||
};
|
||||
const webhooksMiddleware = webhooksNodeMiddleware(app.webhooks, {
|
||||
path: optionsWithDefaults.pathPrefix + "/webhooks",
|
||||
log
|
||||
});
|
||||
const oauthMiddleware = oauthNodeMiddleware(app.oauth, {
|
||||
pathPrefix: optionsWithDefaults.pathPrefix + "/oauth"
|
||||
});
|
||||
return middleware.bind(
|
||||
null,
|
||||
optionsWithDefaults.pathPrefix,
|
||||
webhooksMiddleware,
|
||||
oauthMiddleware
|
||||
);
|
||||
}
|
||||
async function middleware(pathPrefix, webhooksMiddleware, oauthMiddleware, request, response, next) {
|
||||
const { pathname } = new URL(request.url, "http://localhost");
|
||||
if (pathname.startsWith(`${pathPrefix}/`)) {
|
||||
if (pathname === `${pathPrefix}/webhooks`) {
|
||||
webhooksMiddleware(request, response);
|
||||
} else if (pathname.startsWith(`${pathPrefix}/oauth/`)) {
|
||||
oauthMiddleware(request, response);
|
||||
} else {
|
||||
sendNodeResponse(unknownRouteResponse(request), response);
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
next?.();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
export {
|
||||
createNodeMiddleware,
|
||||
middleware
|
||||
};
|
||||
4
node_modules/@octokit/app/dist-src/version.js
generated
vendored
Normal file
4
node_modules/@octokit/app/dist-src/version.js
generated
vendored
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
const VERSION = "15.1.4";
|
||||
export {
|
||||
VERSION
|
||||
};
|
||||
49
node_modules/@octokit/app/dist-src/webhooks.js
generated
vendored
Normal file
49
node_modules/@octokit/app/dist-src/webhooks.js
generated
vendored
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
import { createAppAuth } from "@octokit/auth-app";
|
||||
import { createUnauthenticatedAuth } from "@octokit/auth-unauthenticated";
|
||||
import { Webhooks } from "@octokit/webhooks";
|
||||
function webhooks(appOctokit, options) {
|
||||
return new Webhooks({
|
||||
secret: options.secret,
|
||||
transform: async (event) => {
|
||||
if (!("installation" in event.payload) || typeof event.payload.installation !== "object") {
|
||||
const octokit2 = new appOctokit.constructor({
|
||||
authStrategy: createUnauthenticatedAuth,
|
||||
auth: {
|
||||
reason: `"installation" key missing in webhook event payload`
|
||||
}
|
||||
});
|
||||
return {
|
||||
...event,
|
||||
octokit: octokit2
|
||||
};
|
||||
}
|
||||
const installationId = event.payload.installation.id;
|
||||
const octokit = await appOctokit.auth({
|
||||
type: "installation",
|
||||
installationId,
|
||||
factory(auth) {
|
||||
return new auth.octokit.constructor({
|
||||
...auth.octokitOptions,
|
||||
authStrategy: createAppAuth,
|
||||
...{
|
||||
auth: {
|
||||
...auth,
|
||||
installationId
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
octokit.hook.before("request", (options2) => {
|
||||
options2.headers["x-github-delivery"] = event.id;
|
||||
});
|
||||
return {
|
||||
...event,
|
||||
octokit
|
||||
};
|
||||
}
|
||||
});
|
||||
}
|
||||
export {
|
||||
webhooks
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue