mirror of
https://github.com/tdurieux/anonymous_github.git
synced 2026-08-09 05:26:10 +02:00
feat: add support for .git url
This commit is contained in:
@@ -146,6 +146,9 @@ export async function getRepositoryFromGitHub(opt: {
|
|||||||
repo: string;
|
repo: string;
|
||||||
accessToken: string;
|
accessToken: string;
|
||||||
}) {
|
}) {
|
||||||
|
if (opt.repo.indexOf(".git") > -1) {
|
||||||
|
opt.repo = opt.repo.replace(".git", "");
|
||||||
|
}
|
||||||
const octokit = new Octokit({ auth: opt.accessToken });
|
const octokit = new Octokit({ auth: opt.accessToken });
|
||||||
let r;
|
let r;
|
||||||
try {
|
try {
|
||||||
@@ -157,11 +160,18 @@ export async function getRepositoryFromGitHub(opt: {
|
|||||||
).data;
|
).data;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (error.status == 404) {
|
if (error.status == 404) {
|
||||||
throw new AnonymousError("repo_not_found", {owner: opt.owner, repo: opt.repo});
|
throw new AnonymousError("repo_not_found", {
|
||||||
|
owner: opt.owner,
|
||||||
|
repo: opt.repo,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
if (!r) throw new AnonymousError("repo_not_found", {owner: opt.owner, repo: opt.repo});
|
if (!r)
|
||||||
|
throw new AnonymousError("repo_not_found", {
|
||||||
|
owner: opt.owner,
|
||||||
|
repo: opt.repo,
|
||||||
|
});
|
||||||
let model = await RepositoryModel.findOne({ externalId: "gh_" + r.id });
|
let model = await RepositoryModel.findOne({ externalId: "gh_" + r.id });
|
||||||
if (!model) {
|
if (!model) {
|
||||||
model = new RepositoryModel({ externalId: "gh_" + r.id });
|
model = new RepositoryModel({ externalId: "gh_" + r.id });
|
||||||
|
|||||||
Reference in New Issue
Block a user