mirror of
https://github.com/go-gitea/gitea
synced 2025-07-22 18:28:37 +00:00
* Make branch deletion URL more like GitHub's, fixes #1397 * Add PR branch deletion integration test * Do not allow deleting protected branch * Change http error code to 403 if user has no write rights to repository * Add check to not panic if forked repository has alrady been deleted
This commit is contained in:
@@ -647,19 +647,21 @@ func ViewIssue(ctx *context.Context) {
|
||||
pull := issue.PullRequest
|
||||
canDelete := false
|
||||
|
||||
if ctx.IsSigned && pull.HeadBranch != "master" {
|
||||
if ctx.IsSigned {
|
||||
if err := pull.GetHeadRepo(); err != nil {
|
||||
log.Error(4, "GetHeadRepo: %v", err)
|
||||
} else if ctx.User.IsWriterOfRepo(pull.HeadRepo) {
|
||||
canDelete = true
|
||||
deleteBranchURL := pull.HeadRepo.Link() + "/branches/" + pull.HeadBranch + "/delete"
|
||||
ctx.Data["DeleteBranchLink"] = fmt.Sprintf("%s?commit=%s&redirect_to=%s&issue_id=%d",
|
||||
deleteBranchURL, pull.MergedCommitID, ctx.Data["Link"], issue.ID)
|
||||
|
||||
} else if pull.HeadRepo != nil && pull.HeadBranch != pull.HeadRepo.DefaultBranch && ctx.User.IsWriterOfRepo(pull.HeadRepo) {
|
||||
// Check if branch is not protected
|
||||
if protected, err := pull.HeadRepo.IsProtectedBranch(pull.HeadBranch); err != nil {
|
||||
log.Error(4, "IsProtectedBranch: %v", err)
|
||||
} else if !protected {
|
||||
canDelete = true
|
||||
ctx.Data["DeleteBranchLink"] = ctx.Repo.RepoLink + "/pulls/" + com.ToStr(issue.Index) + "/cleanup"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ctx.Data["IsPullBranchDeletable"] = canDelete && git.IsBranchExist(pull.HeadRepo.RepoPath(), pull.HeadBranch)
|
||||
ctx.Data["IsPullBranchDeletable"] = canDelete && pull.HeadRepo != nil && git.IsBranchExist(pull.HeadRepo.RepoPath(), pull.HeadBranch)
|
||||
}
|
||||
|
||||
ctx.Data["Participants"] = participants
|
||||
|
Reference in New Issue
Block a user