Fix 9 bugs and add 103 tests for core anonymization, config, and routing (#669)

This commit is contained in:
Thomas Durieux
2026-04-15 09:41:00 +02:00
committed by GitHub
parent 261eaa8d79
commit 188066e91d
23 changed files with 2630 additions and 39 deletions
+1 -1
View File
@@ -5,7 +5,7 @@ import { ConferenceStatus } from "./types";
export default class Conference {
private _data: IConferenceDocument;
private _repositories: Repository[] = [];
private _repositories: Repository[] | null = null;
constructor(data: IConferenceDocument) {
this._data = data;
+2 -2
View File
@@ -98,14 +98,14 @@ export default class PullRequest {
/**
* Check the status of the pullRequest
*/
check() {
async check() {
if (
this._model.options.expirationMode !== "never" &&
this.status == "ready" &&
this._model.options.expirationDate
) {
if (this._model.options.expirationDate <= new Date()) {
this.expire();
await this.expire();
}
}
if (
+18 -16
View File
@@ -60,7 +60,6 @@ export default class Repository {
constructor(data: IAnonymizedRepositoryDocument) {
this._model = data;
this.owner = new User(new UserModel({ _id: data.owner }));
this.owner = new User(new UserModel({ _id: data.owner }));
this.owner.model.isNew = false;
}
@@ -169,11 +168,14 @@ export default class Repository {
opt.path = await f.originalPath();
}
let pathQuery: string | RegExp | undefined = opt.path
? new RegExp(`^${opt.path}`)
const escapedPath = opt.path
? opt.path.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&")
: undefined;
let pathQuery: string | RegExp | undefined = escapedPath
? new RegExp(`^${escapedPath}`)
: undefined;
if (opt.recursive === false) {
pathQuery = opt.path ? new RegExp(`^${opt.path}$`) : "";
pathQuery = escapedPath ? new RegExp(`^${escapedPath}$`) : "";
}
const query: FilterQuery<IFile> = {
@@ -328,6 +330,18 @@ export default class Repository {
this.model.source.branch || ghRepo.model.defaultBranch;
const newCommit = branches.filter((f) => f.name == branchName)[0]
?.commit;
if (!newCommit) {
console.error(
`${branchName} for ${this.model.source.repositoryName} is not found`
);
await this.updateStatus(RepositoryStatus.ERROR, "branch_not_found");
await this.resetSate();
throw new AnonymousError("branch_not_found", {
object: this,
httpStatus: 404,
});
}
if (
this.model.source.commit == newCommit &&
this.status == RepositoryStatus.READY
@@ -348,18 +362,6 @@ export default class Repository {
this._model.source.commitDate = new Date(d);
}
this.model.source.commit = newCommit;
if (!newCommit) {
console.error(
`${branchName} for ${this.model.source.repositoryName} is not found`
);
await this.updateStatus(RepositoryStatus.ERROR, "branch_not_found");
await this.resetSate();
throw new AnonymousError("branch_not_found", {
object: this,
httpStatus: 404,
});
}
this._model.anonymizeDate = new Date();
console.log(
`[UPDATE] ${this._model.repoId} will be updated to ${newCommit}`
-2
View File
@@ -102,8 +102,6 @@ export default class GitHubDownload extends GitHubBase {
function humanFileSize(bytes: number, si = false, dp = 1) {
const thresh = si ? 1000 : 1024;
bytes = bytes / 8;
if (Math.abs(bytes) < thresh) {
return bytes + "B";
}
+3 -2
View File
@@ -70,8 +70,9 @@ export default class FileSystem extends StorageBase {
});
}
return await fs.promises.writeFile(fullPath, data, "utf-8");
} catch {
// write error ignored
} catch (err) {
console.error("[ERROR] FileSystem.write failed:", err);
throw err;
}
}