Skip to content

Commit 3ed30a7

Browse files
committed
Add api to update
1 parent 6c1ffb7 commit 3ed30a7

File tree

5 files changed

+112
-0
lines changed

5 files changed

+112
-0
lines changed

modules/structs/repo_branch.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,3 +125,6 @@ type EditBranchProtectionOption struct {
125125
ProtectedFilePatterns *string `json:"protected_file_patterns"`
126126
UnprotectedFilePatterns *string `json:"unprotected_file_patterns"`
127127
}
128+
129+
// UpdateBranchProtectionPriories a list to update the branch protection rule priorities
130+
type UpdateBranchProtectionPriories []int64

routers/api/v1/api.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1196,6 +1196,7 @@ func Routes() *web.Router {
11961196
m.Patch("", bind(api.EditBranchProtectionOption{}), mustNotBeArchived, repo.EditBranchProtection)
11971197
m.Delete("", repo.DeleteBranchProtection)
11981198
})
1199+
m.Post("/priority/move", bind(api.UpdateBranchProtectionPriories{}), mustNotBeArchived, repo.UpdateBranchProtectionPriories)
11991200
}, reqToken(), reqAdmin())
12001201
m.Group("/tags", func() {
12011202
m.Get("", repo.ListTags)

routers/api/v1/repo/branch.go

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1085,3 +1085,47 @@ func DeleteBranchProtection(ctx *context.APIContext) {
10851085

10861086
ctx.Status(http.StatusNoContent)
10871087
}
1088+
1089+
// UpdateBranchProtectionPriories updates the priorities of branch protections for a repo
1090+
func UpdateBranchProtectionPriories(ctx *context.APIContext) {
1091+
// swagger:operation POST /repos/{owner}/{repo}/branch_protections/priority/move repository repoUpdateBranchProtectionPriories
1092+
// ---
1093+
// summary: Update the priorities of branch protections for a repository.
1094+
// consumes:
1095+
// - application/json
1096+
// produces:
1097+
// - application/json
1098+
// parameters:
1099+
// - name: owner
1100+
// in: path
1101+
// description: owner of the repo
1102+
// type: string
1103+
// required: true
1104+
// - name: repo
1105+
// in: path
1106+
// description: name of the repo
1107+
// type: string
1108+
// required: true
1109+
// - name: body
1110+
// in: body
1111+
// schema:
1112+
// "$ref": "#/definitions/UpdateBranchProtectionPriories"
1113+
// responses:
1114+
// "204":
1115+
// "$ref": "#/responses/empty"
1116+
// "404":
1117+
// "$ref": "#/responses/notFound"
1118+
// "422":
1119+
// "$ref": "#/responses/validationError"
1120+
// "423":
1121+
// "$ref": "#/responses/repoArchivedError"
1122+
form := web.GetForm(ctx).(*api.UpdateBranchProtectionPriories)
1123+
repo := ctx.Repo.Repository
1124+
1125+
if err := git_model.UpdateProtectBranchPriorities(ctx, repo, *form); err != nil {
1126+
ctx.Error(http.StatusInternalServerError, "UpdateProtectBranchPriorities", err)
1127+
return
1128+
}
1129+
1130+
ctx.Status(http.StatusNoContent)
1131+
}

routers/api/v1/swagger/options.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,9 @@ type swaggerParameterBodies struct {
146146
// in:body
147147
EditBranchProtectionOption api.EditBranchProtectionOption
148148

149+
// in:body
150+
UpdateBranchProtectionPriories api.UpdateBranchProtectionPriories
151+
149152
// in:body
150153
CreateOAuth2ApplicationOptions api.CreateOAuth2ApplicationOptions
151154

templates/swagger/v1_json.tmpl

Lines changed: 61 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)