mirror of
https://github.com/go-gitea/gitea
synced 2025-12-07 13:28:25 +00:00
Merge branch 'main' into allow-force-push-protected-branches
This commit is contained in:
+77
-13
@@ -512,19 +512,7 @@ func CommonRoutes() *web.Route {
|
||||
r.Get("/files/{id}/{version}/{filename}", pypi.DownloadPackageFile)
|
||||
r.Get("/simple/{id}", pypi.PackageMetadata)
|
||||
}, reqPackageAccess(perm.AccessModeRead))
|
||||
r.Group("/rpm", func() {
|
||||
r.Get(".repo", rpm.GetRepositoryConfig)
|
||||
r.Get("/repository.key", rpm.GetRepositoryKey)
|
||||
r.Put("/upload", reqPackageAccess(perm.AccessModeWrite), rpm.UploadPackageFile)
|
||||
r.Group("/package/{name}/{version}/{architecture}", func() {
|
||||
r.Get("", rpm.DownloadPackageFile)
|
||||
r.Delete("", reqPackageAccess(perm.AccessModeWrite), rpm.DeletePackageFile)
|
||||
})
|
||||
r.Group("/repodata/{filename}", func() {
|
||||
r.Head("", rpm.CheckRepositoryFileExistence)
|
||||
r.Get("", rpm.GetRepositoryFile)
|
||||
})
|
||||
}, reqPackageAccess(perm.AccessModeRead))
|
||||
r.Group("/rpm", RpmRoutes(r), reqPackageAccess(perm.AccessModeRead))
|
||||
r.Group("/rubygems", func() {
|
||||
r.Get("/specs.4.8.gz", rubygems.EnumeratePackages)
|
||||
r.Get("/latest_specs.4.8.gz", rubygems.EnumeratePackagesLatest)
|
||||
@@ -589,6 +577,82 @@ func CommonRoutes() *web.Route {
|
||||
return r
|
||||
}
|
||||
|
||||
// Support for uploading rpm packages with arbitrary depth paths
|
||||
func RpmRoutes(r *web.Route) func() {
|
||||
var (
|
||||
groupRepoInfo = regexp.MustCompile(`\A((?:/(?:[^/]+))*|)\.repo\z`)
|
||||
groupUpload = regexp.MustCompile(`\A((?:/(?:[^/]+))*|)/upload\z`)
|
||||
groupRpm = regexp.MustCompile(`\A((?:/(?:[^/]+))*|)/package/([^/]+)/([^/]+)/([^/]+)(?:/([^/]+\.rpm)|)\z`)
|
||||
groupMetadata = regexp.MustCompile(`\A((?:/(?:[^/]+))*|)/repodata/([^/]+)\z`)
|
||||
)
|
||||
|
||||
return func() {
|
||||
r.Methods("HEAD,GET,POST,PUT,PATCH,DELETE", "*", func(ctx *context.Context) {
|
||||
path := ctx.Params("*")
|
||||
isHead := ctx.Req.Method == "HEAD"
|
||||
isGetHead := ctx.Req.Method == "HEAD" || ctx.Req.Method == "GET"
|
||||
isPut := ctx.Req.Method == "PUT"
|
||||
isDelete := ctx.Req.Method == "DELETE"
|
||||
|
||||
if path == "/repository.key" && isGetHead {
|
||||
rpm.GetRepositoryKey(ctx)
|
||||
return
|
||||
}
|
||||
|
||||
// get repo
|
||||
m := groupRepoInfo.FindStringSubmatch(path)
|
||||
if len(m) == 2 && isGetHead {
|
||||
ctx.SetParams("group", strings.Trim(m[1], "/"))
|
||||
rpm.GetRepositoryConfig(ctx)
|
||||
return
|
||||
}
|
||||
// get meta
|
||||
m = groupMetadata.FindStringSubmatch(path)
|
||||
if len(m) == 3 && isGetHead {
|
||||
ctx.SetParams("group", strings.Trim(m[1], "/"))
|
||||
ctx.SetParams("filename", m[2])
|
||||
if isHead {
|
||||
rpm.CheckRepositoryFileExistence(ctx)
|
||||
} else {
|
||||
rpm.GetRepositoryFile(ctx)
|
||||
}
|
||||
return
|
||||
}
|
||||
// upload
|
||||
m = groupUpload.FindStringSubmatch(path)
|
||||
if len(m) == 2 && isPut {
|
||||
reqPackageAccess(perm.AccessModeWrite)(ctx)
|
||||
if ctx.Written() {
|
||||
return
|
||||
}
|
||||
ctx.SetParams("group", strings.Trim(m[1], "/"))
|
||||
rpm.UploadPackageFile(ctx)
|
||||
return
|
||||
}
|
||||
// rpm down/delete
|
||||
m = groupRpm.FindStringSubmatch(path)
|
||||
if len(m) == 6 {
|
||||
ctx.SetParams("group", strings.Trim(m[1], "/"))
|
||||
ctx.SetParams("name", m[2])
|
||||
ctx.SetParams("version", m[3])
|
||||
ctx.SetParams("architecture", m[4])
|
||||
if isGetHead {
|
||||
rpm.DownloadPackageFile(ctx)
|
||||
return
|
||||
} else if isDelete {
|
||||
reqPackageAccess(perm.AccessModeWrite)(ctx)
|
||||
if ctx.Written() {
|
||||
return
|
||||
}
|
||||
rpm.DeletePackageFile(ctx)
|
||||
}
|
||||
}
|
||||
// default
|
||||
ctx.Status(http.StatusNotFound)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// ContainerRoutes provides endpoints that implement the OCI API to serve containers
|
||||
// These have to be mounted on `/v2/...` to comply with the OCI spec:
|
||||
// https://github.com/opencontainers/distribution-spec/blob/main/spec.md
|
||||
|
||||
@@ -33,11 +33,14 @@ func apiError(ctx *context.Context, status int, obj any) {
|
||||
|
||||
// https://dnf.readthedocs.io/en/latest/conf_ref.html
|
||||
func GetRepositoryConfig(ctx *context.Context) {
|
||||
group := ctx.Params("group")
|
||||
if group != "" {
|
||||
group = fmt.Sprintf("/%s", group)
|
||||
}
|
||||
url := fmt.Sprintf("%sapi/packages/%s/rpm", setting.AppURL, ctx.Package.Owner.Name)
|
||||
|
||||
ctx.PlainText(http.StatusOK, `[gitea-`+ctx.Package.Owner.LowerName+`]
|
||||
name=`+ctx.Package.Owner.Name+` - `+setting.AppName+`
|
||||
baseurl=`+url+`
|
||||
ctx.PlainText(http.StatusOK, `[gitea-`+ctx.Package.Owner.LowerName+strings.ReplaceAll(group, "/", "-")+`]
|
||||
name=`+ctx.Package.Owner.Name+` - `+setting.AppName+strings.ReplaceAll(group, "/", " - ")+`
|
||||
baseurl=`+url+group+`/
|
||||
enabled=1
|
||||
gpgcheck=1
|
||||
gpgkey=`+url+`/repository.key`)
|
||||
@@ -64,7 +67,7 @@ func CheckRepositoryFileExistence(ctx *context.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
pf, err := packages_model.GetFileForVersionByName(ctx, pv.ID, ctx.Params("filename"), packages_model.EmptyFileKey)
|
||||
pf, err := packages_model.GetFileForVersionByName(ctx, pv.ID, ctx.Params("filename"), ctx.Params("group"))
|
||||
if err != nil {
|
||||
if errors.Is(err, util.ErrNotExist) {
|
||||
ctx.Status(http.StatusNotFound)
|
||||
@@ -93,7 +96,8 @@ func GetRepositoryFile(ctx *context.Context) {
|
||||
ctx,
|
||||
pv,
|
||||
&packages_service.PackageFileInfo{
|
||||
Filename: ctx.Params("filename"),
|
||||
Filename: ctx.Params("filename"),
|
||||
CompositeKey: ctx.Params("group"),
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
@@ -145,7 +149,7 @@ func UploadPackageFile(ctx *context.Context) {
|
||||
apiError(ctx, http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
|
||||
group := ctx.Params("group")
|
||||
_, _, err = packages_service.CreatePackageOrAddFileToExisting(
|
||||
ctx,
|
||||
&packages_service.PackageCreationInfo{
|
||||
@@ -153,14 +157,15 @@ func UploadPackageFile(ctx *context.Context) {
|
||||
Owner: ctx.Package.Owner,
|
||||
PackageType: packages_model.TypeRpm,
|
||||
Name: pck.Name,
|
||||
Version: pck.Version,
|
||||
Version: strings.Trim(fmt.Sprintf("%s/%s", group, pck.Version), "/"),
|
||||
},
|
||||
Creator: ctx.Doer,
|
||||
Metadata: pck.VersionMetadata,
|
||||
},
|
||||
&packages_service.PackageFileCreationInfo{
|
||||
PackageFileInfo: packages_service.PackageFileInfo{
|
||||
Filename: fmt.Sprintf("%s-%s.%s.rpm", pck.Name, pck.Version, pck.FileMetadata.Architecture),
|
||||
Filename: fmt.Sprintf("%s-%s.%s.rpm", pck.Name, pck.Version, pck.FileMetadata.Architecture),
|
||||
CompositeKey: group,
|
||||
},
|
||||
Creator: ctx.Doer,
|
||||
Data: buf,
|
||||
@@ -182,7 +187,7 @@ func UploadPackageFile(ctx *context.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
if err := rpm_service.BuildRepositoryFiles(ctx, ctx.Package.Owner.ID); err != nil {
|
||||
if err := rpm_service.BuildRepositoryFiles(ctx, ctx.Package.Owner.ID, group); err != nil {
|
||||
apiError(ctx, http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
@@ -191,19 +196,20 @@ func UploadPackageFile(ctx *context.Context) {
|
||||
}
|
||||
|
||||
func DownloadPackageFile(ctx *context.Context) {
|
||||
group := ctx.Params("group")
|
||||
name := ctx.Params("name")
|
||||
version := ctx.Params("version")
|
||||
|
||||
s, u, pf, err := packages_service.GetFileStreamByPackageNameAndVersion(
|
||||
ctx,
|
||||
&packages_service.PackageInfo{
|
||||
Owner: ctx.Package.Owner,
|
||||
PackageType: packages_model.TypeRpm,
|
||||
Name: name,
|
||||
Version: version,
|
||||
Version: strings.Trim(fmt.Sprintf("%s/%s", group, version), "/"),
|
||||
},
|
||||
&packages_service.PackageFileInfo{
|
||||
Filename: fmt.Sprintf("%s-%s.%s.rpm", name, version, ctx.Params("architecture")),
|
||||
Filename: fmt.Sprintf("%s-%s.%s.rpm", name, version, ctx.Params("architecture")),
|
||||
CompositeKey: group,
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
@@ -219,14 +225,19 @@ func DownloadPackageFile(ctx *context.Context) {
|
||||
}
|
||||
|
||||
func DeletePackageFile(webctx *context.Context) {
|
||||
group := webctx.Params("group")
|
||||
name := webctx.Params("name")
|
||||
version := webctx.Params("version")
|
||||
architecture := webctx.Params("architecture")
|
||||
|
||||
var pd *packages_model.PackageDescriptor
|
||||
|
||||
err := db.WithTx(webctx, func(ctx stdctx.Context) error {
|
||||
pv, err := packages_model.GetVersionByNameAndVersion(ctx, webctx.Package.Owner.ID, packages_model.TypeRpm, name, version)
|
||||
pv, err := packages_model.GetVersionByNameAndVersion(ctx,
|
||||
webctx.Package.Owner.ID,
|
||||
packages_model.TypeRpm,
|
||||
name,
|
||||
strings.Trim(fmt.Sprintf("%s/%s", group, version), "/"),
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -235,7 +246,7 @@ func DeletePackageFile(webctx *context.Context) {
|
||||
ctx,
|
||||
pv.ID,
|
||||
fmt.Sprintf("%s-%s.%s.rpm", name, version, architecture),
|
||||
packages_model.EmptyFileKey,
|
||||
group,
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -275,7 +286,7 @@ func DeletePackageFile(webctx *context.Context) {
|
||||
notify_service.PackageDelete(webctx, webctx.Doer, pd)
|
||||
}
|
||||
|
||||
if err := rpm_service.BuildRepositoryFiles(webctx, webctx.Package.Owner.ID); err != nil {
|
||||
if err := rpm_service.BuildRepositoryFiles(webctx, webctx.Package.Owner.ID, group); err != nil {
|
||||
apiError(webctx, http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -183,6 +183,8 @@ func EditUser(ctx *context.APIContext) {
|
||||
// responses:
|
||||
// "200":
|
||||
// "$ref": "#/responses/User"
|
||||
// "400":
|
||||
// "$ref": "#/responses/error"
|
||||
// "403":
|
||||
// "$ref": "#/responses/forbidden"
|
||||
// "422":
|
||||
@@ -264,6 +266,10 @@ func EditUser(ctx *context.APIContext) {
|
||||
ctx.ContextUser.Visibility = api.VisibilityModes[form.Visibility]
|
||||
}
|
||||
if form.Admin != nil {
|
||||
if !*form.Admin && user_model.IsLastAdminUser(ctx, ctx.ContextUser) {
|
||||
ctx.Error(http.StatusBadRequest, "LastAdmin", ctx.Tr("auth.last_admin"))
|
||||
return
|
||||
}
|
||||
ctx.ContextUser.IsAdmin = *form.Admin
|
||||
}
|
||||
if form.AllowGitHook != nil {
|
||||
@@ -341,7 +347,8 @@ func DeleteUser(ctx *context.APIContext) {
|
||||
if err := user_service.DeleteUser(ctx, ctx.ContextUser, ctx.FormBool("purge")); err != nil {
|
||||
if models.IsErrUserOwnRepos(err) ||
|
||||
models.IsErrUserHasOrgs(err) ||
|
||||
models.IsErrUserOwnPackages(err) {
|
||||
models.IsErrUserOwnPackages(err) ||
|
||||
models.IsErrDeleteLastAdminUser(err) {
|
||||
ctx.Error(http.StatusUnprocessableEntity, "", err)
|
||||
} else {
|
||||
ctx.Error(http.StatusInternalServerError, "DeleteUser", err)
|
||||
|
||||
@@ -1156,9 +1156,9 @@ func Routes() *web.Route {
|
||||
m.Get("/subscribers", repo.ListSubscribers)
|
||||
m.Group("/subscription", func() {
|
||||
m.Get("", user.IsWatching)
|
||||
m.Put("", reqToken(), user.Watch)
|
||||
m.Delete("", reqToken(), user.Unwatch)
|
||||
})
|
||||
m.Put("", user.Watch)
|
||||
m.Delete("", user.Unwatch)
|
||||
}, reqToken())
|
||||
m.Group("/releases", func() {
|
||||
m.Combo("").Get(repo.ListReleases).
|
||||
Post(reqToken(), reqRepoWriter(unit.TypeReleases), context.ReferencesGitRepo(), bind(api.CreateReleaseOption{}), repo.CreateRelease)
|
||||
|
||||
@@ -636,6 +636,7 @@ func CreateBranchProtection(ctx *context.APIContext) {
|
||||
BlockOnRejectedReviews: form.BlockOnRejectedReviews,
|
||||
BlockOnOfficialReviewRequests: form.BlockOnOfficialReviewRequests,
|
||||
DismissStaleApprovals: form.DismissStaleApprovals,
|
||||
IgnoreStaleApprovals: form.IgnoreStaleApprovals,
|
||||
RequireSignedCommits: form.RequireSignedCommits,
|
||||
ProtectedFilePatterns: form.ProtectedFilePatterns,
|
||||
UnprotectedFilePatterns: form.UnprotectedFilePatterns,
|
||||
@@ -830,6 +831,10 @@ func EditBranchProtection(ctx *context.APIContext) {
|
||||
protectBranch.DismissStaleApprovals = *form.DismissStaleApprovals
|
||||
}
|
||||
|
||||
if form.IgnoreStaleApprovals != nil {
|
||||
protectBranch.IgnoreStaleApprovals = *form.IgnoreStaleApprovals
|
||||
}
|
||||
|
||||
if form.RequireSignedCommits != nil {
|
||||
protectBranch.RequireSignedCommits = *form.RequireSignedCommits
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
"code.gitea.io/gitea/models/db"
|
||||
"code.gitea.io/gitea/models/perm"
|
||||
access_model "code.gitea.io/gitea/models/perm/access"
|
||||
repo_model "code.gitea.io/gitea/models/repo"
|
||||
@@ -53,7 +54,9 @@ func ListCollaborators(ctx *context.APIContext) {
|
||||
// "404":
|
||||
// "$ref": "#/responses/notFound"
|
||||
|
||||
count, err := repo_model.CountCollaborators(ctx, ctx.Repo.Repository.ID)
|
||||
count, err := db.Count[repo_model.Collaboration](ctx, repo_model.FindCollaborationOptions{
|
||||
RepoID: ctx.Repo.Repository.ID,
|
||||
})
|
||||
if err != nil {
|
||||
ctx.InternalServerError(err)
|
||||
return
|
||||
|
||||
@@ -102,23 +102,24 @@ func GetIssueDependencies(ctx *context.APIContext) {
|
||||
return
|
||||
}
|
||||
|
||||
var lastRepoID int64
|
||||
var lastPerm access_model.Permission
|
||||
repoPerms := make(map[int64]access_model.Permission)
|
||||
repoPerms[ctx.Repo.Repository.ID] = ctx.Repo.Permission
|
||||
for _, blocker := range blockersInfo {
|
||||
// Get the permissions for this repository
|
||||
perm := lastPerm
|
||||
if lastRepoID != blocker.Repository.ID {
|
||||
if blocker.Repository.ID == ctx.Repo.Repository.ID {
|
||||
perm = ctx.Repo.Permission
|
||||
} else {
|
||||
var err error
|
||||
perm, err = access_model.GetUserRepoPermission(ctx, &blocker.Repository, ctx.Doer)
|
||||
if err != nil {
|
||||
ctx.ServerError("GetUserRepoPermission", err)
|
||||
return
|
||||
}
|
||||
// If the repo ID exists in the map, return the exist permissions
|
||||
// else get the permission and add it to the map
|
||||
var perm access_model.Permission
|
||||
existPerm, ok := repoPerms[blocker.RepoID]
|
||||
if ok {
|
||||
perm = existPerm
|
||||
} else {
|
||||
var err error
|
||||
perm, err = access_model.GetUserRepoPermission(ctx, &blocker.Repository, ctx.Doer)
|
||||
if err != nil {
|
||||
ctx.ServerError("GetUserRepoPermission", err)
|
||||
return
|
||||
}
|
||||
lastRepoID = blocker.Repository.ID
|
||||
repoPerms[blocker.RepoID] = perm
|
||||
}
|
||||
|
||||
// check permission
|
||||
@@ -345,29 +346,31 @@ func GetIssueBlocks(ctx *context.APIContext) {
|
||||
return
|
||||
}
|
||||
|
||||
var lastRepoID int64
|
||||
var lastPerm access_model.Permission
|
||||
|
||||
var issues []*issues_model.Issue
|
||||
|
||||
repoPerms := make(map[int64]access_model.Permission)
|
||||
repoPerms[ctx.Repo.Repository.ID] = ctx.Repo.Permission
|
||||
|
||||
for i, depMeta := range deps {
|
||||
if i < skip || i >= max {
|
||||
continue
|
||||
}
|
||||
|
||||
// Get the permissions for this repository
|
||||
perm := lastPerm
|
||||
if lastRepoID != depMeta.Repository.ID {
|
||||
if depMeta.Repository.ID == ctx.Repo.Repository.ID {
|
||||
perm = ctx.Repo.Permission
|
||||
} else {
|
||||
var err error
|
||||
perm, err = access_model.GetUserRepoPermission(ctx, &depMeta.Repository, ctx.Doer)
|
||||
if err != nil {
|
||||
ctx.ServerError("GetUserRepoPermission", err)
|
||||
return
|
||||
}
|
||||
// If the repo ID exists in the map, return the exist permissions
|
||||
// else get the permission and add it to the map
|
||||
var perm access_model.Permission
|
||||
existPerm, ok := repoPerms[depMeta.RepoID]
|
||||
if ok {
|
||||
perm = existPerm
|
||||
} else {
|
||||
var err error
|
||||
perm, err = access_model.GetUserRepoPermission(ctx, &depMeta.Repository, ctx.Doer)
|
||||
if err != nil {
|
||||
ctx.ServerError("GetUserRepoPermission", err)
|
||||
return
|
||||
}
|
||||
lastRepoID = depMeta.Repository.ID
|
||||
repoPerms[depMeta.RepoID] = perm
|
||||
}
|
||||
|
||||
if !perm.CanReadIssuesOrPulls(depMeta.Issue.IsPull) {
|
||||
|
||||
+10
-16
@@ -1329,17 +1329,16 @@ func GetPullRequestCommits(ctx *context.APIContext) {
|
||||
|
||||
userCache := make(map[string]*user_model.User)
|
||||
|
||||
start, end := listOptions.GetStartEnd()
|
||||
start, limit := listOptions.GetSkipTake()
|
||||
|
||||
if end > totalNumberOfCommits {
|
||||
end = totalNumberOfCommits
|
||||
}
|
||||
limit = min(limit, totalNumberOfCommits-start)
|
||||
limit = max(limit, 0)
|
||||
|
||||
verification := ctx.FormString("verification") == "" || ctx.FormBool("verification")
|
||||
files := ctx.FormString("files") == "" || ctx.FormBool("files")
|
||||
|
||||
apiCommits := make([]*api.Commit, 0, end-start)
|
||||
for i := start; i < end; i++ {
|
||||
apiCommits := make([]*api.Commit, 0, limit)
|
||||
for i := start; i < start+limit; i++ {
|
||||
apiCommit, err := convert.ToCommit(ctx, ctx.Repo.Repository, baseGitRepo, commits[i], userCache,
|
||||
convert.ToCommitOptions{
|
||||
Stat: true,
|
||||
@@ -1477,19 +1476,14 @@ func GetPullRequestFiles(ctx *context.APIContext) {
|
||||
totalNumberOfFiles := diff.NumFiles
|
||||
totalNumberOfPages := int(math.Ceil(float64(totalNumberOfFiles) / float64(listOptions.PageSize)))
|
||||
|
||||
start, end := listOptions.GetStartEnd()
|
||||
start, limit := listOptions.GetSkipTake()
|
||||
|
||||
if end > totalNumberOfFiles {
|
||||
end = totalNumberOfFiles
|
||||
}
|
||||
limit = min(limit, totalNumberOfFiles-start)
|
||||
|
||||
lenFiles := end - start
|
||||
if lenFiles < 0 {
|
||||
lenFiles = 0
|
||||
}
|
||||
limit = max(limit, 0)
|
||||
|
||||
apiFiles := make([]*api.ChangedFile, 0, lenFiles)
|
||||
for i := start; i < end; i++ {
|
||||
apiFiles := make([]*api.ChangedFile, 0, limit)
|
||||
for i := start; i < start+limit; i++ {
|
||||
apiFiles = append(apiFiles, convert.ToChangedFile(diff.Files[i], pr.HeadRepo, endCommitID))
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"net/http"
|
||||
|
||||
"code.gitea.io/gitea/models"
|
||||
"code.gitea.io/gitea/models/db"
|
||||
"code.gitea.io/gitea/models/perm"
|
||||
repo_model "code.gitea.io/gitea/models/repo"
|
||||
"code.gitea.io/gitea/models/unit"
|
||||
@@ -154,9 +155,10 @@ func ListReleases(ctx *context.APIContext) {
|
||||
IncludeTags: false,
|
||||
IsDraft: ctx.FormOptionalBool("draft"),
|
||||
IsPreRelease: ctx.FormOptionalBool("pre-release"),
|
||||
RepoID: ctx.Repo.Repository.ID,
|
||||
}
|
||||
|
||||
releases, err := repo_model.GetReleasesByRepoID(ctx, ctx.Repo.Repository.ID, opts)
|
||||
releases, err := db.Find[repo_model.Release](ctx, opts)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "GetReleasesByRepoID", err)
|
||||
return
|
||||
@@ -170,7 +172,7 @@ func ListReleases(ctx *context.APIContext) {
|
||||
rels[i] = convert.ToAPIRelease(ctx, ctx.Repo.Repository, release)
|
||||
}
|
||||
|
||||
filteredCount, err := repo_model.CountReleasesByRepoID(ctx, ctx.Repo.Repository.ID, opts)
|
||||
filteredCount, err := db.Count[repo_model.Release](ctx, opts)
|
||||
if err != nil {
|
||||
ctx.InternalServerError(err)
|
||||
return
|
||||
|
||||
@@ -983,7 +983,7 @@ func updateRepoUnits(ctx *context.APIContext, opts api.EditRepoOption) error {
|
||||
}
|
||||
|
||||
if len(units)+len(deleteUnitTypes) > 0 {
|
||||
if err := repo_model.UpdateRepositoryUnits(ctx, repo, units, deleteUnitTypes); err != nil {
|
||||
if err := repo_service.UpdateRepositoryUnits(ctx, repo, units, deleteUnitTypes); err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "UpdateRepositoryUnits", err)
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -18,23 +18,25 @@ import (
|
||||
)
|
||||
|
||||
func listGPGKeys(ctx *context.APIContext, uid int64, listOptions db.ListOptions) {
|
||||
keys, err := asymkey_model.ListGPGKeys(ctx, uid, listOptions)
|
||||
keys, total, err := db.FindAndCount[asymkey_model.GPGKey](ctx, asymkey_model.FindGPGKeyOptions{
|
||||
ListOptions: listOptions,
|
||||
OwnerID: uid,
|
||||
})
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "ListGPGKeys", err)
|
||||
return
|
||||
}
|
||||
|
||||
if err := asymkey_model.GPGKeyList(keys).LoadSubKeys(ctx); err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "ListGPGKeys", err)
|
||||
return
|
||||
}
|
||||
|
||||
apiKeys := make([]*api.GPGKey, len(keys))
|
||||
for i := range keys {
|
||||
apiKeys[i] = convert.ToGPGKey(keys[i])
|
||||
}
|
||||
|
||||
total, err := asymkey_model.CountUserGPGKeys(ctx, uid)
|
||||
if err != nil {
|
||||
ctx.InternalServerError(err)
|
||||
return
|
||||
}
|
||||
|
||||
ctx.SetTotalCountHeader(total)
|
||||
ctx.JSON(http.StatusOK, &apiKeys)
|
||||
}
|
||||
@@ -121,6 +123,10 @@ func GetGPGKey(ctx *context.APIContext) {
|
||||
}
|
||||
return
|
||||
}
|
||||
if err := key.LoadSubKeys(ctx); err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "LoadSubKeys", err)
|
||||
return
|
||||
}
|
||||
ctx.JSON(http.StatusOK, convert.ToGPGKey(key))
|
||||
}
|
||||
|
||||
@@ -198,7 +204,10 @@ func VerifyUserGPGKey(ctx *context.APIContext) {
|
||||
ctx.Error(http.StatusInternalServerError, "VerifyUserGPGKey", err)
|
||||
}
|
||||
|
||||
key, err := asymkey_model.GetGPGKeysByKeyID(ctx, form.KeyID)
|
||||
keys, err := db.Find[asymkey_model.GPGKey](ctx, asymkey_model.FindGPGKeyOptions{
|
||||
KeyID: form.KeyID,
|
||||
IncludeSubKeys: true,
|
||||
})
|
||||
if err != nil {
|
||||
if asymkey_model.IsErrGPGKeyNotExist(err) {
|
||||
ctx.NotFound()
|
||||
@@ -207,7 +216,7 @@ func VerifyUserGPGKey(ctx *context.APIContext) {
|
||||
}
|
||||
return
|
||||
}
|
||||
ctx.JSON(http.StatusOK, convert.ToGPGKey(key[0]))
|
||||
ctx.JSON(http.StatusOK, convert.ToGPGKey(keys[0]))
|
||||
}
|
||||
|
||||
// swagger:parameters userCurrentPostGPGKey
|
||||
|
||||
Reference in New Issue
Block a user