mirror of
https://github.com/tdurieux/anonymous_github.git
synced 2026-07-09 15:17:49 +02:00
fix: improve repository rename
This commit is contained in:
+13
-2
@@ -1052,6 +1052,7 @@ angular
|
|||||||
$scope.source = res.data.source;
|
$scope.source = res.data.source;
|
||||||
$scope.options = res.data.options;
|
$scope.options = res.data.options;
|
||||||
$scope.conference = res.data.conference;
|
$scope.conference = res.data.conference;
|
||||||
|
$scope.repositoryID = res.data.source.repositoryID;
|
||||||
if (res.data.options.expirationDate) {
|
if (res.data.options.expirationDate) {
|
||||||
$scope.options.expirationDate = new Date(
|
$scope.options.expirationDate = new Date(
|
||||||
res.data.options.expirationDate
|
res.data.options.expirationDate
|
||||||
@@ -1139,7 +1140,12 @@ angular
|
|||||||
const o = parseGithubUrl($scope.repoUrl);
|
const o = parseGithubUrl($scope.repoUrl);
|
||||||
const branches = await $http.get(
|
const branches = await $http.get(
|
||||||
`/api/repo/${o.owner}/${o.repo}/branches`,
|
`/api/repo/${o.owner}/${o.repo}/branches`,
|
||||||
{ params: { force: force === true ? "1" : "0" } }
|
{
|
||||||
|
params: {
|
||||||
|
force: force === true ? "1" : "0",
|
||||||
|
repositoryID: $scope.repositoryID,
|
||||||
|
},
|
||||||
|
}
|
||||||
);
|
);
|
||||||
$scope.branches = branches.data;
|
$scope.branches = branches.data;
|
||||||
if (!$scope.source.branch) {
|
if (!$scope.source.branch) {
|
||||||
@@ -1160,7 +1166,11 @@ angular
|
|||||||
const o = parseGithubUrl($scope.repoUrl);
|
const o = parseGithubUrl($scope.repoUrl);
|
||||||
try {
|
try {
|
||||||
resetValidity();
|
resetValidity();
|
||||||
const res = await $http.get(`/api/repo/${o.owner}/${o.repo}/`);
|
const res = await $http.get(`/api/repo/${o.owner}/${o.repo}/`, {
|
||||||
|
params: {
|
||||||
|
repositoryID: $scope.repositoryID,
|
||||||
|
},
|
||||||
|
});
|
||||||
$scope.details = res.data;
|
$scope.details = res.data;
|
||||||
if (!$scope.repoId) {
|
if (!$scope.repoId) {
|
||||||
$scope.repoId = $scope.details.repo + "-" + generateRandomId(4);
|
$scope.repoId = $scope.details.repo + "-" + generateRandomId(4);
|
||||||
@@ -1200,6 +1210,7 @@ angular
|
|||||||
params: {
|
params: {
|
||||||
force: force === true ? "1" : "0",
|
force: force === true ? "1" : "0",
|
||||||
branch: $scope.source.branch,
|
branch: $scope.source.branch,
|
||||||
|
repositoryID: $scope.repositoryID,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
$scope.readme = res.data;
|
$scope.readme = res.data;
|
||||||
|
|||||||
Vendored
+1
-1
File diff suppressed because one or more lines are too long
+15
-12
@@ -286,14 +286,22 @@ export default class Repository {
|
|||||||
// 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 token = await this.getToken();
|
const token = await this.getToken();
|
||||||
const ghRepo = new GitHubRepository({
|
|
||||||
name: this.model.source.repositoryName,
|
const ghRepo = await getRepositoryFromGitHub({
|
||||||
|
accessToken: token,
|
||||||
|
owner: this.source.data.organization,
|
||||||
|
repo: this.source.data.repoName,
|
||||||
|
repositoryID: this.model.source.repositoryId,
|
||||||
|
force: true,
|
||||||
});
|
});
|
||||||
|
// update the repository name if it has changed
|
||||||
|
this.model.source.repositoryName = ghRepo.fullName;
|
||||||
const branches = await ghRepo.branches({
|
const branches = await ghRepo.branches({
|
||||||
force: true,
|
force: true,
|
||||||
accessToken: token,
|
accessToken: token,
|
||||||
});
|
});
|
||||||
const branchName = this.model.source.branch || "main";
|
const branchName =
|
||||||
|
this.model.source.branch || ghRepo.model.defaultBranch;
|
||||||
const newCommit = branches.filter((f) => f.name == branchName)[0]
|
const newCommit = branches.filter((f) => f.name == branchName)[0]
|
||||||
?.commit;
|
?.commit;
|
||||||
if (
|
if (
|
||||||
@@ -336,20 +344,14 @@ export default class Repository {
|
|||||||
`[UPDATE] ${this._model.repoId} will be updated to ${newCommit}`
|
`[UPDATE] ${this._model.repoId} will be updated to ${newCommit}`
|
||||||
);
|
);
|
||||||
|
|
||||||
const repository = await getRepositoryFromGitHub({
|
if (ghRepo.size) {
|
||||||
accessToken: await this.getToken(),
|
|
||||||
owner: this.source.data.organization,
|
|
||||||
repo: this.source.data.repoName,
|
|
||||||
force: true,
|
|
||||||
});
|
|
||||||
if (repository.size) {
|
|
||||||
if (
|
if (
|
||||||
repository.size > config.AUTO_DOWNLOAD_REPO_SIZE &&
|
ghRepo.size > config.AUTO_DOWNLOAD_REPO_SIZE &&
|
||||||
this.model.source.type == "GitHubDownload"
|
this.model.source.type == "GitHubDownload"
|
||||||
) {
|
) {
|
||||||
this.model.source.type = "GitHubStream";
|
this.model.source.type = "GitHubStream";
|
||||||
} else if (
|
} else if (
|
||||||
repository.size < config.AUTO_DOWNLOAD_REPO_SIZE &&
|
ghRepo.size < config.AUTO_DOWNLOAD_REPO_SIZE &&
|
||||||
this.model.source.type == "GitHubStream"
|
this.model.source.type == "GitHubStream"
|
||||||
) {
|
) {
|
||||||
this.model.source.type = "GitHubDownload";
|
this.model.source.type = "GitHubDownload";
|
||||||
@@ -596,6 +598,7 @@ export default class Repository {
|
|||||||
pageView: this._model.pageView,
|
pageView: this._model.pageView,
|
||||||
size: this.size,
|
size: this.size,
|
||||||
source: {
|
source: {
|
||||||
|
repositoryID: this.model.source.repositoryId,
|
||||||
fullName: this.model.source.repositoryName,
|
fullName: this.model.source.repositoryName,
|
||||||
commit: this.model.source.commit,
|
commit: this.model.source.commit,
|
||||||
branch: this.model.source.branch,
|
branch: this.model.source.branch,
|
||||||
|
|||||||
@@ -21,6 +21,8 @@ export class GitHubRepository {
|
|||||||
|
|
||||||
toJSON() {
|
toJSON() {
|
||||||
return {
|
return {
|
||||||
|
id: this.model._id,
|
||||||
|
externalId: this._data.externalId,
|
||||||
repo: this.repo,
|
repo: this.repo,
|
||||||
owner: this.owner,
|
owner: this.owner,
|
||||||
hasPage: this._data.hasPage,
|
hasPage: this._data.hasPage,
|
||||||
@@ -229,6 +231,7 @@ export class GitHubRepository {
|
|||||||
export async function getRepositoryFromGitHub(opt: {
|
export async function getRepositoryFromGitHub(opt: {
|
||||||
owner: string;
|
owner: string;
|
||||||
repo: string;
|
repo: string;
|
||||||
|
repositoryID?: string;
|
||||||
accessToken: string;
|
accessToken: string;
|
||||||
force?: boolean;
|
force?: boolean;
|
||||||
}) {
|
}) {
|
||||||
@@ -241,11 +244,20 @@ export async function getRepositoryFromGitHub(opt: {
|
|||||||
if (opt.repo.indexOf(".git") > -1) {
|
if (opt.repo.indexOf(".git") > -1) {
|
||||||
opt.repo = opt.repo.replace(".git", "");
|
opt.repo = opt.repo.replace(".git", "");
|
||||||
}
|
}
|
||||||
const dbModel = isConnected
|
let dbModel = null;
|
||||||
? await RepositoryModel.findOne({
|
if (opt.repositoryID) {
|
||||||
name: opt.owner + "/" + opt.repo,
|
dbModel = isConnected
|
||||||
})
|
? await RepositoryModel.findById(opt.repositoryID)
|
||||||
: null;
|
: null;
|
||||||
|
opt.owner = dbModel?.name?.split("/")[0] || opt.owner;
|
||||||
|
opt.repo = dbModel?.name?.split("/")[1] || opt.repo;
|
||||||
|
} else {
|
||||||
|
dbModel = isConnected
|
||||||
|
? await RepositoryModel.findOne({
|
||||||
|
name: opt.owner + "/" + opt.repo,
|
||||||
|
})
|
||||||
|
: null;
|
||||||
|
}
|
||||||
if (dbModel && !opt.force) {
|
if (dbModel && !opt.force) {
|
||||||
return new GitHubRepository(dbModel);
|
return new GitHubRepository(dbModel);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -90,6 +90,7 @@ router.post("/claim", async (req: express.Request, res: express.Response) => {
|
|||||||
const repo = await getRepositoryFromGitHub({
|
const repo = await getRepositoryFromGitHub({
|
||||||
owner: r.owner,
|
owner: r.owner,
|
||||||
repo: r.name,
|
repo: r.name,
|
||||||
|
repositoryID: req.query.repositoryID as string,
|
||||||
accessToken: user.accessToken,
|
accessToken: user.accessToken,
|
||||||
});
|
});
|
||||||
if (!repo) {
|
if (!repo) {
|
||||||
@@ -191,6 +192,7 @@ router.get(
|
|||||||
owner: req.params.owner,
|
owner: req.params.owner,
|
||||||
repo: req.params.repo,
|
repo: req.params.repo,
|
||||||
accessToken: token,
|
accessToken: token,
|
||||||
|
repositoryID: req.query.repositoryID as string,
|
||||||
force: req.query.force == "1",
|
force: req.query.force == "1",
|
||||||
});
|
});
|
||||||
res.json(repo.toJSON());
|
res.json(repo.toJSON());
|
||||||
@@ -213,6 +215,7 @@ router.get(
|
|||||||
accessToken: token,
|
accessToken: token,
|
||||||
owner: req.params.owner,
|
owner: req.params.owner,
|
||||||
repo: req.params.repo,
|
repo: req.params.repo,
|
||||||
|
repositoryID: req.query.repositoryID as string,
|
||||||
force: req.query.force == "1",
|
force: req.query.force == "1",
|
||||||
});
|
});
|
||||||
return res.json(
|
return res.json(
|
||||||
@@ -241,6 +244,7 @@ router.get(
|
|||||||
owner: req.params.owner,
|
owner: req.params.owner,
|
||||||
repo: req.params.repo,
|
repo: req.params.repo,
|
||||||
accessToken: token,
|
accessToken: token,
|
||||||
|
repositoryID: req.query.repositoryID as string,
|
||||||
force: req.query.force == "1",
|
force: req.query.force == "1",
|
||||||
});
|
});
|
||||||
if (!repo) {
|
if (!repo) {
|
||||||
@@ -379,7 +383,7 @@ router.post(
|
|||||||
|
|
||||||
updateRepoModel(repo.model, repoUpdate);
|
updateRepoModel(repo.model, repoUpdate);
|
||||||
|
|
||||||
const r = gh(repoUpdate.fullName);
|
const r = gh(repo.model.source.repositoryName || repoUpdate.fullName);
|
||||||
if (!r?.owner || !r?.name) {
|
if (!r?.owner || !r?.name) {
|
||||||
await repo.resetSate(RepositoryStatus.ERROR, "repo_not_found");
|
await repo.resetSate(RepositoryStatus.ERROR, "repo_not_found");
|
||||||
throw new AnonymousError("repo_not_found", {
|
throw new AnonymousError("repo_not_found", {
|
||||||
@@ -391,6 +395,7 @@ router.post(
|
|||||||
accessToken: user.accessToken,
|
accessToken: user.accessToken,
|
||||||
owner: r.owner,
|
owner: r.owner,
|
||||||
repo: r.name,
|
repo: r.name,
|
||||||
|
repositoryID: repo.model.source.repositoryId,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!repository) {
|
if (!repository) {
|
||||||
|
|||||||
Reference in New Issue
Block a user