mirror of
https://github.com/tdurieux/anonymous_github.git
synced 2026-07-10 15:38:35 +02:00
fix: repository refresh will check if new a new commit is available
This commit is contained in:
+7
-24
@@ -141,32 +141,13 @@ export default class Repository {
|
|||||||
*
|
*
|
||||||
* @returns void
|
* @returns void
|
||||||
*/
|
*/
|
||||||
async updateIfNeeded(): Promise<void> {
|
async updateIfNeeded(opt?: { force: boolean }): Promise<void> {
|
||||||
if (
|
|
||||||
this.status == "expired" ||
|
|
||||||
this.status == "expiring" ||
|
|
||||||
this.status == "removing" ||
|
|
||||||
this.status == "removed"
|
|
||||||
) {
|
|
||||||
throw new AnonymousError("repository_expired", this);
|
|
||||||
}
|
|
||||||
|
|
||||||
const fiveMinuteAgo = new Date();
|
|
||||||
fiveMinuteAgo.setMinutes(fiveMinuteAgo.getMinutes() - 5);
|
|
||||||
if (this.status != "ready") {
|
|
||||||
if (
|
|
||||||
this._model.statusDate < fiveMinuteAgo &&
|
|
||||||
this.status != "preparing"
|
|
||||||
) {
|
|
||||||
await this.updateStatus("preparing");
|
|
||||||
await downloadQueue.add(this, { jobId: this.repoId });
|
|
||||||
}
|
|
||||||
throw new AnonymousError("repository_not_ready", this);
|
|
||||||
}
|
|
||||||
|
|
||||||
const yesterday = new Date();
|
const yesterday = new Date();
|
||||||
yesterday.setDate(yesterday.getDate() - 1);
|
yesterday.setDate(yesterday.getDate() - 1);
|
||||||
if (this._model.options.update && this._model.lastView < yesterday) {
|
if (
|
||||||
|
opt?.force ||
|
||||||
|
(this._model.options.update && this._model.lastView < yesterday)
|
||||||
|
) {
|
||||||
// Only GitHubBase can be update for the moment
|
// Only GitHubBase can be update for the moment
|
||||||
if (this.source instanceof GitHubBase) {
|
if (this.source instanceof GitHubBase) {
|
||||||
const branches = await this.source.githubRepository.branches({
|
const branches = await this.source.githubRepository.branches({
|
||||||
@@ -187,6 +168,8 @@ export default class Repository {
|
|||||||
console.error(
|
console.error(
|
||||||
`${branch.name} for ${this.source.githubRepository.fullName} is not found`
|
`${branch.name} for ${this.source.githubRepository.fullName} is not found`
|
||||||
);
|
);
|
||||||
|
await this.updateStatus("error", "branch_not_found");
|
||||||
|
await this.resetSate();
|
||||||
throw new AnonymousError("branch_not_found", this);
|
throw new AnonymousError("branch_not_found", this);
|
||||||
}
|
}
|
||||||
this._model.anonymizeDate = new Date();
|
this._model.anonymizeDate = new Date();
|
||||||
|
|||||||
@@ -72,8 +72,7 @@ router.post(
|
|||||||
if (repo.owner.id != user.id) {
|
if (repo.owner.id != user.id) {
|
||||||
return res.status(401).json({ error: "not_authorized" });
|
return res.status(401).json({ error: "not_authorized" });
|
||||||
}
|
}
|
||||||
await repo.updateStatus("preparing");
|
await repo.updateIfNeeded({ force: true });
|
||||||
await downloadQueue.add(repo, {jobId: repo.repoId});
|
|
||||||
res.json({ status: repo.status });
|
res.json({ status: repo.status });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
handleError(error, res);
|
handleError(error, res);
|
||||||
@@ -95,7 +94,7 @@ router.delete(
|
|||||||
return res.status(401).json({ error: "not_authorized" });
|
return res.status(401).json({ error: "not_authorized" });
|
||||||
}
|
}
|
||||||
await repo.updateStatus("removing");
|
await repo.updateStatus("removing");
|
||||||
await removeQueue.add(repo, {jobId: repo.repoId});
|
await removeQueue.add(repo, { jobId: repo.repoId });
|
||||||
return res.json({ status: repo.status });
|
return res.json({ status: repo.status });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
handleError(error, res);
|
handleError(error, res);
|
||||||
@@ -312,7 +311,7 @@ router.post(
|
|||||||
repo.model.conference = repoUpdate.conference;
|
repo.model.conference = repoUpdate.conference;
|
||||||
await repo.updateStatus("preparing");
|
await repo.updateStatus("preparing");
|
||||||
res.json({ status: repo.status });
|
res.json({ status: repo.status });
|
||||||
await downloadQueue.add(repo, {jobId: repo.repoId});
|
await downloadQueue.add(repo, { jobId: repo.repoId });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return handleError(error, res);
|
return handleError(error, res);
|
||||||
}
|
}
|
||||||
@@ -376,7 +375,7 @@ router.post("/", async (req: express.Request, res: express.Response) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
res.send({ status: repo.status });
|
res.send({ status: repo.status });
|
||||||
downloadQueue.add(new Repository(repo), {jobId: repo.repoId});
|
downloadQueue.add(new Repository(repo), { jobId: repo.repoId });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (error.message?.indexOf(" duplicate key") > -1) {
|
if (error.message?.indexOf(" duplicate key") > -1) {
|
||||||
return handleError(
|
return handleError(
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ import * as stream from "stream";
|
|||||||
import config from "../../config";
|
import config from "../../config";
|
||||||
|
|
||||||
import { getRepo, handleError } from "./route-utils";
|
import { getRepo, handleError } from "./route-utils";
|
||||||
|
import AnonymousError from "../AnonymousError";
|
||||||
|
import { downloadQueue } from "../queue";
|
||||||
|
|
||||||
const router = express.Router();
|
const router = express.Router();
|
||||||
|
|
||||||
@@ -59,6 +61,28 @@ router.get(
|
|||||||
) {
|
) {
|
||||||
redirectURL = repo.source.url;
|
redirectURL = repo.source.url;
|
||||||
} else {
|
} else {
|
||||||
|
if (
|
||||||
|
repo.status == "expired" ||
|
||||||
|
repo.status == "expiring" ||
|
||||||
|
repo.status == "removing" ||
|
||||||
|
repo.status == "removed"
|
||||||
|
) {
|
||||||
|
throw new AnonymousError("repository_expired", this);
|
||||||
|
}
|
||||||
|
|
||||||
|
const fiveMinuteAgo = new Date();
|
||||||
|
fiveMinuteAgo.setMinutes(fiveMinuteAgo.getMinutes() - 5);
|
||||||
|
if (repo.status != "ready") {
|
||||||
|
if (
|
||||||
|
repo.model.statusDate < fiveMinuteAgo &&
|
||||||
|
repo.status != "preparing"
|
||||||
|
) {
|
||||||
|
await repo.updateStatus("preparing");
|
||||||
|
await downloadQueue.add(this, { jobId: repo.repoId });
|
||||||
|
}
|
||||||
|
throw new AnonymousError("repository_not_ready", this);
|
||||||
|
}
|
||||||
|
|
||||||
await repo.updateIfNeeded();
|
await repo.updateIfNeeded();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user