mirror of
https://github.com/go-gitea/gitea.git
synced 2024-11-26 10:14:08 +08:00
Remove unnecessary parameter (#27671)
This commit is contained in:
parent
83186eca80
commit
9852c92e9a
|
@ -200,7 +200,7 @@ func Migrate(ctx *context.APIContext) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if repo != nil {
|
if repo != nil {
|
||||||
if errDelete := repo_service.DeleteRepositoryDirectly(ctx, ctx.Doer, repoOwner.ID, repo.ID); errDelete != nil {
|
if errDelete := repo_service.DeleteRepositoryDirectly(ctx, ctx.Doer, repo.ID); errDelete != nil {
|
||||||
log.Error("DeleteRepository: %v", errDelete)
|
log.Error("DeleteRepository: %v", errDelete)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -164,7 +164,7 @@ func DeleteMissingRepositories(ctx context.Context, doer *user_model.User) error
|
||||||
default:
|
default:
|
||||||
}
|
}
|
||||||
log.Trace("Deleting %d/%d...", repo.OwnerID, repo.ID)
|
log.Trace("Deleting %d/%d...", repo.OwnerID, repo.ID)
|
||||||
if err := DeleteRepositoryDirectly(ctx, doer, repo.OwnerID, repo.ID); err != nil {
|
if err := DeleteRepositoryDirectly(ctx, doer, repo.ID); err != nil {
|
||||||
log.Error("Failed to DeleteRepository %-v: Error: %v", repo, err)
|
log.Error("Failed to DeleteRepository %-v: Error: %v", repo, err)
|
||||||
if err2 := system_model.CreateRepositoryNotice("Failed to DeleteRepository %s [%d]: Error: %v", repo.FullName(), repo.ID, err); err2 != nil {
|
if err2 := system_model.CreateRepositoryNotice("Failed to DeleteRepository %s [%d]: Error: %v", repo.FullName(), repo.ID, err); err2 != nil {
|
||||||
log.Error("CreateRepositoryNotice: %v", err)
|
log.Error("CreateRepositoryNotice: %v", err)
|
||||||
|
|
|
@ -302,7 +302,7 @@ func CreateRepositoryDirectly(ctx context.Context, doer, u *user_model.User, opt
|
||||||
return nil
|
return nil
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
if rollbackRepo != nil {
|
if rollbackRepo != nil {
|
||||||
if errDelete := DeleteRepositoryDirectly(ctx, doer, rollbackRepo.OwnerID, rollbackRepo.ID); errDelete != nil {
|
if errDelete := DeleteRepositoryDirectly(ctx, doer, rollbackRepo.ID); errDelete != nil {
|
||||||
log.Error("Rollback deleteRepository: %v", errDelete)
|
log.Error("Rollback deleteRepository: %v", errDelete)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -129,7 +129,7 @@ func TestIncludesAllRepositoriesTeams(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove repo and check teams repositories.
|
// Remove repo and check teams repositories.
|
||||||
assert.NoError(t, DeleteRepositoryDirectly(db.DefaultContext, user, org.ID, repoIds[0]), "DeleteRepository")
|
assert.NoError(t, DeleteRepositoryDirectly(db.DefaultContext, user, repoIds[0]), "DeleteRepository")
|
||||||
teamRepos[0] = repoIds[1:]
|
teamRepos[0] = repoIds[1:]
|
||||||
teamRepos[1] = repoIds[1:]
|
teamRepos[1] = repoIds[1:]
|
||||||
teamRepos[3] = repoIds[1:3]
|
teamRepos[3] = repoIds[1:3]
|
||||||
|
@ -141,7 +141,7 @@ func TestIncludesAllRepositoriesTeams(t *testing.T) {
|
||||||
// Wipe created items.
|
// Wipe created items.
|
||||||
for i, rid := range repoIds {
|
for i, rid := range repoIds {
|
||||||
if i > 0 { // first repo already deleted.
|
if i > 0 { // first repo already deleted.
|
||||||
assert.NoError(t, DeleteRepositoryDirectly(db.DefaultContext, user, org.ID, rid), "DeleteRepository %d", i)
|
assert.NoError(t, DeleteRepositoryDirectly(db.DefaultContext, user, rid), "DeleteRepository %d", i)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
assert.NoError(t, organization.DeleteOrganization(db.DefaultContext, org), "DeleteOrganization")
|
assert.NoError(t, organization.DeleteOrganization(db.DefaultContext, org), "DeleteOrganization")
|
||||||
|
|
|
@ -33,7 +33,7 @@ import (
|
||||||
|
|
||||||
// DeleteRepository deletes a repository for a user or organization.
|
// DeleteRepository deletes a repository for a user or organization.
|
||||||
// make sure if you call this func to close open sessions (sqlite will otherwise get a deadlock)
|
// make sure if you call this func to close open sessions (sqlite will otherwise get a deadlock)
|
||||||
func DeleteRepositoryDirectly(ctx context.Context, doer *user_model.User, uid, repoID int64) error {
|
func DeleteRepositoryDirectly(ctx context.Context, doer *user_model.User, repoID int64) error {
|
||||||
ctx, committer, err := db.TxContext(ctx)
|
ctx, committer, err := db.TxContext(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -41,6 +41,18 @@ func DeleteRepositoryDirectly(ctx context.Context, doer *user_model.User, uid, r
|
||||||
defer committer.Close()
|
defer committer.Close()
|
||||||
sess := db.GetEngine(ctx)
|
sess := db.GetEngine(ctx)
|
||||||
|
|
||||||
|
repo := &repo_model.Repository{}
|
||||||
|
has, err := sess.ID(repoID).Get(repo)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
} else if !has {
|
||||||
|
return repo_model.ErrRepoNotExist{
|
||||||
|
ID: repoID,
|
||||||
|
OwnerName: "",
|
||||||
|
Name: "",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Query the action tasks of this repo, they will be needed after they have been deleted to remove the logs
|
// Query the action tasks of this repo, they will be needed after they have been deleted to remove the logs
|
||||||
tasks, err := actions_model.FindTasks(ctx, actions_model.FindTaskOptions{RepoID: repoID})
|
tasks, err := actions_model.FindTasks(ctx, actions_model.FindTaskOptions{RepoID: repoID})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -54,24 +66,11 @@ func DeleteRepositoryDirectly(ctx context.Context, doer *user_model.User, uid, r
|
||||||
}
|
}
|
||||||
|
|
||||||
// In case is a organization.
|
// In case is a organization.
|
||||||
org, err := user_model.GetUserByID(ctx, uid)
|
org, err := user_model.GetUserByID(ctx, repo.OwnerID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
repo := &repo_model.Repository{OwnerID: uid}
|
|
||||||
has, err := sess.ID(repoID).Get(repo)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
} else if !has {
|
|
||||||
return repo_model.ErrRepoNotExist{
|
|
||||||
ID: repoID,
|
|
||||||
UID: uid,
|
|
||||||
OwnerName: "",
|
|
||||||
Name: "",
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Delete Deploy Keys
|
// Delete Deploy Keys
|
||||||
deployKeys, err := asymkey_model.ListDeployKeys(ctx, &asymkey_model.ListDeployKeysOptions{RepoID: repoID})
|
deployKeys, err := asymkey_model.ListDeployKeys(ctx, &asymkey_model.ListDeployKeysOptions{RepoID: repoID})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -89,7 +88,6 @@ func DeleteRepositoryDirectly(ctx context.Context, doer *user_model.User, uid, r
|
||||||
} else if cnt != 1 {
|
} else if cnt != 1 {
|
||||||
return repo_model.ErrRepoNotExist{
|
return repo_model.ErrRepoNotExist{
|
||||||
ID: repoID,
|
ID: repoID,
|
||||||
UID: uid,
|
|
||||||
OwnerName: "",
|
OwnerName: "",
|
||||||
Name: "",
|
Name: "",
|
||||||
}
|
}
|
||||||
|
@ -192,7 +190,7 @@ func DeleteRepositoryDirectly(ctx context.Context, doer *user_model.User, uid, r
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := db.Exec(ctx, "UPDATE `user` SET num_repos=num_repos-1 WHERE id=?", uid); err != nil {
|
if _, err := db.Exec(ctx, "UPDATE `user` SET num_repos=num_repos-1 WHERE id=?", repo.OwnerID); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -62,7 +62,7 @@ func DeleteRepository(ctx context.Context, doer *user_model.User, repo *repo_mod
|
||||||
notify_service.DeleteRepository(ctx, doer, repo)
|
notify_service.DeleteRepository(ctx, doer, repo)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := DeleteRepositoryDirectly(ctx, doer, repo.OwnerID, repo.ID); err != nil {
|
if err := DeleteRepositoryDirectly(ctx, doer, repo.ID); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -175,7 +175,7 @@ func DeleteUser(ctx context.Context, u *user_model.User, purge bool) error {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
for _, repo := range repos {
|
for _, repo := range repos {
|
||||||
if err := repo_service.DeleteRepositoryDirectly(ctx, u, u.ID, repo.ID); err != nil {
|
if err := repo_service.DeleteRepositoryDirectly(ctx, u, repo.ID); err != nil {
|
||||||
return fmt.Errorf("unable to delete repository %s for %s[%d]. Error: %w", repo.Name, u.Name, u.ID, err)
|
return fmt.Errorf("unable to delete repository %s for %s[%d]. Error: %w", repo.Name, u.Name, u.ID, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -541,7 +541,7 @@ func TestAPIRepoTransfer(t *testing.T) {
|
||||||
|
|
||||||
// cleanup
|
// cleanup
|
||||||
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: apiRepo.ID})
|
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: apiRepo.ID})
|
||||||
_ = repo_service.DeleteRepositoryDirectly(db.DefaultContext, user, repo.OwnerID, repo.ID)
|
_ = repo_service.DeleteRepositoryDirectly(db.DefaultContext, user, repo.ID)
|
||||||
}
|
}
|
||||||
|
|
||||||
func transfer(t *testing.T) *repo_model.Repository {
|
func transfer(t *testing.T) *repo_model.Repository {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user