mirror of
				https://github.com/go-gitea/gitea
				synced 2025-10-31 11:28:24 +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 { | ||||
| 	_, 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 | ||||
| } | ||||
|   | ||||
| @@ -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 { | ||||
|   | ||||
| @@ -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) | ||||
|  | ||||
|   | ||||
| @@ -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 | ||||
| 	} | ||||
|   | ||||
| @@ -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, | ||||
| 		}) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user