diff options
author | 6543 <6543@obermui.de> | 2024-11-27 05:41:06 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-11-27 05:41:06 +0100 |
commit | 846f6187168c807e1353d46d5d2260bf077b43cd (patch) | |
tree | c3c36ad22c01cdaeaa71fd5e7e9fd0cb7738538f /routers/api/v1 | |
parent | 3fc1bbe971db0b1591d32c4f561fdccc9c34daf4 (diff) | |
download | gitea-846f6187168c807e1353d46d5d2260bf077b43cd.tar.gz gitea-846f6187168c807e1353d46d5d2260bf077b43cd.zip |
Add priority to protected branch (#32286)
## Solves
Currently for rules to re-order them you have to alter the creation
date. so you basicly have to delete and recreate them in the right
order. This is more than just inconvinient ...
## Solution
Add a new col for prioritization
## Demo WebUI Video
https://github.com/user-attachments/assets/92182a31-9705-4ac5-b6e3-9bb74108cbd1
---
*Sponsored by Kithara Software GmbH*
Diffstat (limited to 'routers/api/v1')
-rw-r--r-- | routers/api/v1/api.go | 1 | ||||
-rw-r--r-- | routers/api/v1/repo/branch.go | 56 | ||||
-rw-r--r-- | routers/api/v1/swagger/options.go | 3 |
3 files changed, 56 insertions, 4 deletions
diff --git a/routers/api/v1/api.go b/routers/api/v1/api.go index aee76325a8..f28ee980e1 100644 --- a/routers/api/v1/api.go +++ b/routers/api/v1/api.go @@ -1204,6 +1204,7 @@ func Routes() *web.Router { m.Patch("", bind(api.EditBranchProtectionOption{}), mustNotBeArchived, repo.EditBranchProtection) m.Delete("", repo.DeleteBranchProtection) }) + m.Post("/priority", bind(api.UpdateBranchProtectionPriories{}), mustNotBeArchived, repo.UpdateBranchProtectionPriories) }, reqToken(), reqAdmin()) m.Group("/tags", func() { m.Get("", repo.ListTags) diff --git a/routers/api/v1/repo/branch.go b/routers/api/v1/repo/branch.go index 1cea7d8c72..45c5c1cd14 100644 --- a/routers/api/v1/repo/branch.go +++ b/routers/api/v1/repo/branch.go @@ -618,6 +618,7 @@ func CreateBranchProtection(ctx *context.APIContext) { protectBranch = &git_model.ProtectedBranch{ RepoID: ctx.Repo.Repository.ID, RuleName: ruleName, + Priority: form.Priority, CanPush: form.EnablePush, EnableWhitelist: form.EnablePush && form.EnablePushWhitelist, WhitelistDeployKeys: form.EnablePush && form.EnablePushWhitelist && form.PushWhitelistDeployKeys, @@ -640,7 +641,7 @@ func CreateBranchProtection(ctx *context.APIContext) { BlockAdminMergeOverride: form.BlockAdminMergeOverride, } - err = git_model.UpdateProtectBranch(ctx, ctx.Repo.Repository, protectBranch, git_model.WhitelistOptions{ + if err := git_model.UpdateProtectBranch(ctx, ctx.Repo.Repository, protectBranch, git_model.WhitelistOptions{ UserIDs: whitelistUsers, TeamIDs: whitelistTeams, ForcePushUserIDs: forcePushAllowlistUsers, @@ -649,14 +650,13 @@ func CreateBranchProtection(ctx *context.APIContext) { MergeTeamIDs: mergeWhitelistTeams, ApprovalsUserIDs: approvalsWhitelistUsers, ApprovalsTeamIDs: approvalsWhitelistTeams, - }) - if err != nil { + }); err != nil { ctx.Error(http.StatusInternalServerError, "UpdateProtectBranch", err) return } if isBranchExist { - if err = pull_service.CheckPRsForBaseBranch(ctx, ctx.Repo.Repository, ruleName); err != nil { + if err := pull_service.CheckPRsForBaseBranch(ctx, ctx.Repo.Repository, ruleName); err != nil { ctx.Error(http.StatusInternalServerError, "CheckPRsForBaseBranch", err) return } @@ -796,6 +796,10 @@ func EditBranchProtection(ctx *context.APIContext) { } } + if form.Priority != nil { + protectBranch.Priority = *form.Priority + } + if form.EnableMergeWhitelist != nil { protectBranch.EnableMergeWhitelist = *form.EnableMergeWhitelist } @@ -1080,3 +1084,47 @@ func DeleteBranchProtection(ctx *context.APIContext) { ctx.Status(http.StatusNoContent) } + +// UpdateBranchProtectionPriories updates the priorities of branch protections for a repo +func UpdateBranchProtectionPriories(ctx *context.APIContext) { + // swagger:operation POST /repos/{owner}/{repo}/branch_protections/priority repository repoUpdateBranchProtectionPriories + // --- + // summary: Update the priorities of branch protections for a repository. + // consumes: + // - application/json + // produces: + // - application/json + // parameters: + // - name: owner + // in: path + // description: owner of the repo + // type: string + // required: true + // - name: repo + // in: path + // description: name of the repo + // type: string + // required: true + // - name: body + // in: body + // schema: + // "$ref": "#/definitions/UpdateBranchProtectionPriories" + // responses: + // "204": + // "$ref": "#/responses/empty" + // "404": + // "$ref": "#/responses/notFound" + // "422": + // "$ref": "#/responses/validationError" + // "423": + // "$ref": "#/responses/repoArchivedError" + form := web.GetForm(ctx).(*api.UpdateBranchProtectionPriories) + repo := ctx.Repo.Repository + + if err := git_model.UpdateProtectBranchPriorities(ctx, repo, form.IDs); err != nil { + ctx.Error(http.StatusInternalServerError, "UpdateProtectBranchPriorities", err) + return + } + + ctx.Status(http.StatusNoContent) +} diff --git a/routers/api/v1/swagger/options.go b/routers/api/v1/swagger/options.go index 1de58632d5..39c98c666e 100644 --- a/routers/api/v1/swagger/options.go +++ b/routers/api/v1/swagger/options.go @@ -147,6 +147,9 @@ type swaggerParameterBodies struct { EditBranchProtectionOption api.EditBranchProtectionOption // in:body + UpdateBranchProtectionPriories api.UpdateBranchProtectionPriories + + // in:body CreateOAuth2ApplicationOptions api.CreateOAuth2ApplicationOptions // in:body |