mirror of
https://github.com/go-gitea/gitea.git
synced 2025-08-08 07:41:50 +00:00
Fix bug
This commit is contained in:
parent
2256fa7e9c
commit
65a01c2c47
@ -15,7 +15,6 @@ import (
|
|||||||
"code.gitea.io/gitea/models/db"
|
"code.gitea.io/gitea/models/db"
|
||||||
git_model "code.gitea.io/gitea/models/git"
|
git_model "code.gitea.io/gitea/models/git"
|
||||||
org_model "code.gitea.io/gitea/models/organization"
|
org_model "code.gitea.io/gitea/models/organization"
|
||||||
pull_model "code.gitea.io/gitea/models/pull"
|
|
||||||
repo_model "code.gitea.io/gitea/models/repo"
|
repo_model "code.gitea.io/gitea/models/repo"
|
||||||
user_model "code.gitea.io/gitea/models/user"
|
user_model "code.gitea.io/gitea/models/user"
|
||||||
"code.gitea.io/gitea/modules/git"
|
"code.gitea.io/gitea/modules/git"
|
||||||
@ -156,26 +155,6 @@ func init() {
|
|||||||
db.RegisterModel(new(PullRequest))
|
db.RegisterModel(new(PullRequest))
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeletePullsByBaseRepoID deletes all pull requests by the base repository ID
|
|
||||||
func DeletePullsByBaseRepoID(ctx context.Context, repoID int64) error {
|
|
||||||
deleteCond := builder.Select("id").From("pull_request").Where(builder.Eq{"pull_request.base_repo_id": repoID})
|
|
||||||
|
|
||||||
// Delete scheduled auto merges
|
|
||||||
if _, err := db.GetEngine(ctx).In("pull_id", deleteCond).
|
|
||||||
Delete(&pull_model.AutoMerge{}); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// Delete review states
|
|
||||||
if _, err := db.GetEngine(ctx).In("pull_id", deleteCond).
|
|
||||||
Delete(&pull_model.ReviewState{}); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err := db.DeleteByBean(ctx, &PullRequest{BaseRepoID: repoID})
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
func (pr *PullRequest) String() string {
|
func (pr *PullRequest) String() string {
|
||||||
if pr == nil {
|
if pr == nil {
|
||||||
return "<PullRequest nil>"
|
return "<PullRequest nil>"
|
||||||
|
@ -12,6 +12,7 @@ import (
|
|||||||
issues_model "code.gitea.io/gitea/models/issues"
|
issues_model "code.gitea.io/gitea/models/issues"
|
||||||
access_model "code.gitea.io/gitea/models/perm/access"
|
access_model "code.gitea.io/gitea/models/perm/access"
|
||||||
project_model "code.gitea.io/gitea/models/project"
|
project_model "code.gitea.io/gitea/models/project"
|
||||||
|
pull_model "code.gitea.io/gitea/models/pull"
|
||||||
repo_model "code.gitea.io/gitea/models/repo"
|
repo_model "code.gitea.io/gitea/models/repo"
|
||||||
system_model "code.gitea.io/gitea/models/system"
|
system_model "code.gitea.io/gitea/models/system"
|
||||||
user_model "code.gitea.io/gitea/models/user"
|
user_model "code.gitea.io/gitea/models/user"
|
||||||
@ -267,10 +268,6 @@ func deleteIssue(ctx context.Context, issue *issues_model.Issue) ([]string, erro
|
|||||||
}
|
}
|
||||||
defer committer.Close()
|
defer committer.Close()
|
||||||
|
|
||||||
if _, err := db.GetEngine(ctx).ID(issue.ID).NoAutoCondition().Delete(issue); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
// update the total issue numbers
|
// update the total issue numbers
|
||||||
if err := repo_model.UpdateRepoIssueNumbers(ctx, issue.RepoID, issue.IsPull, false); err != nil {
|
if err := repo_model.UpdateRepoIssueNumbers(ctx, issue.RepoID, issue.IsPull, false); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -302,6 +299,13 @@ func deleteIssue(ctx context.Context, issue *issues_model.Issue) ([]string, erro
|
|||||||
}
|
}
|
||||||
|
|
||||||
// deference all review comments
|
// deference all review comments
|
||||||
|
if err := issue.LoadRepo(ctx); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if err := issue.LoadPullRequest(ctx); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
if err := issue.LoadComments(ctx); err != nil {
|
if err := issue.LoadComments(ctx); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -335,17 +339,8 @@ func deleteIssue(ctx context.Context, issue *issues_model.Issue) ([]string, erro
|
|||||||
}
|
}
|
||||||
|
|
||||||
if comment.ReviewID > 0 {
|
if comment.ReviewID > 0 {
|
||||||
if err := comment.LoadIssue(ctx); err != nil {
|
if err := git.RemoveRef(ctx, issue.Repo.RepoPath(), issues_model.GetCodeCommentRef(issue.PullRequest.Index, comment.ID)); err != nil {
|
||||||
return nil, err
|
log.Error("Unable to remove ref in base repository for PR[%d] Error: %v", issue.PullRequest.ID, err)
|
||||||
}
|
|
||||||
if err := comment.Issue.LoadRepo(ctx); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
if err := comment.Issue.LoadPullRequest(ctx); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
if err := git.RemoveRef(ctx, comment.Issue.Repo.RepoPath(), issues_model.GetCodeCommentRef(comment.Issue.PullRequest.Index, comment.ID)); err != nil {
|
|
||||||
log.Error("Unable to remove ref in base repository for PR[%d] Error: %v", comment.Issue.PullRequest.ID, err)
|
|
||||||
// We should not return error here, because the comment has been removed from database.
|
// We should not return error here, because the comment has been removed from database.
|
||||||
// users have to delete this ref manually or we should have a synchronize between
|
// users have to delete this ref manually or we should have a synchronize between
|
||||||
// database comment table and git refs.
|
// database comment table and git refs.
|
||||||
@ -364,6 +359,29 @@ func deleteIssue(ctx context.Context, issue *issues_model.Issue) ([]string, erro
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// delete all pull request records
|
||||||
|
if issue.IsPull {
|
||||||
|
// Delete scheduled auto merges
|
||||||
|
if _, err := db.GetEngine(ctx).Where("pull_id=?", issue.PullRequest.ID).
|
||||||
|
Delete(&pull_model.AutoMerge{}); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Delete review states
|
||||||
|
if _, err := db.GetEngine(ctx).Where("pull_id=?", issue.PullRequest.ID).
|
||||||
|
Delete(&pull_model.ReviewState{}); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, err := db.GetEngine(ctx).ID(issue.PullRequest.ID).Delete(&issues_model.PullRequest{}); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, err := db.GetEngine(ctx).ID(issue.ID).NoAutoCondition().Delete(issue); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
if err := committer.Commit(); err != nil {
|
if err := committer.Commit(); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -97,10 +97,6 @@ func DeleteRepositoryDirectly(ctx context.Context, repoID int64, ignoreOrgTeams
|
|||||||
}
|
}
|
||||||
needRewriteKeysFile := deleted > 0
|
needRewriteKeysFile := deleted > 0
|
||||||
|
|
||||||
if err := deleteDBRepository(ctx, repoID); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if org != nil && org.IsOrganization() {
|
if org != nil && org.IsOrganization() {
|
||||||
teams, err := organization.FindOrgTeams(ctx, org.ID)
|
teams, err := organization.FindOrgTeams(ctx, org.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -187,11 +183,6 @@ func DeleteRepositoryDirectly(ctx context.Context, repoID int64, ignoreOrgTeams
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete Pulls and related objects
|
|
||||||
if err := issues_model.DeletePullsByBaseRepoID(ctx, repoID); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// Delete Issues and related objects
|
// Delete Issues and related objects
|
||||||
var attachmentPaths []string
|
var attachmentPaths []string
|
||||||
if attachmentPaths, err = issue_service.DeleteIssuesByRepoID(ctx, repoID); err != nil {
|
if attachmentPaths, err = issue_service.DeleteIssuesByRepoID(ctx, repoID); err != nil {
|
||||||
@ -291,6 +282,11 @@ func DeleteRepositoryDirectly(ctx context.Context, repoID int64, ignoreOrgTeams
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// delete all related database records first before deleting the repository record
|
||||||
|
if err := deleteDBRepository(ctx, repoID); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
if err = committer.Commit(); err != nil {
|
if err = committer.Commit(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user