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