fix(#174) improve cli interface to anonimize repositories

This commit is contained in:
tdurieux
2023-02-15 19:23:45 +01:00
parent fb9bbe105a
commit da194d9d71
3 changed files with 58 additions and 27 deletions

View File

@@ -4,6 +4,7 @@ import { IRepositoryDocument } from "../database/repositories/repositories.types
import { Octokit, RestEndpointMethodTypes } from "@octokit/rest";
import RepositoryModel from "../database/repositories/repositories.model";
import AnonymousError from "../AnonymousError";
import { database, isConnected } from "../database/database";
export class GitHubRepository {
private _data: Partial<{
@@ -71,11 +72,13 @@ export class GitHubRepository {
});
this._data.branches = branches;
await RepositoryModel.updateOne(
{ externalId: this.id },
{ $set: { branches } }
);
} else {
if (isConnected) {
await RepositoryModel.updateOne(
{ externalId: this.id },
{ $set: { branches } }
);
}
} else if (isConnected) {
const q = await RepositoryModel.findOne({ externalId: this.id }).select(
"branches"
);
@@ -208,9 +211,12 @@ export async function getRepositoryFromGitHub(opt: {
repo: opt.repo,
},
});
let model = await RepositoryModel.findOne({ externalId: "gh_" + r.id });
if (!model) {
model = new RepositoryModel({ externalId: "gh_" + r.id });
let model = new RepositoryModel({ externalId: "gh_" + r.id });
if (isConnected) {
const dbModel = await RepositoryModel.findOne({ externalId: "gh_" + r.id });
if (dbModel) {
model = dbModel;
}
}
model.name = r.full_name;
model.url = r.html_url;
@@ -224,6 +230,8 @@ export async function getRepositoryFromGitHub(opt: {
});
model.pageSource = ghPageRes.data.source;
}
await model.save();
if (isConnected) {
await model.save();
}
return new GitHubRepository(model);
}

View File

@@ -108,7 +108,7 @@ export default class FileSystem implements StorageBase {
return pipe(
data,
Extract({
path: join(join(config.FOLDER, p)),
path: join(config.FOLDER, p),
decodeString: (buf) => {
const name = buf.toString();
const newName = name.substr(name.indexOf("/") + 1);
@@ -124,7 +124,7 @@ export default class FileSystem implements StorageBase {
dir: string,
opt?: {
format?: "zip" | "tar";
fileTransformer? (path: string): Transform;
fileTransformer?: (path: string) => Transform;
}
) {
const archive = archiver(opt?.format || "zip", {});