Skip to content

Commit 6b829f7

Browse files
committed
Delete dev links when repository/issue/pull/branch deleted
1 parent e64f232 commit 6b829f7

File tree

5 files changed

+21
-2
lines changed

5 files changed

+21
-2
lines changed

models/issues/issue_dev_link.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ func CreateIssueDevLink(ctx context.Context, link *IssueDevLink) error {
6464

6565
func DeleteIssueDevLinkByBranchName(ctx context.Context, repoID int64, branchName string) error {
6666
_, err := db.GetEngine(ctx).
67-
Where("link_type = ? AND link_index = ? AND linked_repo_id = ?",
68-
IssueDevLinkTypeBranch, branchName, repoID).
67+
Where("linked_repo_id = ? AND link_type = ? AND link_index = ?",
68+
repoID, IssueDevLinkTypeBranch, branchName).
6969
Delete(new(IssueDevLink))
7070
return err
7171
}

models/issues/issue_update.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -718,6 +718,10 @@ func DeleteIssuesByRepoID(ctx context.Context, repoID int64) (attachmentPaths []
718718
return nil, err
719719
}
720720

721+
if _, err = sess.In("issue_id", issueIDs).Delete(&IssueDevLink{}); err != nil {
722+
return nil, err
723+
}
724+
721725
var attachments []*repo_model.Attachment
722726
err = sess.In("issue_id", issueIDs).Find(&attachments)
723727
if err != nil {

routers/private/hook_post_receive.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,10 @@ func HookPostReceive(ctx *gitea_context.PrivateContext) {
114114
})
115115
return
116116
}
117+
118+
if err := issues_model.DeleteIssueDevLinkByBranchName(ctx, repo.ID, update.RefFullName.BranchName()); err != nil {
119+
log.Error("Failed to DeleteIssueDevLinkByBranchName: %s/%s %s Error: %v", ownerName, repoName, update.RefFullName.BranchName(), err)
120+
}
117121
} else {
118122
branchesToSync = append(branchesToSync, update)
119123

services/issue/issue.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,12 @@ func deleteIssue(ctx context.Context, issue *issues_model.Issue) error {
283283
return err
284284
}
285285

286+
if issue.IsPull {
287+
if err := issues_model.DeleteIssueDevLinkByPullRequestID(ctx, issue.ID); err != nil {
288+
return err
289+
}
290+
}
291+
286292
// find attachments related to this issue and remove them
287293
if err := issue.LoadAttributes(ctx); err != nil {
288294
return err
@@ -311,6 +317,7 @@ func deleteIssue(ctx context.Context, issue *issues_model.Issue) error {
311317
&issues_model.Comment{RefIssueID: issue.ID},
312318
&issues_model.IssueDependency{DependencyID: issue.ID},
313319
&issues_model.Comment{DependentIssueID: issue.ID},
320+
&issues_model.IssueDevLink{IssueID: issue.ID},
314321
); err != nil {
315322
return err
316323
}

services/repository/branch.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -501,6 +501,10 @@ func DeleteBranch(ctx context.Context, doer *user_model.User, repo *repo_model.R
501501
return err
502502
}
503503

504+
if err := issues_model.DeleteIssueDevLinkByBranchName(ctx, repo.ID, branchName); err != nil {
505+
return err
506+
}
507+
504508
return gitRepo.DeleteBranch(branchName, git.DeleteBranchOptions{
505509
Force: true,
506510
})

0 commit comments

Comments
 (0)