1
1
mirror of https://github.com/go-gitea/gitea synced 2025-01-09 09:24:25 +00:00

Delete dev links when repository/issue/pull/branch deleted

This commit is contained in:
Lunny Xiao 2024-08-29 12:13:49 -07:00
parent e64f2322de
commit 6b829f77a3
No known key found for this signature in database
GPG Key ID: C3B7C91B632F738A
5 changed files with 21 additions and 2 deletions

View File

@ -64,8 +64,8 @@ func CreateIssueDevLink(ctx context.Context, link *IssueDevLink) error {
func DeleteIssueDevLinkByBranchName(ctx context.Context, repoID int64, branchName string) error {
_, err := db.GetEngine(ctx).
Where("link_type = ? AND link_index = ? AND linked_repo_id = ?",
IssueDevLinkTypeBranch, branchName, repoID).
Where("linked_repo_id = ? AND link_type = ? AND link_index = ?",
repoID, IssueDevLinkTypeBranch, branchName).
Delete(new(IssueDevLink))
return err
}

View File

@ -718,6 +718,10 @@ func DeleteIssuesByRepoID(ctx context.Context, repoID int64) (attachmentPaths []
return nil, err
}
if _, err = sess.In("issue_id", issueIDs).Delete(&IssueDevLink{}); err != nil {
return nil, err
}
var attachments []*repo_model.Attachment
err = sess.In("issue_id", issueIDs).Find(&attachments)
if err != nil {

View File

@ -114,6 +114,10 @@ func HookPostReceive(ctx *gitea_context.PrivateContext) {
})
return
}
if err := issues_model.DeleteIssueDevLinkByBranchName(ctx, repo.ID, update.RefFullName.BranchName()); err != nil {
log.Error("Failed to DeleteIssueDevLinkByBranchName: %s/%s %s Error: %v", ownerName, repoName, update.RefFullName.BranchName(), err)
}
} else {
branchesToSync = append(branchesToSync, update)

View File

@ -283,6 +283,12 @@ func deleteIssue(ctx context.Context, issue *issues_model.Issue) error {
return err
}
if issue.IsPull {
if err := issues_model.DeleteIssueDevLinkByPullRequestID(ctx, issue.ID); err != nil {
return err
}
}
// find attachments related to this issue and remove them
if err := issue.LoadAttributes(ctx); err != nil {
return err
@ -311,6 +317,7 @@ func deleteIssue(ctx context.Context, issue *issues_model.Issue) error {
&issues_model.Comment{RefIssueID: issue.ID},
&issues_model.IssueDependency{DependencyID: issue.ID},
&issues_model.Comment{DependentIssueID: issue.ID},
&issues_model.IssueDevLink{IssueID: issue.ID},
); err != nil {
return err
}

View File

@ -501,6 +501,10 @@ func DeleteBranch(ctx context.Context, doer *user_model.User, repo *repo_model.R
return err
}
if err := issues_model.DeleteIssueDevLinkByBranchName(ctx, repo.ID, branchName); err != nil {
return err
}
return gitRepo.DeleteBranch(branchName, git.DeleteBranchOptions{
Force: true,
})