mirror of
https://github.com/tdurieux/anonymous_github.git
synced 2026-10-20 14:47:18 +02:00
fix: recover renamed repositories by ID and hide archived actions
This commit is contained in:
1 parent
3140ad3c45
commit
a7ae790640
8 files changed
+54
-11
No files matched your search
@@ -253,12 +253,12 @@ export async function boundAppToken(ownerId: string, binding: RepositoryAccess,
|
||||
return token;
|
||||
}
|
||||
|
||||
export async function selectRepositoryAccess(ownerId: string, fullName: string, choice?: unknown): Promise<{ token: string; binding: RepositoryAccess }> {
|
||||
export async function selectRepositoryAccess(ownerId: string, fullName: string, choice?: unknown, repositoryId?: number): Promise<{ token: string; binding: RepositoryAccess }> {
|
||||
if (!/^[^/\s]+\/[^/\s]+$/.test(fullName)) throw appError("repo_not_found", 400);
|
||||
if (choice !== undefined && choice !== "oauth" && choice !== "github-app") throw appError("invalid_connection", 400);
|
||||
const hasApp = config.GITHUB_APP_ENABLED && await CredentialModel.exists({ ownerId, provider: APP_PROVIDER });
|
||||
if (choice === "github-app" || (choice === undefined && hasApp)) {
|
||||
const repo = (await appRepositories(ownerId)).find(r => r.full_name.toLowerCase() === fullName.toLowerCase());
|
||||
const repo = (await appRepositories(ownerId)).find(r => repositoryId === undefined ? r.full_name.toLowerCase() === fullName.toLowerCase() : r.id === repositoryId);
|
||||
if (!repo) {
|
||||
const userToken = await appUserToken(ownerId);
|
||||
const publicRepo = await githubRequest<GitHubRepositoryInfo>(
|
||||
|
||||
@@ -194,13 +194,16 @@ router.post("/connections/migrate", async (req, res) => {
|
||||
if (["preparing", "removing", "expiring"].includes(model.status || "")) throw appError("repository_busy", 409);
|
||||
const source = model.source as { repositoryName?: string; repositoryFullName?: string; commit?: string; pullRequestId?: number };
|
||||
const name = source.repositoryName || source.repositoryFullName || "";
|
||||
const selected = await selectRepositoryAccess(user.id, name, connection);
|
||||
const repositoryId = model.githubAccess?.kind === "github-app" && connection === "github-app"
|
||||
? model.githubAccess.repositoryId : undefined;
|
||||
const selected = await selectRepositoryAccess(user.id, name, connection, repositoryId);
|
||||
// Repair an installation binding without silently adopting a repository
|
||||
// recreated at the same name. Replacing a source requires its own preview.
|
||||
if (model.githubAccess?.kind === "github-app" && selected.binding.kind === "github-app" &&
|
||||
model.githubAccess.repositoryId !== selected.binding.repositoryId) throw appError("connection_changed", 409);
|
||||
const parts = name.split("/").map(encodeURIComponent).join("/");
|
||||
await githubRequest(`/repos/${parts}/${isRepo ? `commits/${encodeURIComponent(source.commit || "")}` : `pulls/${source.pullRequestId}`}`, selected.token);
|
||||
const repositoryPath = repositoryId === undefined ? `/repos/${parts}` : `/repositories/${repositoryId}`;
|
||||
await githubRequest(`${repositoryPath}/${isRepo ? `commits/${encodeURIComponent(source.commit || "")}` : `pulls/${source.pullRequestId}`}`, selected.token);
|
||||
if (preview === true) return res.json({ eligible: true, connection });
|
||||
const filter = { _id: model._id, owner: user.id, status: model.status, source: model.source,
|
||||
githubAccess: model.githubAccess ? model.githubAccess : { $exists: false } };
|
||||
|
||||
Reference in new issue
Block a user