Upgrade octokit to v4.1.2
This commit is contained in:
parent
dbbcbe019d
commit
c1745a9831
1214 changed files with 160765 additions and 0 deletions
78
node_modules/@octokit/auth-app/dist-src/cache.js
generated
vendored
Normal file
78
node_modules/@octokit/auth-app/dist-src/cache.js
generated
vendored
Normal file
|
|
@ -0,0 +1,78 @@
|
|||
import { Lru } from "toad-cache";
|
||||
function getCache() {
|
||||
return new Lru(
|
||||
// cache max. 15000 tokens, that will use less than 10mb memory
|
||||
15e3,
|
||||
// Cache for 1 minute less than GitHub expiry
|
||||
1e3 * 60 * 59
|
||||
);
|
||||
}
|
||||
async function get(cache, options) {
|
||||
const cacheKey = optionsToCacheKey(options);
|
||||
const result = await cache.get(cacheKey);
|
||||
if (!result) {
|
||||
return;
|
||||
}
|
||||
const [
|
||||
token,
|
||||
createdAt,
|
||||
expiresAt,
|
||||
repositorySelection,
|
||||
permissionsString,
|
||||
singleFileName
|
||||
] = result.split("|");
|
||||
const permissions = options.permissions || permissionsString.split(/,/).reduce((permissions2, string) => {
|
||||
if (/!$/.test(string)) {
|
||||
permissions2[string.slice(0, -1)] = "write";
|
||||
} else {
|
||||
permissions2[string] = "read";
|
||||
}
|
||||
return permissions2;
|
||||
}, {});
|
||||
return {
|
||||
token,
|
||||
createdAt,
|
||||
expiresAt,
|
||||
permissions,
|
||||
repositoryIds: options.repositoryIds,
|
||||
repositoryNames: options.repositoryNames,
|
||||
singleFileName,
|
||||
repositorySelection
|
||||
};
|
||||
}
|
||||
async function set(cache, options, data) {
|
||||
const key = optionsToCacheKey(options);
|
||||
const permissionsString = options.permissions ? "" : Object.keys(data.permissions).map(
|
||||
(name) => `${name}${data.permissions[name] === "write" ? "!" : ""}`
|
||||
).join(",");
|
||||
const value = [
|
||||
data.token,
|
||||
data.createdAt,
|
||||
data.expiresAt,
|
||||
data.repositorySelection,
|
||||
permissionsString,
|
||||
data.singleFileName
|
||||
].join("|");
|
||||
await cache.set(key, value);
|
||||
}
|
||||
function optionsToCacheKey({
|
||||
installationId,
|
||||
permissions = {},
|
||||
repositoryIds = [],
|
||||
repositoryNames = []
|
||||
}) {
|
||||
const permissionsString = Object.keys(permissions).sort().map((name) => permissions[name] === "read" ? name : `${name}!`).join(",");
|
||||
const repositoryIdsString = repositoryIds.sort().join(",");
|
||||
const repositoryNamesString = repositoryNames.join(",");
|
||||
return [
|
||||
installationId,
|
||||
repositoryIdsString,
|
||||
repositoryNamesString,
|
||||
permissionsString
|
||||
].filter(Boolean).join("|");
|
||||
}
|
||||
export {
|
||||
get,
|
||||
getCache,
|
||||
set
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue