Remove unnecessary parameter (#27671)

This commit is contained in:
Lunny Xiao 2023-10-18 23:03:10 +08:00 committed by GitHub
parent 83186eca80
commit 9852c92e9a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 23 additions and 25 deletions

View file

@ -33,7 +33,7 @@ import (
// 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)
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)
if err != nil {
return err
@ -41,6 +41,18 @@ func DeleteRepositoryDirectly(ctx context.Context, doer *user_model.User, uid, r
defer committer.Close()
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
tasks, err := actions_model.FindTasks(ctx, actions_model.FindTaskOptions{RepoID: repoID})
if err != nil {
@ -54,24 +66,11 @@ func DeleteRepositoryDirectly(ctx context.Context, doer *user_model.User, uid, r
}
// In case is a organization.
org, err := user_model.GetUserByID(ctx, uid)
org, err := user_model.GetUserByID(ctx, repo.OwnerID)
if err != nil {
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
deployKeys, err := asymkey_model.ListDeployKeys(ctx, &asymkey_model.ListDeployKeysOptions{RepoID: repoID})
if err != nil {
@ -89,7 +88,6 @@ func DeleteRepositoryDirectly(ctx context.Context, doer *user_model.User, uid, r
} else if cnt != 1 {
return repo_model.ErrRepoNotExist{
ID: repoID,
UID: uid,
OwnerName: "",
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
}