mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-08-03 09:52:26 +02:00
Move some code into models/git (#19879)
* Move access and repo permission to models/perm/access * fix test * Move some git related files into sub package models/git * Fix build * fix git test * move lfs to sub package * move more git related functions to models/git * Move functions sequence * Some improvements per @KN4CK3R and @delvh
This commit is contained in:
parent
a9dc9b06e4
commit
110fc57cbc
67 changed files with 549 additions and 495 deletions
|
@ -11,6 +11,7 @@ import (
|
|||
"net/http"
|
||||
|
||||
"code.gitea.io/gitea/models"
|
||||
git_model "code.gitea.io/gitea/models/git"
|
||||
"code.gitea.io/gitea/models/organization"
|
||||
user_model "code.gitea.io/gitea/models/user"
|
||||
"code.gitea.io/gitea/modules/context"
|
||||
|
@ -70,7 +71,7 @@ func GetBranch(ctx *context.APIContext) {
|
|||
return
|
||||
}
|
||||
|
||||
branchProtection, err := models.GetProtectedBranchBy(ctx, ctx.Repo.Repository.ID, branchName)
|
||||
branchProtection, err := git_model.GetProtectedBranchBy(ctx, ctx.Repo.Repository.ID, branchName)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "GetBranchProtection", err)
|
||||
return
|
||||
|
@ -206,7 +207,7 @@ func CreateBranch(ctx *context.APIContext) {
|
|||
return
|
||||
}
|
||||
|
||||
branchProtection, err := models.GetProtectedBranchBy(ctx, ctx.Repo.Repository.ID, branch.Name)
|
||||
branchProtection, err := git_model.GetProtectedBranchBy(ctx, ctx.Repo.Repository.ID, branch.Name)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "GetBranchProtection", err)
|
||||
return
|
||||
|
@ -271,7 +272,7 @@ func ListBranches(ctx *context.APIContext) {
|
|||
ctx.Error(http.StatusInternalServerError, "GetCommit", err)
|
||||
return
|
||||
}
|
||||
branchProtection, err := models.GetProtectedBranchBy(ctx, ctx.Repo.Repository.ID, branches[i].Name)
|
||||
branchProtection, err := git_model.GetProtectedBranchBy(ctx, ctx.Repo.Repository.ID, branches[i].Name)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "GetBranchProtection", err)
|
||||
return
|
||||
|
@ -320,7 +321,7 @@ func GetBranchProtection(ctx *context.APIContext) {
|
|||
|
||||
repo := ctx.Repo.Repository
|
||||
bpName := ctx.Params(":name")
|
||||
bp, err := models.GetProtectedBranchBy(ctx, repo.ID, bpName)
|
||||
bp, err := git_model.GetProtectedBranchBy(ctx, repo.ID, bpName)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "GetProtectedBranchByID", err)
|
||||
return
|
||||
|
@ -356,7 +357,7 @@ func ListBranchProtections(ctx *context.APIContext) {
|
|||
// "$ref": "#/responses/BranchProtectionList"
|
||||
|
||||
repo := ctx.Repo.Repository
|
||||
bps, err := models.GetProtectedBranches(repo.ID)
|
||||
bps, err := git_model.GetProtectedBranches(repo.ID)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "GetProtectedBranches", err)
|
||||
return
|
||||
|
@ -412,7 +413,7 @@ func CreateBranchProtection(ctx *context.APIContext) {
|
|||
return
|
||||
}
|
||||
|
||||
protectBranch, err := models.GetProtectedBranchBy(ctx, repo.ID, form.BranchName)
|
||||
protectBranch, err := git_model.GetProtectedBranchBy(ctx, repo.ID, form.BranchName)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "GetProtectBranchOfRepoByName", err)
|
||||
return
|
||||
|
@ -484,7 +485,7 @@ func CreateBranchProtection(ctx *context.APIContext) {
|
|||
}
|
||||
}
|
||||
|
||||
protectBranch = &models.ProtectedBranch{
|
||||
protectBranch = &git_model.ProtectedBranch{
|
||||
RepoID: ctx.Repo.Repository.ID,
|
||||
BranchName: form.BranchName,
|
||||
CanPush: form.EnablePush,
|
||||
|
@ -504,7 +505,7 @@ func CreateBranchProtection(ctx *context.APIContext) {
|
|||
BlockOnOutdatedBranch: form.BlockOnOutdatedBranch,
|
||||
}
|
||||
|
||||
err = models.UpdateProtectBranch(ctx, ctx.Repo.Repository, protectBranch, models.WhitelistOptions{
|
||||
err = git_model.UpdateProtectBranch(ctx, ctx.Repo.Repository, protectBranch, git_model.WhitelistOptions{
|
||||
UserIDs: whitelistUsers,
|
||||
TeamIDs: whitelistTeams,
|
||||
MergeUserIDs: mergeWhitelistUsers,
|
||||
|
@ -523,7 +524,7 @@ func CreateBranchProtection(ctx *context.APIContext) {
|
|||
}
|
||||
|
||||
// Reload from db to get all whitelists
|
||||
bp, err := models.GetProtectedBranchBy(ctx, ctx.Repo.Repository.ID, form.BranchName)
|
||||
bp, err := git_model.GetProtectedBranchBy(ctx, ctx.Repo.Repository.ID, form.BranchName)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "GetProtectedBranchByID", err)
|
||||
return
|
||||
|
@ -575,7 +576,7 @@ func EditBranchProtection(ctx *context.APIContext) {
|
|||
form := web.GetForm(ctx).(*api.EditBranchProtectionOption)
|
||||
repo := ctx.Repo.Repository
|
||||
bpName := ctx.Params(":name")
|
||||
protectBranch, err := models.GetProtectedBranchBy(ctx, repo.ID, bpName)
|
||||
protectBranch, err := git_model.GetProtectedBranchBy(ctx, repo.ID, bpName)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "GetProtectedBranchByID", err)
|
||||
return
|
||||
|
@ -739,7 +740,7 @@ func EditBranchProtection(ctx *context.APIContext) {
|
|||
}
|
||||
}
|
||||
|
||||
err = models.UpdateProtectBranch(ctx, ctx.Repo.Repository, protectBranch, models.WhitelistOptions{
|
||||
err = git_model.UpdateProtectBranch(ctx, ctx.Repo.Repository, protectBranch, git_model.WhitelistOptions{
|
||||
UserIDs: whitelistUsers,
|
||||
TeamIDs: whitelistTeams,
|
||||
MergeUserIDs: mergeWhitelistUsers,
|
||||
|
@ -758,7 +759,7 @@ func EditBranchProtection(ctx *context.APIContext) {
|
|||
}
|
||||
|
||||
// Reload from db to ensure get all whitelists
|
||||
bp, err := models.GetProtectedBranchBy(ctx, repo.ID, bpName)
|
||||
bp, err := git_model.GetProtectedBranchBy(ctx, repo.ID, bpName)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "GetProtectedBranchBy", err)
|
||||
return
|
||||
|
@ -802,7 +803,7 @@ func DeleteBranchProtection(ctx *context.APIContext) {
|
|||
|
||||
repo := ctx.Repo.Repository
|
||||
bpName := ctx.Params(":name")
|
||||
bp, err := models.GetProtectedBranchBy(ctx, repo.ID, bpName)
|
||||
bp, err := git_model.GetProtectedBranchBy(ctx, repo.ID, bpName)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "GetProtectedBranchByID", err)
|
||||
return
|
||||
|
@ -812,7 +813,7 @@ func DeleteBranchProtection(ctx *context.APIContext) {
|
|||
return
|
||||
}
|
||||
|
||||
if err := models.DeleteProtectedBranch(ctx.Repo.Repository.ID, bp.ID); err != nil {
|
||||
if err := git_model.DeleteProtectedBranch(ctx.Repo.Repository.ID, bp.ID); err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "DeleteProtectedBranch", err)
|
||||
return
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue