mirror of
https://github.com/github/codeql-action.git
synced 2025-12-27 09:40:17 +08:00
32 lines
1020 B
JavaScript
32 lines
1020 B
JavaScript
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
|
|
};
|