|
|
|
@ -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
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|