fix: archive ownerless repositories without assigning ownership (#800)

This commit is contained in:
Thomas Durieux
2026-09-08 14:03:09 +02:00
committed by GitHub
parent 8de4a536cc
commit 530e388e46
13 changed files with 364 additions and 53 deletions
+8 -4
View File
@@ -6,12 +6,15 @@ import { recoverRepositoryOwners } from "../core/recover-repository-owners";
async function main() {
const args = process.argv.slice(2);
const apply = args.includes("--apply");
let concurrency = 5;
let repositoryId: mongoose.mongo.ObjectId | undefined;
for (const arg of args) {
if (arg.startsWith("--id=") && /^[a-f0-9]{24}$/i.test(arg.slice(5))) {
if (/^--concurrency=([1-9]|[12][0-9]|3[0-2])$/.test(arg)) {
concurrency = Number(arg.split("=")[1]);
} else if (arg.startsWith("--id=") && /^[a-f0-9]{24}$/i.test(arg.slice(5))) {
repositoryId = new mongoose.mongo.ObjectId(arg.slice(5));
} else if (arg !== "--apply" && arg !== "--maintenance") {
process.stderr.write("Usage: recover-repository-owners.js [--id=<MongoDB document ID>] [--apply --maintenance]\n");
} else if (arg !== "--apply" && arg !== "--maintenance" && arg !== "--archive-unrecoverable" && arg !== "--archive-all-ownerless") {
process.stderr.write("Usage: recover-repository-owners.js [--id=<MongoDB document ID>] [--apply --maintenance] [--archive-unrecoverable | --archive-all-ownerless] [--concurrency=1..32]\n");
process.exitCode = 1;
return;
}
@@ -24,7 +27,8 @@ async function main() {
const uri = config.MONGODB_URI || `mongodb://${config.DB_USERNAME}:${config.DB_PASSWORD}@${config.DB_HOSTNAME}:27017/production`;
await mongoose.connect(uri, { ...(config.MONGODB_URI ? {} : { authSource: "admin" }), autoIndex: false });
const counts = await recoverRepositoryOwners(mongoose.connection.db, {
apply, repositoryId,
apply, repositoryId, concurrency, archiveUnrecoverable: args.includes("--archive-unrecoverable"),
archiveAllOwnerless: args.includes("--archive-all-ownerless"),
report: event => process.stdout.write(JSON.stringify(event) + "\n"),
});
process.stdout.write(JSON.stringify(counts) + "\n");