mirror of
https://github.com/tdurieux/anonymous_github.git
synced 2026-05-15 22:48:00 +02:00
always use githubStream
This commit is contained in:
+8
-1
@@ -106,7 +106,14 @@ async function main() {
|
||||
console.info(
|
||||
`[INFO] Downloading repository: ${repository.model.source.repositoryName} from branch ${repository.model.source.branch} and commit ${repository.model.source.commit}...`
|
||||
);
|
||||
await (repository.source as GitHubDownload).download(inq.token);
|
||||
const cliDownload = new GitHubDownload({
|
||||
repoId: repository.repoId,
|
||||
organization: ghURL.owner,
|
||||
repoName: ghURL.name,
|
||||
commit: branch?.commit || "HEAD",
|
||||
getToken: () => inq.token,
|
||||
});
|
||||
await cliDownload.download(inq.token);
|
||||
const outputFileName = join(inq.output, generateRandomFileName(8) + ".zip");
|
||||
console.info("[INFO] Anonymizing repository and creation zip file...");
|
||||
await writeFile(outputFileName, await repository.zip());
|
||||
|
||||
+10
-31
@@ -4,7 +4,6 @@ import { Readable } from "stream";
|
||||
import * as sha1 from "crypto-js/sha1";
|
||||
import User from "./User";
|
||||
import GitHubStream from "./source/GitHubStream";
|
||||
import GitHubDownload from "./source/GitHubDownload";
|
||||
import Zip from "./source/Zip";
|
||||
import { anonymizePath } from "./anonymize-utils";
|
||||
import UserModel from "./model/users/users.model";
|
||||
@@ -21,7 +20,6 @@ import {
|
||||
GitHubRepository,
|
||||
} from "./source/GitHubRepository";
|
||||
import { getToken } from "./GitHubUtils";
|
||||
import { FILE_TYPE } from "./storage/Storage";
|
||||
import config from "../config";
|
||||
import FileModel from "./model/files/files.model";
|
||||
import { IFile } from "./model/files/files.types";
|
||||
@@ -83,31 +81,16 @@ export default class Repository {
|
||||
const ghRepo = new GitHubRepository({
|
||||
name: this.model.source.repositoryName,
|
||||
});
|
||||
switch (this.model.source.type) {
|
||||
case "GitHubDownload":
|
||||
return new GitHubDownload({
|
||||
repoId: this.repoId,
|
||||
commit: this.model.source.commit || "HEAD",
|
||||
organization: ghRepo.owner,
|
||||
repoName: ghRepo.repo,
|
||||
getToken: () => this.getToken(),
|
||||
});
|
||||
case "GitHubStream":
|
||||
return new GitHubStream({
|
||||
repoId: this.repoId,
|
||||
commit: this.model.source.commit || "HEAD",
|
||||
organization: ghRepo.owner,
|
||||
repoName: ghRepo.repo,
|
||||
getToken: () => this.getToken(),
|
||||
});
|
||||
case "Zip":
|
||||
return new Zip(this.model.source, this.repoId);
|
||||
default:
|
||||
throw new AnonymousError("unsupported_source", {
|
||||
object: this,
|
||||
httpStatus: 400,
|
||||
});
|
||||
if (this.model.source.type === "Zip") {
|
||||
return new Zip(this.model.source, this.repoId);
|
||||
}
|
||||
return new GitHubStream({
|
||||
repoId: this.repoId,
|
||||
commit: this.model.source.commit || "HEAD",
|
||||
organization: ghRepo.owner,
|
||||
repoName: ghRepo.repo,
|
||||
getToken: () => this.getToken(),
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -264,11 +247,7 @@ export default class Repository {
|
||||
|
||||
async isReady() {
|
||||
if (this.status !== RepositoryStatus.READY) return false;
|
||||
if (
|
||||
(this.source.type == "GitHubDownload" &&
|
||||
(await storage.exists(this.repoId)) == FILE_TYPE.NOT_FOUND) ||
|
||||
!(await FileModel.exists({ repoId: this.repoId }).exec())
|
||||
) {
|
||||
if (!(await FileModel.exists({ repoId: this.repoId }).exec())) {
|
||||
this.model.status = RepositoryStatus.PREPARING;
|
||||
await this.updateIfNeeded({ force: true });
|
||||
return false;
|
||||
|
||||
@@ -329,15 +329,7 @@ function updateRepoModel(
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
repoUpdate: any
|
||||
) {
|
||||
if (repoUpdate.source.type) {
|
||||
model.source.type = repoUpdate.source.type;
|
||||
if (
|
||||
model.source.type != "GitHubStream" &&
|
||||
model.source.type != "GitHubDownload"
|
||||
) {
|
||||
model.source.type = "GitHubStream";
|
||||
}
|
||||
}
|
||||
model.source.type = "GitHubStream";
|
||||
model.source.commit = repoUpdate.source.commit;
|
||||
model.source.branch = repoUpdate.source.branch;
|
||||
model.options = {
|
||||
|
||||
Reference in New Issue
Block a user