mirror of
https://github.com/go-gitea/gitea.git
synced 2026-08-03 04:43:43 +02:00
Merge remote-tracking branch 'upstream/main' into ssh-mirroring
This commit is contained in:
@@ -428,7 +428,7 @@ func (ar artifactRoutes) getDownloadArtifactURL(ctx *ArtifactContext) {
|
||||
for _, artifact := range artifacts {
|
||||
var downloadURL string
|
||||
if setting.Actions.ArtifactStorage.ServeDirect() {
|
||||
u, err := ar.fs.URL(artifact.StoragePath, artifact.ArtifactName, nil)
|
||||
u, err := ar.fs.URL(artifact.StoragePath, artifact.ArtifactName, ctx.Req.Method, nil)
|
||||
if err != nil && !errors.Is(err, storage.ErrURLNotSupported) {
|
||||
log.Error("Error getting serve direct url: %v", err)
|
||||
}
|
||||
|
||||
@@ -517,7 +517,7 @@ func (r *artifactV4Routes) getSignedArtifactURL(ctx *ArtifactContext) {
|
||||
respData := GetSignedArtifactURLResponse{}
|
||||
|
||||
if setting.Actions.ArtifactStorage.ServeDirect() {
|
||||
u, err := storage.ActionsArtifacts.URL(artifact.StoragePath, artifact.ArtifactPath, nil)
|
||||
u, err := storage.ActionsArtifacts.URL(artifact.StoragePath, artifact.ArtifactPath, ctx.Req.Method, nil)
|
||||
if u != nil && err == nil {
|
||||
respData.SignedUrl = u.String()
|
||||
}
|
||||
|
||||
@@ -25,9 +25,8 @@ import (
|
||||
)
|
||||
|
||||
func apiError(ctx *context.Context, status int, obj any) {
|
||||
helper.LogAndProcessError(ctx, status, obj, func(message string) {
|
||||
ctx.PlainText(status, message)
|
||||
})
|
||||
message := helper.ProcessErrorForUser(ctx, status, obj)
|
||||
ctx.PlainText(status, message)
|
||||
}
|
||||
|
||||
func GetRepositoryKey(ctx *context.Context) {
|
||||
@@ -75,6 +74,7 @@ func GetRepositoryFile(ctx *context.Context) {
|
||||
Filename: alpine_service.IndexArchiveFilename,
|
||||
CompositeKey: fmt.Sprintf("%s|%s|%s", ctx.PathParam("branch"), ctx.PathParam("repository"), ctx.PathParam("architecture")),
|
||||
},
|
||||
ctx.Req.Method,
|
||||
)
|
||||
if err != nil {
|
||||
if errors.Is(err, util.ErrNotExist) {
|
||||
@@ -216,7 +216,7 @@ func DownloadPackageFile(ctx *context.Context) {
|
||||
}
|
||||
}
|
||||
|
||||
s, u, pf, err := packages_service.OpenFileForDownload(ctx, pfs[0])
|
||||
s, u, pf, err := packages_service.OpenFileForDownload(ctx, pfs[0], ctx.Req.Method)
|
||||
if err != nil {
|
||||
if errors.Is(err, util.ErrNotExist) {
|
||||
apiError(ctx, http.StatusNotFound, err)
|
||||
|
||||
@@ -99,7 +99,7 @@ func verifyAuth(r *web.Router, authMethods []auth.Method) {
|
||||
ctx.Doer, err = authGroup.Verify(ctx.Req, ctx.Resp, ctx, ctx.Session)
|
||||
if err != nil {
|
||||
log.Error("Failed to verify user: %v", err)
|
||||
ctx.HTTPError(http.StatusUnauthorized, "authGroup.Verify")
|
||||
ctx.HTTPError(http.StatusUnauthorized, "Failed to authenticate user")
|
||||
return
|
||||
}
|
||||
ctx.IsSigned = ctx.Doer != nil
|
||||
@@ -339,7 +339,7 @@ func CommonRoutes() *web.Router {
|
||||
r.Group("/{packagename}/{packageversion}", func() {
|
||||
r.Delete("", reqPackageAccess(perm.AccessModeWrite), generic.DeletePackage)
|
||||
r.Group("/{filename}", func() {
|
||||
r.Get("", generic.DownloadPackageFile)
|
||||
r.Methods("HEAD,GET", "", generic.DownloadPackageFile)
|
||||
r.Group("", func() {
|
||||
r.Put("", generic.UploadPackage)
|
||||
r.Delete("", generic.DeletePackageFile)
|
||||
|
||||
@@ -24,9 +24,8 @@ import (
|
||||
)
|
||||
|
||||
func apiError(ctx *context.Context, status int, obj any) {
|
||||
helper.LogAndProcessError(ctx, status, obj, func(message string) {
|
||||
ctx.PlainText(status, message)
|
||||
})
|
||||
message := helper.ProcessErrorForUser(ctx, status, obj)
|
||||
ctx.PlainText(status, message)
|
||||
}
|
||||
|
||||
func GetRepositoryKey(ctx *context.Context) {
|
||||
@@ -239,7 +238,7 @@ func GetPackageOrRepositoryFile(ctx *context.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
s, u, pf, err := packages_service.OpenFileForDownload(ctx, pfs[0])
|
||||
s, u, pf, err := packages_service.OpenFileForDownload(ctx, pfs[0], ctx.Req.Method)
|
||||
if err != nil {
|
||||
if errors.Is(err, util.ErrNotExist) {
|
||||
apiError(ctx, http.StatusNotFound, err)
|
||||
|
||||
@@ -37,15 +37,14 @@ type StatusMessage struct {
|
||||
}
|
||||
|
||||
func apiError(ctx *context.Context, status int, obj any) {
|
||||
helper.LogAndProcessError(ctx, status, obj, func(message string) {
|
||||
ctx.JSON(status, StatusResponse{
|
||||
OK: false,
|
||||
Errors: []StatusMessage{
|
||||
{
|
||||
Message: message,
|
||||
},
|
||||
message := helper.ProcessErrorForUser(ctx, status, obj)
|
||||
ctx.JSON(status, StatusResponse{
|
||||
OK: false,
|
||||
Errors: []StatusMessage{
|
||||
{
|
||||
Message: message,
|
||||
},
|
||||
})
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
@@ -176,6 +175,7 @@ func DownloadPackageFile(ctx *context.Context) {
|
||||
&packages_service.PackageFileInfo{
|
||||
Filename: strings.ToLower(fmt.Sprintf("%s-%s.crate", ctx.PathParam("package"), ctx.PathParam("version"))),
|
||||
},
|
||||
ctx.Req.Method,
|
||||
)
|
||||
if err != nil {
|
||||
if errors.Is(err, packages_model.ErrPackageNotExist) || errors.Is(err, packages_model.ErrPackageFileNotExist) {
|
||||
|
||||
@@ -30,10 +30,9 @@ func apiError(ctx *context.Context, status int, obj any) {
|
||||
ErrorMessages []string `json:"error_messages"`
|
||||
}
|
||||
|
||||
helper.LogAndProcessError(ctx, status, obj, func(message string) {
|
||||
ctx.JSON(status, Error{
|
||||
ErrorMessages: []string{message},
|
||||
})
|
||||
message := helper.ProcessErrorForUser(ctx, status, obj)
|
||||
ctx.JSON(status, Error{
|
||||
ErrorMessages: []string{message},
|
||||
})
|
||||
}
|
||||
|
||||
@@ -343,7 +342,7 @@ func DownloadPackage(ctx *context.Context) {
|
||||
|
||||
pf := pd.Files[0].File
|
||||
|
||||
s, u, _, err := packages_service.OpenFileForDownload(ctx, pf)
|
||||
s, u, _, err := packages_service.OpenFileForDownload(ctx, pf, ctx.Req.Method)
|
||||
if err != nil {
|
||||
apiError(ctx, http.StatusInternalServerError, err)
|
||||
return
|
||||
|
||||
@@ -28,18 +28,17 @@ import (
|
||||
)
|
||||
|
||||
func apiError(ctx *context.Context, status int, obj any) {
|
||||
helper.LogAndProcessError(ctx, status, obj, func(message string) {
|
||||
type Error struct {
|
||||
Status int `json:"status"`
|
||||
Message string `json:"message"`
|
||||
}
|
||||
ctx.JSON(status, struct {
|
||||
Errors []Error `json:"errors"`
|
||||
}{
|
||||
Errors: []Error{
|
||||
{Status: status, Message: message},
|
||||
},
|
||||
})
|
||||
message := helper.ProcessErrorForUser(ctx, status, obj)
|
||||
type Error struct {
|
||||
Status int `json:"status"`
|
||||
Message string `json:"message"`
|
||||
}
|
||||
ctx.JSON(status, struct {
|
||||
Errors []Error `json:"errors"`
|
||||
}{
|
||||
Errors: []Error{
|
||||
{Status: status, Message: message},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
@@ -171,6 +170,7 @@ func DownloadPackageFile(ctx *context.Context) {
|
||||
&packages_service.PackageFileInfo{
|
||||
Filename: ctx.PathParam("filename"),
|
||||
},
|
||||
ctx.Req.Method,
|
||||
)
|
||||
if err != nil {
|
||||
if errors.Is(err, packages_model.ErrPackageNotExist) || errors.Is(err, packages_model.ErrPackageFileNotExist) {
|
||||
|
||||
@@ -34,7 +34,6 @@ func (a *Auth) Verify(req *http.Request, w http.ResponseWriter, store auth.DataS
|
||||
|
||||
u, err := user_model.GetUserByID(req.Context(), packageMeta.UserID)
|
||||
if err != nil {
|
||||
log.Error("GetUserByID: %v", err)
|
||||
return nil, err
|
||||
}
|
||||
if packageMeta.Scope != "" {
|
||||
|
||||
@@ -55,16 +55,13 @@ func jsonResponse(ctx *context.Context, status int, obj any) {
|
||||
// https://github.com/conan-io/conan/issues/6613
|
||||
ctx.Resp.Header().Set("Content-Type", "application/json")
|
||||
ctx.Status(status)
|
||||
if err := json.NewEncoder(ctx.Resp).Encode(obj); err != nil {
|
||||
log.Error("JSON encode: %v", err)
|
||||
}
|
||||
_ = json.NewEncoder(ctx.Resp).Encode(obj)
|
||||
}
|
||||
|
||||
func apiError(ctx *context.Context, status int, obj any) {
|
||||
helper.LogAndProcessError(ctx, status, obj, func(message string) {
|
||||
jsonResponse(ctx, status, map[string]string{
|
||||
"message": message,
|
||||
})
|
||||
message := helper.ProcessErrorForUser(ctx, status, obj)
|
||||
jsonResponse(ctx, status, map[string]string{
|
||||
"message": message,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -393,7 +390,6 @@ func uploadFile(ctx *context.Context, fileFilter container.Set[string], fileKey
|
||||
if isConanfileFile {
|
||||
metadata, err := conan_module.ParseConanfile(buf)
|
||||
if err != nil {
|
||||
log.Error("Error parsing package metadata: %v", err)
|
||||
apiError(ctx, http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
@@ -419,7 +415,6 @@ func uploadFile(ctx *context.Context, fileFilter container.Set[string], fileKey
|
||||
} else {
|
||||
info, err := conan_module.ParseConaninfo(buf)
|
||||
if err != nil {
|
||||
log.Error("Error parsing conan info: %v", err)
|
||||
apiError(ctx, http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
@@ -492,6 +487,7 @@ func downloadFile(ctx *context.Context, fileFilter container.Set[string], fileKe
|
||||
Filename: filename,
|
||||
CompositeKey: fileKey,
|
||||
},
|
||||
ctx.Req.Method,
|
||||
)
|
||||
if err != nil {
|
||||
if errors.Is(err, packages_model.ErrPackageNotExist) || errors.Is(err, packages_model.ErrPackageFileNotExist) {
|
||||
|
||||
@@ -13,7 +13,6 @@ import (
|
||||
packages_model "code.gitea.io/gitea/models/packages"
|
||||
conda_model "code.gitea.io/gitea/models/packages/conda"
|
||||
"code.gitea.io/gitea/modules/json"
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
packages_module "code.gitea.io/gitea/modules/packages"
|
||||
conda_module "code.gitea.io/gitea/modules/packages/conda"
|
||||
"code.gitea.io/gitea/modules/util"
|
||||
@@ -25,14 +24,13 @@ import (
|
||||
)
|
||||
|
||||
func apiError(ctx *context.Context, status int, obj any) {
|
||||
helper.LogAndProcessError(ctx, status, obj, func(message string) {
|
||||
ctx.JSON(status, struct {
|
||||
Reason string `json:"reason"`
|
||||
Message string `json:"message"`
|
||||
}{
|
||||
Reason: http.StatusText(status),
|
||||
Message: message,
|
||||
})
|
||||
message := helper.ProcessErrorForUser(ctx, status, obj)
|
||||
ctx.JSON(status, struct {
|
||||
Reason string `json:"reason"`
|
||||
Message string `json:"message"`
|
||||
}{
|
||||
Reason: http.StatusText(status),
|
||||
Message: message,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -185,10 +183,7 @@ func EnumeratePackages(ctx *context.Context) {
|
||||
}
|
||||
|
||||
resp.WriteHeader(http.StatusOK)
|
||||
|
||||
if err := json.NewEncoder(w).Encode(repoData); err != nil {
|
||||
log.Error("JSON encode: %v", err)
|
||||
}
|
||||
_ = json.NewEncoder(w).Encode(repoData)
|
||||
}
|
||||
|
||||
func UploadPackageFile(ctx *context.Context) {
|
||||
@@ -317,7 +312,7 @@ func DownloadPackageFile(ctx *context.Context) {
|
||||
|
||||
pf := pfs[0]
|
||||
|
||||
s, u, _, err := packages_service.OpenFileForDownload(ctx, pf)
|
||||
s, u, _, err := packages_service.OpenFileForDownload(ctx, pf, ctx.Req.Method)
|
||||
if err != nil {
|
||||
apiError(ctx, http.StatusInternalServerError, err)
|
||||
return
|
||||
|
||||
@@ -35,7 +35,6 @@ func (a *Auth) Verify(req *http.Request, w http.ResponseWriter, store auth.DataS
|
||||
|
||||
u, err := user_model.GetPossibleUserByID(req.Context(), packageMeta.UserID)
|
||||
if err != nil {
|
||||
log.Error("GetPossibleUserByID: %v", err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
||||
@@ -93,10 +93,9 @@ func jsonResponse(ctx *context.Context, status int, obj any) {
|
||||
}
|
||||
|
||||
func apiError(ctx *context.Context, status int, err error) {
|
||||
helper.LogAndProcessError(ctx, status, err, func(message string) {
|
||||
setResponseHeaders(ctx.Resp, &containerHeaders{
|
||||
Status: status,
|
||||
})
|
||||
_ = helper.ProcessErrorForUser(ctx, status, err)
|
||||
setResponseHeaders(ctx.Resp, &containerHeaders{
|
||||
Status: status,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -449,9 +448,9 @@ func PutBlobsUpload(ctx *context.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
// There was a strange bug: the "Close" fails with error "close .../tmp/package-upload/....: file already closed"
|
||||
// AFAIK there should be no other "Close" call to the uploader between NewBlobUploader and this line.
|
||||
// At least it's safe to call Close twice, so ignore the error.
|
||||
// Some SDK (e.g.: minio) will close the Reader if it is also a Closer after "uploading".
|
||||
// And we don't need to wrap the reader to anything else because the SDK will benefit from other interfaces like Seeker.
|
||||
// It's safe to call Close twice, so ignore the error.
|
||||
_ = uploader.Close()
|
||||
|
||||
if err := container_service.RemoveBlobUploadByID(ctx, uploader.ID); err != nil {
|
||||
@@ -710,7 +709,7 @@ func DeleteManifest(ctx *context.Context) {
|
||||
func serveBlob(ctx *context.Context, pfd *packages_model.PackageFileDescriptor) {
|
||||
serveDirectReqParams := make(url.Values)
|
||||
serveDirectReqParams.Set("response-content-type", pfd.Properties.GetByName(container_module.PropertyMediaType))
|
||||
s, u, _, err := packages_service.OpenBlobForDownload(ctx, pfd.File, pfd.Blob, serveDirectReqParams)
|
||||
s, u, _, err := packages_service.OpenBlobForDownload(ctx, pfd.File, pfd.Blob, ctx.Req.Method, serveDirectReqParams)
|
||||
if err != nil {
|
||||
apiError(ctx, http.StatusInternalServerError, err)
|
||||
return
|
||||
@@ -734,9 +733,7 @@ func serveBlob(ctx *context.Context, pfd *packages_model.PackageFileDescriptor)
|
||||
defer s.Close()
|
||||
|
||||
setResponseHeaders(ctx.Resp, headers)
|
||||
if _, err := io.Copy(ctx.Resp, s); err != nil {
|
||||
log.Error("Error whilst copying content to response: %v", err)
|
||||
}
|
||||
_, _ = io.Copy(ctx.Resp, s)
|
||||
}
|
||||
|
||||
// https://github.com/opencontainers/distribution-spec/blob/main/spec.md#content-discovery
|
||||
|
||||
@@ -22,9 +22,8 @@ import (
|
||||
)
|
||||
|
||||
func apiError(ctx *context.Context, status int, obj any) {
|
||||
helper.LogAndProcessError(ctx, status, obj, func(message string) {
|
||||
ctx.PlainText(status, message)
|
||||
})
|
||||
message := helper.ProcessErrorForUser(ctx, status, obj)
|
||||
ctx.PlainText(status, message)
|
||||
}
|
||||
|
||||
func EnumerateSourcePackages(ctx *context.Context) {
|
||||
@@ -250,7 +249,7 @@ func downloadPackageFile(ctx *context.Context, opts *cran_model.SearchOptions) {
|
||||
return
|
||||
}
|
||||
|
||||
s, u, _, err := packages_service.OpenFileForDownload(ctx, pf)
|
||||
s, u, _, err := packages_service.OpenFileForDownload(ctx, pf, ctx.Req.Method)
|
||||
if err != nil {
|
||||
if errors.Is(err, util.ErrNotExist) {
|
||||
apiError(ctx, http.StatusNotFound, err)
|
||||
|
||||
@@ -24,9 +24,8 @@ import (
|
||||
)
|
||||
|
||||
func apiError(ctx *context.Context, status int, obj any) {
|
||||
helper.LogAndProcessError(ctx, status, obj, func(message string) {
|
||||
ctx.PlainText(status, message)
|
||||
})
|
||||
message := helper.ProcessErrorForUser(ctx, status, obj)
|
||||
ctx.PlainText(status, message)
|
||||
}
|
||||
|
||||
func GetRepositoryKey(ctx *context.Context) {
|
||||
@@ -66,6 +65,7 @@ func GetRepositoryFile(ctx *context.Context) {
|
||||
Filename: ctx.PathParam("filename"),
|
||||
CompositeKey: key,
|
||||
},
|
||||
ctx.Req.Method,
|
||||
)
|
||||
if err != nil {
|
||||
if errors.Is(err, packages_model.ErrPackageNotExist) || errors.Is(err, packages_model.ErrPackageFileNotExist) {
|
||||
@@ -106,7 +106,7 @@ func GetRepositoryFileByHash(ctx *context.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
s, u, pf, err := packages_service.OpenFileForDownload(ctx, pfs[0])
|
||||
s, u, pf, err := packages_service.OpenFileForDownload(ctx, pfs[0], ctx.Req.Method)
|
||||
if err != nil {
|
||||
if errors.Is(err, util.ErrNotExist) {
|
||||
apiError(ctx, http.StatusNotFound, err)
|
||||
@@ -222,6 +222,7 @@ func DownloadPackageFile(ctx *context.Context) {
|
||||
Filename: fmt.Sprintf("%s_%s_%s.deb", name, version, ctx.PathParam("architecture")),
|
||||
CompositeKey: fmt.Sprintf("%s|%s", ctx.PathParam("distribution"), ctx.PathParam("component")),
|
||||
},
|
||||
ctx.Req.Method,
|
||||
)
|
||||
if err != nil {
|
||||
if errors.Is(err, util.ErrNotExist) {
|
||||
|
||||
@@ -11,7 +11,6 @@ import (
|
||||
"unicode"
|
||||
|
||||
packages_model "code.gitea.io/gitea/models/packages"
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
packages_module "code.gitea.io/gitea/modules/packages"
|
||||
"code.gitea.io/gitea/routers/api/packages/helper"
|
||||
"code.gitea.io/gitea/services/context"
|
||||
@@ -24,9 +23,8 @@ var (
|
||||
)
|
||||
|
||||
func apiError(ctx *context.Context, status int, obj any) {
|
||||
helper.LogAndProcessError(ctx, status, obj, func(message string) {
|
||||
ctx.PlainText(status, message)
|
||||
})
|
||||
message := helper.ProcessErrorForUser(ctx, status, obj)
|
||||
ctx.PlainText(status, message)
|
||||
}
|
||||
|
||||
// DownloadPackageFile serves the specific generic package.
|
||||
@@ -42,6 +40,7 @@ func DownloadPackageFile(ctx *context.Context) {
|
||||
&packages_service.PackageFileInfo{
|
||||
Filename: ctx.PathParam("filename"),
|
||||
},
|
||||
ctx.Req.Method,
|
||||
)
|
||||
if err != nil {
|
||||
if errors.Is(err, packages_model.ErrPackageNotExist) || errors.Is(err, packages_model.ErrPackageFileNotExist) {
|
||||
@@ -101,7 +100,6 @@ func UploadPackage(ctx *context.Context) {
|
||||
|
||||
buf, err := packages_module.CreateHashedBufferFromReader(upload)
|
||||
if err != nil {
|
||||
log.Error("Error creating hashed buffer: %v", err)
|
||||
apiError(ctx, http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -22,9 +22,8 @@ import (
|
||||
)
|
||||
|
||||
func apiError(ctx *context.Context, status int, obj any) {
|
||||
helper.LogAndProcessError(ctx, status, obj, func(message string) {
|
||||
ctx.PlainText(status, message)
|
||||
})
|
||||
message := helper.ProcessErrorForUser(ctx, status, obj)
|
||||
ctx.PlainText(status, message)
|
||||
}
|
||||
|
||||
func EnumeratePackageVersions(ctx *context.Context) {
|
||||
@@ -106,7 +105,7 @@ func DownloadPackageFile(ctx *context.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
s, u, _, err := packages_service.OpenFileForDownload(ctx, pfs[0])
|
||||
s, u, _, err := packages_service.OpenFileForDownload(ctx, pfs[0], ctx.Req.Method)
|
||||
if err != nil {
|
||||
if errors.Is(err, util.ErrNotExist) {
|
||||
apiError(ctx, http.StatusNotFound, err)
|
||||
|
||||
@@ -14,7 +14,6 @@ import (
|
||||
|
||||
packages_model "code.gitea.io/gitea/models/packages"
|
||||
"code.gitea.io/gitea/modules/json"
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
"code.gitea.io/gitea/modules/optional"
|
||||
packages_module "code.gitea.io/gitea/modules/packages"
|
||||
helm_module "code.gitea.io/gitea/modules/packages/helm"
|
||||
@@ -28,13 +27,12 @@ import (
|
||||
)
|
||||
|
||||
func apiError(ctx *context.Context, status int, obj any) {
|
||||
helper.LogAndProcessError(ctx, status, obj, func(message string) {
|
||||
type Error struct {
|
||||
Error string `json:"error"`
|
||||
}
|
||||
ctx.JSON(status, Error{
|
||||
Error: message,
|
||||
})
|
||||
message := helper.ProcessErrorForUser(ctx, status, obj)
|
||||
type Error struct {
|
||||
Error string `json:"error"`
|
||||
}
|
||||
ctx.JSON(status, Error{
|
||||
Error: message,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -87,16 +85,14 @@ func Index(ctx *context.Context) {
|
||||
}
|
||||
|
||||
ctx.Resp.WriteHeader(http.StatusOK)
|
||||
if err := yaml.NewEncoder(ctx.Resp).Encode(&Index{
|
||||
_ = yaml.NewEncoder(ctx.Resp).Encode(&Index{
|
||||
APIVersion: "v1",
|
||||
Entries: entries,
|
||||
Generated: time.Now(),
|
||||
ServerInfo: &ServerInfo{
|
||||
ContextPath: setting.AppSubURL + "/api/packages/" + url.PathEscape(ctx.Package.Owner.Name) + "/helm",
|
||||
},
|
||||
}); err != nil {
|
||||
log.Error("YAML encode failed: %v", err)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// DownloadPackageFile serves the content of a package
|
||||
@@ -128,6 +124,7 @@ func DownloadPackageFile(ctx *context.Context) {
|
||||
&packages_service.PackageFileInfo{
|
||||
Filename: filename,
|
||||
},
|
||||
ctx.Req.Method,
|
||||
)
|
||||
if err != nil {
|
||||
if errors.Is(err, packages_model.ErrPackageFileNotExist) {
|
||||
|
||||
@@ -15,31 +15,29 @@ import (
|
||||
"code.gitea.io/gitea/services/context"
|
||||
)
|
||||
|
||||
// LogAndProcessError logs an error and calls a custom callback with the processed error message.
|
||||
// If the error is an InternalServerError the message is stripped if the user is not an admin.
|
||||
func LogAndProcessError(ctx *context.Context, status int, obj any, cb func(string)) {
|
||||
// ProcessErrorForUser logs the error and returns a user-error message for the end user.
|
||||
// If the status is http.StatusInternalServerError, the message is stripped for non-admin users in production.
|
||||
func ProcessErrorForUser(ctx *context.Context, status int, errObj any) string {
|
||||
var message string
|
||||
if err, ok := obj.(error); ok {
|
||||
if err, ok := errObj.(error); ok {
|
||||
message = err.Error()
|
||||
} else if obj != nil {
|
||||
message = fmt.Sprintf("%s", obj)
|
||||
} else if errObj != nil {
|
||||
message = fmt.Sprint(errObj)
|
||||
}
|
||||
|
||||
if status == http.StatusInternalServerError {
|
||||
log.ErrorWithSkip(1, message)
|
||||
|
||||
log.Log(2, log.ERROR, "Package registry API internal error: %d %s", status, message)
|
||||
if setting.IsProd && (ctx.Doer == nil || !ctx.Doer.IsAdmin) {
|
||||
message = ""
|
||||
message = "internal server error"
|
||||
}
|
||||
} else {
|
||||
log.Debug(message)
|
||||
return message
|
||||
}
|
||||
|
||||
if cb != nil {
|
||||
cb(message)
|
||||
}
|
||||
log.Log(2, log.DEBUG, "Package registry API user error: %d %s", status, message)
|
||||
return message
|
||||
}
|
||||
|
||||
// Serves the content of the package file
|
||||
// ServePackageFile the content of the package file
|
||||
// If the url is set it will redirect the request, otherwise the content is copied to the response.
|
||||
func ServePackageFile(ctx *context.Context, s io.ReadSeekCloser, u *url.URL, pf *packages_model.PackageFile, forceOpts ...*context.ServeHeaderOptions) {
|
||||
if u != nil {
|
||||
|
||||
@@ -22,7 +22,6 @@ import (
|
||||
packages_model "code.gitea.io/gitea/models/packages"
|
||||
"code.gitea.io/gitea/modules/globallock"
|
||||
"code.gitea.io/gitea/modules/json"
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
packages_module "code.gitea.io/gitea/modules/packages"
|
||||
maven_module "code.gitea.io/gitea/modules/packages/maven"
|
||||
"code.gitea.io/gitea/modules/util"
|
||||
@@ -49,14 +48,9 @@ var (
|
||||
)
|
||||
|
||||
func apiError(ctx *context.Context, status int, obj any) {
|
||||
helper.LogAndProcessError(ctx, status, obj, func(message string) {
|
||||
// The maven client does not present the error message to the user. Log it for users with access to server logs.
|
||||
if status == http.StatusBadRequest || status == http.StatusInternalServerError {
|
||||
log.Error(message)
|
||||
}
|
||||
|
||||
ctx.PlainText(status, message)
|
||||
})
|
||||
message := helper.ProcessErrorForUser(ctx, status, obj)
|
||||
// Maven client doesn't present the error message to end users; site admin can check the server logs that outputted by ProcessErrorForUser
|
||||
ctx.PlainText(status, message)
|
||||
}
|
||||
|
||||
// DownloadPackageFile serves the content of a package
|
||||
@@ -223,7 +217,7 @@ func servePackageFile(ctx *context.Context, params parameters, serveContent bool
|
||||
return
|
||||
}
|
||||
|
||||
s, u, _, err := packages_service.OpenBlobForDownload(ctx, pf, pb, nil)
|
||||
s, u, _, err := packages_service.OpenBlobForDownload(ctx, pf, pb, ctx.Req.Method, nil)
|
||||
if err != nil {
|
||||
apiError(ctx, http.StatusInternalServerError, err)
|
||||
return
|
||||
|
||||
@@ -33,10 +33,9 @@ import (
|
||||
var errInvalidTagName = errors.New("The tag name is invalid")
|
||||
|
||||
func apiError(ctx *context.Context, status int, obj any) {
|
||||
helper.LogAndProcessError(ctx, status, obj, func(message string) {
|
||||
ctx.JSON(status, map[string]string{
|
||||
"error": message,
|
||||
})
|
||||
message := helper.ProcessErrorForUser(ctx, status, obj)
|
||||
ctx.JSON(status, map[string]string{
|
||||
"error": message,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -96,6 +95,7 @@ func DownloadPackageFile(ctx *context.Context) {
|
||||
&packages_service.PackageFileInfo{
|
||||
Filename: filename,
|
||||
},
|
||||
ctx.Req.Method,
|
||||
)
|
||||
if err != nil {
|
||||
if errors.Is(err, packages_model.ErrPackageNotExist) || errors.Is(err, packages_model.ErrPackageFileNotExist) {
|
||||
@@ -138,6 +138,7 @@ func DownloadPackageFileByName(ctx *context.Context) {
|
||||
&packages_service.PackageFileInfo{
|
||||
Filename: filename,
|
||||
},
|
||||
ctx.Req.Method,
|
||||
)
|
||||
if err != nil {
|
||||
if errors.Is(err, packages_model.ErrPackageFileNotExist) {
|
||||
|
||||
@@ -26,7 +26,6 @@ func (a *Auth) Verify(req *http.Request, w http.ResponseWriter, store auth.DataS
|
||||
token, err := auth_model.GetAccessTokenBySHA(req.Context(), req.Header.Get("X-NuGet-ApiKey"))
|
||||
if err != nil {
|
||||
if !(auth_model.IsErrAccessTokenNotExist(err) || auth_model.IsErrAccessTokenEmpty(err)) {
|
||||
log.Error("GetAccessTokenBySHA: %v", err)
|
||||
return nil, err
|
||||
}
|
||||
return nil, nil
|
||||
@@ -34,7 +33,6 @@ func (a *Auth) Verify(req *http.Request, w http.ResponseWriter, store auth.DataS
|
||||
|
||||
u, err := user_model.GetUserByID(req.Context(), token.UID)
|
||||
if err != nil {
|
||||
log.Error("GetUserByID: %v", err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,6 @@ import (
|
||||
"code.gitea.io/gitea/models/db"
|
||||
packages_model "code.gitea.io/gitea/models/packages"
|
||||
nuget_model "code.gitea.io/gitea/models/packages/nuget"
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
"code.gitea.io/gitea/modules/optional"
|
||||
packages_module "code.gitea.io/gitea/modules/packages"
|
||||
nuget_module "code.gitea.io/gitea/modules/packages/nuget"
|
||||
@@ -29,22 +28,17 @@ import (
|
||||
)
|
||||
|
||||
func apiError(ctx *context.Context, status int, obj any) {
|
||||
helper.LogAndProcessError(ctx, status, obj, func(message string) {
|
||||
ctx.JSON(status, map[string]string{
|
||||
"Message": message,
|
||||
})
|
||||
message := helper.ProcessErrorForUser(ctx, status, obj)
|
||||
ctx.JSON(status, map[string]string{
|
||||
"Message": message,
|
||||
})
|
||||
}
|
||||
|
||||
func xmlResponse(ctx *context.Context, status int, obj any) { //nolint:unparam // status is always StatusOK
|
||||
ctx.Resp.Header().Set("Content-Type", "application/atom+xml; charset=utf-8")
|
||||
ctx.Resp.WriteHeader(status)
|
||||
if _, err := ctx.Resp.Write([]byte(xml.Header)); err != nil {
|
||||
log.Error("Write failed: %v", err)
|
||||
}
|
||||
if err := xml.NewEncoder(ctx.Resp).Encode(obj); err != nil {
|
||||
log.Error("XML encode failed: %v", err)
|
||||
}
|
||||
_, _ = ctx.Resp.Write([]byte(xml.Header))
|
||||
_ = xml.NewEncoder(ctx.Resp).Encode(obj)
|
||||
}
|
||||
|
||||
// https://github.com/NuGet/NuGet.Client/blob/dev/src/NuGet.Core/NuGet.Protocol/LegacyFeed/V2FeedQueryBuilder.cs
|
||||
@@ -416,6 +410,7 @@ func DownloadPackageFile(ctx *context.Context) {
|
||||
&packages_service.PackageFileInfo{
|
||||
Filename: filename,
|
||||
},
|
||||
ctx.Req.Method,
|
||||
)
|
||||
if err != nil {
|
||||
if errors.Is(err, packages_model.ErrPackageNotExist) || errors.Is(err, packages_model.ErrPackageFileNotExist) {
|
||||
@@ -669,7 +664,7 @@ func DownloadSymbolFile(ctx *context.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
s, u, pf, err := packages_service.OpenFileForDownload(ctx, pfs[0])
|
||||
s, u, pf, err := packages_service.OpenFileForDownload(ctx, pfs[0], ctx.Req.Method)
|
||||
if err != nil {
|
||||
if errors.Is(err, packages_model.ErrPackageNotExist) || errors.Is(err, packages_model.ErrPackageFileNotExist) {
|
||||
apiError(ctx, http.StatusNotFound, err)
|
||||
|
||||
@@ -15,7 +15,6 @@ import (
|
||||
|
||||
packages_model "code.gitea.io/gitea/models/packages"
|
||||
"code.gitea.io/gitea/modules/json"
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
packages_module "code.gitea.io/gitea/modules/packages"
|
||||
pub_module "code.gitea.io/gitea/modules/packages/pub"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
@@ -29,9 +28,7 @@ func jsonResponse(ctx *context.Context, status int, obj any) {
|
||||
resp := ctx.Resp
|
||||
resp.Header().Set("Content-Type", "application/vnd.pub.v2+json")
|
||||
resp.WriteHeader(status)
|
||||
if err := json.NewEncoder(resp).Encode(obj); err != nil {
|
||||
log.Error("JSON encode: %v", err)
|
||||
}
|
||||
_ = json.NewEncoder(resp).Encode(obj)
|
||||
}
|
||||
|
||||
func apiError(ctx *context.Context, status int, obj any) {
|
||||
@@ -43,13 +40,12 @@ func apiError(ctx *context.Context, status int, obj any) {
|
||||
Error Error `json:"error"`
|
||||
}
|
||||
|
||||
helper.LogAndProcessError(ctx, status, obj, func(message string) {
|
||||
jsonResponse(ctx, status, ErrorWrapper{
|
||||
Error: Error{
|
||||
Code: http.StatusText(status),
|
||||
Message: message,
|
||||
},
|
||||
})
|
||||
message := helper.ProcessErrorForUser(ctx, status, obj)
|
||||
jsonResponse(ctx, status, ErrorWrapper{
|
||||
Error: Error{
|
||||
Code: http.StatusText(status),
|
||||
Message: message,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
@@ -274,7 +270,7 @@ func DownloadPackageFile(ctx *context.Context) {
|
||||
|
||||
pf := pd.Files[0].File
|
||||
|
||||
s, u, _, err := packages_service.OpenFileForDownload(ctx, pf)
|
||||
s, u, _, err := packages_service.OpenFileForDownload(ctx, pf, ctx.Req.Method)
|
||||
if err != nil {
|
||||
apiError(ctx, http.StatusInternalServerError, err)
|
||||
return
|
||||
|
||||
@@ -40,9 +40,8 @@ var versionMatcher = regexp.MustCompile(`\Av?` +
|
||||
`\z`)
|
||||
|
||||
func apiError(ctx *context.Context, status int, obj any) {
|
||||
helper.LogAndProcessError(ctx, status, obj, func(message string) {
|
||||
ctx.PlainText(status, message)
|
||||
})
|
||||
message := helper.ProcessErrorForUser(ctx, status, obj)
|
||||
ctx.PlainText(status, message)
|
||||
}
|
||||
|
||||
// PackageMetadata returns the metadata for a single package
|
||||
@@ -93,6 +92,7 @@ func DownloadPackageFile(ctx *context.Context) {
|
||||
&packages_service.PackageFileInfo{
|
||||
Filename: filename,
|
||||
},
|
||||
ctx.Req.Method,
|
||||
)
|
||||
if err != nil {
|
||||
if errors.Is(err, packages_model.ErrPackageNotExist) || errors.Is(err, packages_model.ErrPackageFileNotExist) {
|
||||
|
||||
@@ -26,9 +26,8 @@ import (
|
||||
)
|
||||
|
||||
func apiError(ctx *context.Context, status int, obj any) {
|
||||
helper.LogAndProcessError(ctx, status, obj, func(message string) {
|
||||
ctx.PlainText(status, message)
|
||||
})
|
||||
message := helper.ProcessErrorForUser(ctx, status, obj)
|
||||
ctx.PlainText(status, message)
|
||||
}
|
||||
|
||||
// https://dnf.readthedocs.io/en/latest/conf_ref.html
|
||||
@@ -103,6 +102,7 @@ func GetRepositoryFile(ctx *context.Context) {
|
||||
Filename: ctx.PathParam("filename"),
|
||||
CompositeKey: ctx.PathParam("group"),
|
||||
},
|
||||
ctx.Req.Method,
|
||||
)
|
||||
if err != nil {
|
||||
if errors.Is(err, util.ErrNotExist) {
|
||||
@@ -232,6 +232,7 @@ func DownloadPackageFile(ctx *context.Context) {
|
||||
Filename: fmt.Sprintf("%s-%s.%s.rpm", name, version, ctx.PathParam("architecture")),
|
||||
CompositeKey: ctx.PathParam("group"),
|
||||
},
|
||||
ctx.Req.Method,
|
||||
)
|
||||
if err != nil {
|
||||
if errors.Is(err, util.ErrNotExist) {
|
||||
|
||||
@@ -25,9 +25,8 @@ import (
|
||||
)
|
||||
|
||||
func apiError(ctx *context.Context, status int, obj any) {
|
||||
helper.LogAndProcessError(ctx, status, obj, func(message string) {
|
||||
ctx.PlainText(status, message)
|
||||
})
|
||||
message := helper.ProcessErrorForUser(ctx, status, obj)
|
||||
ctx.PlainText(status, message)
|
||||
}
|
||||
|
||||
// EnumeratePackages serves the package list
|
||||
@@ -184,6 +183,7 @@ func DownloadPackageFile(ctx *context.Context) {
|
||||
&packages_service.PackageFileInfo{
|
||||
Filename: filename,
|
||||
},
|
||||
ctx.Req.Method,
|
||||
)
|
||||
if err != nil {
|
||||
if errors.Is(err, packages_model.ErrPackageFileNotExist) {
|
||||
|
||||
@@ -77,17 +77,14 @@ func apiError(ctx *context.Context, status int, obj any) {
|
||||
Detail string `json:"detail"`
|
||||
}
|
||||
|
||||
helper.LogAndProcessError(ctx, status, obj, func(message string) {
|
||||
setResponseHeaders(ctx.Resp, &headers{
|
||||
Status: status,
|
||||
ContentType: "application/problem+json",
|
||||
})
|
||||
if err := json.NewEncoder(ctx.Resp).Encode(Problem{
|
||||
Status: status,
|
||||
Detail: message,
|
||||
}); err != nil {
|
||||
log.Error("JSON encode: %v", err)
|
||||
}
|
||||
message := helper.ProcessErrorForUser(ctx, status, obj)
|
||||
setResponseHeaders(ctx.Resp, &headers{
|
||||
Status: status,
|
||||
ContentType: "application/problem+json",
|
||||
})
|
||||
_ = json.NewEncoder(ctx.Resp).Encode(Problem{
|
||||
Status: status,
|
||||
Detail: message,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -429,7 +426,7 @@ func DownloadPackageFile(ctx *context.Context) {
|
||||
|
||||
pf := pd.Files[0].File
|
||||
|
||||
s, u, _, err := packages_service.OpenFileForDownload(ctx, pf)
|
||||
s, u, _, err := packages_service.OpenFileForDownload(ctx, pf, ctx.Req.Method)
|
||||
if err != nil {
|
||||
apiError(ctx, http.StatusInternalServerError, err)
|
||||
return
|
||||
|
||||
@@ -24,14 +24,13 @@ import (
|
||||
)
|
||||
|
||||
func apiError(ctx *context.Context, status int, obj any) {
|
||||
helper.LogAndProcessError(ctx, status, obj, func(message string) {
|
||||
ctx.JSON(status, struct {
|
||||
Errors []string `json:"errors"`
|
||||
}{
|
||||
Errors: []string{
|
||||
message,
|
||||
},
|
||||
})
|
||||
message := helper.ProcessErrorForUser(ctx, status, obj)
|
||||
ctx.JSON(status, struct {
|
||||
Errors []string `json:"errors"`
|
||||
}{
|
||||
Errors: []string{
|
||||
message,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
@@ -229,6 +228,7 @@ func DownloadPackageFile(ctx *context.Context) {
|
||||
&packages_service.PackageFileInfo{
|
||||
Filename: ctx.PathParam("provider"),
|
||||
},
|
||||
ctx.Req.Method,
|
||||
)
|
||||
if err != nil {
|
||||
if errors.Is(err, packages_model.ErrPackageNotExist) || errors.Is(err, packages_model.ErrPackageFileNotExist) {
|
||||
|
||||
@@ -46,7 +46,7 @@ func (Action) ListActionsSecrets(ctx *context.APIContext) {
|
||||
// parameters:
|
||||
// - name: owner
|
||||
// in: path
|
||||
// description: owner of the repository
|
||||
// description: owner of the repo
|
||||
// type: string
|
||||
// required: true
|
||||
// - name: repo
|
||||
@@ -216,7 +216,7 @@ func (Action) GetVariable(ctx *context.APIContext) {
|
||||
// parameters:
|
||||
// - name: owner
|
||||
// in: path
|
||||
// description: name of the owner
|
||||
// description: owner of the repo
|
||||
// type: string
|
||||
// required: true
|
||||
// - name: repo
|
||||
@@ -270,7 +270,7 @@ func (Action) DeleteVariable(ctx *context.APIContext) {
|
||||
// parameters:
|
||||
// - name: owner
|
||||
// in: path
|
||||
// description: name of the owner
|
||||
// description: owner of the repo
|
||||
// type: string
|
||||
// required: true
|
||||
// - name: repo
|
||||
@@ -319,7 +319,7 @@ func (Action) CreateVariable(ctx *context.APIContext) {
|
||||
// parameters:
|
||||
// - name: owner
|
||||
// in: path
|
||||
// description: name of the owner
|
||||
// description: owner of the repo
|
||||
// type: string
|
||||
// required: true
|
||||
// - name: repo
|
||||
@@ -386,7 +386,7 @@ func (Action) UpdateVariable(ctx *context.APIContext) {
|
||||
// parameters:
|
||||
// - name: owner
|
||||
// in: path
|
||||
// description: name of the owner
|
||||
// description: owner of the repo
|
||||
// type: string
|
||||
// required: true
|
||||
// - name: repo
|
||||
@@ -458,7 +458,7 @@ func (Action) ListVariables(ctx *context.APIContext) {
|
||||
// parameters:
|
||||
// - name: owner
|
||||
// in: path
|
||||
// description: name of the owner
|
||||
// description: owner of the repo
|
||||
// type: string
|
||||
// required: true
|
||||
// - name: repo
|
||||
@@ -660,7 +660,7 @@ func (Action) ListWorkflowJobs(ctx *context.APIContext) {
|
||||
// parameters:
|
||||
// - name: owner
|
||||
// in: path
|
||||
// description: name of the owner
|
||||
// description: owner of the repo
|
||||
// type: string
|
||||
// required: true
|
||||
// - name: repo
|
||||
@@ -704,7 +704,7 @@ func (Action) ListWorkflowRuns(ctx *context.APIContext) {
|
||||
// parameters:
|
||||
// - name: owner
|
||||
// in: path
|
||||
// description: name of the owner
|
||||
// description: owner of the repo
|
||||
// type: string
|
||||
// required: true
|
||||
// - name: repo
|
||||
@@ -1110,7 +1110,7 @@ func GetWorkflowRun(ctx *context.APIContext) {
|
||||
// parameters:
|
||||
// - name: owner
|
||||
// in: path
|
||||
// description: name of the owner
|
||||
// description: owner of the repo
|
||||
// type: string
|
||||
// required: true
|
||||
// - name: repo
|
||||
@@ -1132,18 +1132,23 @@ func GetWorkflowRun(ctx *context.APIContext) {
|
||||
// "$ref": "#/responses/notFound"
|
||||
|
||||
runID := ctx.PathParamInt64("run")
|
||||
job, _, err := db.GetByID[actions_model.ActionRun](ctx, runID)
|
||||
|
||||
if err != nil || job.RepoID != ctx.Repo.Repository.ID {
|
||||
ctx.APIError(http.StatusNotFound, util.ErrNotExist)
|
||||
}
|
||||
|
||||
convertedArtifact, err := convert.ToActionWorkflowRun(ctx, ctx.Repo.Repository, job)
|
||||
job, has, err := db.GetByID[actions_model.ActionRun](ctx, runID)
|
||||
if err != nil {
|
||||
ctx.APIErrorInternal(err)
|
||||
return
|
||||
}
|
||||
ctx.JSON(http.StatusOK, convertedArtifact)
|
||||
|
||||
if !has || job.RepoID != ctx.Repo.Repository.ID {
|
||||
ctx.APIErrorNotFound(util.ErrNotExist)
|
||||
return
|
||||
}
|
||||
|
||||
convertedRun, err := convert.ToActionWorkflowRun(ctx, ctx.Repo.Repository, job)
|
||||
if err != nil {
|
||||
ctx.APIErrorInternal(err)
|
||||
return
|
||||
}
|
||||
ctx.JSON(http.StatusOK, convertedRun)
|
||||
}
|
||||
|
||||
// ListWorkflowRunJobs Lists all jobs for a workflow run.
|
||||
@@ -1156,7 +1161,7 @@ func ListWorkflowRunJobs(ctx *context.APIContext) {
|
||||
// parameters:
|
||||
// - name: owner
|
||||
// in: path
|
||||
// description: name of the owner
|
||||
// description: owner of the repo
|
||||
// type: string
|
||||
// required: true
|
||||
// - name: repo
|
||||
@@ -1215,7 +1220,7 @@ func GetWorkflowJob(ctx *context.APIContext) {
|
||||
// parameters:
|
||||
// - name: owner
|
||||
// in: path
|
||||
// description: name of the owner
|
||||
// description: owner of the repo
|
||||
// type: string
|
||||
// required: true
|
||||
// - name: repo
|
||||
@@ -1237,10 +1242,15 @@ func GetWorkflowJob(ctx *context.APIContext) {
|
||||
// "$ref": "#/responses/notFound"
|
||||
|
||||
jobID := ctx.PathParamInt64("job_id")
|
||||
job, _, err := db.GetByID[actions_model.ActionRunJob](ctx, jobID)
|
||||
job, has, err := db.GetByID[actions_model.ActionRunJob](ctx, jobID)
|
||||
if err != nil {
|
||||
ctx.APIErrorInternal(err)
|
||||
return
|
||||
}
|
||||
|
||||
if err != nil || job.RepoID != ctx.Repo.Repository.ID {
|
||||
ctx.APIError(http.StatusNotFound, util.ErrNotExist)
|
||||
if !has || job.RepoID != ctx.Repo.Repository.ID {
|
||||
ctx.APIErrorNotFound(util.ErrNotExist)
|
||||
return
|
||||
}
|
||||
|
||||
convertedWorkflowJob, err := convert.ToActionWorkflowJob(ctx, ctx.Repo.Repository, nil, job)
|
||||
@@ -1251,7 +1261,7 @@ func GetWorkflowJob(ctx *context.APIContext) {
|
||||
ctx.JSON(http.StatusOK, convertedWorkflowJob)
|
||||
}
|
||||
|
||||
// GetArtifacts Lists all artifacts for a repository.
|
||||
// GetArtifactsOfRun Lists all artifacts for a repository.
|
||||
func GetArtifactsOfRun(ctx *context.APIContext) {
|
||||
// swagger:operation GET /repos/{owner}/{repo}/actions/runs/{run}/artifacts repository getArtifactsOfRun
|
||||
// ---
|
||||
@@ -1261,7 +1271,7 @@ func GetArtifactsOfRun(ctx *context.APIContext) {
|
||||
// parameters:
|
||||
// - name: owner
|
||||
// in: path
|
||||
// description: name of the owner
|
||||
// description: owner of the repo
|
||||
// type: string
|
||||
// required: true
|
||||
// - name: repo
|
||||
@@ -1330,7 +1340,7 @@ func DeleteActionRun(ctx *context.APIContext) {
|
||||
// parameters:
|
||||
// - name: owner
|
||||
// in: path
|
||||
// description: name of the owner
|
||||
// description: owner of the repo
|
||||
// type: string
|
||||
// required: true
|
||||
// - name: repo
|
||||
@@ -1354,7 +1364,7 @@ func DeleteActionRun(ctx *context.APIContext) {
|
||||
runID := ctx.PathParamInt64("run")
|
||||
run, err := actions_model.GetRunByRepoAndID(ctx, ctx.Repo.Repository.ID, runID)
|
||||
if errors.Is(err, util.ErrNotExist) {
|
||||
ctx.APIError(http.StatusNotFound, err)
|
||||
ctx.APIErrorNotFound(err)
|
||||
return
|
||||
} else if err != nil {
|
||||
ctx.APIErrorInternal(err)
|
||||
@@ -1382,7 +1392,7 @@ func GetArtifacts(ctx *context.APIContext) {
|
||||
// parameters:
|
||||
// - name: owner
|
||||
// in: path
|
||||
// description: name of the owner
|
||||
// description: owner of the repo
|
||||
// type: string
|
||||
// required: true
|
||||
// - name: repo
|
||||
@@ -1443,7 +1453,7 @@ func GetArtifact(ctx *context.APIContext) {
|
||||
// parameters:
|
||||
// - name: owner
|
||||
// in: path
|
||||
// description: name of the owner
|
||||
// description: owner of the repo
|
||||
// type: string
|
||||
// required: true
|
||||
// - name: repo
|
||||
@@ -1492,7 +1502,7 @@ func DeleteArtifact(ctx *context.APIContext) {
|
||||
// parameters:
|
||||
// - name: owner
|
||||
// in: path
|
||||
// description: name of the owner
|
||||
// description: owner of the repo
|
||||
// type: string
|
||||
// required: true
|
||||
// - name: repo
|
||||
@@ -1559,7 +1569,7 @@ func DownloadArtifact(ctx *context.APIContext) {
|
||||
// parameters:
|
||||
// - name: owner
|
||||
// in: path
|
||||
// description: name of the owner
|
||||
// description: owner of the repo
|
||||
// type: string
|
||||
// required: true
|
||||
// - name: repo
|
||||
|
||||
@@ -21,7 +21,7 @@ func DownloadActionsRunJobLogs(ctx *context.APIContext) {
|
||||
// parameters:
|
||||
// - name: owner
|
||||
// in: path
|
||||
// description: name of the owner
|
||||
// description: owner of the repo
|
||||
// type: string
|
||||
// required: true
|
||||
// - name: repo
|
||||
|
||||
@@ -210,7 +210,7 @@ func GetRawFileOrLFS(ctx *context.APIContext) {
|
||||
|
||||
if setting.LFS.Storage.ServeDirect() {
|
||||
// If we have a signed url (S3, object storage), redirect to this directly.
|
||||
u, err := storage.LFS.URL(pointer.RelativePath(), blob.Name(), nil)
|
||||
u, err := storage.LFS.URL(pointer.RelativePath(), blob.Name(), ctx.Req.Method, nil)
|
||||
if u != nil && err == nil {
|
||||
ctx.Redirect(u.String())
|
||||
return
|
||||
@@ -331,7 +331,7 @@ func download(ctx *context.APIContext, archiveName string, archiver *repo_model.
|
||||
rPath := archiver.RelativePath()
|
||||
if setting.RepoArchive.Storage.ServeDirect() {
|
||||
// If we have a signed url (S3, object storage), redirect to this directly.
|
||||
u, err := storage.RepoArchives.URL(rPath, downloadName, nil)
|
||||
u, err := storage.RepoArchives.URL(rPath, downloadName, ctx.Req.Method, nil)
|
||||
if u != nil && err == nil {
|
||||
ctx.Redirect(u.String())
|
||||
return
|
||||
|
||||
@@ -52,7 +52,7 @@ func ListPullRequests(ctx *context.APIContext) {
|
||||
// parameters:
|
||||
// - name: owner
|
||||
// in: path
|
||||
// description: Owner of the repo
|
||||
// description: owner of the repo
|
||||
// type: string
|
||||
// required: true
|
||||
// - name: repo
|
||||
@@ -1461,9 +1461,9 @@ func GetPullRequestCommits(ctx *context.APIContext) {
|
||||
defer closer.Close()
|
||||
|
||||
if pr.HasMerged {
|
||||
prInfo, err = baseGitRepo.GetCompareInfo(pr.BaseRepo.RepoPath(), pr.MergeBase, pr.GetGitRefName(), false, false)
|
||||
prInfo, err = baseGitRepo.GetCompareInfo(pr.BaseRepo.RepoPath(), pr.MergeBase, pr.GetGitHeadRefName(), false, false)
|
||||
} else {
|
||||
prInfo, err = baseGitRepo.GetCompareInfo(pr.BaseRepo.RepoPath(), pr.BaseBranch, pr.GetGitRefName(), false, false)
|
||||
prInfo, err = baseGitRepo.GetCompareInfo(pr.BaseRepo.RepoPath(), pr.BaseBranch, pr.GetGitHeadRefName(), false, false)
|
||||
}
|
||||
if err != nil {
|
||||
ctx.APIErrorInternal(err)
|
||||
@@ -1584,16 +1584,16 @@ func GetPullRequestFiles(ctx *context.APIContext) {
|
||||
|
||||
var prInfo *git.CompareInfo
|
||||
if pr.HasMerged {
|
||||
prInfo, err = baseGitRepo.GetCompareInfo(pr.BaseRepo.RepoPath(), pr.MergeBase, pr.GetGitRefName(), true, false)
|
||||
prInfo, err = baseGitRepo.GetCompareInfo(pr.BaseRepo.RepoPath(), pr.MergeBase, pr.GetGitHeadRefName(), true, false)
|
||||
} else {
|
||||
prInfo, err = baseGitRepo.GetCompareInfo(pr.BaseRepo.RepoPath(), pr.BaseBranch, pr.GetGitRefName(), true, false)
|
||||
prInfo, err = baseGitRepo.GetCompareInfo(pr.BaseRepo.RepoPath(), pr.BaseBranch, pr.GetGitHeadRefName(), true, false)
|
||||
}
|
||||
if err != nil {
|
||||
ctx.APIErrorInternal(err)
|
||||
return
|
||||
}
|
||||
|
||||
headCommitID, err := baseGitRepo.GetRefCommitID(pr.GetGitRefName())
|
||||
headCommitID, err := baseGitRepo.GetRefCommitID(pr.GetGitHeadRefName())
|
||||
if err != nil {
|
||||
ctx.APIErrorInternal(err)
|
||||
return
|
||||
|
||||
@@ -336,7 +336,7 @@ func CreatePullReview(ctx *context.APIContext) {
|
||||
}
|
||||
defer closer.Close()
|
||||
|
||||
headCommitID, err := gitRepo.GetRefCommitID(pr.GetGitRefName())
|
||||
headCommitID, err := gitRepo.GetRefCommitID(pr.GetGitHeadRefName())
|
||||
if err != nil {
|
||||
ctx.APIErrorInternal(err)
|
||||
return
|
||||
@@ -455,7 +455,7 @@ func SubmitPullReview(ctx *context.APIContext) {
|
||||
return
|
||||
}
|
||||
|
||||
headCommitID, err := ctx.Repo.GitRepo.GetRefCommitID(pr.GetGitRefName())
|
||||
headCommitID, err := ctx.Repo.GitRepo.GetRefCommitID(pr.GetGitHeadRefName())
|
||||
if err != nil {
|
||||
ctx.APIErrorInternal(err)
|
||||
return
|
||||
|
||||
+13
-33
@@ -329,7 +329,7 @@ func Generate(ctx *context.APIContext) {
|
||||
// parameters:
|
||||
// - name: template_owner
|
||||
// in: path
|
||||
// description: name of the template repository owner
|
||||
// description: owner of the template repository
|
||||
// type: string
|
||||
// required: true
|
||||
// - name: template_repo
|
||||
@@ -772,13 +772,8 @@ func updateRepoUnits(ctx *context.APIContext, opts api.EditRepoOption) error {
|
||||
var units []repo_model.RepoUnit
|
||||
var deleteUnitTypes []unit_model.Type
|
||||
|
||||
currHasIssues := repo.UnitEnabled(ctx, unit_model.TypeIssues)
|
||||
newHasIssues := currHasIssues
|
||||
if opts.HasIssues != nil {
|
||||
newHasIssues = *opts.HasIssues
|
||||
}
|
||||
if currHasIssues || newHasIssues {
|
||||
if newHasIssues && opts.ExternalTracker != nil && !unit_model.TypeExternalTracker.UnitGlobalDisabled() {
|
||||
if *opts.HasIssues && opts.ExternalTracker != nil && !unit_model.TypeExternalTracker.UnitGlobalDisabled() {
|
||||
// Check that values are valid
|
||||
if !validation.IsValidExternalURL(opts.ExternalTracker.ExternalTrackerURL) {
|
||||
err := errors.New("External tracker URL not valid")
|
||||
@@ -802,7 +797,7 @@ func updateRepoUnits(ctx *context.APIContext, opts api.EditRepoOption) error {
|
||||
},
|
||||
})
|
||||
deleteUnitTypes = append(deleteUnitTypes, unit_model.TypeIssues)
|
||||
} else if newHasIssues && opts.ExternalTracker == nil && !unit_model.TypeIssues.UnitGlobalDisabled() {
|
||||
} else if *opts.HasIssues && opts.ExternalTracker == nil && !unit_model.TypeIssues.UnitGlobalDisabled() {
|
||||
// Default to built-in tracker
|
||||
var config *repo_model.IssuesConfig
|
||||
|
||||
@@ -829,7 +824,7 @@ func updateRepoUnits(ctx *context.APIContext, opts api.EditRepoOption) error {
|
||||
Config: config,
|
||||
})
|
||||
deleteUnitTypes = append(deleteUnitTypes, unit_model.TypeExternalTracker)
|
||||
} else if !newHasIssues {
|
||||
} else if !*opts.HasIssues {
|
||||
if !unit_model.TypeExternalTracker.UnitGlobalDisabled() {
|
||||
deleteUnitTypes = append(deleteUnitTypes, unit_model.TypeExternalTracker)
|
||||
}
|
||||
@@ -839,13 +834,8 @@ func updateRepoUnits(ctx *context.APIContext, opts api.EditRepoOption) error {
|
||||
}
|
||||
}
|
||||
|
||||
currHasWiki := repo.UnitEnabled(ctx, unit_model.TypeWiki)
|
||||
newHasWiki := currHasWiki
|
||||
if opts.HasWiki != nil {
|
||||
newHasWiki = *opts.HasWiki
|
||||
}
|
||||
if currHasWiki || newHasWiki {
|
||||
if newHasWiki && opts.ExternalWiki != nil && !unit_model.TypeExternalWiki.UnitGlobalDisabled() {
|
||||
if *opts.HasWiki && opts.ExternalWiki != nil && !unit_model.TypeExternalWiki.UnitGlobalDisabled() {
|
||||
// Check that values are valid
|
||||
if !validation.IsValidExternalURL(opts.ExternalWiki.ExternalWikiURL) {
|
||||
err := errors.New("External wiki URL not valid")
|
||||
@@ -861,7 +851,7 @@ func updateRepoUnits(ctx *context.APIContext, opts api.EditRepoOption) error {
|
||||
},
|
||||
})
|
||||
deleteUnitTypes = append(deleteUnitTypes, unit_model.TypeWiki)
|
||||
} else if newHasWiki && opts.ExternalWiki == nil && !unit_model.TypeWiki.UnitGlobalDisabled() {
|
||||
} else if *opts.HasWiki && opts.ExternalWiki == nil && !unit_model.TypeWiki.UnitGlobalDisabled() {
|
||||
config := &repo_model.UnitConfig{}
|
||||
units = append(units, repo_model.RepoUnit{
|
||||
RepoID: repo.ID,
|
||||
@@ -869,7 +859,7 @@ func updateRepoUnits(ctx *context.APIContext, opts api.EditRepoOption) error {
|
||||
Config: config,
|
||||
})
|
||||
deleteUnitTypes = append(deleteUnitTypes, unit_model.TypeExternalWiki)
|
||||
} else if !newHasWiki {
|
||||
} else if !*opts.HasWiki {
|
||||
if !unit_model.TypeExternalWiki.UnitGlobalDisabled() {
|
||||
deleteUnitTypes = append(deleteUnitTypes, unit_model.TypeExternalWiki)
|
||||
}
|
||||
@@ -879,13 +869,8 @@ func updateRepoUnits(ctx *context.APIContext, opts api.EditRepoOption) error {
|
||||
}
|
||||
}
|
||||
|
||||
currHasPullRequests := repo.UnitEnabled(ctx, unit_model.TypePullRequests)
|
||||
newHasPullRequests := currHasPullRequests
|
||||
if opts.HasPullRequests != nil {
|
||||
newHasPullRequests = *opts.HasPullRequests
|
||||
}
|
||||
if currHasPullRequests || newHasPullRequests {
|
||||
if newHasPullRequests && !unit_model.TypePullRequests.UnitGlobalDisabled() {
|
||||
if opts.HasPullRequests != nil && !unit_model.TypePullRequests.UnitGlobalDisabled() {
|
||||
if *opts.HasPullRequests {
|
||||
// We do allow setting individual PR settings through the API, so
|
||||
// we get the config settings and then set them
|
||||
// if those settings were provided in the opts.
|
||||
@@ -953,18 +938,13 @@ func updateRepoUnits(ctx *context.APIContext, opts api.EditRepoOption) error {
|
||||
Type: unit_model.TypePullRequests,
|
||||
Config: config,
|
||||
})
|
||||
} else if !newHasPullRequests && !unit_model.TypePullRequests.UnitGlobalDisabled() {
|
||||
} else {
|
||||
deleteUnitTypes = append(deleteUnitTypes, unit_model.TypePullRequests)
|
||||
}
|
||||
}
|
||||
|
||||
currHasProjects := repo.UnitEnabled(ctx, unit_model.TypeProjects)
|
||||
newHasProjects := currHasProjects
|
||||
if opts.HasProjects != nil {
|
||||
newHasProjects = *opts.HasProjects
|
||||
}
|
||||
if currHasProjects || newHasProjects {
|
||||
if newHasProjects && !unit_model.TypeProjects.UnitGlobalDisabled() {
|
||||
if opts.HasProjects != nil && !unit_model.TypeProjects.UnitGlobalDisabled() {
|
||||
if *opts.HasProjects {
|
||||
unit, err := repo.GetUnit(ctx, unit_model.TypeProjects)
|
||||
var config *repo_model.ProjectsConfig
|
||||
if err != nil {
|
||||
@@ -984,7 +964,7 @@ func updateRepoUnits(ctx *context.APIContext, opts api.EditRepoOption) error {
|
||||
Type: unit_model.TypeProjects,
|
||||
Config: config,
|
||||
})
|
||||
} else if !newHasProjects && !unit_model.TypeProjects.UnitGlobalDisabled() {
|
||||
} else {
|
||||
deleteUnitTypes = append(deleteUnitTypes, unit_model.TypeProjects)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user