@@ -618,6 +618,7 @@ func CreateBranchProtection(ctx *context.APIContext) {
618618	protectBranch  =  & git_model.ProtectedBranch {
619619		RepoID :                        ctx .Repo .Repository .ID ,
620620		RuleName :                      ruleName ,
621+ 		Priority :                      form .Priority ,
621622		CanPush :                       form .EnablePush ,
622623		EnableWhitelist :               form .EnablePush  &&  form .EnablePushWhitelist ,
623624		WhitelistDeployKeys :           form .EnablePush  &&  form .EnablePushWhitelist  &&  form .PushWhitelistDeployKeys ,
@@ -640,7 +641,7 @@ func CreateBranchProtection(ctx *context.APIContext) {
640641		BlockAdminMergeOverride :       form .BlockAdminMergeOverride ,
641642	}
642643
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 {
644645		UserIDs :          whitelistUsers ,
645646		TeamIDs :          whitelistTeams ,
646647		ForcePushUserIDs : forcePushAllowlistUsers ,
@@ -649,14 +650,13 @@ func CreateBranchProtection(ctx *context.APIContext) {
649650		MergeTeamIDs :     mergeWhitelistTeams ,
650651		ApprovalsUserIDs : approvalsWhitelistUsers ,
651652		ApprovalsTeamIDs : approvalsWhitelistTeams ,
652- 	})
653- 	if  err  !=  nil  {
653+ 	}); err  !=  nil  {
654654		ctx .Error (http .StatusInternalServerError , "UpdateProtectBranch" , err )
655655		return 
656656	}
657657
658658	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  {
660660			ctx .Error (http .StatusInternalServerError , "CheckPRsForBaseBranch" , err )
661661			return 
662662		}
@@ -796,6 +796,10 @@ func EditBranchProtection(ctx *context.APIContext) {
796796		}
797797	}
798798
799+ 	if  form .Priority  !=  nil  {
800+ 		protectBranch .Priority  =  * form .Priority 
801+ 	}
802+ 
799803	if  form .EnableMergeWhitelist  !=  nil  {
800804		protectBranch .EnableMergeWhitelist  =  * form .EnableMergeWhitelist 
801805	}
@@ -1080,3 +1084,47 @@ func DeleteBranchProtection(ctx *context.APIContext) {
10801084
10811085	ctx .Status (http .StatusNoContent )
10821086}
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