mirror of
https://github.com/tdurieux/anonymous_github.git
synced 2026-02-12 18:32:44 +00:00
refactor: rely more on the db instead of querying GH
This commit is contained in:
@@ -69,6 +69,7 @@ async function main() {
|
||||
accessToken: inq.token,
|
||||
owner: ghURL.owner,
|
||||
repo: ghURL.name,
|
||||
force: true,
|
||||
});
|
||||
const branches = await ghRepo.branches({
|
||||
accessToken: inq.token,
|
||||
|
||||
@@ -324,6 +324,7 @@ export default class Repository {
|
||||
accessToken: await this.getToken(),
|
||||
owner: this.source.data.organization,
|
||||
repo: this.source.data.repoName,
|
||||
force: true,
|
||||
});
|
||||
if (repository.size) {
|
||||
if (
|
||||
|
||||
@@ -230,6 +230,7 @@ export async function getRepositoryFromGitHub(opt: {
|
||||
owner: string;
|
||||
repo: string;
|
||||
accessToken: string;
|
||||
force?: boolean;
|
||||
}) {
|
||||
const span = trace
|
||||
.getTracer("ano-file")
|
||||
@@ -240,6 +241,14 @@ export async function getRepositoryFromGitHub(opt: {
|
||||
if (opt.repo.indexOf(".git") > -1) {
|
||||
opt.repo = opt.repo.replace(".git", "");
|
||||
}
|
||||
const dbModel = isConnected
|
||||
? await RepositoryModel.findOne({
|
||||
name: opt.owner + "/" + opt.repo,
|
||||
})
|
||||
: null;
|
||||
if (dbModel && !opt.force) {
|
||||
return new GitHubRepository(dbModel);
|
||||
}
|
||||
const oct = octokit(opt.accessToken);
|
||||
let r: RestEndpointMethodTypes["repos"]["get"]["response"]["data"];
|
||||
try {
|
||||
@@ -268,15 +277,7 @@ export async function getRepositoryFromGitHub(opt: {
|
||||
repo: opt.repo,
|
||||
},
|
||||
});
|
||||
let model = new RepositoryModel({ externalId: "gh_" + r.id });
|
||||
if (isConnected) {
|
||||
const dbModel = await RepositoryModel.findOne({
|
||||
externalId: "gh_" + r.id,
|
||||
});
|
||||
if (dbModel) {
|
||||
model = dbModel;
|
||||
}
|
||||
}
|
||||
const model = dbModel || new RepositoryModel({ externalId: "gh_" + r.id });
|
||||
model.name = r.full_name;
|
||||
model.url = r.html_url;
|
||||
model.size = r.size;
|
||||
|
||||
@@ -191,6 +191,7 @@ router.get(
|
||||
owner: req.params.owner,
|
||||
repo: req.params.repo,
|
||||
accessToken: token,
|
||||
force: req.query.force == "1",
|
||||
});
|
||||
res.json(repo.toJSON());
|
||||
} catch (error) {
|
||||
@@ -212,6 +213,7 @@ router.get(
|
||||
accessToken: token,
|
||||
owner: req.params.owner,
|
||||
repo: req.params.repo,
|
||||
force: req.query.force == "1",
|
||||
});
|
||||
return res.json(
|
||||
await repository.branches({
|
||||
@@ -239,6 +241,7 @@ router.get(
|
||||
owner: req.params.owner,
|
||||
repo: req.params.repo,
|
||||
accessToken: token,
|
||||
force: req.query.force == "1",
|
||||
});
|
||||
if (!repo) {
|
||||
throw new AnonymousError("repo_not_found", {
|
||||
|
||||
Reference in New Issue
Block a user