File tree Expand file tree Collapse file tree 2 files changed +17
-3
lines changed Expand file tree Collapse file tree 2 files changed +17
-3
lines changed Original file line number Diff line number Diff line change @@ -651,8 +651,13 @@ func ViewIssue(ctx *context.Context) {
651
651
if err := pull .GetHeadRepo (); err != nil {
652
652
log .Error (4 , "GetHeadRepo: %v" , err )
653
653
} else if pull .HeadBranch != pull .HeadRepo .DefaultBranch && ctx .User .IsWriterOfRepo (pull .HeadRepo ) {
654
- canDelete = true
655
- ctx .Data ["DeleteBranchLink" ] = ctx .Repo .RepoLink + "/pulls/" + com .ToStr (issue .Index ) + "/cleanup"
654
+ // Check if branch is not protected
655
+ if protected , err := pull .HeadRepo .IsProtectedBranch (pull .HeadBranch ); err != nil {
656
+ log .Error (4 , "IsProtectedBranch: %v" , err )
657
+ } else if ! protected {
658
+ canDelete = true
659
+ ctx .Data ["DeleteBranchLink" ] = ctx .Repo .RepoLink + "/pulls/" + com .ToStr (issue .Index ) + "/cleanup"
660
+ }
656
661
}
657
662
}
658
663
Original file line number Diff line number Diff line change @@ -788,7 +788,7 @@ func CleanUpPullRequest(ctx *context.Context) {
788
788
ctx .Handle (500 , "GetBaseRepo" , err )
789
789
return
790
790
} else if pr .HeadRepo .GetOwner (); err != nil {
791
- ctx .Handle (500 , "GetOwner" , err )
791
+ ctx .Handle (500 , "HeadRepo. GetOwner" , err )
792
792
return
793
793
}
794
794
@@ -822,6 +822,15 @@ func CleanUpPullRequest(ctx *context.Context) {
822
822
return
823
823
}
824
824
825
+ // Check if branch is not protected
826
+ if protected , err := pr .HeadRepo .IsProtectedBranch (pr .HeadBranch ); err != nil || protected {
827
+ if err != nil {
828
+ log .Error (4 , "HeadRepo.IsProtectedBranch: %v" , err )
829
+ }
830
+ ctx .Flash .Error (ctx .Tr ("repo.branch.deletion_failed" , fullBranchName ))
831
+ return
832
+ }
833
+
825
834
// Check if branch has no new commits
826
835
if len (pr .MergedCommitID ) > 0 {
827
836
branchCommitID , err := gitRepo .GetBranchCommitID (pr .HeadBranch )
You can’t perform that action at this time.
0 commit comments