mirror of
				https://github.com/go-gitea/gitea
				synced 2025-11-04 05:18:25 +00:00 
			
		
		
		
	Delete dev links when repository/issue/pull/branch deleted
This commit is contained in:
		@@ -64,8 +64,8 @@ func CreateIssueDevLink(ctx context.Context, link *IssueDevLink) error {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
func DeleteIssueDevLinkByBranchName(ctx context.Context, repoID int64, branchName string) error {
 | 
					func DeleteIssueDevLinkByBranchName(ctx context.Context, repoID int64, branchName string) error {
 | 
				
			||||||
	_, err := db.GetEngine(ctx).
 | 
						_, err := db.GetEngine(ctx).
 | 
				
			||||||
		Where("link_type = ? AND link_index = ? AND linked_repo_id = ?",
 | 
							Where("linked_repo_id = ? AND link_type = ? AND link_index = ?",
 | 
				
			||||||
			IssueDevLinkTypeBranch, branchName, repoID).
 | 
								repoID, IssueDevLinkTypeBranch, branchName).
 | 
				
			||||||
		Delete(new(IssueDevLink))
 | 
							Delete(new(IssueDevLink))
 | 
				
			||||||
	return err
 | 
						return err
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -718,6 +718,10 @@ func DeleteIssuesByRepoID(ctx context.Context, repoID int64) (attachmentPaths []
 | 
				
			|||||||
			return nil, err
 | 
								return nil, err
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							if _, err = sess.In("issue_id", issueIDs).Delete(&IssueDevLink{}); err != nil {
 | 
				
			||||||
 | 
								return nil, err
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		var attachments []*repo_model.Attachment
 | 
							var attachments []*repo_model.Attachment
 | 
				
			||||||
		err = sess.In("issue_id", issueIDs).Find(&attachments)
 | 
							err = sess.In("issue_id", issueIDs).Find(&attachments)
 | 
				
			||||||
		if err != nil {
 | 
							if err != nil {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -114,6 +114,10 @@ func HookPostReceive(ctx *gitea_context.PrivateContext) {
 | 
				
			|||||||
					})
 | 
										})
 | 
				
			||||||
					return
 | 
										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 {
 | 
								} else {
 | 
				
			||||||
				branchesToSync = append(branchesToSync, update)
 | 
									branchesToSync = append(branchesToSync, update)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -283,6 +283,12 @@ func deleteIssue(ctx context.Context, issue *issues_model.Issue) error {
 | 
				
			|||||||
		return err
 | 
							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
 | 
						// find attachments related to this issue and remove them
 | 
				
			||||||
	if err := issue.LoadAttributes(ctx); err != nil {
 | 
						if err := issue.LoadAttributes(ctx); err != nil {
 | 
				
			||||||
		return err
 | 
							return err
 | 
				
			||||||
@@ -311,6 +317,7 @@ func deleteIssue(ctx context.Context, issue *issues_model.Issue) error {
 | 
				
			|||||||
		&issues_model.Comment{RefIssueID: issue.ID},
 | 
							&issues_model.Comment{RefIssueID: issue.ID},
 | 
				
			||||||
		&issues_model.IssueDependency{DependencyID: issue.ID},
 | 
							&issues_model.IssueDependency{DependencyID: issue.ID},
 | 
				
			||||||
		&issues_model.Comment{DependentIssueID: issue.ID},
 | 
							&issues_model.Comment{DependentIssueID: issue.ID},
 | 
				
			||||||
 | 
							&issues_model.IssueDevLink{IssueID: issue.ID},
 | 
				
			||||||
	); err != nil {
 | 
						); err != nil {
 | 
				
			||||||
		return err
 | 
							return err
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -501,6 +501,10 @@ func DeleteBranch(ctx context.Context, doer *user_model.User, repo *repo_model.R
 | 
				
			|||||||
			return err
 | 
								return err
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							if err := issues_model.DeleteIssueDevLinkByBranchName(ctx, repo.ID, branchName); err != nil {
 | 
				
			||||||
 | 
								return err
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		return gitRepo.DeleteBranch(branchName, git.DeleteBranchOptions{
 | 
							return gitRepo.DeleteBranch(branchName, git.DeleteBranchOptions{
 | 
				
			||||||
			Force: true,
 | 
								Force: true,
 | 
				
			||||||
		})
 | 
							})
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user