Files
PaperClipAI/server/src/services/chat-channels/github/inventory.ts
T
DottaandPaperclip d837b65be8 refactor(server): move provider setup, inventory and delivery into channel folders (#16058)
Consolidate the ten reviewed provider-folder extractions. Preserve the verified source tree and current master changes.

Co-Authored-By: Paperclip <noreply@paperclip.ing>
2026-10-13 00:26:33 -05:00

51 lines
1.8 KiB
TypeScript

import { githubAppJwt } from "../../chat-github-client.js";
import { discoverDedicatedGitHubAppInstallation, listGitHubInstallationRepositories } from "../../chat-provider-inventory.js";
import type { PreparedProviderInventory } from "../runtime-types.js";
export async function prepareGitHubInventory(credentials: Record<string,string>, fetchImpl: typeof fetch): Promise<PreparedProviderInventory> {
const appJwt = githubAppJwt(credentials.appId, credentials.privateKey);
const installation = await discoverDedicatedGitHubAppInstallation({
appJwt,
fetch: fetchImpl,
});
const preparedCredentials = {
...credentials,
installationId: installation.installationId,
};
const inventory = await listGitHubInstallationRepositories({
appJwt,
installationId: installation.installationId,
fetch: fetchImpl,
});
return {
credentials: preparedCredentials,
managementUrl: installation.accountType === "Organization" && installation.accountLabel
? `https://github.com/organizations/${encodeURIComponent(installation.accountLabel)}/settings/installations/${installation.installationId}`
: `https://github.com/settings/installations/${installation.installationId}`,
inventory: {
...inventory,
resources: inventory.resources.map((resource) => {
const fullName =
typeof resource.metadata?.fullName === "string"
? resource.metadata.fullName
: resource.label.includes("/")
? resource.label
: null;
return fullName
? {
...resource,
providerResourceId: fullName.toLowerCase(),
metadata: {
...resource.metadata,
providerRepositoryId: resource.providerResourceId,
fullName,
},
}
: resource;
}),
},
};
}