@@ -618,6 +618,7 @@ func CreateBranchProtection(ctx *context.APIContext) {
618
618
protectBranch = & git_model.ProtectedBranch {
619
619
RepoID : ctx .Repo .Repository .ID ,
620
620
RuleName : ruleName ,
621
+ Priority : form .Priority ,
621
622
CanPush : form .EnablePush ,
622
623
EnableWhitelist : form .EnablePush && form .EnablePushWhitelist ,
623
624
WhitelistDeployKeys : form .EnablePush && form .EnablePushWhitelist && form .PushWhitelistDeployKeys ,
@@ -640,7 +641,7 @@ func CreateBranchProtection(ctx *context.APIContext) {
640
641
BlockAdminMergeOverride : form .BlockAdminMergeOverride ,
641
642
}
642
643
643
- err = git_model .UpdateProtectBranch (ctx , ctx .Repo .Repository , protectBranch , git_model.WhitelistOptions {
644
+ if err : = git_model .UpdateProtectBranch (ctx , ctx .Repo .Repository , protectBranch , git_model.WhitelistOptions {
644
645
UserIDs : whitelistUsers ,
645
646
TeamIDs : whitelistTeams ,
646
647
ForcePushUserIDs : forcePushAllowlistUsers ,
@@ -649,14 +650,13 @@ func CreateBranchProtection(ctx *context.APIContext) {
649
650
MergeTeamIDs : mergeWhitelistTeams ,
650
651
ApprovalsUserIDs : approvalsWhitelistUsers ,
651
652
ApprovalsTeamIDs : approvalsWhitelistTeams ,
652
- })
653
- if err != nil {
653
+ }); err != nil {
654
654
ctx .Error (http .StatusInternalServerError , "UpdateProtectBranch" , err )
655
655
return
656
656
}
657
657
658
658
if isBranchExist {
659
- if err = pull_service .CheckPRsForBaseBranch (ctx , ctx .Repo .Repository , ruleName ); err != nil {
659
+ if err : = pull_service .CheckPRsForBaseBranch (ctx , ctx .Repo .Repository , ruleName ); err != nil {
660
660
ctx .Error (http .StatusInternalServerError , "CheckPRsForBaseBranch" , err )
661
661
return
662
662
}
@@ -796,6 +796,10 @@ func EditBranchProtection(ctx *context.APIContext) {
796
796
}
797
797
}
798
798
799
+ if form .Priority != nil {
800
+ protectBranch .Priority = * form .Priority
801
+ }
802
+
799
803
if form .EnableMergeWhitelist != nil {
800
804
protectBranch .EnableMergeWhitelist = * form .EnableMergeWhitelist
801
805
}
@@ -1080,3 +1084,47 @@ func DeleteBranchProtection(ctx *context.APIContext) {
1080
1084
1081
1085
ctx .Status (http .StatusNoContent )
1082
1086
}
1087
+
1088
+ // UpdateBranchProtectionPriories updates the priorities of branch protections for a repo
1089
+ func UpdateBranchProtectionPriories (ctx * context.APIContext ) {
1090
+ // swagger:operation POST /repos/{owner}/{repo}/branch_protections/priority repository repoUpdateBranchProtectionPriories
1091
+ // ---
1092
+ // summary: Update the priorities of branch protections for a repository.
1093
+ // consumes:
1094
+ // - application/json
1095
+ // produces:
1096
+ // - application/json
1097
+ // parameters:
1098
+ // - name: owner
1099
+ // in: path
1100
+ // description: owner of the repo
1101
+ // type: string
1102
+ // required: true
1103
+ // - name: repo
1104
+ // in: path
1105
+ // description: name of the repo
1106
+ // type: string
1107
+ // required: true
1108
+ // - name: body
1109
+ // in: body
1110
+ // schema:
1111
+ // "$ref": "#/definitions/UpdateBranchProtectionPriories"
1112
+ // responses:
1113
+ // "204":
1114
+ // "$ref": "#/responses/empty"
1115
+ // "404":
1116
+ // "$ref": "#/responses/notFound"
1117
+ // "422":
1118
+ // "$ref": "#/responses/validationError"
1119
+ // "423":
1120
+ // "$ref": "#/responses/repoArchivedError"
1121
+ form := web .GetForm (ctx ).(* api.UpdateBranchProtectionPriories )
1122
+ repo := ctx .Repo .Repository
1123
+
1124
+ if err := git_model .UpdateProtectBranchPriorities (ctx , repo , form .IDs ); err != nil {
1125
+ ctx .Error (http .StatusInternalServerError , "UpdateProtectBranchPriorities" , err )
1126
+ return
1127
+ }
1128
+
1129
+ ctx .Status (http .StatusNoContent )
1130
+ }
0 commit comments