Refactor error system (#33610)
This commit is contained in:
parent
69de5a65c2
commit
f35850f48e
184 changed files with 2100 additions and 2106 deletions
|
@ -135,7 +135,7 @@ func ArtifactContexter() func(next http.Handler) http.Handler {
|
||||||
// we should verify the ACTIONS_RUNTIME_TOKEN
|
// we should verify the ACTIONS_RUNTIME_TOKEN
|
||||||
authHeader := req.Header.Get("Authorization")
|
authHeader := req.Header.Get("Authorization")
|
||||||
if len(authHeader) == 0 || !strings.HasPrefix(authHeader, "Bearer ") {
|
if len(authHeader) == 0 || !strings.HasPrefix(authHeader, "Bearer ") {
|
||||||
ctx.Error(http.StatusUnauthorized, "Bad authorization header")
|
ctx.HTTPError(http.StatusUnauthorized, "Bad authorization header")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -147,12 +147,12 @@ func ArtifactContexter() func(next http.Handler) http.Handler {
|
||||||
task, err = actions.GetTaskByID(req.Context(), tID)
|
task, err = actions.GetTaskByID(req.Context(), tID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("Error runner api getting task by ID: %v", err)
|
log.Error("Error runner api getting task by ID: %v", err)
|
||||||
ctx.Error(http.StatusInternalServerError, "Error runner api getting task by ID")
|
ctx.HTTPError(http.StatusInternalServerError, "Error runner api getting task by ID")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if task.Status != actions.StatusRunning {
|
if task.Status != actions.StatusRunning {
|
||||||
log.Error("Error runner api getting task: task is not running")
|
log.Error("Error runner api getting task: task is not running")
|
||||||
ctx.Error(http.StatusInternalServerError, "Error runner api getting task: task is not running")
|
ctx.HTTPError(http.StatusInternalServerError, "Error runner api getting task: task is not running")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -162,14 +162,14 @@ func ArtifactContexter() func(next http.Handler) http.Handler {
|
||||||
task, err = actions.GetRunningTaskByToken(req.Context(), authToken)
|
task, err = actions.GetRunningTaskByToken(req.Context(), authToken)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("Error runner api getting task: %v", err)
|
log.Error("Error runner api getting task: %v", err)
|
||||||
ctx.Error(http.StatusInternalServerError, "Error runner api getting task")
|
ctx.HTTPError(http.StatusInternalServerError, "Error runner api getting task")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := task.LoadJob(req.Context()); err != nil {
|
if err := task.LoadJob(req.Context()); err != nil {
|
||||||
log.Error("Error runner api getting job: %v", err)
|
log.Error("Error runner api getting job: %v", err)
|
||||||
ctx.Error(http.StatusInternalServerError, "Error runner api getting job")
|
ctx.HTTPError(http.StatusInternalServerError, "Error runner api getting job")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -211,7 +211,7 @@ func (ar artifactRoutes) getUploadArtifactURL(ctx *ArtifactContext) {
|
||||||
var req getUploadArtifactRequest
|
var req getUploadArtifactRequest
|
||||||
if err := json.NewDecoder(ctx.Req.Body).Decode(&req); err != nil {
|
if err := json.NewDecoder(ctx.Req.Body).Decode(&req); err != nil {
|
||||||
log.Error("Error decode request body: %v", err)
|
log.Error("Error decode request body: %v", err)
|
||||||
ctx.Error(http.StatusInternalServerError, "Error decode request body")
|
ctx.HTTPError(http.StatusInternalServerError, "Error decode request body")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -250,7 +250,7 @@ func (ar artifactRoutes) uploadArtifact(ctx *ArtifactContext) {
|
||||||
expiredDays, err = strconv.ParseInt(queryRetentionDays, 10, 64)
|
expiredDays, err = strconv.ParseInt(queryRetentionDays, 10, 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("Error parse retention days: %v", err)
|
log.Error("Error parse retention days: %v", err)
|
||||||
ctx.Error(http.StatusBadRequest, "Error parse retention days")
|
ctx.HTTPError(http.StatusBadRequest, "Error parse retention days")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -261,7 +261,7 @@ func (ar artifactRoutes) uploadArtifact(ctx *ArtifactContext) {
|
||||||
artifact, err := actions.CreateArtifact(ctx, task, artifactName, artifactPath, expiredDays)
|
artifact, err := actions.CreateArtifact(ctx, task, artifactName, artifactPath, expiredDays)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("Error create or get artifact: %v", err)
|
log.Error("Error create or get artifact: %v", err)
|
||||||
ctx.Error(http.StatusInternalServerError, "Error create or get artifact")
|
ctx.HTTPError(http.StatusInternalServerError, "Error create or get artifact")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -271,7 +271,7 @@ func (ar artifactRoutes) uploadArtifact(ctx *ArtifactContext) {
|
||||||
chunksTotalSize, err := saveUploadChunk(ar.fs, ctx, artifact, contentLength, runID)
|
chunksTotalSize, err := saveUploadChunk(ar.fs, ctx, artifact, contentLength, runID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("Error save upload chunk: %v", err)
|
log.Error("Error save upload chunk: %v", err)
|
||||||
ctx.Error(http.StatusInternalServerError, "Error save upload chunk")
|
ctx.HTTPError(http.StatusInternalServerError, "Error save upload chunk")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -285,7 +285,7 @@ func (ar artifactRoutes) uploadArtifact(ctx *ArtifactContext) {
|
||||||
artifact.ContentEncoding = ctx.Req.Header.Get("Content-Encoding")
|
artifact.ContentEncoding = ctx.Req.Header.Get("Content-Encoding")
|
||||||
if err := actions.UpdateArtifactByID(ctx, artifact.ID, artifact); err != nil {
|
if err := actions.UpdateArtifactByID(ctx, artifact.ID, artifact); err != nil {
|
||||||
log.Error("Error update artifact: %v", err)
|
log.Error("Error update artifact: %v", err)
|
||||||
ctx.Error(http.StatusInternalServerError, "Error update artifact")
|
ctx.HTTPError(http.StatusInternalServerError, "Error update artifact")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
log.Debug("[artifact] update artifact size, artifact_id: %d, size: %d, compressed size: %d",
|
log.Debug("[artifact] update artifact size, artifact_id: %d, size: %d, compressed size: %d",
|
||||||
|
@ -307,12 +307,12 @@ func (ar artifactRoutes) comfirmUploadArtifact(ctx *ArtifactContext) {
|
||||||
artifactName := ctx.Req.URL.Query().Get("artifactName")
|
artifactName := ctx.Req.URL.Query().Get("artifactName")
|
||||||
if artifactName == "" {
|
if artifactName == "" {
|
||||||
log.Error("Error artifact name is empty")
|
log.Error("Error artifact name is empty")
|
||||||
ctx.Error(http.StatusBadRequest, "Error artifact name is empty")
|
ctx.HTTPError(http.StatusBadRequest, "Error artifact name is empty")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if err := mergeChunksForRun(ctx, ar.fs, runID, artifactName); err != nil {
|
if err := mergeChunksForRun(ctx, ar.fs, runID, artifactName); err != nil {
|
||||||
log.Error("Error merge chunks: %v", err)
|
log.Error("Error merge chunks: %v", err)
|
||||||
ctx.Error(http.StatusInternalServerError, "Error merge chunks")
|
ctx.HTTPError(http.StatusInternalServerError, "Error merge chunks")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.JSON(http.StatusOK, map[string]string{
|
ctx.JSON(http.StatusOK, map[string]string{
|
||||||
|
@ -340,12 +340,12 @@ func (ar artifactRoutes) listArtifacts(ctx *ArtifactContext) {
|
||||||
artifacts, err := db.Find[actions.ActionArtifact](ctx, actions.FindArtifactsOptions{RunID: runID})
|
artifacts, err := db.Find[actions.ActionArtifact](ctx, actions.FindArtifactsOptions{RunID: runID})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("Error getting artifacts: %v", err)
|
log.Error("Error getting artifacts: %v", err)
|
||||||
ctx.Error(http.StatusInternalServerError, err.Error())
|
ctx.HTTPError(http.StatusInternalServerError, err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if len(artifacts) == 0 {
|
if len(artifacts) == 0 {
|
||||||
log.Debug("[artifact] handleListArtifacts, no artifacts")
|
log.Debug("[artifact] handleListArtifacts, no artifacts")
|
||||||
ctx.Error(http.StatusNotFound)
|
ctx.HTTPError(http.StatusNotFound)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -405,18 +405,18 @@ func (ar artifactRoutes) getDownloadArtifactURL(ctx *ArtifactContext) {
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("Error getting artifacts: %v", err)
|
log.Error("Error getting artifacts: %v", err)
|
||||||
ctx.Error(http.StatusInternalServerError, err.Error())
|
ctx.HTTPError(http.StatusInternalServerError, err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if len(artifacts) == 0 {
|
if len(artifacts) == 0 {
|
||||||
log.Debug("[artifact] getDownloadArtifactURL, no artifacts")
|
log.Debug("[artifact] getDownloadArtifactURL, no artifacts")
|
||||||
ctx.Error(http.StatusNotFound)
|
ctx.HTTPError(http.StatusNotFound)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if itemPath != artifacts[0].ArtifactName {
|
if itemPath != artifacts[0].ArtifactName {
|
||||||
log.Error("Error dismatch artifact name, itemPath: %v, artifact: %v", itemPath, artifacts[0].ArtifactName)
|
log.Error("Error dismatch artifact name, itemPath: %v, artifact: %v", itemPath, artifacts[0].ArtifactName)
|
||||||
ctx.Error(http.StatusBadRequest, "Error dismatch artifact name")
|
ctx.HTTPError(http.StatusBadRequest, "Error dismatch artifact name")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -460,24 +460,24 @@ func (ar artifactRoutes) downloadArtifact(ctx *ArtifactContext) {
|
||||||
artifact, exist, err := db.GetByID[actions.ActionArtifact](ctx, artifactID)
|
artifact, exist, err := db.GetByID[actions.ActionArtifact](ctx, artifactID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("Error getting artifact: %v", err)
|
log.Error("Error getting artifact: %v", err)
|
||||||
ctx.Error(http.StatusInternalServerError, err.Error())
|
ctx.HTTPError(http.StatusInternalServerError, err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if !exist {
|
if !exist {
|
||||||
log.Error("artifact with ID %d does not exist", artifactID)
|
log.Error("artifact with ID %d does not exist", artifactID)
|
||||||
ctx.Error(http.StatusNotFound, fmt.Sprintf("artifact with ID %d does not exist", artifactID))
|
ctx.HTTPError(http.StatusNotFound, fmt.Sprintf("artifact with ID %d does not exist", artifactID))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if artifact.RunID != runID {
|
if artifact.RunID != runID {
|
||||||
log.Error("Error mismatch runID and artifactID, task: %v, artifact: %v", runID, artifactID)
|
log.Error("Error mismatch runID and artifactID, task: %v, artifact: %v", runID, artifactID)
|
||||||
ctx.Error(http.StatusBadRequest)
|
ctx.HTTPError(http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
fd, err := ar.fs.Open(artifact.StoragePath)
|
fd, err := ar.fs.Open(artifact.StoragePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("Error opening file: %v", err)
|
log.Error("Error opening file: %v", err)
|
||||||
ctx.Error(http.StatusInternalServerError, err.Error())
|
ctx.HTTPError(http.StatusInternalServerError, err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
defer fd.Close()
|
defer fd.Close()
|
||||||
|
|
|
@ -26,7 +26,7 @@ var invalidArtifactNameChars = strings.Join([]string{"\\", "/", "\"", ":", "<",
|
||||||
func validateArtifactName(ctx *ArtifactContext, artifactName string) bool {
|
func validateArtifactName(ctx *ArtifactContext, artifactName string) bool {
|
||||||
if strings.ContainsAny(artifactName, invalidArtifactNameChars) {
|
if strings.ContainsAny(artifactName, invalidArtifactNameChars) {
|
||||||
log.Error("Error checking artifact name contains invalid character")
|
log.Error("Error checking artifact name contains invalid character")
|
||||||
ctx.Error(http.StatusBadRequest, "Error checking artifact name contains invalid character")
|
ctx.HTTPError(http.StatusBadRequest, "Error checking artifact name contains invalid character")
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
|
@ -37,7 +37,7 @@ func validateRunID(ctx *ArtifactContext) (*actions.ActionTask, int64, bool) {
|
||||||
runID := ctx.PathParamInt64("run_id")
|
runID := ctx.PathParamInt64("run_id")
|
||||||
if task.Job.RunID != runID {
|
if task.Job.RunID != runID {
|
||||||
log.Error("Error runID not match")
|
log.Error("Error runID not match")
|
||||||
ctx.Error(http.StatusBadRequest, "run-id does not match")
|
ctx.HTTPError(http.StatusBadRequest, "run-id does not match")
|
||||||
return nil, 0, false
|
return nil, 0, false
|
||||||
}
|
}
|
||||||
return task, runID, true
|
return task, runID, true
|
||||||
|
@ -48,7 +48,7 @@ func validateRunIDV4(ctx *ArtifactContext, rawRunID string) (*actions.ActionTask
|
||||||
runID, err := strconv.ParseInt(rawRunID, 10, 64)
|
runID, err := strconv.ParseInt(rawRunID, 10, 64)
|
||||||
if err != nil || task.Job.RunID != runID {
|
if err != nil || task.Job.RunID != runID {
|
||||||
log.Error("Error runID not match")
|
log.Error("Error runID not match")
|
||||||
ctx.Error(http.StatusBadRequest, "run-id does not match")
|
ctx.HTTPError(http.StatusBadRequest, "run-id does not match")
|
||||||
return nil, 0, false
|
return nil, 0, false
|
||||||
}
|
}
|
||||||
return task, runID, true
|
return task, runID, true
|
||||||
|
@ -62,7 +62,7 @@ func validateArtifactHash(ctx *ArtifactContext, artifactName string) bool {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
log.Error("Invalid artifact hash: %s", paramHash)
|
log.Error("Invalid artifact hash: %s", paramHash)
|
||||||
ctx.Error(http.StatusBadRequest, "Invalid artifact hash")
|
ctx.HTTPError(http.StatusBadRequest, "Invalid artifact hash")
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -187,29 +187,29 @@ func (r artifactV4Routes) verifySignature(ctx *ArtifactContext, endp string) (*a
|
||||||
expecedsig := r.buildSignature(endp, expires, artifactName, taskID, artifactID)
|
expecedsig := r.buildSignature(endp, expires, artifactName, taskID, artifactID)
|
||||||
if !hmac.Equal(dsig, expecedsig) {
|
if !hmac.Equal(dsig, expecedsig) {
|
||||||
log.Error("Error unauthorized")
|
log.Error("Error unauthorized")
|
||||||
ctx.Error(http.StatusUnauthorized, "Error unauthorized")
|
ctx.HTTPError(http.StatusUnauthorized, "Error unauthorized")
|
||||||
return nil, "", false
|
return nil, "", false
|
||||||
}
|
}
|
||||||
t, err := time.Parse("2006-01-02 15:04:05.999999999 -0700 MST", expires)
|
t, err := time.Parse("2006-01-02 15:04:05.999999999 -0700 MST", expires)
|
||||||
if err != nil || t.Before(time.Now()) {
|
if err != nil || t.Before(time.Now()) {
|
||||||
log.Error("Error link expired")
|
log.Error("Error link expired")
|
||||||
ctx.Error(http.StatusUnauthorized, "Error link expired")
|
ctx.HTTPError(http.StatusUnauthorized, "Error link expired")
|
||||||
return nil, "", false
|
return nil, "", false
|
||||||
}
|
}
|
||||||
task, err := actions.GetTaskByID(ctx, taskID)
|
task, err := actions.GetTaskByID(ctx, taskID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("Error runner api getting task by ID: %v", err)
|
log.Error("Error runner api getting task by ID: %v", err)
|
||||||
ctx.Error(http.StatusInternalServerError, "Error runner api getting task by ID")
|
ctx.HTTPError(http.StatusInternalServerError, "Error runner api getting task by ID")
|
||||||
return nil, "", false
|
return nil, "", false
|
||||||
}
|
}
|
||||||
if task.Status != actions.StatusRunning {
|
if task.Status != actions.StatusRunning {
|
||||||
log.Error("Error runner api getting task: task is not running")
|
log.Error("Error runner api getting task: task is not running")
|
||||||
ctx.Error(http.StatusInternalServerError, "Error runner api getting task: task is not running")
|
ctx.HTTPError(http.StatusInternalServerError, "Error runner api getting task: task is not running")
|
||||||
return nil, "", false
|
return nil, "", false
|
||||||
}
|
}
|
||||||
if err := task.LoadJob(ctx); err != nil {
|
if err := task.LoadJob(ctx); err != nil {
|
||||||
log.Error("Error runner api getting job: %v", err)
|
log.Error("Error runner api getting job: %v", err)
|
||||||
ctx.Error(http.StatusInternalServerError, "Error runner api getting job")
|
ctx.HTTPError(http.StatusInternalServerError, "Error runner api getting job")
|
||||||
return nil, "", false
|
return nil, "", false
|
||||||
}
|
}
|
||||||
return task, artifactName, true
|
return task, artifactName, true
|
||||||
|
@ -230,13 +230,13 @@ func (r *artifactV4Routes) parseProtbufBody(ctx *ArtifactContext, req protorefle
|
||||||
body, err := io.ReadAll(ctx.Req.Body)
|
body, err := io.ReadAll(ctx.Req.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("Error decode request body: %v", err)
|
log.Error("Error decode request body: %v", err)
|
||||||
ctx.Error(http.StatusInternalServerError, "Error decode request body")
|
ctx.HTTPError(http.StatusInternalServerError, "Error decode request body")
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
err = protojson.Unmarshal(body, req)
|
err = protojson.Unmarshal(body, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("Error decode request body: %v", err)
|
log.Error("Error decode request body: %v", err)
|
||||||
ctx.Error(http.StatusInternalServerError, "Error decode request body")
|
ctx.HTTPError(http.StatusInternalServerError, "Error decode request body")
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
|
@ -246,7 +246,7 @@ func (r *artifactV4Routes) sendProtbufBody(ctx *ArtifactContext, req protoreflec
|
||||||
resp, err := protojson.Marshal(req)
|
resp, err := protojson.Marshal(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("Error encode response body: %v", err)
|
log.Error("Error encode response body: %v", err)
|
||||||
ctx.Error(http.StatusInternalServerError, "Error encode response body")
|
ctx.HTTPError(http.StatusInternalServerError, "Error encode response body")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.Resp.Header().Set("Content-Type", "application/json;charset=utf-8")
|
ctx.Resp.Header().Set("Content-Type", "application/json;charset=utf-8")
|
||||||
|
@ -275,7 +275,7 @@ func (r *artifactV4Routes) createArtifact(ctx *ArtifactContext) {
|
||||||
artifact, err := actions.CreateArtifact(ctx, ctx.ActionTask, artifactName, artifactName+".zip", rententionDays)
|
artifact, err := actions.CreateArtifact(ctx, ctx.ActionTask, artifactName, artifactName+".zip", rententionDays)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("Error create or get artifact: %v", err)
|
log.Error("Error create or get artifact: %v", err)
|
||||||
ctx.Error(http.StatusInternalServerError, "Error create or get artifact")
|
ctx.HTTPError(http.StatusInternalServerError, "Error create or get artifact")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
artifact.ContentEncoding = ArtifactV4ContentEncoding
|
artifact.ContentEncoding = ArtifactV4ContentEncoding
|
||||||
|
@ -283,7 +283,7 @@ func (r *artifactV4Routes) createArtifact(ctx *ArtifactContext) {
|
||||||
artifact.FileCompressedSize = 0
|
artifact.FileCompressedSize = 0
|
||||||
if err := actions.UpdateArtifactByID(ctx, artifact.ID, artifact); err != nil {
|
if err := actions.UpdateArtifactByID(ctx, artifact.ID, artifact); err != nil {
|
||||||
log.Error("Error UpdateArtifactByID: %v", err)
|
log.Error("Error UpdateArtifactByID: %v", err)
|
||||||
ctx.Error(http.StatusInternalServerError, "Error UpdateArtifactByID")
|
ctx.HTTPError(http.StatusInternalServerError, "Error UpdateArtifactByID")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -309,28 +309,28 @@ func (r *artifactV4Routes) uploadArtifact(ctx *ArtifactContext) {
|
||||||
artifact, err := r.getArtifactByName(ctx, task.Job.RunID, artifactName)
|
artifact, err := r.getArtifactByName(ctx, task.Job.RunID, artifactName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("Error artifact not found: %v", err)
|
log.Error("Error artifact not found: %v", err)
|
||||||
ctx.Error(http.StatusNotFound, "Error artifact not found")
|
ctx.HTTPError(http.StatusNotFound, "Error artifact not found")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = appendUploadChunk(r.fs, ctx, artifact, artifact.FileSize, ctx.Req.ContentLength, artifact.RunID)
|
_, err = appendUploadChunk(r.fs, ctx, artifact, artifact.FileSize, ctx.Req.ContentLength, artifact.RunID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("Error runner api getting task: task is not running")
|
log.Error("Error runner api getting task: task is not running")
|
||||||
ctx.Error(http.StatusInternalServerError, "Error runner api getting task: task is not running")
|
ctx.HTTPError(http.StatusInternalServerError, "Error runner api getting task: task is not running")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
artifact.FileCompressedSize += ctx.Req.ContentLength
|
artifact.FileCompressedSize += ctx.Req.ContentLength
|
||||||
artifact.FileSize += ctx.Req.ContentLength
|
artifact.FileSize += ctx.Req.ContentLength
|
||||||
if err := actions.UpdateArtifactByID(ctx, artifact.ID, artifact); err != nil {
|
if err := actions.UpdateArtifactByID(ctx, artifact.ID, artifact); err != nil {
|
||||||
log.Error("Error UpdateArtifactByID: %v", err)
|
log.Error("Error UpdateArtifactByID: %v", err)
|
||||||
ctx.Error(http.StatusInternalServerError, "Error UpdateArtifactByID")
|
ctx.HTTPError(http.StatusInternalServerError, "Error UpdateArtifactByID")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
_, err := r.fs.Save(fmt.Sprintf("tmpv4%d/block-%d-%d-%s", task.Job.RunID, task.Job.RunID, ctx.Req.ContentLength, base64.URLEncoding.EncodeToString([]byte(blockid))), ctx.Req.Body, -1)
|
_, err := r.fs.Save(fmt.Sprintf("tmpv4%d/block-%d-%d-%s", task.Job.RunID, task.Job.RunID, ctx.Req.ContentLength, base64.URLEncoding.EncodeToString([]byte(blockid))), ctx.Req.Body, -1)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("Error runner api getting task: task is not running")
|
log.Error("Error runner api getting task: task is not running")
|
||||||
ctx.Error(http.StatusInternalServerError, "Error runner api getting task: task is not running")
|
ctx.HTTPError(http.StatusInternalServerError, "Error runner api getting task: task is not running")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -341,7 +341,7 @@ func (r *artifactV4Routes) uploadArtifact(ctx *ArtifactContext) {
|
||||||
_, err := r.fs.Save(fmt.Sprintf("tmpv4%d/%d-%d-blocklist", task.Job.RunID, task.Job.RunID, artifactID), ctx.Req.Body, -1)
|
_, err := r.fs.Save(fmt.Sprintf("tmpv4%d/%d-%d-blocklist", task.Job.RunID, task.Job.RunID, artifactID), ctx.Req.Body, -1)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("Error runner api getting task: task is not running")
|
log.Error("Error runner api getting task: task is not running")
|
||||||
ctx.Error(http.StatusInternalServerError, "Error runner api getting task: task is not running")
|
ctx.HTTPError(http.StatusInternalServerError, "Error runner api getting task: task is not running")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.JSON(http.StatusCreated, "created")
|
ctx.JSON(http.StatusCreated, "created")
|
||||||
|
@ -389,7 +389,7 @@ func (r *artifactV4Routes) finalizeArtifact(ctx *ArtifactContext) {
|
||||||
artifact, err := r.getArtifactByName(ctx, runID, req.Name)
|
artifact, err := r.getArtifactByName(ctx, runID, req.Name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("Error artifact not found: %v", err)
|
log.Error("Error artifact not found: %v", err)
|
||||||
ctx.Error(http.StatusNotFound, "Error artifact not found")
|
ctx.HTTPError(http.StatusNotFound, "Error artifact not found")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -400,20 +400,20 @@ func (r *artifactV4Routes) finalizeArtifact(ctx *ArtifactContext) {
|
||||||
chunkMap, err := listChunksByRunID(r.fs, runID)
|
chunkMap, err := listChunksByRunID(r.fs, runID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("Error merge chunks: %v", err)
|
log.Error("Error merge chunks: %v", err)
|
||||||
ctx.Error(http.StatusInternalServerError, "Error merge chunks")
|
ctx.HTTPError(http.StatusInternalServerError, "Error merge chunks")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
chunks, ok = chunkMap[artifact.ID]
|
chunks, ok = chunkMap[artifact.ID]
|
||||||
if !ok {
|
if !ok {
|
||||||
log.Error("Error merge chunks")
|
log.Error("Error merge chunks")
|
||||||
ctx.Error(http.StatusInternalServerError, "Error merge chunks")
|
ctx.HTTPError(http.StatusInternalServerError, "Error merge chunks")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
chunks, err = listChunksByRunIDV4(r.fs, runID, artifact.ID, blockList)
|
chunks, err = listChunksByRunIDV4(r.fs, runID, artifact.ID, blockList)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("Error merge chunks: %v", err)
|
log.Error("Error merge chunks: %v", err)
|
||||||
ctx.Error(http.StatusInternalServerError, "Error merge chunks")
|
ctx.HTTPError(http.StatusInternalServerError, "Error merge chunks")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
artifact.FileSize = chunks[len(chunks)-1].End + 1
|
artifact.FileSize = chunks[len(chunks)-1].End + 1
|
||||||
|
@ -426,7 +426,7 @@ func (r *artifactV4Routes) finalizeArtifact(ctx *ArtifactContext) {
|
||||||
}
|
}
|
||||||
if err := mergeChunksForArtifact(ctx, chunks, r.fs, artifact, checksum); err != nil {
|
if err := mergeChunksForArtifact(ctx, chunks, r.fs, artifact, checksum); err != nil {
|
||||||
log.Error("Error merge chunks: %v", err)
|
log.Error("Error merge chunks: %v", err)
|
||||||
ctx.Error(http.StatusInternalServerError, "Error merge chunks")
|
ctx.HTTPError(http.StatusInternalServerError, "Error merge chunks")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -451,12 +451,12 @@ func (r *artifactV4Routes) listArtifacts(ctx *ArtifactContext) {
|
||||||
artifacts, err := db.Find[actions.ActionArtifact](ctx, actions.FindArtifactsOptions{RunID: runID})
|
artifacts, err := db.Find[actions.ActionArtifact](ctx, actions.FindArtifactsOptions{RunID: runID})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("Error getting artifacts: %v", err)
|
log.Error("Error getting artifacts: %v", err)
|
||||||
ctx.Error(http.StatusInternalServerError, err.Error())
|
ctx.HTTPError(http.StatusInternalServerError, err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if len(artifacts) == 0 {
|
if len(artifacts) == 0 {
|
||||||
log.Debug("[artifact] handleListArtifacts, no artifacts")
|
log.Debug("[artifact] handleListArtifacts, no artifacts")
|
||||||
ctx.Error(http.StatusNotFound)
|
ctx.HTTPError(http.StatusNotFound)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -507,7 +507,7 @@ func (r *artifactV4Routes) getSignedArtifactURL(ctx *ArtifactContext) {
|
||||||
artifact, err := r.getArtifactByName(ctx, runID, artifactName)
|
artifact, err := r.getArtifactByName(ctx, runID, artifactName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("Error artifact not found: %v", err)
|
log.Error("Error artifact not found: %v", err)
|
||||||
ctx.Error(http.StatusNotFound, "Error artifact not found")
|
ctx.HTTPError(http.StatusNotFound, "Error artifact not found")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -535,7 +535,7 @@ func (r *artifactV4Routes) downloadArtifact(ctx *ArtifactContext) {
|
||||||
artifact, err := r.getArtifactByName(ctx, task.Job.RunID, artifactName)
|
artifact, err := r.getArtifactByName(ctx, task.Job.RunID, artifactName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("Error artifact not found: %v", err)
|
log.Error("Error artifact not found: %v", err)
|
||||||
ctx.Error(http.StatusNotFound, "Error artifact not found")
|
ctx.HTTPError(http.StatusNotFound, "Error artifact not found")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -559,14 +559,14 @@ func (r *artifactV4Routes) deleteArtifact(ctx *ArtifactContext) {
|
||||||
artifact, err := r.getArtifactByName(ctx, runID, req.Name)
|
artifact, err := r.getArtifactByName(ctx, runID, req.Name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("Error artifact not found: %v", err)
|
log.Error("Error artifact not found: %v", err)
|
||||||
ctx.Error(http.StatusNotFound, "Error artifact not found")
|
ctx.HTTPError(http.StatusNotFound, "Error artifact not found")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
err = actions.SetArtifactNeedDelete(ctx, runID, req.Name)
|
err = actions.SetArtifactNeedDelete(ctx, runID, req.Name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("Error deleting artifacts: %v", err)
|
log.Error("Error deleting artifacts: %v", err)
|
||||||
ctx.Error(http.StatusInternalServerError, err.Error())
|
ctx.HTTPError(http.StatusInternalServerError, err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -49,32 +49,32 @@ func reqPackageAccess(accessMode perm.AccessMode) func(ctx *context.Context) {
|
||||||
if accessMode == perm.AccessModeRead {
|
if accessMode == perm.AccessModeRead {
|
||||||
scopeMatched, err = scope.HasScope(auth_model.AccessTokenScopeReadPackage)
|
scopeMatched, err = scope.HasScope(auth_model.AccessTokenScopeReadPackage)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "HasScope", err.Error())
|
ctx.HTTPError(http.StatusInternalServerError, "HasScope", err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
} else if accessMode == perm.AccessModeWrite {
|
} else if accessMode == perm.AccessModeWrite {
|
||||||
scopeMatched, err = scope.HasScope(auth_model.AccessTokenScopeWritePackage)
|
scopeMatched, err = scope.HasScope(auth_model.AccessTokenScopeWritePackage)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "HasScope", err.Error())
|
ctx.HTTPError(http.StatusInternalServerError, "HasScope", err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if !scopeMatched {
|
if !scopeMatched {
|
||||||
ctx.Resp.Header().Set("WWW-Authenticate", `Basic realm="Gitea Package API"`)
|
ctx.Resp.Header().Set("WWW-Authenticate", `Basic realm="Gitea Package API"`)
|
||||||
ctx.Error(http.StatusUnauthorized, "reqPackageAccess", "user should have specific permission or be a site admin")
|
ctx.HTTPError(http.StatusUnauthorized, "reqPackageAccess", "user should have specific permission or be a site admin")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// check if scope only applies to public resources
|
// check if scope only applies to public resources
|
||||||
publicOnly, err := scope.PublicOnly()
|
publicOnly, err := scope.PublicOnly()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusForbidden, "tokenRequiresScope", "parsing public resource scope failed: "+err.Error())
|
ctx.HTTPError(http.StatusForbidden, "tokenRequiresScope", "parsing public resource scope failed: "+err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if publicOnly {
|
if publicOnly {
|
||||||
if ctx.Package != nil && ctx.Package.Owner.Visibility.IsPrivate() {
|
if ctx.Package != nil && ctx.Package.Owner.Visibility.IsPrivate() {
|
||||||
ctx.Error(http.StatusForbidden, "reqToken", "token scope is limited to public packages")
|
ctx.HTTPError(http.StatusForbidden, "reqToken", "token scope is limited to public packages")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -83,7 +83,7 @@ func reqPackageAccess(accessMode perm.AccessMode) func(ctx *context.Context) {
|
||||||
|
|
||||||
if ctx.Package.AccessMode < accessMode && !ctx.IsUserSiteAdmin() {
|
if ctx.Package.AccessMode < accessMode && !ctx.IsUserSiteAdmin() {
|
||||||
ctx.Resp.Header().Set("WWW-Authenticate", `Basic realm="Gitea Package API"`)
|
ctx.Resp.Header().Set("WWW-Authenticate", `Basic realm="Gitea Package API"`)
|
||||||
ctx.Error(http.StatusUnauthorized, "reqPackageAccess", "user should have specific permission or be a site admin")
|
ctx.HTTPError(http.StatusUnauthorized, "reqPackageAccess", "user should have specific permission or be a site admin")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -100,7 +100,7 @@ func verifyAuth(r *web.Router, authMethods []auth.Method) {
|
||||||
ctx.Doer, err = authGroup.Verify(ctx.Req, ctx.Resp, ctx, ctx.Session)
|
ctx.Doer, err = authGroup.Verify(ctx.Req, ctx.Resp, ctx, ctx.Session)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("Failed to verify user: %v", err)
|
log.Error("Failed to verify user: %v", err)
|
||||||
ctx.Error(http.StatusUnauthorized, "authGroup.Verify")
|
ctx.HTTPError(http.StatusUnauthorized, "authGroup.Verify")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.IsSigned = ctx.Doer != nil
|
ctx.IsSigned = ctx.Doer != nil
|
||||||
|
|
|
@ -41,14 +41,14 @@ func Person(ctx *context.APIContext) {
|
||||||
person.Name = ap.NaturalLanguageValuesNew()
|
person.Name = ap.NaturalLanguageValuesNew()
|
||||||
err := person.Name.Set("en", ap.Content(ctx.ContextUser.FullName))
|
err := person.Name.Set("en", ap.Content(ctx.ContextUser.FullName))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.ServerError("Set Name", err)
|
ctx.APIErrorInternal(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
person.PreferredUsername = ap.NaturalLanguageValuesNew()
|
person.PreferredUsername = ap.NaturalLanguageValuesNew()
|
||||||
err = person.PreferredUsername.Set("en", ap.Content(ctx.ContextUser.Name))
|
err = person.PreferredUsername.Set("en", ap.Content(ctx.ContextUser.Name))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.ServerError("Set PreferredUsername", err)
|
ctx.APIErrorInternal(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -68,14 +68,14 @@ func Person(ctx *context.APIContext) {
|
||||||
|
|
||||||
publicKeyPem, err := activitypub.GetPublicKey(ctx, ctx.ContextUser)
|
publicKeyPem, err := activitypub.GetPublicKey(ctx, ctx.ContextUser)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.ServerError("GetPublicKey", err)
|
ctx.APIErrorInternal(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
person.PublicKey.PublicKeyPem = publicKeyPem
|
person.PublicKey.PublicKeyPem = publicKeyPem
|
||||||
|
|
||||||
binary, err := jsonld.WithContext(jsonld.IRI(ap.ActivityBaseURI), jsonld.IRI(ap.SecurityContextURI)).Marshal(person)
|
binary, err := jsonld.WithContext(jsonld.IRI(ap.ActivityBaseURI), jsonld.IRI(ap.SecurityContextURI)).Marshal(person)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.ServerError("MarshalJSON", err)
|
ctx.APIErrorInternal(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.Resp.Header().Add("Content-Type", activitypub.ActivityStreamsContentType)
|
ctx.Resp.Header().Add("Content-Type", activitypub.ActivityStreamsContentType)
|
||||||
|
|
|
@ -89,9 +89,9 @@ func verifyHTTPSignatures(ctx *gitea_context.APIContext) (authenticated bool, er
|
||||||
func ReqHTTPSignature() func(ctx *gitea_context.APIContext) {
|
func ReqHTTPSignature() func(ctx *gitea_context.APIContext) {
|
||||||
return func(ctx *gitea_context.APIContext) {
|
return func(ctx *gitea_context.APIContext) {
|
||||||
if authenticated, err := verifyHTTPSignatures(ctx); err != nil {
|
if authenticated, err := verifyHTTPSignatures(ctx); err != nil {
|
||||||
ctx.ServerError("verifyHttpSignatures", err)
|
ctx.APIErrorInternal(err)
|
||||||
} else if !authenticated {
|
} else if !authenticated {
|
||||||
ctx.Error(http.StatusForbidden, "reqSignature", "request signature verification failed")
|
ctx.APIError(http.StatusForbidden, "request signature verification failed")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,7 +46,7 @@ func ListUnadoptedRepositories(ctx *context.APIContext) {
|
||||||
}
|
}
|
||||||
repoNames, count, err := repo_service.ListUnadoptedRepositories(ctx, ctx.FormString("query"), &listOptions)
|
repoNames, count, err := repo_service.ListUnadoptedRepositories(ctx, ctx.FormString("query"), &listOptions)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.InternalServerError(err)
|
ctx.APIErrorInternal(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -86,33 +86,33 @@ func AdoptRepository(ctx *context.APIContext) {
|
||||||
ctxUser, err := user_model.GetUserByName(ctx, ownerName)
|
ctxUser, err := user_model.GetUserByName(ctx, ownerName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if user_model.IsErrUserNotExist(err) {
|
if user_model.IsErrUserNotExist(err) {
|
||||||
ctx.NotFound()
|
ctx.APIErrorNotFound()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.InternalServerError(err)
|
ctx.APIErrorInternal(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// check not a repo
|
// check not a repo
|
||||||
has, err := repo_model.IsRepositoryModelExist(ctx, ctxUser, repoName)
|
has, err := repo_model.IsRepositoryModelExist(ctx, ctxUser, repoName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.InternalServerError(err)
|
ctx.APIErrorInternal(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
isDir, err := util.IsDir(repo_model.RepoPath(ctxUser.Name, repoName))
|
isDir, err := util.IsDir(repo_model.RepoPath(ctxUser.Name, repoName))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.InternalServerError(err)
|
ctx.APIErrorInternal(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if has || !isDir {
|
if has || !isDir {
|
||||||
ctx.NotFound()
|
ctx.APIErrorNotFound()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if _, err := repo_service.AdoptRepository(ctx, ctx.Doer, ctxUser, repo_service.CreateRepoOptions{
|
if _, err := repo_service.AdoptRepository(ctx, ctx.Doer, ctxUser, repo_service.CreateRepoOptions{
|
||||||
Name: repoName,
|
Name: repoName,
|
||||||
IsPrivate: true,
|
IsPrivate: true,
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
ctx.InternalServerError(err)
|
ctx.APIErrorInternal(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -148,31 +148,31 @@ func DeleteUnadoptedRepository(ctx *context.APIContext) {
|
||||||
ctxUser, err := user_model.GetUserByName(ctx, ownerName)
|
ctxUser, err := user_model.GetUserByName(ctx, ownerName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if user_model.IsErrUserNotExist(err) {
|
if user_model.IsErrUserNotExist(err) {
|
||||||
ctx.NotFound()
|
ctx.APIErrorNotFound()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.InternalServerError(err)
|
ctx.APIErrorInternal(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// check not a repo
|
// check not a repo
|
||||||
has, err := repo_model.IsRepositoryModelExist(ctx, ctxUser, repoName)
|
has, err := repo_model.IsRepositoryModelExist(ctx, ctxUser, repoName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.InternalServerError(err)
|
ctx.APIErrorInternal(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
isDir, err := util.IsDir(repo_model.RepoPath(ctxUser.Name, repoName))
|
isDir, err := util.IsDir(repo_model.RepoPath(ctxUser.Name, repoName))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.InternalServerError(err)
|
ctx.APIErrorInternal(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if has || !isDir {
|
if has || !isDir {
|
||||||
ctx.NotFound()
|
ctx.APIErrorNotFound()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := repo_service.DeleteUnadoptedRepository(ctx, ctx.Doer, ctxUser, repoName); err != nil {
|
if err := repo_service.DeleteUnadoptedRepository(ctx, ctx.Doer, ctxUser, repoName); err != nil {
|
||||||
ctx.InternalServerError(err)
|
ctx.APIErrorInternal(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -76,7 +76,7 @@ func PostCronTask(ctx *context.APIContext) {
|
||||||
// "$ref": "#/responses/notFound"
|
// "$ref": "#/responses/notFound"
|
||||||
task := cron.GetTask(ctx.PathParam("task"))
|
task := cron.GetTask(ctx.PathParam("task"))
|
||||||
if task == nil {
|
if task == nil {
|
||||||
ctx.NotFound()
|
ctx.APIErrorNotFound()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
task.Run()
|
task.Run()
|
||||||
|
|
|
@ -42,7 +42,7 @@ func GetAllEmails(ctx *context.APIContext) {
|
||||||
ListOptions: listOptions,
|
ListOptions: listOptions,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetAllEmails", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -59,14 +59,14 @@ func ListHooks(ctx *context.APIContext) {
|
||||||
|
|
||||||
sysHooks, err := webhook.GetSystemOrDefaultWebhooks(ctx, isSystemWebhook)
|
sysHooks, err := webhook.GetSystemOrDefaultWebhooks(ctx, isSystemWebhook)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetSystemWebhooks", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
hooks := make([]*api.Hook, len(sysHooks))
|
hooks := make([]*api.Hook, len(sysHooks))
|
||||||
for i, hook := range sysHooks {
|
for i, hook := range sysHooks {
|
||||||
h, err := webhook_service.ToHook(setting.AppURL+"/-/admin", hook)
|
h, err := webhook_service.ToHook(setting.AppURL+"/-/admin", hook)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "convert.ToHook", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
hooks[i] = h
|
hooks[i] = h
|
||||||
|
@ -96,15 +96,15 @@ func GetHook(ctx *context.APIContext) {
|
||||||
hook, err := webhook.GetSystemOrDefaultWebhook(ctx, hookID)
|
hook, err := webhook.GetSystemOrDefaultWebhook(ctx, hookID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if errors.Is(err, util.ErrNotExist) {
|
if errors.Is(err, util.ErrNotExist) {
|
||||||
ctx.NotFound()
|
ctx.APIErrorNotFound()
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetSystemOrDefaultWebhook", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
h, err := webhook_service.ToHook("/-/admin/", hook)
|
h, err := webhook_service.ToHook("/-/admin/", hook)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "convert.ToHook", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.JSON(http.StatusOK, h)
|
ctx.JSON(http.StatusOK, h)
|
||||||
|
@ -186,9 +186,9 @@ func DeleteHook(ctx *context.APIContext) {
|
||||||
hookID := ctx.PathParamInt64("id")
|
hookID := ctx.PathParamInt64("id")
|
||||||
if err := webhook.DeleteDefaultSystemWebhook(ctx, hookID); err != nil {
|
if err := webhook.DeleteDefaultSystemWebhook(ctx, hookID); err != nil {
|
||||||
if errors.Is(err, util.ErrNotExist) {
|
if errors.Is(err, util.ErrNotExist) {
|
||||||
ctx.NotFound()
|
ctx.APIErrorNotFound()
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "DeleteDefaultSystemWebhook", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -67,9 +67,9 @@ func CreateOrg(ctx *context.APIContext) {
|
||||||
db.IsErrNameReserved(err) ||
|
db.IsErrNameReserved(err) ||
|
||||||
db.IsErrNameCharsNotAllowed(err) ||
|
db.IsErrNameCharsNotAllowed(err) ||
|
||||||
db.IsErrNamePatternNotAllowed(err) {
|
db.IsErrNamePatternNotAllowed(err) {
|
||||||
ctx.Error(http.StatusUnprocessableEntity, "", err)
|
ctx.APIError(http.StatusUnprocessableEntity, err)
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "CreateOrganization", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -109,7 +109,7 @@ func GetAllOrgs(ctx *context.APIContext) {
|
||||||
Visible: []api.VisibleType{api.VisibleTypePublic, api.VisibleTypeLimited, api.VisibleTypePrivate},
|
Visible: []api.VisibleType{api.VisibleTypePublic, api.VisibleTypeLimited, api.VisibleTypePrivate},
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "SearchOrganizations", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
orgs := make([]*api.Organization, len(users))
|
orgs := make([]*api.Organization, len(users))
|
||||||
|
|
|
@ -40,9 +40,9 @@ func parseAuthSource(ctx *context.APIContext, u *user_model.User, sourceID int64
|
||||||
source, err := auth.GetSourceByID(ctx, sourceID)
|
source, err := auth.GetSourceByID(ctx, sourceID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if auth.IsErrSourceNotExist(err) {
|
if auth.IsErrSourceNotExist(err) {
|
||||||
ctx.Error(http.StatusUnprocessableEntity, "", err)
|
ctx.APIError(http.StatusUnprocessableEntity, err)
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "auth.GetSourceByID", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -98,13 +98,13 @@ func CreateUser(ctx *context.APIContext) {
|
||||||
if u.LoginType == auth.Plain {
|
if u.LoginType == auth.Plain {
|
||||||
if len(form.Password) < setting.MinPasswordLength {
|
if len(form.Password) < setting.MinPasswordLength {
|
||||||
err := errors.New("PasswordIsRequired")
|
err := errors.New("PasswordIsRequired")
|
||||||
ctx.Error(http.StatusBadRequest, "PasswordIsRequired", err)
|
ctx.APIError(http.StatusBadRequest, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if !password.IsComplexEnough(form.Password) {
|
if !password.IsComplexEnough(form.Password) {
|
||||||
err := errors.New("PasswordComplexity")
|
err := errors.New("PasswordComplexity")
|
||||||
ctx.Error(http.StatusBadRequest, "PasswordComplexity", err)
|
ctx.APIError(http.StatusBadRequest, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -112,7 +112,7 @@ func CreateUser(ctx *context.APIContext) {
|
||||||
if password.IsErrIsPwnedRequest(err) {
|
if password.IsErrIsPwnedRequest(err) {
|
||||||
log.Error(err.Error())
|
log.Error(err.Error())
|
||||||
}
|
}
|
||||||
ctx.Error(http.StatusBadRequest, "PasswordPwned", errors.New("PasswordPwned"))
|
ctx.APIError(http.StatusBadRequest, errors.New("PasswordPwned"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -143,9 +143,9 @@ func CreateUser(ctx *context.APIContext) {
|
||||||
user_model.IsErrEmailCharIsNotSupported(err) ||
|
user_model.IsErrEmailCharIsNotSupported(err) ||
|
||||||
user_model.IsErrEmailInvalid(err) ||
|
user_model.IsErrEmailInvalid(err) ||
|
||||||
db.IsErrNamePatternNotAllowed(err) {
|
db.IsErrNamePatternNotAllowed(err) {
|
||||||
ctx.Error(http.StatusUnprocessableEntity, "", err)
|
ctx.APIError(http.StatusUnprocessableEntity, err)
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "CreateUser", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -204,13 +204,13 @@ func EditUser(ctx *context.APIContext) {
|
||||||
if err := user_service.UpdateAuth(ctx, ctx.ContextUser, authOpts); err != nil {
|
if err := user_service.UpdateAuth(ctx, ctx.ContextUser, authOpts); err != nil {
|
||||||
switch {
|
switch {
|
||||||
case errors.Is(err, password.ErrMinLength):
|
case errors.Is(err, password.ErrMinLength):
|
||||||
ctx.Error(http.StatusBadRequest, "PasswordTooShort", fmt.Errorf("password must be at least %d characters", setting.MinPasswordLength))
|
ctx.APIError(http.StatusBadRequest, fmt.Errorf("password must be at least %d characters", setting.MinPasswordLength))
|
||||||
case errors.Is(err, password.ErrComplexity):
|
case errors.Is(err, password.ErrComplexity):
|
||||||
ctx.Error(http.StatusBadRequest, "PasswordComplexity", err)
|
ctx.APIError(http.StatusBadRequest, err)
|
||||||
case errors.Is(err, password.ErrIsPwned), password.IsErrIsPwnedRequest(err):
|
case errors.Is(err, password.ErrIsPwned), password.IsErrIsPwnedRequest(err):
|
||||||
ctx.Error(http.StatusBadRequest, "PasswordIsPwned", err)
|
ctx.APIError(http.StatusBadRequest, err)
|
||||||
default:
|
default:
|
||||||
ctx.Error(http.StatusInternalServerError, "UpdateAuth", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -219,11 +219,11 @@ func EditUser(ctx *context.APIContext) {
|
||||||
if err := user_service.AdminAddOrSetPrimaryEmailAddress(ctx, ctx.ContextUser, *form.Email); err != nil {
|
if err := user_service.AdminAddOrSetPrimaryEmailAddress(ctx, ctx.ContextUser, *form.Email); err != nil {
|
||||||
switch {
|
switch {
|
||||||
case user_model.IsErrEmailCharIsNotSupported(err), user_model.IsErrEmailInvalid(err):
|
case user_model.IsErrEmailCharIsNotSupported(err), user_model.IsErrEmailInvalid(err):
|
||||||
ctx.Error(http.StatusBadRequest, "EmailInvalid", err)
|
ctx.APIError(http.StatusBadRequest, err)
|
||||||
case user_model.IsErrEmailAlreadyUsed(err):
|
case user_model.IsErrEmailAlreadyUsed(err):
|
||||||
ctx.Error(http.StatusBadRequest, "EmailUsed", err)
|
ctx.APIError(http.StatusBadRequest, err)
|
||||||
default:
|
default:
|
||||||
ctx.Error(http.StatusInternalServerError, "AddOrSetPrimaryEmailAddress", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -250,9 +250,9 @@ func EditUser(ctx *context.APIContext) {
|
||||||
|
|
||||||
if err := user_service.UpdateUser(ctx, ctx.ContextUser, opts); err != nil {
|
if err := user_service.UpdateUser(ctx, ctx.ContextUser, opts); err != nil {
|
||||||
if user_model.IsErrDeleteLastAdminUser(err) {
|
if user_model.IsErrDeleteLastAdminUser(err) {
|
||||||
ctx.Error(http.StatusBadRequest, "LastAdmin", err)
|
ctx.APIError(http.StatusBadRequest, err)
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "UpdateUser", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -290,13 +290,13 @@ func DeleteUser(ctx *context.APIContext) {
|
||||||
// "$ref": "#/responses/validationError"
|
// "$ref": "#/responses/validationError"
|
||||||
|
|
||||||
if ctx.ContextUser.IsOrganization() {
|
if ctx.ContextUser.IsOrganization() {
|
||||||
ctx.Error(http.StatusUnprocessableEntity, "", fmt.Errorf("%s is an organization not a user", ctx.ContextUser.Name))
|
ctx.APIError(http.StatusUnprocessableEntity, fmt.Errorf("%s is an organization not a user", ctx.ContextUser.Name))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// admin should not delete themself
|
// admin should not delete themself
|
||||||
if ctx.ContextUser.ID == ctx.Doer.ID {
|
if ctx.ContextUser.ID == ctx.Doer.ID {
|
||||||
ctx.Error(http.StatusUnprocessableEntity, "", fmt.Errorf("you cannot delete yourself"))
|
ctx.APIError(http.StatusUnprocessableEntity, fmt.Errorf("you cannot delete yourself"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -305,9 +305,9 @@ func DeleteUser(ctx *context.APIContext) {
|
||||||
org_model.IsErrUserHasOrgs(err) ||
|
org_model.IsErrUserHasOrgs(err) ||
|
||||||
packages_model.IsErrUserOwnPackages(err) ||
|
packages_model.IsErrUserOwnPackages(err) ||
|
||||||
user_model.IsErrDeleteLastAdminUser(err) {
|
user_model.IsErrDeleteLastAdminUser(err) {
|
||||||
ctx.Error(http.StatusUnprocessableEntity, "", err)
|
ctx.APIError(http.StatusUnprocessableEntity, err)
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "DeleteUser", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -377,11 +377,11 @@ func DeleteUserPublicKey(ctx *context.APIContext) {
|
||||||
|
|
||||||
if err := asymkey_service.DeletePublicKey(ctx, ctx.ContextUser, ctx.PathParamInt64("id")); err != nil {
|
if err := asymkey_service.DeletePublicKey(ctx, ctx.ContextUser, ctx.PathParamInt64("id")); err != nil {
|
||||||
if asymkey_model.IsErrKeyNotExist(err) {
|
if asymkey_model.IsErrKeyNotExist(err) {
|
||||||
ctx.NotFound()
|
ctx.APIErrorNotFound()
|
||||||
} else if asymkey_model.IsErrKeyAccessDenied(err) {
|
} else if asymkey_model.IsErrKeyAccessDenied(err) {
|
||||||
ctx.Error(http.StatusForbidden, "", "You do not have access to this key")
|
ctx.APIError(http.StatusForbidden, "You do not have access to this key")
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "DeleteUserPublicKey", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -432,7 +432,7 @@ func SearchUsers(ctx *context.APIContext) {
|
||||||
ListOptions: listOptions,
|
ListOptions: listOptions,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "SearchUsers", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -473,7 +473,7 @@ func RenameUser(ctx *context.APIContext) {
|
||||||
// "$ref": "#/responses/validationError"
|
// "$ref": "#/responses/validationError"
|
||||||
|
|
||||||
if ctx.ContextUser.IsOrganization() {
|
if ctx.ContextUser.IsOrganization() {
|
||||||
ctx.Error(http.StatusUnprocessableEntity, "", fmt.Errorf("%s is an organization not a user", ctx.ContextUser.Name))
|
ctx.APIError(http.StatusUnprocessableEntity, fmt.Errorf("%s is an organization not a user", ctx.ContextUser.Name))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -482,9 +482,9 @@ func RenameUser(ctx *context.APIContext) {
|
||||||
// Check if username has been changed
|
// Check if username has been changed
|
||||||
if err := user_service.RenameUser(ctx, ctx.ContextUser, newName); err != nil {
|
if err := user_service.RenameUser(ctx, ctx.ContextUser, newName); err != nil {
|
||||||
if user_model.IsErrUserAlreadyExist(err) || db.IsErrNameReserved(err) || db.IsErrNamePatternNotAllowed(err) || db.IsErrNameCharsNotAllowed(err) {
|
if user_model.IsErrUserAlreadyExist(err) || db.IsErrNameReserved(err) || db.IsErrNamePatternNotAllowed(err) || db.IsErrNameCharsNotAllowed(err) {
|
||||||
ctx.Error(http.StatusUnprocessableEntity, "", err)
|
ctx.APIError(http.StatusUnprocessableEntity, err)
|
||||||
} else {
|
} else {
|
||||||
ctx.ServerError("ChangeUserName", err)
|
ctx.APIErrorInternal(err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,7 +33,7 @@ func ListUserBadges(ctx *context.APIContext) {
|
||||||
|
|
||||||
badges, maxResults, err := user_model.GetUserBadges(ctx, ctx.ContextUser)
|
badges, maxResults, err := user_model.GetUserBadges(ctx, ctx.ContextUser)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetUserBadges", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -70,7 +70,7 @@ func AddUserBadges(ctx *context.APIContext) {
|
||||||
badges := prepareBadgesForReplaceOrAdd(*form)
|
badges := prepareBadgesForReplaceOrAdd(*form)
|
||||||
|
|
||||||
if err := user_model.AddUserBadges(ctx, ctx.ContextUser, badges); err != nil {
|
if err := user_model.AddUserBadges(ctx, ctx.ContextUser, badges); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "ReplaceUserBadges", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -106,7 +106,7 @@ func DeleteUserBadges(ctx *context.APIContext) {
|
||||||
badges := prepareBadgesForReplaceOrAdd(*form)
|
badges := prepareBadgesForReplaceOrAdd(*form)
|
||||||
|
|
||||||
if err := user_model.RemoveUserBadges(ctx, ctx.ContextUser, badges); err != nil {
|
if err := user_model.RemoveUserBadges(ctx, ctx.ContextUser, badges); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "ReplaceUserBadges", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -116,9 +116,9 @@ func sudo() func(ctx *context.APIContext) {
|
||||||
user, err := user_model.GetUserByName(ctx, sudo)
|
user, err := user_model.GetUserByName(ctx, sudo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if user_model.IsErrUserNotExist(err) {
|
if user_model.IsErrUserNotExist(err) {
|
||||||
ctx.NotFound()
|
ctx.APIErrorNotFound()
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetUserByName", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -154,12 +154,12 @@ func repoAssignment() func(ctx *context.APIContext) {
|
||||||
if redirectUserID, err := user_model.LookupUserRedirect(ctx, userName); err == nil {
|
if redirectUserID, err := user_model.LookupUserRedirect(ctx, userName); err == nil {
|
||||||
context.RedirectToUser(ctx.Base, userName, redirectUserID)
|
context.RedirectToUser(ctx.Base, userName, redirectUserID)
|
||||||
} else if user_model.IsErrUserRedirectNotExist(err) {
|
} else if user_model.IsErrUserRedirectNotExist(err) {
|
||||||
ctx.NotFound("GetUserByName", err)
|
ctx.APIErrorNotFound("GetUserByName", err)
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "LookupUserRedirect", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetUserByName", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -175,12 +175,12 @@ func repoAssignment() func(ctx *context.APIContext) {
|
||||||
if err == nil {
|
if err == nil {
|
||||||
context.RedirectToRepo(ctx.Base, redirectRepoID)
|
context.RedirectToRepo(ctx.Base, redirectRepoID)
|
||||||
} else if repo_model.IsErrRedirectNotExist(err) {
|
} else if repo_model.IsErrRedirectNotExist(err) {
|
||||||
ctx.NotFound()
|
ctx.APIErrorNotFound()
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "LookupRepoRedirect", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetRepositoryByName", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -192,11 +192,11 @@ func repoAssignment() func(ctx *context.APIContext) {
|
||||||
taskID := ctx.Data["ActionsTaskID"].(int64)
|
taskID := ctx.Data["ActionsTaskID"].(int64)
|
||||||
task, err := actions_model.GetTaskByID(ctx, taskID)
|
task, err := actions_model.GetTaskByID(ctx, taskID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "actions_model.GetTaskByID", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if task.RepoID != repo.ID {
|
if task.RepoID != repo.ID {
|
||||||
ctx.NotFound()
|
ctx.APIErrorNotFound()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -207,20 +207,20 @@ func repoAssignment() func(ctx *context.APIContext) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := ctx.Repo.Repository.LoadUnits(ctx); err != nil {
|
if err := ctx.Repo.Repository.LoadUnits(ctx); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "LoadUnits", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.Repo.Permission.SetUnitsWithDefaultAccessMode(ctx.Repo.Repository.Units, ctx.Repo.Permission.AccessMode)
|
ctx.Repo.Permission.SetUnitsWithDefaultAccessMode(ctx.Repo.Repository.Units, ctx.Repo.Permission.AccessMode)
|
||||||
} else {
|
} else {
|
||||||
ctx.Repo.Permission, err = access_model.GetUserRepoPermission(ctx, repo, ctx.Doer)
|
ctx.Repo.Permission, err = access_model.GetUserRepoPermission(ctx, repo, ctx.Doer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetUserRepoPermission", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if !ctx.Repo.Permission.HasAnyUnitAccess() {
|
if !ctx.Repo.Permission.HasAnyUnitAccess() {
|
||||||
ctx.NotFound()
|
ctx.APIErrorNotFound()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -229,7 +229,7 @@ func repoAssignment() func(ctx *context.APIContext) {
|
||||||
func reqPackageAccess(accessMode perm.AccessMode) func(ctx *context.APIContext) {
|
func reqPackageAccess(accessMode perm.AccessMode) func(ctx *context.APIContext) {
|
||||||
return func(ctx *context.APIContext) {
|
return func(ctx *context.APIContext) {
|
||||||
if ctx.Package.AccessMode < accessMode && !ctx.IsUserSiteAdmin() {
|
if ctx.Package.AccessMode < accessMode && !ctx.IsUserSiteAdmin() {
|
||||||
ctx.Error(http.StatusForbidden, "reqPackageAccess", "user should have specific permission or be a site admin")
|
ctx.APIError(http.StatusForbidden, "user should have specific permission or be a site admin")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -250,41 +250,41 @@ func checkTokenPublicOnly() func(ctx *context.APIContext) {
|
||||||
switch {
|
switch {
|
||||||
case auth_model.ContainsCategory(requiredScopeCategories, auth_model.AccessTokenScopeCategoryRepository):
|
case auth_model.ContainsCategory(requiredScopeCategories, auth_model.AccessTokenScopeCategoryRepository):
|
||||||
if ctx.Repo.Repository != nil && ctx.Repo.Repository.IsPrivate {
|
if ctx.Repo.Repository != nil && ctx.Repo.Repository.IsPrivate {
|
||||||
ctx.Error(http.StatusForbidden, "reqToken", "token scope is limited to public repos")
|
ctx.APIError(http.StatusForbidden, "token scope is limited to public repos")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
case auth_model.ContainsCategory(requiredScopeCategories, auth_model.AccessTokenScopeCategoryIssue):
|
case auth_model.ContainsCategory(requiredScopeCategories, auth_model.AccessTokenScopeCategoryIssue):
|
||||||
if ctx.Repo.Repository != nil && ctx.Repo.Repository.IsPrivate {
|
if ctx.Repo.Repository != nil && ctx.Repo.Repository.IsPrivate {
|
||||||
ctx.Error(http.StatusForbidden, "reqToken", "token scope is limited to public issues")
|
ctx.APIError(http.StatusForbidden, "token scope is limited to public issues")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
case auth_model.ContainsCategory(requiredScopeCategories, auth_model.AccessTokenScopeCategoryOrganization):
|
case auth_model.ContainsCategory(requiredScopeCategories, auth_model.AccessTokenScopeCategoryOrganization):
|
||||||
if ctx.Org.Organization != nil && ctx.Org.Organization.Visibility != api.VisibleTypePublic {
|
if ctx.Org.Organization != nil && ctx.Org.Organization.Visibility != api.VisibleTypePublic {
|
||||||
ctx.Error(http.StatusForbidden, "reqToken", "token scope is limited to public orgs")
|
ctx.APIError(http.StatusForbidden, "token scope is limited to public orgs")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if ctx.ContextUser != nil && ctx.ContextUser.IsOrganization() && ctx.ContextUser.Visibility != api.VisibleTypePublic {
|
if ctx.ContextUser != nil && ctx.ContextUser.IsOrganization() && ctx.ContextUser.Visibility != api.VisibleTypePublic {
|
||||||
ctx.Error(http.StatusForbidden, "reqToken", "token scope is limited to public orgs")
|
ctx.APIError(http.StatusForbidden, "token scope is limited to public orgs")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
case auth_model.ContainsCategory(requiredScopeCategories, auth_model.AccessTokenScopeCategoryUser):
|
case auth_model.ContainsCategory(requiredScopeCategories, auth_model.AccessTokenScopeCategoryUser):
|
||||||
if ctx.ContextUser != nil && ctx.ContextUser.IsTokenAccessAllowed() && ctx.ContextUser.Visibility != api.VisibleTypePublic {
|
if ctx.ContextUser != nil && ctx.ContextUser.IsTokenAccessAllowed() && ctx.ContextUser.Visibility != api.VisibleTypePublic {
|
||||||
ctx.Error(http.StatusForbidden, "reqToken", "token scope is limited to public users")
|
ctx.APIError(http.StatusForbidden, "token scope is limited to public users")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
case auth_model.ContainsCategory(requiredScopeCategories, auth_model.AccessTokenScopeCategoryActivityPub):
|
case auth_model.ContainsCategory(requiredScopeCategories, auth_model.AccessTokenScopeCategoryActivityPub):
|
||||||
if ctx.ContextUser != nil && ctx.ContextUser.IsTokenAccessAllowed() && ctx.ContextUser.Visibility != api.VisibleTypePublic {
|
if ctx.ContextUser != nil && ctx.ContextUser.IsTokenAccessAllowed() && ctx.ContextUser.Visibility != api.VisibleTypePublic {
|
||||||
ctx.Error(http.StatusForbidden, "reqToken", "token scope is limited to public activitypub")
|
ctx.APIError(http.StatusForbidden, "token scope is limited to public activitypub")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
case auth_model.ContainsCategory(requiredScopeCategories, auth_model.AccessTokenScopeCategoryNotification):
|
case auth_model.ContainsCategory(requiredScopeCategories, auth_model.AccessTokenScopeCategoryNotification):
|
||||||
if ctx.Repo.Repository != nil && ctx.Repo.Repository.IsPrivate {
|
if ctx.Repo.Repository != nil && ctx.Repo.Repository.IsPrivate {
|
||||||
ctx.Error(http.StatusForbidden, "reqToken", "token scope is limited to public notifications")
|
ctx.APIError(http.StatusForbidden, "token scope is limited to public notifications")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
case auth_model.ContainsCategory(requiredScopeCategories, auth_model.AccessTokenScopeCategoryPackage):
|
case auth_model.ContainsCategory(requiredScopeCategories, auth_model.AccessTokenScopeCategoryPackage):
|
||||||
if ctx.Package != nil && ctx.Package.Owner.Visibility.IsPrivate() {
|
if ctx.Package != nil && ctx.Package.Owner.Visibility.IsPrivate() {
|
||||||
ctx.Error(http.StatusForbidden, "reqToken", "token scope is limited to public packages")
|
ctx.APIError(http.StatusForbidden, "token scope is limited to public packages")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -316,12 +316,12 @@ func tokenRequiresScopes(requiredScopeCategories ...auth_model.AccessTokenScopeC
|
||||||
requiredScopes := auth_model.GetRequiredScopes(requiredScopeLevel, requiredScopeCategories...)
|
requiredScopes := auth_model.GetRequiredScopes(requiredScopeLevel, requiredScopeCategories...)
|
||||||
allow, err := scope.HasScope(requiredScopes...)
|
allow, err := scope.HasScope(requiredScopes...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusForbidden, "tokenRequiresScope", "checking scope failed: "+err.Error())
|
ctx.APIError(http.StatusForbidden, "checking scope failed: "+err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if !allow {
|
if !allow {
|
||||||
ctx.Error(http.StatusForbidden, "tokenRequiresScope", fmt.Sprintf("token does not have at least one of required scope(s), required=%v, token scope=%v", requiredScopes, scope))
|
ctx.APIError(http.StatusForbidden, fmt.Sprintf("token does not have at least one of required scope(s), required=%v, token scope=%v", requiredScopes, scope))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -330,7 +330,7 @@ func tokenRequiresScopes(requiredScopeCategories ...auth_model.AccessTokenScopeC
|
||||||
// check if scope only applies to public resources
|
// check if scope only applies to public resources
|
||||||
publicOnly, err := scope.PublicOnly()
|
publicOnly, err := scope.PublicOnly()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusForbidden, "tokenRequiresScope", "parsing public resource scope failed: "+err.Error())
|
ctx.APIError(http.StatusForbidden, "parsing public resource scope failed: "+err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -350,14 +350,14 @@ func reqToken() func(ctx *context.APIContext) {
|
||||||
if ctx.IsSigned {
|
if ctx.IsSigned {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.Error(http.StatusUnauthorized, "reqToken", "token is required")
|
ctx.APIError(http.StatusUnauthorized, "token is required")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func reqExploreSignIn() func(ctx *context.APIContext) {
|
func reqExploreSignIn() func(ctx *context.APIContext) {
|
||||||
return func(ctx *context.APIContext) {
|
return func(ctx *context.APIContext) {
|
||||||
if (setting.Service.RequireSignInView || setting.Service.Explore.RequireSigninView) && !ctx.IsSigned {
|
if (setting.Service.RequireSignInView || setting.Service.Explore.RequireSigninView) && !ctx.IsSigned {
|
||||||
ctx.Error(http.StatusUnauthorized, "reqExploreSignIn", "you must be signed in to search for users")
|
ctx.APIError(http.StatusUnauthorized, "you must be signed in to search for users")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -365,7 +365,7 @@ func reqExploreSignIn() func(ctx *context.APIContext) {
|
||||||
func reqUsersExploreEnabled() func(ctx *context.APIContext) {
|
func reqUsersExploreEnabled() func(ctx *context.APIContext) {
|
||||||
return func(ctx *context.APIContext) {
|
return func(ctx *context.APIContext) {
|
||||||
if setting.Service.Explore.DisableUsersPage {
|
if setting.Service.Explore.DisableUsersPage {
|
||||||
ctx.NotFound()
|
ctx.APIErrorNotFound()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -376,7 +376,7 @@ func reqBasicOrRevProxyAuth() func(ctx *context.APIContext) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if !ctx.IsBasicAuth {
|
if !ctx.IsBasicAuth {
|
||||||
ctx.Error(http.StatusUnauthorized, "reqBasicAuth", "auth required")
|
ctx.APIError(http.StatusUnauthorized, "auth required")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -386,7 +386,7 @@ func reqBasicOrRevProxyAuth() func(ctx *context.APIContext) {
|
||||||
func reqSiteAdmin() func(ctx *context.APIContext) {
|
func reqSiteAdmin() func(ctx *context.APIContext) {
|
||||||
return func(ctx *context.APIContext) {
|
return func(ctx *context.APIContext) {
|
||||||
if !ctx.IsUserSiteAdmin() {
|
if !ctx.IsUserSiteAdmin() {
|
||||||
ctx.Error(http.StatusForbidden, "reqSiteAdmin", "user should be the site admin")
|
ctx.APIError(http.StatusForbidden, "user should be the site admin")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -396,7 +396,7 @@ func reqSiteAdmin() func(ctx *context.APIContext) {
|
||||||
func reqOwner() func(ctx *context.APIContext) {
|
func reqOwner() func(ctx *context.APIContext) {
|
||||||
return func(ctx *context.APIContext) {
|
return func(ctx *context.APIContext) {
|
||||||
if !ctx.Repo.IsOwner() && !ctx.IsUserSiteAdmin() {
|
if !ctx.Repo.IsOwner() && !ctx.IsUserSiteAdmin() {
|
||||||
ctx.Error(http.StatusForbidden, "reqOwner", "user should be the owner of the repo")
|
ctx.APIError(http.StatusForbidden, "user should be the owner of the repo")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -406,7 +406,7 @@ func reqOwner() func(ctx *context.APIContext) {
|
||||||
func reqSelfOrAdmin() func(ctx *context.APIContext) {
|
func reqSelfOrAdmin() func(ctx *context.APIContext) {
|
||||||
return func(ctx *context.APIContext) {
|
return func(ctx *context.APIContext) {
|
||||||
if !ctx.IsUserSiteAdmin() && ctx.ContextUser != ctx.Doer {
|
if !ctx.IsUserSiteAdmin() && ctx.ContextUser != ctx.Doer {
|
||||||
ctx.Error(http.StatusForbidden, "reqSelfOrAdmin", "doer should be the site admin or be same as the contextUser")
|
ctx.APIError(http.StatusForbidden, "doer should be the site admin or be same as the contextUser")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -416,7 +416,7 @@ func reqSelfOrAdmin() func(ctx *context.APIContext) {
|
||||||
func reqAdmin() func(ctx *context.APIContext) {
|
func reqAdmin() func(ctx *context.APIContext) {
|
||||||
return func(ctx *context.APIContext) {
|
return func(ctx *context.APIContext) {
|
||||||
if !ctx.IsUserRepoAdmin() && !ctx.IsUserSiteAdmin() {
|
if !ctx.IsUserRepoAdmin() && !ctx.IsUserSiteAdmin() {
|
||||||
ctx.Error(http.StatusForbidden, "reqAdmin", "user should be an owner or a collaborator with admin write of a repository")
|
ctx.APIError(http.StatusForbidden, "user should be an owner or a collaborator with admin write of a repository")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -426,7 +426,7 @@ func reqAdmin() func(ctx *context.APIContext) {
|
||||||
func reqRepoWriter(unitTypes ...unit.Type) func(ctx *context.APIContext) {
|
func reqRepoWriter(unitTypes ...unit.Type) func(ctx *context.APIContext) {
|
||||||
return func(ctx *context.APIContext) {
|
return func(ctx *context.APIContext) {
|
||||||
if !ctx.IsUserRepoWriter(unitTypes) && !ctx.IsUserRepoAdmin() && !ctx.IsUserSiteAdmin() {
|
if !ctx.IsUserRepoWriter(unitTypes) && !ctx.IsUserRepoAdmin() && !ctx.IsUserSiteAdmin() {
|
||||||
ctx.Error(http.StatusForbidden, "reqRepoWriter", "user should have a permission to write to a repo")
|
ctx.APIError(http.StatusForbidden, "user should have a permission to write to a repo")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -436,7 +436,7 @@ func reqRepoWriter(unitTypes ...unit.Type) func(ctx *context.APIContext) {
|
||||||
func reqRepoBranchWriter(ctx *context.APIContext) {
|
func reqRepoBranchWriter(ctx *context.APIContext) {
|
||||||
options, ok := web.GetForm(ctx).(api.FileOptionInterface)
|
options, ok := web.GetForm(ctx).(api.FileOptionInterface)
|
||||||
if !ok || (!ctx.Repo.CanWriteToBranch(ctx, ctx.Doer, options.Branch()) && !ctx.IsUserSiteAdmin()) {
|
if !ok || (!ctx.Repo.CanWriteToBranch(ctx, ctx.Doer, options.Branch()) && !ctx.IsUserSiteAdmin()) {
|
||||||
ctx.Error(http.StatusForbidden, "reqRepoBranchWriter", "user should have a permission to write to this branch")
|
ctx.APIError(http.StatusForbidden, "user should have a permission to write to this branch")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -445,7 +445,7 @@ func reqRepoBranchWriter(ctx *context.APIContext) {
|
||||||
func reqRepoReader(unitType unit.Type) func(ctx *context.APIContext) {
|
func reqRepoReader(unitType unit.Type) func(ctx *context.APIContext) {
|
||||||
return func(ctx *context.APIContext) {
|
return func(ctx *context.APIContext) {
|
||||||
if !ctx.Repo.CanRead(unitType) && !ctx.IsUserRepoAdmin() && !ctx.IsUserSiteAdmin() {
|
if !ctx.Repo.CanRead(unitType) && !ctx.IsUserRepoAdmin() && !ctx.IsUserSiteAdmin() {
|
||||||
ctx.Error(http.StatusForbidden, "reqRepoReader", "user should have specific read permission or be a repo admin or a site admin")
|
ctx.APIError(http.StatusForbidden, "user should have specific read permission or be a repo admin or a site admin")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -455,7 +455,7 @@ func reqRepoReader(unitType unit.Type) func(ctx *context.APIContext) {
|
||||||
func reqAnyRepoReader() func(ctx *context.APIContext) {
|
func reqAnyRepoReader() func(ctx *context.APIContext) {
|
||||||
return func(ctx *context.APIContext) {
|
return func(ctx *context.APIContext) {
|
||||||
if !ctx.Repo.Permission.HasAnyUnitAccess() && !ctx.IsUserSiteAdmin() {
|
if !ctx.Repo.Permission.HasAnyUnitAccess() && !ctx.IsUserSiteAdmin() {
|
||||||
ctx.Error(http.StatusForbidden, "reqAnyRepoReader", "user should have any permission to read repository or permissions of site admin")
|
ctx.APIError(http.StatusForbidden, "user should have any permission to read repository or permissions of site admin")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -474,19 +474,19 @@ func reqOrgOwnership() func(ctx *context.APIContext) {
|
||||||
} else if ctx.Org.Team != nil {
|
} else if ctx.Org.Team != nil {
|
||||||
orgID = ctx.Org.Team.OrgID
|
orgID = ctx.Org.Team.OrgID
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "", "reqOrgOwnership: unprepared context")
|
ctx.APIError(http.StatusInternalServerError, "reqOrgOwnership: unprepared context")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
isOwner, err := organization.IsOrganizationOwner(ctx, orgID, ctx.Doer.ID)
|
isOwner, err := organization.IsOrganizationOwner(ctx, orgID, ctx.Doer.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "IsOrganizationOwner", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
} else if !isOwner {
|
} else if !isOwner {
|
||||||
if ctx.Org.Organization != nil {
|
if ctx.Org.Organization != nil {
|
||||||
ctx.Error(http.StatusForbidden, "", "Must be an organization owner")
|
ctx.APIError(http.StatusForbidden, "Must be an organization owner")
|
||||||
} else {
|
} else {
|
||||||
ctx.NotFound()
|
ctx.APIErrorNotFound()
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -500,30 +500,30 @@ func reqTeamMembership() func(ctx *context.APIContext) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if ctx.Org.Team == nil {
|
if ctx.Org.Team == nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "", "reqTeamMembership: unprepared context")
|
ctx.APIError(http.StatusInternalServerError, "reqTeamMembership: unprepared context")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
orgID := ctx.Org.Team.OrgID
|
orgID := ctx.Org.Team.OrgID
|
||||||
isOwner, err := organization.IsOrganizationOwner(ctx, orgID, ctx.Doer.ID)
|
isOwner, err := organization.IsOrganizationOwner(ctx, orgID, ctx.Doer.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "IsOrganizationOwner", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
} else if isOwner {
|
} else if isOwner {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if isTeamMember, err := organization.IsTeamMember(ctx, orgID, ctx.Org.Team.ID, ctx.Doer.ID); err != nil {
|
if isTeamMember, err := organization.IsTeamMember(ctx, orgID, ctx.Org.Team.ID, ctx.Doer.ID); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "IsTeamMember", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
} else if !isTeamMember {
|
} else if !isTeamMember {
|
||||||
isOrgMember, err := organization.IsOrganizationMember(ctx, orgID, ctx.Doer.ID)
|
isOrgMember, err := organization.IsOrganizationMember(ctx, orgID, ctx.Doer.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "IsOrganizationMember", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
} else if isOrgMember {
|
} else if isOrgMember {
|
||||||
ctx.Error(http.StatusForbidden, "", "Must be a team member")
|
ctx.APIError(http.StatusForbidden, "Must be a team member")
|
||||||
} else {
|
} else {
|
||||||
ctx.NotFound()
|
ctx.APIErrorNotFound()
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -543,18 +543,18 @@ func reqOrgMembership() func(ctx *context.APIContext) {
|
||||||
} else if ctx.Org.Team != nil {
|
} else if ctx.Org.Team != nil {
|
||||||
orgID = ctx.Org.Team.OrgID
|
orgID = ctx.Org.Team.OrgID
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "", "reqOrgMembership: unprepared context")
|
ctx.APIError(http.StatusInternalServerError, "reqOrgMembership: unprepared context")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if isMember, err := organization.IsOrganizationMember(ctx, orgID, ctx.Doer.ID); err != nil {
|
if isMember, err := organization.IsOrganizationMember(ctx, orgID, ctx.Doer.ID); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "IsOrganizationMember", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
} else if !isMember {
|
} else if !isMember {
|
||||||
if ctx.Org.Organization != nil {
|
if ctx.Org.Organization != nil {
|
||||||
ctx.Error(http.StatusForbidden, "", "Must be an organization member")
|
ctx.APIError(http.StatusForbidden, "Must be an organization member")
|
||||||
} else {
|
} else {
|
||||||
ctx.NotFound()
|
ctx.APIErrorNotFound()
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -564,7 +564,7 @@ func reqOrgMembership() func(ctx *context.APIContext) {
|
||||||
func reqGitHook() func(ctx *context.APIContext) {
|
func reqGitHook() func(ctx *context.APIContext) {
|
||||||
return func(ctx *context.APIContext) {
|
return func(ctx *context.APIContext) {
|
||||||
if !ctx.Doer.CanEditGitHook() {
|
if !ctx.Doer.CanEditGitHook() {
|
||||||
ctx.Error(http.StatusForbidden, "", "must be allowed to edit Git hooks")
|
ctx.APIError(http.StatusForbidden, "must be allowed to edit Git hooks")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -574,7 +574,7 @@ func reqGitHook() func(ctx *context.APIContext) {
|
||||||
func reqWebhooksEnabled() func(ctx *context.APIContext) {
|
func reqWebhooksEnabled() func(ctx *context.APIContext) {
|
||||||
return func(ctx *context.APIContext) {
|
return func(ctx *context.APIContext) {
|
||||||
if setting.DisableWebhooks {
|
if setting.DisableWebhooks {
|
||||||
ctx.Error(http.StatusForbidden, "", "webhooks disabled by administrator")
|
ctx.APIError(http.StatusForbidden, "webhooks disabled by administrator")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -584,7 +584,7 @@ func reqWebhooksEnabled() func(ctx *context.APIContext) {
|
||||||
func reqStarsEnabled() func(ctx *context.APIContext) {
|
func reqStarsEnabled() func(ctx *context.APIContext) {
|
||||||
return func(ctx *context.APIContext) {
|
return func(ctx *context.APIContext) {
|
||||||
if setting.Repository.DisableStars {
|
if setting.Repository.DisableStars {
|
||||||
ctx.Error(http.StatusForbidden, "", "stars disabled by administrator")
|
ctx.APIError(http.StatusForbidden, "stars disabled by administrator")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -613,12 +613,12 @@ func orgAssignment(args ...bool) func(ctx *context.APIContext) {
|
||||||
if err == nil {
|
if err == nil {
|
||||||
context.RedirectToUser(ctx.Base, ctx.PathParam("org"), redirectUserID)
|
context.RedirectToUser(ctx.Base, ctx.PathParam("org"), redirectUserID)
|
||||||
} else if user_model.IsErrUserRedirectNotExist(err) {
|
} else if user_model.IsErrUserRedirectNotExist(err) {
|
||||||
ctx.NotFound("GetOrgByName", err)
|
ctx.APIErrorNotFound("GetOrgByName", err)
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "LookupUserRedirect", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetOrgByName", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -629,9 +629,9 @@ func orgAssignment(args ...bool) func(ctx *context.APIContext) {
|
||||||
ctx.Org.Team, err = organization.GetTeamByID(ctx, ctx.PathParamInt64("teamid"))
|
ctx.Org.Team, err = organization.GetTeamByID(ctx, ctx.PathParamInt64("teamid"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if organization.IsErrTeamNotExist(err) {
|
if organization.IsErrTeamNotExist(err) {
|
||||||
ctx.NotFound()
|
ctx.APIErrorNotFound()
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetTeamById", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -657,7 +657,7 @@ func mustEnableIssues(ctx *context.APIContext) {
|
||||||
ctx.Repo.Permission)
|
ctx.Repo.Permission)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ctx.NotFound()
|
ctx.APIErrorNotFound()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -680,7 +680,7 @@ func mustAllowPulls(ctx *context.APIContext) {
|
||||||
ctx.Repo.Permission)
|
ctx.Repo.Permission)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ctx.NotFound()
|
ctx.APIErrorNotFound()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -706,28 +706,28 @@ func mustEnableIssuesOrPulls(ctx *context.APIContext) {
|
||||||
ctx.Repo.Permission)
|
ctx.Repo.Permission)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ctx.NotFound()
|
ctx.APIErrorNotFound()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func mustEnableWiki(ctx *context.APIContext) {
|
func mustEnableWiki(ctx *context.APIContext) {
|
||||||
if !(ctx.Repo.CanRead(unit.TypeWiki)) {
|
if !(ctx.Repo.CanRead(unit.TypeWiki)) {
|
||||||
ctx.NotFound()
|
ctx.APIErrorNotFound()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func mustNotBeArchived(ctx *context.APIContext) {
|
func mustNotBeArchived(ctx *context.APIContext) {
|
||||||
if ctx.Repo.Repository.IsArchived {
|
if ctx.Repo.Repository.IsArchived {
|
||||||
ctx.Error(http.StatusLocked, "RepoArchived", fmt.Errorf("%s is archived", ctx.Repo.Repository.LogString()))
|
ctx.APIError(http.StatusLocked, fmt.Errorf("%s is archived", ctx.Repo.Repository.LogString()))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func mustEnableAttachments(ctx *context.APIContext) {
|
func mustEnableAttachments(ctx *context.APIContext) {
|
||||||
if !setting.Attachment.Enabled {
|
if !setting.Attachment.Enabled {
|
||||||
ctx.NotFound()
|
ctx.APIErrorNotFound()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -738,7 +738,7 @@ func bind[T any](_ T) any {
|
||||||
theObj := new(T) // create a new form obj for every request but not use obj directly
|
theObj := new(T) // create a new form obj for every request but not use obj directly
|
||||||
errs := binding.Bind(ctx.Req, theObj)
|
errs := binding.Bind(ctx.Req, theObj)
|
||||||
if len(errs) > 0 {
|
if len(errs) > 0 {
|
||||||
ctx.Error(http.StatusUnprocessableEntity, "validationError", fmt.Sprintf("%s: %s", errs[0].FieldNames, errs[0].Error()))
|
ctx.APIError(http.StatusUnprocessableEntity, fmt.Sprintf("%s: %s", errs[0].FieldNames, errs[0].Error()))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
web.SetForm(ctx, theObj)
|
web.SetForm(ctx, theObj)
|
||||||
|
@ -766,7 +766,7 @@ func apiAuth(authMethod auth.Method) func(*context.APIContext) {
|
||||||
return func(ctx *context.APIContext) {
|
return func(ctx *context.APIContext) {
|
||||||
ar, err := common.AuthShared(ctx.Base, nil, authMethod)
|
ar, err := common.AuthShared(ctx.Base, nil, authMethod)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusUnauthorized, "APIAuth", err)
|
ctx.APIError(http.StatusUnauthorized, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.Doer = ar.Doer
|
ctx.Doer = ar.Doer
|
||||||
|
@ -843,12 +843,12 @@ func individualPermsChecker(ctx *context.APIContext) {
|
||||||
switch {
|
switch {
|
||||||
case ctx.ContextUser.Visibility == api.VisibleTypePrivate:
|
case ctx.ContextUser.Visibility == api.VisibleTypePrivate:
|
||||||
if ctx.Doer == nil || (ctx.ContextUser.ID != ctx.Doer.ID && !ctx.Doer.IsAdmin) {
|
if ctx.Doer == nil || (ctx.ContextUser.ID != ctx.Doer.ID && !ctx.Doer.IsAdmin) {
|
||||||
ctx.NotFound("Visit Project", nil)
|
ctx.APIErrorNotFound("Visit Project", nil)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
case ctx.ContextUser.Visibility == api.VisibleTypeLimited:
|
case ctx.ContextUser.Visibility == api.VisibleTypeLimited:
|
||||||
if ctx.Doer == nil {
|
if ctx.Doer == nil {
|
||||||
ctx.NotFound("Visit Project", nil)
|
ctx.APIErrorNotFound("Visit Project", nil)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,7 +48,7 @@ func GetGitignoreTemplateInfo(ctx *context.APIContext) {
|
||||||
|
|
||||||
text, err := options.Gitignore(name)
|
text, err := options.Gitignore(name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.NotFound()
|
ctx.APIErrorNotFound()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -52,7 +52,7 @@ func GetLabelTemplate(ctx *context.APIContext) {
|
||||||
|
|
||||||
labels, err := repo_module.LoadTemplateLabelsByDisplayName(name)
|
labels, err := repo_module.LoadTemplateLabelsByDisplayName(name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.NotFound()
|
ctx.APIErrorNotFound()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -59,7 +59,7 @@ func GetLicenseTemplateInfo(ctx *context.APIContext) {
|
||||||
|
|
||||||
text, err := options.License(name)
|
text, err := options.License(name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.NotFound()
|
ctx.APIErrorNotFound()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -38,7 +38,7 @@ func Markup(ctx *context.APIContext) {
|
||||||
form := web.GetForm(ctx).(*api.MarkupOption)
|
form := web.GetForm(ctx).(*api.MarkupOption)
|
||||||
|
|
||||||
if ctx.HasAPIError() {
|
if ctx.HasAPIError() {
|
||||||
ctx.Error(http.StatusUnprocessableEntity, "", ctx.GetErrMsg())
|
ctx.APIError(http.StatusUnprocessableEntity, ctx.GetErrMsg())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -69,7 +69,7 @@ func Markdown(ctx *context.APIContext) {
|
||||||
form := web.GetForm(ctx).(*api.MarkdownOption)
|
form := web.GetForm(ctx).(*api.MarkdownOption)
|
||||||
|
|
||||||
if ctx.HasAPIError() {
|
if ctx.HasAPIError() {
|
||||||
ctx.Error(http.StatusUnprocessableEntity, "", ctx.GetErrMsg())
|
ctx.APIError(http.StatusUnprocessableEntity, ctx.GetErrMsg())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -100,7 +100,7 @@ func MarkdownRaw(ctx *context.APIContext) {
|
||||||
// "$ref": "#/responses/validationError"
|
// "$ref": "#/responses/validationError"
|
||||||
defer ctx.Req.Body.Close()
|
defer ctx.Req.Body.Close()
|
||||||
if err := markdown.RenderRaw(markup.NewRenderContext(ctx), ctx.Req.Body, ctx.Resp); err != nil {
|
if err := markdown.RenderRaw(markup.NewRenderContext(ctx), ctx.Req.Body, ctx.Resp); err != nil {
|
||||||
ctx.InternalServerError(err)
|
ctx.APIErrorInternal(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,7 +52,7 @@ func NodeInfo(ctx *context.APIContext) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := ctx.Cache.PutJSON(cacheKeyNodeInfoUsage, nodeInfoUsage, 180); err != nil {
|
if err := ctx.Cache.PutJSON(cacheKeyNodeInfoUsage, nodeInfoUsage, 180); err != nil {
|
||||||
ctx.InternalServerError(err)
|
ctx.APIErrorInternal(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,11 +53,11 @@ func SigningKey(ctx *context.APIContext) {
|
||||||
|
|
||||||
content, err := asymkey_service.PublicSigningKey(ctx, path)
|
content, err := asymkey_service.PublicSigningKey(ctx, path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "gpg export", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
_, err = ctx.Write([]byte(content))
|
_, err = ctx.Write([]byte(content))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "gpg export", fmt.Errorf("Error writing key content %w", err))
|
ctx.APIError(http.StatusInternalServerError, fmt.Errorf("Error writing key content %w", err))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,7 +28,7 @@ func NewAvailable(ctx *context.APIContext) {
|
||||||
Status: []activities_model.NotificationStatus{activities_model.NotificationStatusUnread},
|
Status: []activities_model.NotificationStatus{activities_model.NotificationStatusUnread},
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusUnprocessableEntity, "db.Count[activities_model.Notification]", err)
|
ctx.APIError(http.StatusUnprocessableEntity, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,7 +38,7 @@ func NewAvailable(ctx *context.APIContext) {
|
||||||
func getFindNotificationOptions(ctx *context.APIContext) *activities_model.FindNotificationOptions {
|
func getFindNotificationOptions(ctx *context.APIContext) *activities_model.FindNotificationOptions {
|
||||||
before, since, err := context.GetQueryBeforeSince(ctx.Base)
|
before, since, err := context.GetQueryBeforeSince(ctx.Base)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusUnprocessableEntity, "GetQueryBeforeSince", err)
|
ctx.APIError(http.StatusUnprocessableEntity, err)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
opts := &activities_model.FindNotificationOptions{
|
opts := &activities_model.FindNotificationOptions{
|
||||||
|
|
|
@ -110,18 +110,18 @@ func ListRepoNotifications(ctx *context.APIContext) {
|
||||||
|
|
||||||
totalCount, err := db.Count[activities_model.Notification](ctx, opts)
|
totalCount, err := db.Count[activities_model.Notification](ctx, opts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.InternalServerError(err)
|
ctx.APIErrorInternal(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
nl, err := db.Find[activities_model.Notification](ctx, opts)
|
nl, err := db.Find[activities_model.Notification](ctx, opts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.InternalServerError(err)
|
ctx.APIErrorInternal(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
err = activities_model.NotificationList(nl).LoadAttributes(ctx)
|
err = activities_model.NotificationList(nl).LoadAttributes(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.InternalServerError(err)
|
ctx.APIErrorInternal(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -183,7 +183,7 @@ func ReadRepoNotifications(ctx *context.APIContext) {
|
||||||
if len(qLastRead) > 0 {
|
if len(qLastRead) > 0 {
|
||||||
tmpLastRead, err := time.Parse(time.RFC3339, qLastRead)
|
tmpLastRead, err := time.Parse(time.RFC3339, qLastRead)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusBadRequest, "Parse", err)
|
ctx.APIError(http.StatusBadRequest, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if !tmpLastRead.IsZero() {
|
if !tmpLastRead.IsZero() {
|
||||||
|
@ -203,7 +203,7 @@ func ReadRepoNotifications(ctx *context.APIContext) {
|
||||||
}
|
}
|
||||||
nl, err := db.Find[activities_model.Notification](ctx, opts)
|
nl, err := db.Find[activities_model.Notification](ctx, opts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.InternalServerError(err)
|
ctx.APIErrorInternal(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -217,7 +217,7 @@ func ReadRepoNotifications(ctx *context.APIContext) {
|
||||||
for _, n := range nl {
|
for _, n := range nl {
|
||||||
notif, err := activities_model.SetNotificationStatus(ctx, n.ID, ctx.Doer, targetStatus)
|
notif, err := activities_model.SetNotificationStatus(ctx, n.ID, ctx.Doer, targetStatus)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.InternalServerError(err)
|
ctx.APIErrorInternal(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
_ = notif.LoadAttributes(ctx)
|
_ = notif.LoadAttributes(ctx)
|
||||||
|
|
|
@ -42,7 +42,7 @@ func GetThread(ctx *context.APIContext) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if err := n.LoadAttributes(ctx); err != nil && !issues_model.IsErrCommentNotExist(err) {
|
if err := n.LoadAttributes(ctx); err != nil && !issues_model.IsErrCommentNotExist(err) {
|
||||||
ctx.InternalServerError(err)
|
ctx.APIErrorInternal(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -90,11 +90,11 @@ func ReadThread(ctx *context.APIContext) {
|
||||||
|
|
||||||
notif, err := activities_model.SetNotificationStatus(ctx, n.ID, ctx.Doer, targetStatus)
|
notif, err := activities_model.SetNotificationStatus(ctx, n.ID, ctx.Doer, targetStatus)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.InternalServerError(err)
|
ctx.APIErrorInternal(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if err = notif.LoadAttributes(ctx); err != nil && !issues_model.IsErrCommentNotExist(err) {
|
if err = notif.LoadAttributes(ctx); err != nil && !issues_model.IsErrCommentNotExist(err) {
|
||||||
ctx.InternalServerError(err)
|
ctx.APIErrorInternal(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.JSON(http.StatusResetContent, convert.ToNotificationThread(ctx, notif))
|
ctx.JSON(http.StatusResetContent, convert.ToNotificationThread(ctx, notif))
|
||||||
|
@ -104,14 +104,14 @@ func getThread(ctx *context.APIContext) *activities_model.Notification {
|
||||||
n, err := activities_model.GetNotificationByID(ctx, ctx.PathParamInt64("id"))
|
n, err := activities_model.GetNotificationByID(ctx, ctx.PathParamInt64("id"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if db.IsErrNotExist(err) {
|
if db.IsErrNotExist(err) {
|
||||||
ctx.Error(http.StatusNotFound, "GetNotificationByID", err)
|
ctx.APIError(http.StatusNotFound, err)
|
||||||
} else {
|
} else {
|
||||||
ctx.InternalServerError(err)
|
ctx.APIErrorInternal(err)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
if n.UserID != ctx.Doer.ID && !ctx.Doer.IsAdmin {
|
if n.UserID != ctx.Doer.ID && !ctx.Doer.IsAdmin {
|
||||||
ctx.Error(http.StatusForbidden, "GetNotificationByID", fmt.Errorf("only user itself and admin are allowed to read/change this thread %d", n.ID))
|
ctx.APIError(http.StatusForbidden, fmt.Errorf("only user itself and admin are allowed to read/change this thread %d", n.ID))
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return n
|
return n
|
||||||
|
|
|
@ -71,18 +71,18 @@ func ListNotifications(ctx *context.APIContext) {
|
||||||
|
|
||||||
totalCount, err := db.Count[activities_model.Notification](ctx, opts)
|
totalCount, err := db.Count[activities_model.Notification](ctx, opts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.InternalServerError(err)
|
ctx.APIErrorInternal(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
nl, err := db.Find[activities_model.Notification](ctx, opts)
|
nl, err := db.Find[activities_model.Notification](ctx, opts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.InternalServerError(err)
|
ctx.APIErrorInternal(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
err = activities_model.NotificationList(nl).LoadAttributes(ctx)
|
err = activities_model.NotificationList(nl).LoadAttributes(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.InternalServerError(err)
|
ctx.APIErrorInternal(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -133,7 +133,7 @@ func ReadNotifications(ctx *context.APIContext) {
|
||||||
if len(qLastRead) > 0 {
|
if len(qLastRead) > 0 {
|
||||||
tmpLastRead, err := time.Parse(time.RFC3339, qLastRead)
|
tmpLastRead, err := time.Parse(time.RFC3339, qLastRead)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusBadRequest, "Parse", err)
|
ctx.APIError(http.StatusBadRequest, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if !tmpLastRead.IsZero() {
|
if !tmpLastRead.IsZero() {
|
||||||
|
@ -150,7 +150,7 @@ func ReadNotifications(ctx *context.APIContext) {
|
||||||
}
|
}
|
||||||
nl, err := db.Find[activities_model.Notification](ctx, opts)
|
nl, err := db.Find[activities_model.Notification](ctx, opts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.InternalServerError(err)
|
ctx.APIErrorInternal(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -164,7 +164,7 @@ func ReadNotifications(ctx *context.APIContext) {
|
||||||
for _, n := range nl {
|
for _, n := range nl {
|
||||||
notif, err := activities_model.SetNotificationStatus(ctx, n.ID, ctx.Doer, targetStatus)
|
notif, err := activities_model.SetNotificationStatus(ctx, n.ID, ctx.Doer, targetStatus)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.InternalServerError(err)
|
ctx.APIErrorInternal(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
_ = notif.LoadAttributes(ctx)
|
_ = notif.LoadAttributes(ctx)
|
||||||
|
|
|
@ -54,7 +54,7 @@ func (Action) ListActionsSecrets(ctx *context.APIContext) {
|
||||||
|
|
||||||
secrets, count, err := db.FindAndCount[secret_model.Secret](ctx, opts)
|
secrets, count, err := db.FindAndCount[secret_model.Secret](ctx, opts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.InternalServerError(err)
|
ctx.APIErrorInternal(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -109,11 +109,11 @@ func (Action) CreateOrUpdateSecret(ctx *context.APIContext) {
|
||||||
_, created, err := secret_service.CreateOrUpdateSecret(ctx, ctx.Org.Organization.ID, 0, ctx.PathParam("secretname"), opt.Data)
|
_, created, err := secret_service.CreateOrUpdateSecret(ctx, ctx.Org.Organization.ID, 0, ctx.PathParam("secretname"), opt.Data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if errors.Is(err, util.ErrInvalidArgument) {
|
if errors.Is(err, util.ErrInvalidArgument) {
|
||||||
ctx.Error(http.StatusBadRequest, "CreateOrUpdateSecret", err)
|
ctx.APIError(http.StatusBadRequest, err)
|
||||||
} else if errors.Is(err, util.ErrNotExist) {
|
} else if errors.Is(err, util.ErrNotExist) {
|
||||||
ctx.Error(http.StatusNotFound, "CreateOrUpdateSecret", err)
|
ctx.APIError(http.StatusNotFound, err)
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "CreateOrUpdateSecret", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -156,11 +156,11 @@ func (Action) DeleteSecret(ctx *context.APIContext) {
|
||||||
err := secret_service.DeleteSecretByName(ctx, ctx.Org.Organization.ID, 0, ctx.PathParam("secretname"))
|
err := secret_service.DeleteSecretByName(ctx, ctx.Org.Organization.ID, 0, ctx.PathParam("secretname"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if errors.Is(err, util.ErrInvalidArgument) {
|
if errors.Is(err, util.ErrInvalidArgument) {
|
||||||
ctx.Error(http.StatusBadRequest, "DeleteSecret", err)
|
ctx.APIError(http.StatusBadRequest, err)
|
||||||
} else if errors.Is(err, util.ErrNotExist) {
|
} else if errors.Is(err, util.ErrNotExist) {
|
||||||
ctx.Error(http.StatusNotFound, "DeleteSecret", err)
|
ctx.APIError(http.StatusNotFound, err)
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "DeleteSecret", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -223,7 +223,7 @@ func (Action) ListVariables(ctx *context.APIContext) {
|
||||||
ListOptions: utils.GetListOptions(ctx),
|
ListOptions: utils.GetListOptions(ctx),
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "FindVariables", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -273,9 +273,9 @@ func (Action) GetVariable(ctx *context.APIContext) {
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if errors.Is(err, util.ErrNotExist) {
|
if errors.Is(err, util.ErrNotExist) {
|
||||||
ctx.Error(http.StatusNotFound, "GetVariable", err)
|
ctx.APIError(http.StatusNotFound, err)
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetVariable", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -322,11 +322,11 @@ func (Action) DeleteVariable(ctx *context.APIContext) {
|
||||||
|
|
||||||
if err := actions_service.DeleteVariableByName(ctx, ctx.Org.Organization.ID, 0, ctx.PathParam("variablename")); err != nil {
|
if err := actions_service.DeleteVariableByName(ctx, ctx.Org.Organization.ID, 0, ctx.PathParam("variablename")); err != nil {
|
||||||
if errors.Is(err, util.ErrInvalidArgument) {
|
if errors.Is(err, util.ErrInvalidArgument) {
|
||||||
ctx.Error(http.StatusBadRequest, "DeleteVariableByName", err)
|
ctx.APIError(http.StatusBadRequest, err)
|
||||||
} else if errors.Is(err, util.ErrNotExist) {
|
} else if errors.Is(err, util.ErrNotExist) {
|
||||||
ctx.Error(http.StatusNotFound, "DeleteVariableByName", err)
|
ctx.APIError(http.StatusNotFound, err)
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "DeleteVariableByName", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -378,19 +378,19 @@ func (Action) CreateVariable(ctx *context.APIContext) {
|
||||||
Name: variableName,
|
Name: variableName,
|
||||||
})
|
})
|
||||||
if err != nil && !errors.Is(err, util.ErrNotExist) {
|
if err != nil && !errors.Is(err, util.ErrNotExist) {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetVariable", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if v != nil && v.ID > 0 {
|
if v != nil && v.ID > 0 {
|
||||||
ctx.Error(http.StatusConflict, "VariableNameAlreadyExists", util.NewAlreadyExistErrorf("variable name %s already exists", variableName))
|
ctx.APIError(http.StatusConflict, util.NewAlreadyExistErrorf("variable name %s already exists", variableName))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := actions_service.CreateVariable(ctx, ownerID, 0, variableName, opt.Value); err != nil {
|
if _, err := actions_service.CreateVariable(ctx, ownerID, 0, variableName, opt.Value); err != nil {
|
||||||
if errors.Is(err, util.ErrInvalidArgument) {
|
if errors.Is(err, util.ErrInvalidArgument) {
|
||||||
ctx.Error(http.StatusBadRequest, "CreateVariable", err)
|
ctx.APIError(http.StatusBadRequest, err)
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "CreateVariable", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -440,9 +440,9 @@ func (Action) UpdateVariable(ctx *context.APIContext) {
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if errors.Is(err, util.ErrNotExist) {
|
if errors.Is(err, util.ErrNotExist) {
|
||||||
ctx.Error(http.StatusNotFound, "GetVariable", err)
|
ctx.APIError(http.StatusNotFound, err)
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetVariable", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -456,9 +456,9 @@ func (Action) UpdateVariable(ctx *context.APIContext) {
|
||||||
|
|
||||||
if _, err := actions_service.UpdateVariableNameData(ctx, v); err != nil {
|
if _, err := actions_service.UpdateVariableNameData(ctx, v); err != nil {
|
||||||
if errors.Is(err, util.ErrInvalidArgument) {
|
if errors.Is(err, util.ErrInvalidArgument) {
|
||||||
ctx.Error(http.StatusBadRequest, "UpdateVariable", err)
|
ctx.APIError(http.StatusBadRequest, err)
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "UpdateVariable", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,13 +39,13 @@ func UpdateAvatar(ctx *context.APIContext) {
|
||||||
|
|
||||||
content, err := base64.StdEncoding.DecodeString(form.Image)
|
content, err := base64.StdEncoding.DecodeString(form.Image)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusBadRequest, "DecodeImage", err)
|
ctx.APIError(http.StatusBadRequest, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
err = user_service.UploadAvatar(ctx, ctx.Org.Organization.AsUser(), content)
|
err = user_service.UploadAvatar(ctx, ctx.Org.Organization.AsUser(), content)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "UploadAvatar", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -72,7 +72,7 @@ func DeleteAvatar(ctx *context.APIContext) {
|
||||||
// "$ref": "#/responses/notFound"
|
// "$ref": "#/responses/notFound"
|
||||||
err := user_service.DeleteAvatar(ctx, ctx.Org.Organization.AsUser())
|
err := user_service.DeleteAvatar(ctx, ctx.Org.Organization.AsUser())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "DeleteAvatar", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -78,7 +78,7 @@ func GetHook(ctx *context.APIContext) {
|
||||||
|
|
||||||
apiHook, err := webhook_service.ToHook(ctx.ContextUser.HomeLink(), hook)
|
apiHook, err := webhook_service.ToHook(ctx.ContextUser.HomeLink(), hook)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.InternalServerError(err)
|
ctx.APIErrorInternal(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.JSON(http.StatusOK, apiHook)
|
ctx.JSON(http.StatusOK, apiHook)
|
||||||
|
|
|
@ -46,13 +46,13 @@ func ListLabels(ctx *context.APIContext) {
|
||||||
|
|
||||||
labels, err := issues_model.GetLabelsByOrgID(ctx, ctx.Org.Organization.ID, ctx.FormString("sort"), utils.GetListOptions(ctx))
|
labels, err := issues_model.GetLabelsByOrgID(ctx, ctx.Org.Organization.ID, ctx.FormString("sort"), utils.GetListOptions(ctx))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetLabelsByOrgID", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
count, err := issues_model.CountLabelsByOrgID(ctx, ctx.Org.Organization.ID)
|
count, err := issues_model.CountLabelsByOrgID(ctx, ctx.Org.Organization.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.InternalServerError(err)
|
ctx.APIErrorInternal(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -90,7 +90,7 @@ func CreateLabel(ctx *context.APIContext) {
|
||||||
form.Color = strings.Trim(form.Color, " ")
|
form.Color = strings.Trim(form.Color, " ")
|
||||||
color, err := label.NormalizeColor(form.Color)
|
color, err := label.NormalizeColor(form.Color)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusUnprocessableEntity, "Color", err)
|
ctx.APIError(http.StatusUnprocessableEntity, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
form.Color = color
|
form.Color = color
|
||||||
|
@ -103,7 +103,7 @@ func CreateLabel(ctx *context.APIContext) {
|
||||||
Description: form.Description,
|
Description: form.Description,
|
||||||
}
|
}
|
||||||
if err := issues_model.NewLabel(ctx, label); err != nil {
|
if err := issues_model.NewLabel(ctx, label); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "NewLabel", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -147,9 +147,9 @@ func GetLabel(ctx *context.APIContext) {
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if issues_model.IsErrOrgLabelNotExist(err) {
|
if issues_model.IsErrOrgLabelNotExist(err) {
|
||||||
ctx.NotFound()
|
ctx.APIErrorNotFound()
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetLabelByOrgID", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -193,9 +193,9 @@ func EditLabel(ctx *context.APIContext) {
|
||||||
l, err := issues_model.GetLabelInOrgByID(ctx, ctx.Org.Organization.ID, ctx.PathParamInt64("id"))
|
l, err := issues_model.GetLabelInOrgByID(ctx, ctx.Org.Organization.ID, ctx.PathParamInt64("id"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if issues_model.IsErrOrgLabelNotExist(err) {
|
if issues_model.IsErrOrgLabelNotExist(err) {
|
||||||
ctx.NotFound()
|
ctx.APIErrorNotFound()
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetLabelByRepoID", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -209,7 +209,7 @@ func EditLabel(ctx *context.APIContext) {
|
||||||
if form.Color != nil {
|
if form.Color != nil {
|
||||||
color, err := label.NormalizeColor(*form.Color)
|
color, err := label.NormalizeColor(*form.Color)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusUnprocessableEntity, "Color", err)
|
ctx.APIError(http.StatusUnprocessableEntity, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
l.Color = color
|
l.Color = color
|
||||||
|
@ -219,7 +219,7 @@ func EditLabel(ctx *context.APIContext) {
|
||||||
}
|
}
|
||||||
l.SetArchived(form.IsArchived != nil && *form.IsArchived)
|
l.SetArchived(form.IsArchived != nil && *form.IsArchived)
|
||||||
if err := issues_model.UpdateLabel(ctx, l); err != nil {
|
if err := issues_model.UpdateLabel(ctx, l); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "UpdateLabel", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -250,7 +250,7 @@ func DeleteLabel(ctx *context.APIContext) {
|
||||||
// "$ref": "#/responses/notFound"
|
// "$ref": "#/responses/notFound"
|
||||||
|
|
||||||
if err := issues_model.DeleteLabel(ctx, ctx.Org.Organization.ID, ctx.PathParamInt64("id")); err != nil {
|
if err := issues_model.DeleteLabel(ctx, ctx.Org.Organization.ID, ctx.PathParamInt64("id")); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "DeleteLabel", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -28,13 +28,13 @@ func listMembers(ctx *context.APIContext, isMember bool) {
|
||||||
|
|
||||||
count, err := organization.CountOrgMembers(ctx, opts)
|
count, err := organization.CountOrgMembers(ctx, opts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.InternalServerError(err)
|
ctx.APIErrorInternal(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
members, _, err := organization.FindOrgMembers(ctx, opts)
|
members, _, err := organization.FindOrgMembers(ctx, opts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.InternalServerError(err)
|
ctx.APIErrorInternal(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -82,7 +82,7 @@ func ListMembers(ctx *context.APIContext) {
|
||||||
if ctx.Doer != nil {
|
if ctx.Doer != nil {
|
||||||
isMember, err = ctx.Org.Organization.IsOrgMember(ctx, ctx.Doer.ID)
|
isMember, err = ctx.Org.Organization.IsOrgMember(ctx, ctx.Doer.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "IsOrgMember", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -150,20 +150,20 @@ func IsMember(ctx *context.APIContext) {
|
||||||
if ctx.Doer != nil {
|
if ctx.Doer != nil {
|
||||||
userIsMember, err := ctx.Org.Organization.IsOrgMember(ctx, ctx.Doer.ID)
|
userIsMember, err := ctx.Org.Organization.IsOrgMember(ctx, ctx.Doer.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "IsOrgMember", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
} else if userIsMember || ctx.Doer.IsAdmin {
|
} else if userIsMember || ctx.Doer.IsAdmin {
|
||||||
userToCheckIsMember, err := ctx.Org.Organization.IsOrgMember(ctx, userToCheck.ID)
|
userToCheckIsMember, err := ctx.Org.Organization.IsOrgMember(ctx, userToCheck.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "IsOrgMember", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
} else if userToCheckIsMember {
|
} else if userToCheckIsMember {
|
||||||
ctx.Status(http.StatusNoContent)
|
ctx.Status(http.StatusNoContent)
|
||||||
} else {
|
} else {
|
||||||
ctx.NotFound()
|
ctx.APIErrorNotFound()
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
} else if ctx.Doer.ID == userToCheck.ID {
|
} else if ctx.Doer.ID == userToCheck.ID {
|
||||||
ctx.NotFound()
|
ctx.APIErrorNotFound()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -200,13 +200,13 @@ func IsPublicMember(ctx *context.APIContext) {
|
||||||
}
|
}
|
||||||
is, err := organization.IsPublicMembership(ctx, ctx.Org.Organization.ID, userToCheck.ID)
|
is, err := organization.IsPublicMembership(ctx, ctx.Org.Organization.ID, userToCheck.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "IsPublicMembership", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if is {
|
if is {
|
||||||
ctx.Status(http.StatusNoContent)
|
ctx.Status(http.StatusNoContent)
|
||||||
} else {
|
} else {
|
||||||
ctx.NotFound()
|
ctx.APIErrorNotFound()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -241,12 +241,12 @@ func PublicizeMember(ctx *context.APIContext) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if userToPublicize.ID != ctx.Doer.ID {
|
if userToPublicize.ID != ctx.Doer.ID {
|
||||||
ctx.Error(http.StatusForbidden, "", "Cannot publicize another member")
|
ctx.APIError(http.StatusForbidden, "Cannot publicize another member")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
err := organization.ChangeOrgUserStatus(ctx, ctx.Org.Organization.ID, userToPublicize.ID, true)
|
err := organization.ChangeOrgUserStatus(ctx, ctx.Org.Organization.ID, userToPublicize.ID, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "ChangeOrgUserStatus", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.Status(http.StatusNoContent)
|
ctx.Status(http.StatusNoContent)
|
||||||
|
@ -283,12 +283,12 @@ func ConcealMember(ctx *context.APIContext) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if userToConceal.ID != ctx.Doer.ID {
|
if userToConceal.ID != ctx.Doer.ID {
|
||||||
ctx.Error(http.StatusForbidden, "", "Cannot conceal another member")
|
ctx.APIError(http.StatusForbidden, "Cannot conceal another member")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
err := organization.ChangeOrgUserStatus(ctx, ctx.Org.Organization.ID, userToConceal.ID, false)
|
err := organization.ChangeOrgUserStatus(ctx, ctx.Org.Organization.ID, userToConceal.ID, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "ChangeOrgUserStatus", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.Status(http.StatusNoContent)
|
ctx.Status(http.StatusNoContent)
|
||||||
|
@ -323,7 +323,7 @@ func DeleteMember(ctx *context.APIContext) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if err := org_service.RemoveOrgUser(ctx, ctx.Org.Organization, member); err != nil {
|
if err := org_service.RemoveOrgUser(ctx, ctx.Org.Organization, member); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "RemoveOrgUser", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
ctx.Status(http.StatusNoContent)
|
ctx.Status(http.StatusNoContent)
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,7 +35,7 @@ func listUserOrgs(ctx *context.APIContext, u *user_model.User) {
|
||||||
}
|
}
|
||||||
orgs, maxResults, err := db.FindAndCount[organization.Organization](ctx, opts)
|
orgs, maxResults, err := db.FindAndCount[organization.Organization](ctx, opts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "db.FindAndCount[organization.Organization]", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -138,14 +138,14 @@ func GetUserOrgsPermissions(ctx *context.APIContext) {
|
||||||
op := api.OrganizationPermissions{}
|
op := api.OrganizationPermissions{}
|
||||||
|
|
||||||
if !organization.HasOrgOrUserVisible(ctx, o, ctx.ContextUser) {
|
if !organization.HasOrgOrUserVisible(ctx, o, ctx.ContextUser) {
|
||||||
ctx.NotFound("HasOrgOrUserVisible", nil)
|
ctx.APIErrorNotFound("HasOrgOrUserVisible", nil)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
org := organization.OrgFromUser(o)
|
org := organization.OrgFromUser(o)
|
||||||
authorizeLevel, err := org.GetOrgUserMaxAuthorizeLevel(ctx, ctx.ContextUser.ID)
|
authorizeLevel, err := org.GetOrgUserMaxAuthorizeLevel(ctx, ctx.ContextUser.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetOrgUserAuthorizeLevel", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -164,7 +164,7 @@ func GetUserOrgsPermissions(ctx *context.APIContext) {
|
||||||
|
|
||||||
op.CanCreateRepository, err = org.CanCreateOrgRepo(ctx, ctx.ContextUser.ID)
|
op.CanCreateRepository, err = org.CanCreateOrgRepo(ctx, ctx.ContextUser.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "CanCreateOrgRepo", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -209,7 +209,7 @@ func GetAll(ctx *context.APIContext) {
|
||||||
Visible: vMode,
|
Visible: vMode,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "SearchOrganizations", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
orgs := make([]*api.Organization, len(publicOrgs))
|
orgs := make([]*api.Organization, len(publicOrgs))
|
||||||
|
@ -245,7 +245,7 @@ func Create(ctx *context.APIContext) {
|
||||||
// "$ref": "#/responses/validationError"
|
// "$ref": "#/responses/validationError"
|
||||||
form := web.GetForm(ctx).(*api.CreateOrgOption)
|
form := web.GetForm(ctx).(*api.CreateOrgOption)
|
||||||
if !ctx.Doer.CanCreateOrganization() {
|
if !ctx.Doer.CanCreateOrganization() {
|
||||||
ctx.Error(http.StatusForbidden, "Create organization not allowed", nil)
|
ctx.APIError(http.StatusForbidden, nil)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -271,9 +271,9 @@ func Create(ctx *context.APIContext) {
|
||||||
db.IsErrNameReserved(err) ||
|
db.IsErrNameReserved(err) ||
|
||||||
db.IsErrNameCharsNotAllowed(err) ||
|
db.IsErrNameCharsNotAllowed(err) ||
|
||||||
db.IsErrNamePatternNotAllowed(err) {
|
db.IsErrNamePatternNotAllowed(err) {
|
||||||
ctx.Error(http.StatusUnprocessableEntity, "", err)
|
ctx.APIError(http.StatusUnprocessableEntity, err)
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "CreateOrganization", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -301,7 +301,7 @@ func Get(ctx *context.APIContext) {
|
||||||
// "$ref": "#/responses/notFound"
|
// "$ref": "#/responses/notFound"
|
||||||
|
|
||||||
if !organization.HasOrgOrUserVisible(ctx, ctx.Org.Organization.AsUser(), ctx.Doer) {
|
if !organization.HasOrgOrUserVisible(ctx, ctx.Org.Organization.AsUser(), ctx.Doer) {
|
||||||
ctx.NotFound("HasOrgOrUserVisible", nil)
|
ctx.APIErrorNotFound("HasOrgOrUserVisible", nil)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -344,9 +344,9 @@ func Rename(ctx *context.APIContext) {
|
||||||
orgUser := ctx.Org.Organization.AsUser()
|
orgUser := ctx.Org.Organization.AsUser()
|
||||||
if err := user_service.RenameUser(ctx, orgUser, form.NewName); err != nil {
|
if err := user_service.RenameUser(ctx, orgUser, form.NewName); err != nil {
|
||||||
if user_model.IsErrUserAlreadyExist(err) || db.IsErrNameReserved(err) || db.IsErrNamePatternNotAllowed(err) || db.IsErrNameCharsNotAllowed(err) {
|
if user_model.IsErrUserAlreadyExist(err) || db.IsErrNameReserved(err) || db.IsErrNamePatternNotAllowed(err) || db.IsErrNameCharsNotAllowed(err) {
|
||||||
ctx.Error(http.StatusUnprocessableEntity, "RenameOrg", err)
|
ctx.APIError(http.StatusUnprocessableEntity, err)
|
||||||
} else {
|
} else {
|
||||||
ctx.ServerError("RenameOrg", err)
|
ctx.APIErrorInternal(err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -383,7 +383,7 @@ func Edit(ctx *context.APIContext) {
|
||||||
|
|
||||||
if form.Email != "" {
|
if form.Email != "" {
|
||||||
if err := user_service.ReplacePrimaryEmailAddress(ctx, ctx.Org.Organization.AsUser(), form.Email); err != nil {
|
if err := user_service.ReplacePrimaryEmailAddress(ctx, ctx.Org.Organization.AsUser(), form.Email); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "ReplacePrimaryEmailAddress", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -397,7 +397,7 @@ func Edit(ctx *context.APIContext) {
|
||||||
RepoAdminChangeTeamAccess: optional.FromPtr(form.RepoAdminChangeTeamAccess),
|
RepoAdminChangeTeamAccess: optional.FromPtr(form.RepoAdminChangeTeamAccess),
|
||||||
}
|
}
|
||||||
if err := user_service.UpdateUser(ctx, ctx.Org.Organization.AsUser(), opts); err != nil {
|
if err := user_service.UpdateUser(ctx, ctx.Org.Organization.AsUser(), opts); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "UpdateUser", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -424,7 +424,7 @@ func Delete(ctx *context.APIContext) {
|
||||||
// "$ref": "#/responses/notFound"
|
// "$ref": "#/responses/notFound"
|
||||||
|
|
||||||
if err := org.DeleteOrganization(ctx, ctx.Org.Organization, false); err != nil {
|
if err := org.DeleteOrganization(ctx, ctx.Org.Organization, false); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "DeleteOrganization", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.Status(http.StatusNoContent)
|
ctx.Status(http.StatusNoContent)
|
||||||
|
@ -469,7 +469,7 @@ func ListOrgActivityFeeds(ctx *context.APIContext) {
|
||||||
org := organization.OrgFromUser(ctx.ContextUser)
|
org := organization.OrgFromUser(ctx.ContextUser)
|
||||||
isMember, err := org.IsOrgMember(ctx, ctx.Doer.ID)
|
isMember, err := org.IsOrgMember(ctx, ctx.Doer.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "IsOrgMember", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
includePrivate = isMember
|
includePrivate = isMember
|
||||||
|
@ -488,7 +488,7 @@ func ListOrgActivityFeeds(ctx *context.APIContext) {
|
||||||
|
|
||||||
feeds, count, err := feed_service.GetFeeds(ctx, opts)
|
feeds, count, err := feed_service.GetFeeds(ctx, opts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetFeeds", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.SetTotalCountHeader(count)
|
ctx.SetTotalCountHeader(count)
|
||||||
|
|
|
@ -59,13 +59,13 @@ func ListTeams(ctx *context.APIContext) {
|
||||||
OrgID: ctx.Org.Organization.ID,
|
OrgID: ctx.Org.Organization.ID,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "LoadTeams", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
apiTeams, err := convert.ToTeams(ctx, teams, false)
|
apiTeams, err := convert.ToTeams(ctx, teams, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "ConvertToTeams", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -98,13 +98,13 @@ func ListUserTeams(ctx *context.APIContext) {
|
||||||
UserID: ctx.Doer.ID,
|
UserID: ctx.Doer.ID,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetUserTeams", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
apiTeams, err := convert.ToTeams(ctx, teams, true)
|
apiTeams, err := convert.ToTeams(ctx, teams, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "ConvertToTeams", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -134,7 +134,7 @@ func GetTeam(ctx *context.APIContext) {
|
||||||
|
|
||||||
apiTeam, err := convert.ToTeam(ctx, ctx.Org.Team, true)
|
apiTeam, err := convert.ToTeam(ctx, ctx.Org.Team, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.InternalServerError(err)
|
ctx.APIErrorInternal(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -233,7 +233,7 @@ func CreateTeam(ctx *context.APIContext) {
|
||||||
} else if len(form.Units) > 0 {
|
} else if len(form.Units) > 0 {
|
||||||
attachTeamUnits(team, form.Units)
|
attachTeamUnits(team, form.Units)
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "getTeamUnits", errors.New("units permission should not be empty"))
|
ctx.APIError(http.StatusInternalServerError, errors.New("units permission should not be empty"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -242,16 +242,16 @@ func CreateTeam(ctx *context.APIContext) {
|
||||||
|
|
||||||
if err := org_service.NewTeam(ctx, team); err != nil {
|
if err := org_service.NewTeam(ctx, team); err != nil {
|
||||||
if organization.IsErrTeamAlreadyExist(err) {
|
if organization.IsErrTeamAlreadyExist(err) {
|
||||||
ctx.Error(http.StatusUnprocessableEntity, "", err)
|
ctx.APIError(http.StatusUnprocessableEntity, err)
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "NewTeam", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
apiTeam, err := convert.ToTeam(ctx, team, true)
|
apiTeam, err := convert.ToTeam(ctx, team, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.InternalServerError(err)
|
ctx.APIErrorInternal(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.JSON(http.StatusCreated, apiTeam)
|
ctx.JSON(http.StatusCreated, apiTeam)
|
||||||
|
@ -285,7 +285,7 @@ func EditTeam(ctx *context.APIContext) {
|
||||||
form := web.GetForm(ctx).(*api.EditTeamOption)
|
form := web.GetForm(ctx).(*api.EditTeamOption)
|
||||||
team := ctx.Org.Team
|
team := ctx.Org.Team
|
||||||
if err := team.LoadUnits(ctx); err != nil {
|
if err := team.LoadUnits(ctx); err != nil {
|
||||||
ctx.InternalServerError(err)
|
ctx.APIErrorInternal(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -332,13 +332,13 @@ func EditTeam(ctx *context.APIContext) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := org_service.UpdateTeam(ctx, team, isAuthChanged, isIncludeAllChanged); err != nil {
|
if err := org_service.UpdateTeam(ctx, team, isAuthChanged, isIncludeAllChanged); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "EditTeam", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
apiTeam, err := convert.ToTeam(ctx, team)
|
apiTeam, err := convert.ToTeam(ctx, team)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.InternalServerError(err)
|
ctx.APIErrorInternal(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.JSON(http.StatusOK, apiTeam)
|
ctx.JSON(http.StatusOK, apiTeam)
|
||||||
|
@ -363,7 +363,7 @@ func DeleteTeam(ctx *context.APIContext) {
|
||||||
// "$ref": "#/responses/notFound"
|
// "$ref": "#/responses/notFound"
|
||||||
|
|
||||||
if err := org_service.DeleteTeam(ctx, ctx.Org.Team); err != nil {
|
if err := org_service.DeleteTeam(ctx, ctx.Org.Team); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "DeleteTeam", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.Status(http.StatusNoContent)
|
ctx.Status(http.StatusNoContent)
|
||||||
|
@ -399,10 +399,10 @@ func GetTeamMembers(ctx *context.APIContext) {
|
||||||
|
|
||||||
isMember, err := organization.IsOrganizationMember(ctx, ctx.Org.Team.OrgID, ctx.Doer.ID)
|
isMember, err := organization.IsOrganizationMember(ctx, ctx.Org.Team.OrgID, ctx.Doer.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "IsOrganizationMember", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
} else if !isMember && !ctx.Doer.IsAdmin {
|
} else if !isMember && !ctx.Doer.IsAdmin {
|
||||||
ctx.NotFound()
|
ctx.APIErrorNotFound()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -411,7 +411,7 @@ func GetTeamMembers(ctx *context.APIContext) {
|
||||||
TeamID: ctx.Org.Team.ID,
|
TeamID: ctx.Org.Team.ID,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetTeamMembers", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -456,10 +456,10 @@ func GetTeamMember(ctx *context.APIContext) {
|
||||||
teamID := ctx.PathParamInt64("teamid")
|
teamID := ctx.PathParamInt64("teamid")
|
||||||
isTeamMember, err := organization.IsUserInTeams(ctx, u.ID, []int64{teamID})
|
isTeamMember, err := organization.IsUserInTeams(ctx, u.ID, []int64{teamID})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "IsUserInTeams", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
} else if !isTeamMember {
|
} else if !isTeamMember {
|
||||||
ctx.NotFound()
|
ctx.APIErrorNotFound()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.JSON(http.StatusOK, convert.ToUser(ctx, u, ctx.Doer))
|
ctx.JSON(http.StatusOK, convert.ToUser(ctx, u, ctx.Doer))
|
||||||
|
@ -498,9 +498,9 @@ func AddTeamMember(ctx *context.APIContext) {
|
||||||
}
|
}
|
||||||
if err := org_service.AddTeamMember(ctx, ctx.Org.Team, u); err != nil {
|
if err := org_service.AddTeamMember(ctx, ctx.Org.Team, u); err != nil {
|
||||||
if errors.Is(err, user_model.ErrBlockedUser) {
|
if errors.Is(err, user_model.ErrBlockedUser) {
|
||||||
ctx.Error(http.StatusForbidden, "AddTeamMember", err)
|
ctx.APIError(http.StatusForbidden, err)
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "AddTeamMember", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -538,7 +538,7 @@ func RemoveTeamMember(ctx *context.APIContext) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := org_service.RemoveTeamMember(ctx, ctx.Org.Team, u); err != nil {
|
if err := org_service.RemoveTeamMember(ctx, ctx.Org.Team, u); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "RemoveTeamMember", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.Status(http.StatusNoContent)
|
ctx.Status(http.StatusNoContent)
|
||||||
|
@ -578,14 +578,14 @@ func GetTeamRepos(ctx *context.APIContext) {
|
||||||
TeamID: team.ID,
|
TeamID: team.ID,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetTeamRepositories", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
repos := make([]*api.Repository, len(teamRepos))
|
repos := make([]*api.Repository, len(teamRepos))
|
||||||
for i, repo := range teamRepos {
|
for i, repo := range teamRepos {
|
||||||
permission, err := access_model.GetUserRepoPermission(ctx, repo, ctx.Doer)
|
permission, err := access_model.GetUserRepoPermission(ctx, repo, ctx.Doer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetUserRepoPermission", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
repos[i] = convert.ToRepo(ctx, repo, permission)
|
repos[i] = convert.ToRepo(ctx, repo, permission)
|
||||||
|
@ -630,13 +630,13 @@ func GetTeamRepo(ctx *context.APIContext) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if !organization.HasTeamRepo(ctx, ctx.Org.Team.OrgID, ctx.Org.Team.ID, repo.ID) {
|
if !organization.HasTeamRepo(ctx, ctx.Org.Team.OrgID, ctx.Org.Team.ID, repo.ID) {
|
||||||
ctx.NotFound()
|
ctx.APIErrorNotFound()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
permission, err := access_model.GetUserRepoPermission(ctx, repo, ctx.Doer)
|
permission, err := access_model.GetUserRepoPermission(ctx, repo, ctx.Doer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetTeamRepos", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -648,9 +648,9 @@ func getRepositoryByParams(ctx *context.APIContext) *repo_model.Repository {
|
||||||
repo, err := repo_model.GetRepositoryByName(ctx, ctx.Org.Team.OrgID, ctx.PathParam("reponame"))
|
repo, err := repo_model.GetRepositoryByName(ctx, ctx.Org.Team.OrgID, ctx.PathParam("reponame"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if repo_model.IsErrRepoNotExist(err) {
|
if repo_model.IsErrRepoNotExist(err) {
|
||||||
ctx.NotFound()
|
ctx.APIErrorNotFound()
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetRepositoryByName", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -694,14 +694,14 @@ func AddTeamRepository(ctx *context.APIContext) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if access, err := access_model.AccessLevel(ctx, ctx.Doer, repo); err != nil {
|
if access, err := access_model.AccessLevel(ctx, ctx.Doer, repo); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "AccessLevel", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
} else if access < perm.AccessModeAdmin {
|
} else if access < perm.AccessModeAdmin {
|
||||||
ctx.Error(http.StatusForbidden, "", "Must have admin-level access to the repository")
|
ctx.APIError(http.StatusForbidden, "Must have admin-level access to the repository")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if err := repo_service.TeamAddRepository(ctx, ctx.Org.Team, repo); err != nil {
|
if err := repo_service.TeamAddRepository(ctx, ctx.Org.Team, repo); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "TeamAddRepository", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.Status(http.StatusNoContent)
|
ctx.Status(http.StatusNoContent)
|
||||||
|
@ -746,14 +746,14 @@ func RemoveTeamRepository(ctx *context.APIContext) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if access, err := access_model.AccessLevel(ctx, ctx.Doer, repo); err != nil {
|
if access, err := access_model.AccessLevel(ctx, ctx.Doer, repo); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "AccessLevel", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
} else if access < perm.AccessModeAdmin {
|
} else if access < perm.AccessModeAdmin {
|
||||||
ctx.Error(http.StatusForbidden, "", "Must have admin-level access to the repository")
|
ctx.APIError(http.StatusForbidden, "Must have admin-level access to the repository")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if err := repo_service.RemoveRepositoryFromTeam(ctx, ctx.Org.Team, repo.ID); err != nil {
|
if err := repo_service.RemoveRepositoryFromTeam(ctx, ctx.Org.Team, repo.ID); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "RemoveRepository", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.Status(http.StatusNoContent)
|
ctx.Status(http.StatusNoContent)
|
||||||
|
@ -829,7 +829,7 @@ func SearchTeam(ctx *context.APIContext) {
|
||||||
|
|
||||||
apiTeams, err := convert.ToTeams(ctx, teams, false)
|
apiTeams, err := convert.ToTeams(ctx, teams, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.InternalServerError(err)
|
ctx.APIErrorInternal(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -885,7 +885,7 @@ func ListTeamActivityFeeds(ctx *context.APIContext) {
|
||||||
|
|
||||||
feeds, count, err := feed_service.GetFeeds(ctx, opts)
|
feeds, count, err := feed_service.GetFeeds(ctx, opts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetFeeds", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.SetTotalCountHeader(count)
|
ctx.SetTotalCountHeader(count)
|
||||||
|
|
|
@ -67,13 +67,13 @@ func ListPackages(ctx *context.APIContext) {
|
||||||
Paginator: &listOptions,
|
Paginator: &listOptions,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "SearchVersions", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
pds, err := packages.GetPackageDescriptors(ctx, pvs)
|
pds, err := packages.GetPackageDescriptors(ctx, pvs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetPackageDescriptors", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -81,7 +81,7 @@ func ListPackages(ctx *context.APIContext) {
|
||||||
for _, pd := range pds {
|
for _, pd := range pds {
|
||||||
apiPackage, err := convert.ToPackage(ctx, pd, ctx.Doer)
|
apiPackage, err := convert.ToPackage(ctx, pd, ctx.Doer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "Error converting package for api", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
apiPackages = append(apiPackages, apiPackage)
|
apiPackages = append(apiPackages, apiPackage)
|
||||||
|
@ -128,7 +128,7 @@ func GetPackage(ctx *context.APIContext) {
|
||||||
|
|
||||||
apiPackage, err := convert.ToPackage(ctx, ctx.Package.Descriptor, ctx.Doer)
|
apiPackage, err := convert.ToPackage(ctx, ctx.Package.Descriptor, ctx.Doer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "Error converting package for api", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -169,7 +169,7 @@ func DeletePackage(ctx *context.APIContext) {
|
||||||
|
|
||||||
err := packages_service.RemovePackageVersion(ctx, ctx.Doer, ctx.Package.Descriptor.Version)
|
err := packages_service.RemovePackageVersion(ctx, ctx.Doer, ctx.Package.Descriptor.Version)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "RemovePackageVersion", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.Status(http.StatusNoContent)
|
ctx.Status(http.StatusNoContent)
|
||||||
|
@ -252,9 +252,9 @@ func LinkPackage(ctx *context.APIContext) {
|
||||||
pkg, err := packages.GetPackageByName(ctx, ctx.ContextUser.ID, packages.Type(ctx.PathParam("type")), ctx.PathParam("name"))
|
pkg, err := packages.GetPackageByName(ctx, ctx.ContextUser.ID, packages.Type(ctx.PathParam("type")), ctx.PathParam("name"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if errors.Is(err, util.ErrNotExist) {
|
if errors.Is(err, util.ErrNotExist) {
|
||||||
ctx.Error(http.StatusNotFound, "GetPackageByName", err)
|
ctx.APIError(http.StatusNotFound, err)
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetPackageByName", err)
|
ctx.APIErrorInternal(err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -262,9 +262,9 @@ func LinkPackage(ctx *context.APIContext) {
|
||||||
repo, err := repo_model.GetRepositoryByName(ctx, ctx.ContextUser.ID, ctx.PathParam("repo_name"))
|
repo, err := repo_model.GetRepositoryByName(ctx, ctx.ContextUser.ID, ctx.PathParam("repo_name"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if errors.Is(err, util.ErrNotExist) {
|
if errors.Is(err, util.ErrNotExist) {
|
||||||
ctx.Error(http.StatusNotFound, "GetRepositoryByName", err)
|
ctx.APIError(http.StatusNotFound, err)
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetRepositoryByName", err)
|
ctx.APIErrorInternal(err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -273,11 +273,11 @@ func LinkPackage(ctx *context.APIContext) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
switch {
|
switch {
|
||||||
case errors.Is(err, util.ErrInvalidArgument):
|
case errors.Is(err, util.ErrInvalidArgument):
|
||||||
ctx.Error(http.StatusBadRequest, "LinkToRepository", err)
|
ctx.APIError(http.StatusBadRequest, err)
|
||||||
case errors.Is(err, util.ErrPermissionDenied):
|
case errors.Is(err, util.ErrPermissionDenied):
|
||||||
ctx.Error(http.StatusForbidden, "LinkToRepository", err)
|
ctx.APIError(http.StatusForbidden, err)
|
||||||
default:
|
default:
|
||||||
ctx.Error(http.StatusInternalServerError, "LinkToRepository", err)
|
ctx.APIErrorInternal(err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -314,9 +314,9 @@ func UnlinkPackage(ctx *context.APIContext) {
|
||||||
pkg, err := packages.GetPackageByName(ctx, ctx.ContextUser.ID, packages.Type(ctx.PathParam("type")), ctx.PathParam("name"))
|
pkg, err := packages.GetPackageByName(ctx, ctx.ContextUser.ID, packages.Type(ctx.PathParam("type")), ctx.PathParam("name"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if errors.Is(err, util.ErrNotExist) {
|
if errors.Is(err, util.ErrNotExist) {
|
||||||
ctx.Error(http.StatusNotFound, "GetPackageByName", err)
|
ctx.APIError(http.StatusNotFound, err)
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetPackageByName", err)
|
ctx.APIErrorInternal(err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -325,11 +325,11 @@ func UnlinkPackage(ctx *context.APIContext) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
switch {
|
switch {
|
||||||
case errors.Is(err, util.ErrPermissionDenied):
|
case errors.Is(err, util.ErrPermissionDenied):
|
||||||
ctx.Error(http.StatusForbidden, "UnlinkFromRepository", err)
|
ctx.APIError(http.StatusForbidden, err)
|
||||||
case errors.Is(err, util.ErrInvalidArgument):
|
case errors.Is(err, util.ErrInvalidArgument):
|
||||||
ctx.Error(http.StatusBadRequest, "UnlinkFromRepository", err)
|
ctx.APIError(http.StatusBadRequest, err)
|
||||||
default:
|
default:
|
||||||
ctx.Error(http.StatusInternalServerError, "UnlinkFromRepository", err)
|
ctx.APIErrorInternal(err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -77,7 +77,7 @@ func (Action) ListActionsSecrets(ctx *context.APIContext) {
|
||||||
|
|
||||||
secrets, count, err := db.FindAndCount[secret_model.Secret](ctx, opts)
|
secrets, count, err := db.FindAndCount[secret_model.Secret](ctx, opts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.InternalServerError(err)
|
ctx.APIErrorInternal(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -139,11 +139,11 @@ func (Action) CreateOrUpdateSecret(ctx *context.APIContext) {
|
||||||
_, created, err := secret_service.CreateOrUpdateSecret(ctx, 0, repo.ID, ctx.PathParam("secretname"), opt.Data)
|
_, created, err := secret_service.CreateOrUpdateSecret(ctx, 0, repo.ID, ctx.PathParam("secretname"), opt.Data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if errors.Is(err, util.ErrInvalidArgument) {
|
if errors.Is(err, util.ErrInvalidArgument) {
|
||||||
ctx.Error(http.StatusBadRequest, "CreateOrUpdateSecret", err)
|
ctx.APIError(http.StatusBadRequest, err)
|
||||||
} else if errors.Is(err, util.ErrNotExist) {
|
} else if errors.Is(err, util.ErrNotExist) {
|
||||||
ctx.Error(http.StatusNotFound, "CreateOrUpdateSecret", err)
|
ctx.APIError(http.StatusNotFound, err)
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "CreateOrUpdateSecret", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -193,11 +193,11 @@ func (Action) DeleteSecret(ctx *context.APIContext) {
|
||||||
err := secret_service.DeleteSecretByName(ctx, 0, repo.ID, ctx.PathParam("secretname"))
|
err := secret_service.DeleteSecretByName(ctx, 0, repo.ID, ctx.PathParam("secretname"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if errors.Is(err, util.ErrInvalidArgument) {
|
if errors.Is(err, util.ErrInvalidArgument) {
|
||||||
ctx.Error(http.StatusBadRequest, "DeleteSecret", err)
|
ctx.APIError(http.StatusBadRequest, err)
|
||||||
} else if errors.Is(err, util.ErrNotExist) {
|
} else if errors.Is(err, util.ErrNotExist) {
|
||||||
ctx.Error(http.StatusNotFound, "DeleteSecret", err)
|
ctx.APIError(http.StatusNotFound, err)
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "DeleteSecret", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -241,9 +241,9 @@ func (Action) GetVariable(ctx *context.APIContext) {
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if errors.Is(err, util.ErrNotExist) {
|
if errors.Is(err, util.ErrNotExist) {
|
||||||
ctx.Error(http.StatusNotFound, "GetVariable", err)
|
ctx.APIError(http.StatusNotFound, err)
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetVariable", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -295,11 +295,11 @@ func (Action) DeleteVariable(ctx *context.APIContext) {
|
||||||
|
|
||||||
if err := actions_service.DeleteVariableByName(ctx, 0, ctx.Repo.Repository.ID, ctx.PathParam("variablename")); err != nil {
|
if err := actions_service.DeleteVariableByName(ctx, 0, ctx.Repo.Repository.ID, ctx.PathParam("variablename")); err != nil {
|
||||||
if errors.Is(err, util.ErrInvalidArgument) {
|
if errors.Is(err, util.ErrInvalidArgument) {
|
||||||
ctx.Error(http.StatusBadRequest, "DeleteVariableByName", err)
|
ctx.APIError(http.StatusBadRequest, err)
|
||||||
} else if errors.Is(err, util.ErrNotExist) {
|
} else if errors.Is(err, util.ErrNotExist) {
|
||||||
ctx.Error(http.StatusNotFound, "DeleteVariableByName", err)
|
ctx.APIError(http.StatusNotFound, err)
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "DeleteVariableByName", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -354,19 +354,19 @@ func (Action) CreateVariable(ctx *context.APIContext) {
|
||||||
Name: variableName,
|
Name: variableName,
|
||||||
})
|
})
|
||||||
if err != nil && !errors.Is(err, util.ErrNotExist) {
|
if err != nil && !errors.Is(err, util.ErrNotExist) {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetVariable", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if v != nil && v.ID > 0 {
|
if v != nil && v.ID > 0 {
|
||||||
ctx.Error(http.StatusConflict, "VariableNameAlreadyExists", util.NewAlreadyExistErrorf("variable name %s already exists", variableName))
|
ctx.APIError(http.StatusConflict, util.NewAlreadyExistErrorf("variable name %s already exists", variableName))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := actions_service.CreateVariable(ctx, 0, repoID, variableName, opt.Value); err != nil {
|
if _, err := actions_service.CreateVariable(ctx, 0, repoID, variableName, opt.Value); err != nil {
|
||||||
if errors.Is(err, util.ErrInvalidArgument) {
|
if errors.Is(err, util.ErrInvalidArgument) {
|
||||||
ctx.Error(http.StatusBadRequest, "CreateVariable", err)
|
ctx.APIError(http.StatusBadRequest, err)
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "CreateVariable", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -419,9 +419,9 @@ func (Action) UpdateVariable(ctx *context.APIContext) {
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if errors.Is(err, util.ErrNotExist) {
|
if errors.Is(err, util.ErrNotExist) {
|
||||||
ctx.Error(http.StatusNotFound, "GetVariable", err)
|
ctx.APIError(http.StatusNotFound, err)
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetVariable", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -435,9 +435,9 @@ func (Action) UpdateVariable(ctx *context.APIContext) {
|
||||||
|
|
||||||
if _, err := actions_service.UpdateVariableNameData(ctx, v); err != nil {
|
if _, err := actions_service.UpdateVariableNameData(ctx, v); err != nil {
|
||||||
if errors.Is(err, util.ErrInvalidArgument) {
|
if errors.Is(err, util.ErrInvalidArgument) {
|
||||||
ctx.Error(http.StatusBadRequest, "UpdateVariable", err)
|
ctx.APIError(http.StatusBadRequest, err)
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "UpdateVariable", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -484,7 +484,7 @@ func (Action) ListVariables(ctx *context.APIContext) {
|
||||||
ListOptions: utils.GetListOptions(ctx),
|
ListOptions: utils.GetListOptions(ctx),
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "FindVariables", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -581,7 +581,7 @@ func ListActionTasks(ctx *context.APIContext) {
|
||||||
RepoID: ctx.Repo.Repository.ID,
|
RepoID: ctx.Repo.Repository.ID,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "ListActionTasks", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -592,7 +592,7 @@ func ListActionTasks(ctx *context.APIContext) {
|
||||||
for i := range tasks {
|
for i := range tasks {
|
||||||
convertedTask, err := convert.ToActionTask(ctx, tasks[i])
|
convertedTask, err := convert.ToActionTask(ctx, tasks[i])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "ToActionTask", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
res.Entries[i] = convertedTask
|
res.Entries[i] = convertedTask
|
||||||
|
@ -634,7 +634,7 @@ func ActionsListRepositoryWorkflows(ctx *context.APIContext) {
|
||||||
|
|
||||||
workflows, err := actions_service.ListActionWorkflows(ctx)
|
workflows, err := actions_service.ListActionWorkflows(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "ListActionWorkflows", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -681,9 +681,9 @@ func ActionsGetWorkflow(ctx *context.APIContext) {
|
||||||
workflow, err := actions_service.GetActionWorkflow(ctx, workflowID)
|
workflow, err := actions_service.GetActionWorkflow(ctx, workflowID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if errors.Is(err, util.ErrNotExist) {
|
if errors.Is(err, util.ErrNotExist) {
|
||||||
ctx.Error(http.StatusNotFound, "GetActionWorkflow", err)
|
ctx.APIError(http.StatusNotFound, err)
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetActionWorkflow", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -729,9 +729,9 @@ func ActionsDisableWorkflow(ctx *context.APIContext) {
|
||||||
err := actions_service.EnableOrDisableWorkflow(ctx, workflowID, false)
|
err := actions_service.EnableOrDisableWorkflow(ctx, workflowID, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if errors.Is(err, util.ErrNotExist) {
|
if errors.Is(err, util.ErrNotExist) {
|
||||||
ctx.Error(http.StatusNotFound, "DisableActionWorkflow", err)
|
ctx.APIError(http.StatusNotFound, err)
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "DisableActionWorkflow", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -780,7 +780,7 @@ func ActionsDispatchWorkflow(ctx *context.APIContext) {
|
||||||
workflowID := ctx.PathParam("workflow_id")
|
workflowID := ctx.PathParam("workflow_id")
|
||||||
opt := web.GetForm(ctx).(*api.CreateActionWorkflowDispatch)
|
opt := web.GetForm(ctx).(*api.CreateActionWorkflowDispatch)
|
||||||
if opt.Ref == "" {
|
if opt.Ref == "" {
|
||||||
ctx.Error(http.StatusUnprocessableEntity, "MissingWorkflowParameter", util.NewInvalidArgumentErrorf("ref is required parameter"))
|
ctx.APIError(http.StatusUnprocessableEntity, util.NewInvalidArgumentErrorf("ref is required parameter"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -806,11 +806,11 @@ func ActionsDispatchWorkflow(ctx *context.APIContext) {
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if errors.Is(err, util.ErrNotExist) {
|
if errors.Is(err, util.ErrNotExist) {
|
||||||
ctx.Error(http.StatusNotFound, "DispatchActionWorkflow", err)
|
ctx.APIError(http.StatusNotFound, err)
|
||||||
} else if errors.Is(err, util.ErrPermissionDenied) {
|
} else if errors.Is(err, util.ErrPermissionDenied) {
|
||||||
ctx.Error(http.StatusForbidden, "DispatchActionWorkflow", err)
|
ctx.APIError(http.StatusForbidden, err)
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "DispatchActionWorkflow", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -858,9 +858,9 @@ func ActionsEnableWorkflow(ctx *context.APIContext) {
|
||||||
err := actions_service.EnableOrDisableWorkflow(ctx, workflowID, true)
|
err := actions_service.EnableOrDisableWorkflow(ctx, workflowID, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if errors.Is(err, util.ErrNotExist) {
|
if errors.Is(err, util.ErrNotExist) {
|
||||||
ctx.Error(http.StatusNotFound, "EnableActionWorkflow", err)
|
ctx.APIError(http.StatusNotFound, err)
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "EnableActionWorkflow", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -917,7 +917,7 @@ func GetArtifactsOfRun(ctx *context.APIContext) {
|
||||||
ListOptions: utils.GetListOptions(ctx),
|
ListOptions: utils.GetListOptions(ctx),
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, err.Error(), err)
|
ctx.APIErrorInternal(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -928,7 +928,7 @@ func GetArtifactsOfRun(ctx *context.APIContext) {
|
||||||
for i := range artifacts {
|
for i := range artifacts {
|
||||||
convertedArtifact, err := convert.ToActionArtifact(ctx.Repo.Repository, artifacts[i])
|
convertedArtifact, err := convert.ToActionArtifact(ctx.Repo.Repository, artifacts[i])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "ToActionArtifact", err)
|
ctx.APIErrorInternal(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
res.Entries[i] = convertedArtifact
|
res.Entries[i] = convertedArtifact
|
||||||
|
@ -978,7 +978,7 @@ func GetArtifacts(ctx *context.APIContext) {
|
||||||
ListOptions: utils.GetListOptions(ctx),
|
ListOptions: utils.GetListOptions(ctx),
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, err.Error(), err)
|
ctx.APIErrorInternal(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -989,7 +989,7 @@ func GetArtifacts(ctx *context.APIContext) {
|
||||||
for i := range artifacts {
|
for i := range artifacts {
|
||||||
convertedArtifact, err := convert.ToActionArtifact(ctx.Repo.Repository, artifacts[i])
|
convertedArtifact, err := convert.ToActionArtifact(ctx.Repo.Repository, artifacts[i])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "ToActionArtifact", err)
|
ctx.APIErrorInternal(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
res.Entries[i] = convertedArtifact
|
res.Entries[i] = convertedArtifact
|
||||||
|
@ -1037,14 +1037,14 @@ func GetArtifact(ctx *context.APIContext) {
|
||||||
if actions.IsArtifactV4(art) {
|
if actions.IsArtifactV4(art) {
|
||||||
convertedArtifact, err := convert.ToActionArtifact(ctx.Repo.Repository, art)
|
convertedArtifact, err := convert.ToActionArtifact(ctx.Repo.Repository, art)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "ToActionArtifact", err)
|
ctx.APIErrorInternal(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.JSON(http.StatusOK, convertedArtifact)
|
ctx.JSON(http.StatusOK, convertedArtifact)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// v3 not supported due to not having one unique id
|
// v3 not supported due to not having one unique id
|
||||||
ctx.Error(http.StatusNotFound, "GetArtifact", "Artifact not found")
|
ctx.APIError(http.StatusNotFound, "Artifact not found")
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeleteArtifact Deletes a specific artifact for a workflow run.
|
// DeleteArtifact Deletes a specific artifact for a workflow run.
|
||||||
|
@ -1085,14 +1085,14 @@ func DeleteArtifact(ctx *context.APIContext) {
|
||||||
|
|
||||||
if actions.IsArtifactV4(art) {
|
if actions.IsArtifactV4(art) {
|
||||||
if err := actions_model.SetArtifactNeedDelete(ctx, art.RunID, art.ArtifactName); err != nil {
|
if err := actions_model.SetArtifactNeedDelete(ctx, art.RunID, art.ArtifactName); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "DeleteArtifact", err)
|
ctx.APIErrorInternal(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.Status(http.StatusNoContent)
|
ctx.Status(http.StatusNoContent)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// v3 not supported due to not having one unique id
|
// v3 not supported due to not having one unique id
|
||||||
ctx.Error(http.StatusNotFound, "DeleteArtifact", "Artifact not found")
|
ctx.APIError(http.StatusNotFound, "Artifact not found")
|
||||||
}
|
}
|
||||||
|
|
||||||
func buildSignature(endp string, expires, artifactID int64) []byte {
|
func buildSignature(endp string, expires, artifactID int64) []byte {
|
||||||
|
@ -1152,7 +1152,7 @@ func DownloadArtifact(ctx *context.APIContext) {
|
||||||
|
|
||||||
// if artifacts status is not uploaded-confirmed, treat it as not found
|
// if artifacts status is not uploaded-confirmed, treat it as not found
|
||||||
if art.Status == actions_model.ArtifactStatusExpired {
|
if art.Status == actions_model.ArtifactStatusExpired {
|
||||||
ctx.Error(http.StatusNotFound, "DownloadArtifact", "Artifact has expired")
|
ctx.APIError(http.StatusNotFound, "Artifact has expired")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.Resp.Header().Set("Content-Disposition", fmt.Sprintf("attachment; filename=%s.zip; filename*=UTF-8''%s.zip", url.PathEscape(art.ArtifactName), art.ArtifactName))
|
ctx.Resp.Header().Set("Content-Disposition", fmt.Sprintf("attachment; filename=%s.zip; filename*=UTF-8''%s.zip", url.PathEscape(art.ArtifactName), art.ArtifactName))
|
||||||
|
@ -1163,7 +1163,7 @@ func DownloadArtifact(ctx *context.APIContext) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "DownloadArtifactV4ServeDirectOnly", err)
|
ctx.APIErrorInternal(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1172,7 +1172,7 @@ func DownloadArtifact(ctx *context.APIContext) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// v3 not supported due to not having one unique id
|
// v3 not supported due to not having one unique id
|
||||||
ctx.Error(http.StatusNotFound, "DownloadArtifact", "Artifact not found")
|
ctx.APIError(http.StatusNotFound, "Artifact not found")
|
||||||
}
|
}
|
||||||
|
|
||||||
// DownloadArtifactRaw Downloads a specific artifact for a workflow run directly.
|
// DownloadArtifactRaw Downloads a specific artifact for a workflow run directly.
|
||||||
|
@ -1181,9 +1181,9 @@ func DownloadArtifactRaw(ctx *context.APIContext) {
|
||||||
repo, err := repo_model.GetRepositoryByOwnerAndName(ctx, ctx.PathParam("username"), ctx.PathParam("reponame"))
|
repo, err := repo_model.GetRepositoryByOwnerAndName(ctx, ctx.PathParam("username"), ctx.PathParam("reponame"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if errors.Is(err, util.ErrNotExist) {
|
if errors.Is(err, util.ErrNotExist) {
|
||||||
ctx.NotFound()
|
ctx.APIErrorNotFound()
|
||||||
} else {
|
} else {
|
||||||
ctx.InternalServerError(err)
|
ctx.APIErrorInternal(err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -1199,18 +1199,18 @@ func DownloadArtifactRaw(ctx *context.APIContext) {
|
||||||
|
|
||||||
expectedSig := buildSignature(buildDownloadRawEndpoint(repo, art.ID), expires, art.ID)
|
expectedSig := buildSignature(buildDownloadRawEndpoint(repo, art.ID), expires, art.ID)
|
||||||
if !hmac.Equal(sigBytes, expectedSig) {
|
if !hmac.Equal(sigBytes, expectedSig) {
|
||||||
ctx.Error(http.StatusUnauthorized, "DownloadArtifactRaw", "Error unauthorized")
|
ctx.APIError(http.StatusUnauthorized, "Error unauthorized")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
t := time.Unix(expires, 0)
|
t := time.Unix(expires, 0)
|
||||||
if t.Before(time.Now()) {
|
if t.Before(time.Now()) {
|
||||||
ctx.Error(http.StatusUnauthorized, "DownloadArtifactRaw", "Error link expired")
|
ctx.APIError(http.StatusUnauthorized, "Error link expired")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// if artifacts status is not uploaded-confirmed, treat it as not found
|
// if artifacts status is not uploaded-confirmed, treat it as not found
|
||||||
if art.Status == actions_model.ArtifactStatusExpired {
|
if art.Status == actions_model.ArtifactStatusExpired {
|
||||||
ctx.Error(http.StatusNotFound, "DownloadArtifactRaw", "Artifact has expired")
|
ctx.APIError(http.StatusNotFound, "Artifact has expired")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.Resp.Header().Set("Content-Disposition", fmt.Sprintf("attachment; filename=%s.zip; filename*=UTF-8''%s.zip", url.PathEscape(art.ArtifactName), art.ArtifactName))
|
ctx.Resp.Header().Set("Content-Disposition", fmt.Sprintf("attachment; filename=%s.zip; filename*=UTF-8''%s.zip", url.PathEscape(art.ArtifactName), art.ArtifactName))
|
||||||
|
@ -1218,13 +1218,13 @@ func DownloadArtifactRaw(ctx *context.APIContext) {
|
||||||
if actions.IsArtifactV4(art) {
|
if actions.IsArtifactV4(art) {
|
||||||
err := actions.DownloadArtifactV4(ctx.Base, art)
|
err := actions.DownloadArtifactV4(ctx.Base, art)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "DownloadArtifactV4", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// v3 not supported due to not having one unique id
|
// v3 not supported due to not having one unique id
|
||||||
ctx.Error(http.StatusNotFound, "DownloadArtifactRaw", "artifact not found")
|
ctx.APIError(http.StatusNotFound, "artifact not found")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try to get the artifact by ID and check access
|
// Try to get the artifact by ID and check access
|
||||||
|
@ -1233,7 +1233,7 @@ func getArtifactByPathParam(ctx *context.APIContext, repo *repo_model.Repository
|
||||||
|
|
||||||
art, ok, err := db.GetByID[actions_model.ActionArtifact](ctx, artifactID)
|
art, ok, err := db.GetByID[actions_model.ActionArtifact](ctx, artifactID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "getArtifactByPathParam", err)
|
ctx.APIErrorInternal(err)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
// if artifacts status is not uploaded-confirmed, treat it as not found
|
// if artifacts status is not uploaded-confirmed, treat it as not found
|
||||||
|
@ -1241,7 +1241,7 @@ func getArtifactByPathParam(ctx *context.APIContext, repo *repo_model.Repository
|
||||||
if !ok ||
|
if !ok ||
|
||||||
art.RepoID != repo.ID ||
|
art.RepoID != repo.ID ||
|
||||||
art.Status != actions_model.ArtifactStatusUploadConfirmed && art.Status != actions_model.ArtifactStatusExpired {
|
art.Status != actions_model.ArtifactStatusUploadConfirmed && art.Status != actions_model.ArtifactStatusExpired {
|
||||||
ctx.Error(http.StatusNotFound, "getArtifactByPathParam", "artifact not found")
|
ctx.APIError(http.StatusNotFound, "artifact not found")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return art
|
return art
|
||||||
|
|
|
@ -44,13 +44,13 @@ func UpdateAvatar(ctx *context.APIContext) {
|
||||||
|
|
||||||
content, err := base64.StdEncoding.DecodeString(form.Image)
|
content, err := base64.StdEncoding.DecodeString(form.Image)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusBadRequest, "DecodeImage", err)
|
ctx.APIError(http.StatusBadRequest, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
err = repo_service.UploadAvatar(ctx, ctx.Repo.Repository, content)
|
err = repo_service.UploadAvatar(ctx, ctx.Repo.Repository, content)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "UploadAvatar", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.Status(http.StatusNoContent)
|
ctx.Status(http.StatusNoContent)
|
||||||
|
@ -81,7 +81,7 @@ func DeleteAvatar(ctx *context.APIContext) {
|
||||||
// "$ref": "#/responses/notFound"
|
// "$ref": "#/responses/notFound"
|
||||||
err := repo_service.DeleteAvatar(ctx, ctx.Repo.Repository)
|
err := repo_service.DeleteAvatar(ctx, ctx.Repo.Repository)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "DeleteAvatar", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.Status(http.StatusNoContent)
|
ctx.Status(http.StatusNoContent)
|
||||||
|
|
|
@ -43,12 +43,12 @@ func GetBlob(ctx *context.APIContext) {
|
||||||
|
|
||||||
sha := ctx.PathParam("sha")
|
sha := ctx.PathParam("sha")
|
||||||
if len(sha) == 0 {
|
if len(sha) == 0 {
|
||||||
ctx.Error(http.StatusBadRequest, "", "sha not provided")
|
ctx.APIError(http.StatusBadRequest, "sha not provided")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if blob, err := files_service.GetBlobBySHA(ctx, ctx.Repo.Repository, ctx.Repo.GitRepo, sha); err != nil {
|
if blob, err := files_service.GetBlobBySHA(ctx, ctx.Repo.Repository, ctx.Repo.GitRepo, sha); err != nil {
|
||||||
ctx.Error(http.StatusBadRequest, "", err)
|
ctx.APIError(http.StatusBadRequest, err)
|
||||||
} else {
|
} else {
|
||||||
ctx.JSON(http.StatusOK, blob)
|
ctx.JSON(http.StatusOK, blob)
|
||||||
}
|
}
|
||||||
|
|
|
@ -63,28 +63,28 @@ func GetBranch(ctx *context.APIContext) {
|
||||||
branch, err := ctx.Repo.GitRepo.GetBranch(branchName)
|
branch, err := ctx.Repo.GitRepo.GetBranch(branchName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if git.IsErrBranchNotExist(err) {
|
if git.IsErrBranchNotExist(err) {
|
||||||
ctx.NotFound(err)
|
ctx.APIErrorNotFound(err)
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetBranch", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
c, err := branch.GetCommit()
|
c, err := branch.GetCommit()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetCommit", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
branchProtection, err := git_model.GetFirstMatchProtectedBranchRule(ctx, ctx.Repo.Repository.ID, branchName)
|
branchProtection, err := git_model.GetFirstMatchProtectedBranchRule(ctx, ctx.Repo.Repository.ID, branchName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetBranchProtection", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
br, err := convert.ToBranch(ctx, ctx.Repo.Repository, branch.Name, c, branchProtection, ctx.Doer, ctx.Repo.IsAdmin())
|
br, err := convert.ToBranch(ctx, ctx.Repo.Repository, branch.Name, c, branchProtection, ctx.Doer, ctx.Repo.IsAdmin())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "convert.ToBranch", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -124,12 +124,12 @@ func DeleteBranch(ctx *context.APIContext) {
|
||||||
// "423":
|
// "423":
|
||||||
// "$ref": "#/responses/repoArchivedError"
|
// "$ref": "#/responses/repoArchivedError"
|
||||||
if ctx.Repo.Repository.IsEmpty {
|
if ctx.Repo.Repository.IsEmpty {
|
||||||
ctx.Error(http.StatusNotFound, "", "Git Repository is empty.")
|
ctx.APIError(http.StatusNotFound, "Git Repository is empty.")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if ctx.Repo.Repository.IsMirror {
|
if ctx.Repo.Repository.IsMirror {
|
||||||
ctx.Error(http.StatusForbidden, "", "Git Repository is a mirror.")
|
ctx.APIError(http.StatusForbidden, "Git Repository is a mirror.")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -141,13 +141,13 @@ func DeleteBranch(ctx *context.APIContext) {
|
||||||
IsDeletedBranch: optional.Some(false),
|
IsDeletedBranch: optional.Some(false),
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "CountBranches", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if totalNumOfBranches == 0 { // sync branches immediately because non-empty repository should have at least 1 branch
|
if totalNumOfBranches == 0 { // sync branches immediately because non-empty repository should have at least 1 branch
|
||||||
_, err = repo_module.SyncRepoBranches(ctx, ctx.Repo.Repository.ID, 0)
|
_, err = repo_module.SyncRepoBranches(ctx, ctx.Repo.Repository.ID, 0)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.ServerError("SyncRepoBranches", err)
|
ctx.APIErrorInternal(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -155,13 +155,13 @@ func DeleteBranch(ctx *context.APIContext) {
|
||||||
if err := repo_service.DeleteBranch(ctx, ctx.Doer, ctx.Repo.Repository, ctx.Repo.GitRepo, branchName, nil); err != nil {
|
if err := repo_service.DeleteBranch(ctx, ctx.Doer, ctx.Repo.Repository, ctx.Repo.GitRepo, branchName, nil); err != nil {
|
||||||
switch {
|
switch {
|
||||||
case git.IsErrBranchNotExist(err):
|
case git.IsErrBranchNotExist(err):
|
||||||
ctx.NotFound(err)
|
ctx.APIErrorNotFound(err)
|
||||||
case errors.Is(err, repo_service.ErrBranchIsDefault):
|
case errors.Is(err, repo_service.ErrBranchIsDefault):
|
||||||
ctx.Error(http.StatusForbidden, "DefaultBranch", fmt.Errorf("can not delete default branch"))
|
ctx.APIError(http.StatusForbidden, fmt.Errorf("can not delete default branch"))
|
||||||
case errors.Is(err, git_model.ErrBranchIsProtected):
|
case errors.Is(err, git_model.ErrBranchIsProtected):
|
||||||
ctx.Error(http.StatusForbidden, "IsProtectedBranch", fmt.Errorf("branch protected"))
|
ctx.APIError(http.StatusForbidden, fmt.Errorf("branch protected"))
|
||||||
default:
|
default:
|
||||||
ctx.Error(http.StatusInternalServerError, "DeleteBranch", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -206,12 +206,12 @@ func CreateBranch(ctx *context.APIContext) {
|
||||||
// "$ref": "#/responses/repoArchivedError"
|
// "$ref": "#/responses/repoArchivedError"
|
||||||
|
|
||||||
if ctx.Repo.Repository.IsEmpty {
|
if ctx.Repo.Repository.IsEmpty {
|
||||||
ctx.Error(http.StatusNotFound, "", "Git Repository is empty.")
|
ctx.APIError(http.StatusNotFound, "Git Repository is empty.")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if ctx.Repo.Repository.IsMirror {
|
if ctx.Repo.Repository.IsMirror {
|
||||||
ctx.Error(http.StatusForbidden, "", "Git Repository is a mirror.")
|
ctx.APIError(http.StatusForbidden, "Git Repository is a mirror.")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -223,24 +223,24 @@ func CreateBranch(ctx *context.APIContext) {
|
||||||
if len(opt.OldRefName) > 0 {
|
if len(opt.OldRefName) > 0 {
|
||||||
oldCommit, err = ctx.Repo.GitRepo.GetCommit(opt.OldRefName)
|
oldCommit, err = ctx.Repo.GitRepo.GetCommit(opt.OldRefName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetCommit", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
} else if len(opt.OldBranchName) > 0 { //nolint
|
} else if len(opt.OldBranchName) > 0 { //nolint
|
||||||
if ctx.Repo.GitRepo.IsBranchExist(opt.OldBranchName) { //nolint
|
if ctx.Repo.GitRepo.IsBranchExist(opt.OldBranchName) { //nolint
|
||||||
oldCommit, err = ctx.Repo.GitRepo.GetBranchCommit(opt.OldBranchName) //nolint
|
oldCommit, err = ctx.Repo.GitRepo.GetBranchCommit(opt.OldBranchName) //nolint
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetBranchCommit", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusNotFound, "", "The old branch does not exist")
|
ctx.APIError(http.StatusNotFound, "The old branch does not exist")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
oldCommit, err = ctx.Repo.GitRepo.GetBranchCommit(ctx.Repo.Repository.DefaultBranch)
|
oldCommit, err = ctx.Repo.GitRepo.GetBranchCommit(ctx.Repo.Repository.DefaultBranch)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetBranchCommit", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -248,40 +248,40 @@ func CreateBranch(ctx *context.APIContext) {
|
||||||
err = repo_service.CreateNewBranchFromCommit(ctx, ctx.Doer, ctx.Repo.Repository, ctx.Repo.GitRepo, oldCommit.ID.String(), opt.BranchName)
|
err = repo_service.CreateNewBranchFromCommit(ctx, ctx.Doer, ctx.Repo.Repository, ctx.Repo.GitRepo, oldCommit.ID.String(), opt.BranchName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if git_model.IsErrBranchNotExist(err) {
|
if git_model.IsErrBranchNotExist(err) {
|
||||||
ctx.Error(http.StatusNotFound, "", "The old branch does not exist")
|
ctx.APIError(http.StatusNotFound, "The old branch does not exist")
|
||||||
} else if release_service.IsErrTagAlreadyExists(err) {
|
} else if release_service.IsErrTagAlreadyExists(err) {
|
||||||
ctx.Error(http.StatusConflict, "", "The branch with the same tag already exists.")
|
ctx.APIError(http.StatusConflict, "The branch with the same tag already exists.")
|
||||||
} else if git_model.IsErrBranchAlreadyExists(err) || git.IsErrPushOutOfDate(err) {
|
} else if git_model.IsErrBranchAlreadyExists(err) || git.IsErrPushOutOfDate(err) {
|
||||||
ctx.Error(http.StatusConflict, "", "The branch already exists.")
|
ctx.APIError(http.StatusConflict, "The branch already exists.")
|
||||||
} else if git_model.IsErrBranchNameConflict(err) {
|
} else if git_model.IsErrBranchNameConflict(err) {
|
||||||
ctx.Error(http.StatusConflict, "", "The branch with the same name already exists.")
|
ctx.APIError(http.StatusConflict, "The branch with the same name already exists.")
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "CreateNewBranchFromCommit", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
branch, err := ctx.Repo.GitRepo.GetBranch(opt.BranchName)
|
branch, err := ctx.Repo.GitRepo.GetBranch(opt.BranchName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetBranch", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
commit, err := branch.GetCommit()
|
commit, err := branch.GetCommit()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetCommit", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
branchProtection, err := git_model.GetFirstMatchProtectedBranchRule(ctx, ctx.Repo.Repository.ID, branch.Name)
|
branchProtection, err := git_model.GetFirstMatchProtectedBranchRule(ctx, ctx.Repo.Repository.ID, branch.Name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetBranchProtection", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
br, err := convert.ToBranch(ctx, ctx.Repo.Repository, branch.Name, commit, branchProtection, ctx.Doer, ctx.Repo.IsAdmin())
|
br, err := convert.ToBranch(ctx, ctx.Repo.Repository, branch.Name, commit, branchProtection, ctx.Doer, ctx.Repo.IsAdmin())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "convert.ToBranch", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -325,7 +325,7 @@ func ListBranches(ctx *context.APIContext) {
|
||||||
|
|
||||||
if !ctx.Repo.Repository.IsEmpty {
|
if !ctx.Repo.Repository.IsEmpty {
|
||||||
if ctx.Repo.GitRepo == nil {
|
if ctx.Repo.GitRepo == nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "Load git repository failed", nil)
|
ctx.APIError(http.StatusInternalServerError, nil)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -337,26 +337,26 @@ func ListBranches(ctx *context.APIContext) {
|
||||||
var err error
|
var err error
|
||||||
totalNumOfBranches, err = db.Count[git_model.Branch](ctx, branchOpts)
|
totalNumOfBranches, err = db.Count[git_model.Branch](ctx, branchOpts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "CountBranches", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if totalNumOfBranches == 0 { // sync branches immediately because non-empty repository should have at least 1 branch
|
if totalNumOfBranches == 0 { // sync branches immediately because non-empty repository should have at least 1 branch
|
||||||
totalNumOfBranches, err = repo_module.SyncRepoBranches(ctx, ctx.Repo.Repository.ID, 0)
|
totalNumOfBranches, err = repo_module.SyncRepoBranches(ctx, ctx.Repo.Repository.ID, 0)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.ServerError("SyncRepoBranches", err)
|
ctx.APIErrorInternal(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
rules, err := git_model.FindRepoProtectedBranchRules(ctx, ctx.Repo.Repository.ID)
|
rules, err := git_model.FindRepoProtectedBranchRules(ctx, ctx.Repo.Repository.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "FindMatchedProtectedBranchRules", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
branches, err := db.Find[git_model.Branch](ctx, branchOpts)
|
branches, err := db.Find[git_model.Branch](ctx, branchOpts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetBranches", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -369,14 +369,14 @@ func ListBranches(ctx *context.APIContext) {
|
||||||
totalNumOfBranches--
|
totalNumOfBranches--
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
ctx.Error(http.StatusInternalServerError, "GetCommit", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
branchProtection := rules.GetFirstMatched(branches[i].Name)
|
branchProtection := rules.GetFirstMatched(branches[i].Name)
|
||||||
apiBranch, err := convert.ToBranch(ctx, ctx.Repo.Repository, branches[i].Name, c, branchProtection, ctx.Doer, ctx.Repo.IsAdmin())
|
apiBranch, err := convert.ToBranch(ctx, ctx.Repo.Repository, branches[i].Name, c, branchProtection, ctx.Doer, ctx.Repo.IsAdmin())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "convert.ToBranch", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
apiBranches = append(apiBranches, apiBranch)
|
apiBranches = append(apiBranches, apiBranch)
|
||||||
|
@ -433,12 +433,12 @@ func UpdateBranch(ctx *context.APIContext) {
|
||||||
repo := ctx.Repo.Repository
|
repo := ctx.Repo.Repository
|
||||||
|
|
||||||
if repo.IsEmpty {
|
if repo.IsEmpty {
|
||||||
ctx.Error(http.StatusNotFound, "", "Git Repository is empty.")
|
ctx.APIError(http.StatusNotFound, "Git Repository is empty.")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if repo.IsMirror {
|
if repo.IsMirror {
|
||||||
ctx.Error(http.StatusForbidden, "", "Git Repository is a mirror.")
|
ctx.APIError(http.StatusForbidden, "Git Repository is a mirror.")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -446,20 +446,20 @@ func UpdateBranch(ctx *context.APIContext) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
switch {
|
switch {
|
||||||
case repo_model.IsErrUserDoesNotHaveAccessToRepo(err):
|
case repo_model.IsErrUserDoesNotHaveAccessToRepo(err):
|
||||||
ctx.Error(http.StatusForbidden, "", "User must be a repo or site admin to rename default or protected branches.")
|
ctx.APIError(http.StatusForbidden, "User must be a repo or site admin to rename default or protected branches.")
|
||||||
case errors.Is(err, git_model.ErrBranchIsProtected):
|
case errors.Is(err, git_model.ErrBranchIsProtected):
|
||||||
ctx.Error(http.StatusForbidden, "", "Branch is protected by glob-based protection rules.")
|
ctx.APIError(http.StatusForbidden, "Branch is protected by glob-based protection rules.")
|
||||||
default:
|
default:
|
||||||
ctx.Error(http.StatusInternalServerError, "RenameBranch", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if msg == "target_exist" {
|
if msg == "target_exist" {
|
||||||
ctx.Error(http.StatusUnprocessableEntity, "", "Cannot rename a branch using the same name or rename to a branch that already exists.")
|
ctx.APIError(http.StatusUnprocessableEntity, "Cannot rename a branch using the same name or rename to a branch that already exists.")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if msg == "from_not_exist" {
|
if msg == "from_not_exist" {
|
||||||
ctx.Error(http.StatusNotFound, "", "Branch doesn't exist.")
|
ctx.APIError(http.StatusNotFound, "Branch doesn't exist.")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -499,11 +499,11 @@ func GetBranchProtection(ctx *context.APIContext) {
|
||||||
bpName := ctx.PathParam("name")
|
bpName := ctx.PathParam("name")
|
||||||
bp, err := git_model.GetProtectedBranchRuleByName(ctx, repo.ID, bpName)
|
bp, err := git_model.GetProtectedBranchRuleByName(ctx, repo.ID, bpName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetProtectedBranchByID", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if bp == nil || bp.RepoID != repo.ID {
|
if bp == nil || bp.RepoID != repo.ID {
|
||||||
ctx.NotFound()
|
ctx.APIErrorNotFound()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -535,7 +535,7 @@ func ListBranchProtections(ctx *context.APIContext) {
|
||||||
repo := ctx.Repo.Repository
|
repo := ctx.Repo.Repository
|
||||||
bps, err := git_model.FindRepoProtectedBranchRules(ctx, repo.ID)
|
bps, err := git_model.FindRepoProtectedBranchRules(ctx, repo.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetProtectedBranches", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
apiBps := make([]*api.BranchProtection, len(bps))
|
apiBps := make([]*api.BranchProtection, len(bps))
|
||||||
|
@ -590,7 +590,7 @@ func CreateBranchProtection(ctx *context.APIContext) {
|
||||||
ruleName = form.BranchName //nolint
|
ruleName = form.BranchName //nolint
|
||||||
}
|
}
|
||||||
if len(ruleName) == 0 {
|
if len(ruleName) == 0 {
|
||||||
ctx.Error(http.StatusBadRequest, "both rule_name and branch_name are empty", "both rule_name and branch_name are empty")
|
ctx.APIError(http.StatusBadRequest, "both rule_name and branch_name are empty")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -602,10 +602,10 @@ func CreateBranchProtection(ctx *context.APIContext) {
|
||||||
|
|
||||||
protectBranch, err := git_model.GetProtectedBranchRuleByName(ctx, repo.ID, ruleName)
|
protectBranch, err := git_model.GetProtectedBranchRuleByName(ctx, repo.ID, ruleName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetProtectBranchOfRepoByName", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
} else if protectBranch != nil {
|
} else if protectBranch != nil {
|
||||||
ctx.Error(http.StatusForbidden, "Create branch protection", "Branch protection already exist")
|
ctx.APIError(http.StatusForbidden, "Branch protection already exist")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -617,37 +617,37 @@ func CreateBranchProtection(ctx *context.APIContext) {
|
||||||
whitelistUsers, err := user_model.GetUserIDsByNames(ctx, form.PushWhitelistUsernames, false)
|
whitelistUsers, err := user_model.GetUserIDsByNames(ctx, form.PushWhitelistUsernames, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if user_model.IsErrUserNotExist(err) {
|
if user_model.IsErrUserNotExist(err) {
|
||||||
ctx.Error(http.StatusUnprocessableEntity, "User does not exist", err)
|
ctx.APIError(http.StatusUnprocessableEntity, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.Error(http.StatusInternalServerError, "GetUserIDsByNames", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
forcePushAllowlistUsers, err := user_model.GetUserIDsByNames(ctx, form.ForcePushAllowlistUsernames, false)
|
forcePushAllowlistUsers, err := user_model.GetUserIDsByNames(ctx, form.ForcePushAllowlistUsernames, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if user_model.IsErrUserNotExist(err) {
|
if user_model.IsErrUserNotExist(err) {
|
||||||
ctx.Error(http.StatusUnprocessableEntity, "User does not exist", err)
|
ctx.APIError(http.StatusUnprocessableEntity, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.Error(http.StatusInternalServerError, "GetUserIDsByNames", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
mergeWhitelistUsers, err := user_model.GetUserIDsByNames(ctx, form.MergeWhitelistUsernames, false)
|
mergeWhitelistUsers, err := user_model.GetUserIDsByNames(ctx, form.MergeWhitelistUsernames, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if user_model.IsErrUserNotExist(err) {
|
if user_model.IsErrUserNotExist(err) {
|
||||||
ctx.Error(http.StatusUnprocessableEntity, "User does not exist", err)
|
ctx.APIError(http.StatusUnprocessableEntity, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.Error(http.StatusInternalServerError, "GetUserIDsByNames", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
approvalsWhitelistUsers, err := user_model.GetUserIDsByNames(ctx, form.ApprovalsWhitelistUsernames, false)
|
approvalsWhitelistUsers, err := user_model.GetUserIDsByNames(ctx, form.ApprovalsWhitelistUsernames, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if user_model.IsErrUserNotExist(err) {
|
if user_model.IsErrUserNotExist(err) {
|
||||||
ctx.Error(http.StatusUnprocessableEntity, "User does not exist", err)
|
ctx.APIError(http.StatusUnprocessableEntity, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.Error(http.StatusInternalServerError, "GetUserIDsByNames", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
var whitelistTeams, forcePushAllowlistTeams, mergeWhitelistTeams, approvalsWhitelistTeams []int64
|
var whitelistTeams, forcePushAllowlistTeams, mergeWhitelistTeams, approvalsWhitelistTeams []int64
|
||||||
|
@ -655,37 +655,37 @@ func CreateBranchProtection(ctx *context.APIContext) {
|
||||||
whitelistTeams, err = organization.GetTeamIDsByNames(ctx, repo.OwnerID, form.PushWhitelistTeams, false)
|
whitelistTeams, err = organization.GetTeamIDsByNames(ctx, repo.OwnerID, form.PushWhitelistTeams, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if organization.IsErrTeamNotExist(err) {
|
if organization.IsErrTeamNotExist(err) {
|
||||||
ctx.Error(http.StatusUnprocessableEntity, "Team does not exist", err)
|
ctx.APIError(http.StatusUnprocessableEntity, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.Error(http.StatusInternalServerError, "GetTeamIDsByNames", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
forcePushAllowlistTeams, err = organization.GetTeamIDsByNames(ctx, repo.OwnerID, form.ForcePushAllowlistTeams, false)
|
forcePushAllowlistTeams, err = organization.GetTeamIDsByNames(ctx, repo.OwnerID, form.ForcePushAllowlistTeams, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if organization.IsErrTeamNotExist(err) {
|
if organization.IsErrTeamNotExist(err) {
|
||||||
ctx.Error(http.StatusUnprocessableEntity, "Team does not exist", err)
|
ctx.APIError(http.StatusUnprocessableEntity, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.Error(http.StatusInternalServerError, "GetTeamIDsByNames", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
mergeWhitelistTeams, err = organization.GetTeamIDsByNames(ctx, repo.OwnerID, form.MergeWhitelistTeams, false)
|
mergeWhitelistTeams, err = organization.GetTeamIDsByNames(ctx, repo.OwnerID, form.MergeWhitelistTeams, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if organization.IsErrTeamNotExist(err) {
|
if organization.IsErrTeamNotExist(err) {
|
||||||
ctx.Error(http.StatusUnprocessableEntity, "Team does not exist", err)
|
ctx.APIError(http.StatusUnprocessableEntity, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.Error(http.StatusInternalServerError, "GetTeamIDsByNames", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
approvalsWhitelistTeams, err = organization.GetTeamIDsByNames(ctx, repo.OwnerID, form.ApprovalsWhitelistTeams, false)
|
approvalsWhitelistTeams, err = organization.GetTeamIDsByNames(ctx, repo.OwnerID, form.ApprovalsWhitelistTeams, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if organization.IsErrTeamNotExist(err) {
|
if organization.IsErrTeamNotExist(err) {
|
||||||
ctx.Error(http.StatusUnprocessableEntity, "Team does not exist", err)
|
ctx.APIError(http.StatusUnprocessableEntity, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.Error(http.StatusInternalServerError, "GetTeamIDsByNames", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -726,13 +726,13 @@ func CreateBranchProtection(ctx *context.APIContext) {
|
||||||
ApprovalsUserIDs: approvalsWhitelistUsers,
|
ApprovalsUserIDs: approvalsWhitelistUsers,
|
||||||
ApprovalsTeamIDs: approvalsWhitelistTeams,
|
ApprovalsTeamIDs: approvalsWhitelistTeams,
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "UpdateProtectBranch", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if isBranchExist {
|
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)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -740,20 +740,20 @@ func CreateBranchProtection(ctx *context.APIContext) {
|
||||||
if ctx.Repo.GitRepo == nil {
|
if ctx.Repo.GitRepo == nil {
|
||||||
ctx.Repo.GitRepo, err = gitrepo.RepositoryFromRequestContextOrOpen(ctx, ctx.Repo.Repository)
|
ctx.Repo.GitRepo, err = gitrepo.RepositoryFromRequestContextOrOpen(ctx, ctx.Repo.Repository)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "OpenRepository", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// FIXME: since we only need to recheck files protected rules, we could improve this
|
// FIXME: since we only need to recheck files protected rules, we could improve this
|
||||||
matchedBranches, err := git_model.FindAllMatchedBranches(ctx, ctx.Repo.Repository.ID, ruleName)
|
matchedBranches, err := git_model.FindAllMatchedBranches(ctx, ctx.Repo.Repository.ID, ruleName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "FindAllMatchedBranches", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, branchName := range matchedBranches {
|
for _, branchName := range matchedBranches {
|
||||||
if err = pull_service.CheckPRsForBaseBranch(ctx, ctx.Repo.Repository, branchName); err != nil {
|
if err = pull_service.CheckPRsForBaseBranch(ctx, ctx.Repo.Repository, branchName); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "CheckPRsForBaseBranch", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -763,11 +763,11 @@ func CreateBranchProtection(ctx *context.APIContext) {
|
||||||
// Reload from db to get all whitelists
|
// Reload from db to get all whitelists
|
||||||
bp, err := git_model.GetProtectedBranchRuleByName(ctx, ctx.Repo.Repository.ID, ruleName)
|
bp, err := git_model.GetProtectedBranchRuleByName(ctx, ctx.Repo.Repository.ID, ruleName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetProtectedBranchByID", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if bp == nil || bp.RepoID != ctx.Repo.Repository.ID {
|
if bp == nil || bp.RepoID != ctx.Repo.Repository.ID {
|
||||||
ctx.Error(http.StatusInternalServerError, "New branch protection not found", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -817,11 +817,11 @@ func EditBranchProtection(ctx *context.APIContext) {
|
||||||
bpName := ctx.PathParam("name")
|
bpName := ctx.PathParam("name")
|
||||||
protectBranch, err := git_model.GetProtectedBranchRuleByName(ctx, repo.ID, bpName)
|
protectBranch, err := git_model.GetProtectedBranchRuleByName(ctx, repo.ID, bpName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetProtectedBranchByID", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if protectBranch == nil || protectBranch.RepoID != repo.ID {
|
if protectBranch == nil || protectBranch.RepoID != repo.ID {
|
||||||
ctx.NotFound()
|
ctx.APIErrorNotFound()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -932,10 +932,10 @@ func EditBranchProtection(ctx *context.APIContext) {
|
||||||
whitelistUsers, err = user_model.GetUserIDsByNames(ctx, form.PushWhitelistUsernames, false)
|
whitelistUsers, err = user_model.GetUserIDsByNames(ctx, form.PushWhitelistUsernames, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if user_model.IsErrUserNotExist(err) {
|
if user_model.IsErrUserNotExist(err) {
|
||||||
ctx.Error(http.StatusUnprocessableEntity, "User does not exist", err)
|
ctx.APIError(http.StatusUnprocessableEntity, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.Error(http.StatusInternalServerError, "GetUserIDsByNames", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -945,10 +945,10 @@ func EditBranchProtection(ctx *context.APIContext) {
|
||||||
forcePushAllowlistUsers, err = user_model.GetUserIDsByNames(ctx, form.ForcePushAllowlistUsernames, false)
|
forcePushAllowlistUsers, err = user_model.GetUserIDsByNames(ctx, form.ForcePushAllowlistUsernames, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if user_model.IsErrUserNotExist(err) {
|
if user_model.IsErrUserNotExist(err) {
|
||||||
ctx.Error(http.StatusUnprocessableEntity, "User does not exist", err)
|
ctx.APIError(http.StatusUnprocessableEntity, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.Error(http.StatusInternalServerError, "GetUserIDsByNames", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -958,10 +958,10 @@ func EditBranchProtection(ctx *context.APIContext) {
|
||||||
mergeWhitelistUsers, err = user_model.GetUserIDsByNames(ctx, form.MergeWhitelistUsernames, false)
|
mergeWhitelistUsers, err = user_model.GetUserIDsByNames(ctx, form.MergeWhitelistUsernames, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if user_model.IsErrUserNotExist(err) {
|
if user_model.IsErrUserNotExist(err) {
|
||||||
ctx.Error(http.StatusUnprocessableEntity, "User does not exist", err)
|
ctx.APIError(http.StatusUnprocessableEntity, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.Error(http.StatusInternalServerError, "GetUserIDsByNames", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -971,10 +971,10 @@ func EditBranchProtection(ctx *context.APIContext) {
|
||||||
approvalsWhitelistUsers, err = user_model.GetUserIDsByNames(ctx, form.ApprovalsWhitelistUsernames, false)
|
approvalsWhitelistUsers, err = user_model.GetUserIDsByNames(ctx, form.ApprovalsWhitelistUsernames, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if user_model.IsErrUserNotExist(err) {
|
if user_model.IsErrUserNotExist(err) {
|
||||||
ctx.Error(http.StatusUnprocessableEntity, "User does not exist", err)
|
ctx.APIError(http.StatusUnprocessableEntity, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.Error(http.StatusInternalServerError, "GetUserIDsByNames", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -987,10 +987,10 @@ func EditBranchProtection(ctx *context.APIContext) {
|
||||||
whitelistTeams, err = organization.GetTeamIDsByNames(ctx, repo.OwnerID, form.PushWhitelistTeams, false)
|
whitelistTeams, err = organization.GetTeamIDsByNames(ctx, repo.OwnerID, form.PushWhitelistTeams, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if organization.IsErrTeamNotExist(err) {
|
if organization.IsErrTeamNotExist(err) {
|
||||||
ctx.Error(http.StatusUnprocessableEntity, "Team does not exist", err)
|
ctx.APIError(http.StatusUnprocessableEntity, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.Error(http.StatusInternalServerError, "GetTeamIDsByNames", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -1000,10 +1000,10 @@ func EditBranchProtection(ctx *context.APIContext) {
|
||||||
forcePushAllowlistTeams, err = organization.GetTeamIDsByNames(ctx, repo.OwnerID, form.ForcePushAllowlistTeams, false)
|
forcePushAllowlistTeams, err = organization.GetTeamIDsByNames(ctx, repo.OwnerID, form.ForcePushAllowlistTeams, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if organization.IsErrTeamNotExist(err) {
|
if organization.IsErrTeamNotExist(err) {
|
||||||
ctx.Error(http.StatusUnprocessableEntity, "Team does not exist", err)
|
ctx.APIError(http.StatusUnprocessableEntity, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.Error(http.StatusInternalServerError, "GetTeamIDsByNames", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -1013,10 +1013,10 @@ func EditBranchProtection(ctx *context.APIContext) {
|
||||||
mergeWhitelistTeams, err = organization.GetTeamIDsByNames(ctx, repo.OwnerID, form.MergeWhitelistTeams, false)
|
mergeWhitelistTeams, err = organization.GetTeamIDsByNames(ctx, repo.OwnerID, form.MergeWhitelistTeams, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if organization.IsErrTeamNotExist(err) {
|
if organization.IsErrTeamNotExist(err) {
|
||||||
ctx.Error(http.StatusUnprocessableEntity, "Team does not exist", err)
|
ctx.APIError(http.StatusUnprocessableEntity, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.Error(http.StatusInternalServerError, "GetTeamIDsByNames", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -1026,10 +1026,10 @@ func EditBranchProtection(ctx *context.APIContext) {
|
||||||
approvalsWhitelistTeams, err = organization.GetTeamIDsByNames(ctx, repo.OwnerID, form.ApprovalsWhitelistTeams, false)
|
approvalsWhitelistTeams, err = organization.GetTeamIDsByNames(ctx, repo.OwnerID, form.ApprovalsWhitelistTeams, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if organization.IsErrTeamNotExist(err) {
|
if organization.IsErrTeamNotExist(err) {
|
||||||
ctx.Error(http.StatusUnprocessableEntity, "Team does not exist", err)
|
ctx.APIError(http.StatusUnprocessableEntity, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.Error(http.StatusInternalServerError, "GetTeamIDsByNames", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -1048,7 +1048,7 @@ func EditBranchProtection(ctx *context.APIContext) {
|
||||||
ApprovalsTeamIDs: approvalsWhitelistTeams,
|
ApprovalsTeamIDs: approvalsWhitelistTeams,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "UpdateProtectBranch", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1060,7 +1060,7 @@ func EditBranchProtection(ctx *context.APIContext) {
|
||||||
|
|
||||||
if isBranchExist {
|
if isBranchExist {
|
||||||
if err = pull_service.CheckPRsForBaseBranch(ctx, ctx.Repo.Repository, bpName); err != nil {
|
if err = pull_service.CheckPRsForBaseBranch(ctx, ctx.Repo.Repository, bpName); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "CheckPrsForBaseBranch", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -1068,7 +1068,7 @@ func EditBranchProtection(ctx *context.APIContext) {
|
||||||
if ctx.Repo.GitRepo == nil {
|
if ctx.Repo.GitRepo == nil {
|
||||||
ctx.Repo.GitRepo, err = gitrepo.RepositoryFromRequestContextOrOpen(ctx, ctx.Repo.Repository)
|
ctx.Repo.GitRepo, err = gitrepo.RepositoryFromRequestContextOrOpen(ctx, ctx.Repo.Repository)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "OpenRepository", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1076,13 +1076,13 @@ func EditBranchProtection(ctx *context.APIContext) {
|
||||||
// FIXME: since we only need to recheck files protected rules, we could improve this
|
// FIXME: since we only need to recheck files protected rules, we could improve this
|
||||||
matchedBranches, err := git_model.FindAllMatchedBranches(ctx, ctx.Repo.Repository.ID, protectBranch.RuleName)
|
matchedBranches, err := git_model.FindAllMatchedBranches(ctx, ctx.Repo.Repository.ID, protectBranch.RuleName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "FindAllMatchedBranches", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, branchName := range matchedBranches {
|
for _, branchName := range matchedBranches {
|
||||||
if err = pull_service.CheckPRsForBaseBranch(ctx, ctx.Repo.Repository, branchName); err != nil {
|
if err = pull_service.CheckPRsForBaseBranch(ctx, ctx.Repo.Repository, branchName); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "CheckPrsForBaseBranch", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1092,11 +1092,11 @@ func EditBranchProtection(ctx *context.APIContext) {
|
||||||
// Reload from db to ensure get all whitelists
|
// Reload from db to ensure get all whitelists
|
||||||
bp, err := git_model.GetProtectedBranchRuleByName(ctx, repo.ID, bpName)
|
bp, err := git_model.GetProtectedBranchRuleByName(ctx, repo.ID, bpName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetProtectedBranchBy", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if bp == nil || bp.RepoID != ctx.Repo.Repository.ID {
|
if bp == nil || bp.RepoID != ctx.Repo.Repository.ID {
|
||||||
ctx.Error(http.StatusInternalServerError, "New branch protection not found", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1136,16 +1136,16 @@ func DeleteBranchProtection(ctx *context.APIContext) {
|
||||||
bpName := ctx.PathParam("name")
|
bpName := ctx.PathParam("name")
|
||||||
bp, err := git_model.GetProtectedBranchRuleByName(ctx, repo.ID, bpName)
|
bp, err := git_model.GetProtectedBranchRuleByName(ctx, repo.ID, bpName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetProtectedBranchByID", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if bp == nil || bp.RepoID != repo.ID {
|
if bp == nil || bp.RepoID != repo.ID {
|
||||||
ctx.NotFound()
|
ctx.APIErrorNotFound()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := git_model.DeleteProtectedBranch(ctx, ctx.Repo.Repository, bp.ID); err != nil {
|
if err := git_model.DeleteProtectedBranch(ctx, ctx.Repo.Repository, bp.ID); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "DeleteProtectedBranch", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1189,7 +1189,7 @@ func UpdateBranchProtectionPriories(ctx *context.APIContext) {
|
||||||
repo := ctx.Repo.Repository
|
repo := ctx.Repo.Repository
|
||||||
|
|
||||||
if err := git_model.UpdateProtectBranchPriorities(ctx, repo, form.IDs); err != nil {
|
if err := git_model.UpdateProtectBranchPriorities(ctx, repo, form.IDs); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "UpdateProtectBranchPriorities", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1228,13 +1228,13 @@ func MergeUpstream(ctx *context.APIContext) {
|
||||||
mergeStyle, err := repo_service.MergeUpstream(ctx, ctx.Doer, ctx.Repo.Repository, form.Branch)
|
mergeStyle, err := repo_service.MergeUpstream(ctx, ctx.Doer, ctx.Repo.Repository, form.Branch)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if errors.Is(err, util.ErrInvalidArgument) {
|
if errors.Is(err, util.ErrInvalidArgument) {
|
||||||
ctx.Error(http.StatusBadRequest, "MergeUpstream", err)
|
ctx.APIError(http.StatusBadRequest, err)
|
||||||
return
|
return
|
||||||
} else if errors.Is(err, util.ErrNotExist) {
|
} else if errors.Is(err, util.ErrNotExist) {
|
||||||
ctx.Error(http.StatusNotFound, "MergeUpstream", err)
|
ctx.APIError(http.StatusNotFound, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.Error(http.StatusInternalServerError, "MergeUpstream", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.JSON(http.StatusOK, &api.MergeUpstreamResponse{MergeStyle: mergeStyle})
|
ctx.JSON(http.StatusOK, &api.MergeUpstreamResponse{MergeStyle: mergeStyle})
|
||||||
|
|
|
@ -59,7 +59,7 @@ func ListCollaborators(ctx *context.APIContext) {
|
||||||
RepoID: ctx.Repo.Repository.ID,
|
RepoID: ctx.Repo.Repository.ID,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "ListCollaborators", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -106,21 +106,21 @@ func IsCollaborator(ctx *context.APIContext) {
|
||||||
user, err := user_model.GetUserByName(ctx, ctx.PathParam("collaborator"))
|
user, err := user_model.GetUserByName(ctx, ctx.PathParam("collaborator"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if user_model.IsErrUserNotExist(err) {
|
if user_model.IsErrUserNotExist(err) {
|
||||||
ctx.Error(http.StatusUnprocessableEntity, "", err)
|
ctx.APIError(http.StatusUnprocessableEntity, err)
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetUserByName", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
isColab, err := repo_model.IsCollaborator(ctx, ctx.Repo.Repository.ID, user.ID)
|
isColab, err := repo_model.IsCollaborator(ctx, ctx.Repo.Repository.ID, user.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "IsCollaborator", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if isColab {
|
if isColab {
|
||||||
ctx.Status(http.StatusNoContent)
|
ctx.Status(http.StatusNoContent)
|
||||||
} else {
|
} else {
|
||||||
ctx.NotFound()
|
ctx.APIErrorNotFound()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -166,15 +166,15 @@ func AddOrUpdateCollaborator(ctx *context.APIContext) {
|
||||||
collaborator, err := user_model.GetUserByName(ctx, ctx.PathParam("collaborator"))
|
collaborator, err := user_model.GetUserByName(ctx, ctx.PathParam("collaborator"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if user_model.IsErrUserNotExist(err) {
|
if user_model.IsErrUserNotExist(err) {
|
||||||
ctx.Error(http.StatusUnprocessableEntity, "", err)
|
ctx.APIError(http.StatusUnprocessableEntity, err)
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetUserByName", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if !collaborator.IsActive {
|
if !collaborator.IsActive {
|
||||||
ctx.Error(http.StatusInternalServerError, "InactiveCollaborator", errors.New("collaborator's account is inactive"))
|
ctx.APIError(http.StatusInternalServerError, errors.New("collaborator's account is inactive"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -185,9 +185,9 @@ func AddOrUpdateCollaborator(ctx *context.APIContext) {
|
||||||
|
|
||||||
if err := repo_service.AddOrUpdateCollaborator(ctx, ctx.Repo.Repository, collaborator, p); err != nil {
|
if err := repo_service.AddOrUpdateCollaborator(ctx, ctx.Repo.Repository, collaborator, p); err != nil {
|
||||||
if errors.Is(err, user_model.ErrBlockedUser) {
|
if errors.Is(err, user_model.ErrBlockedUser) {
|
||||||
ctx.Error(http.StatusForbidden, "AddOrUpdateCollaborator", err)
|
ctx.APIError(http.StatusForbidden, err)
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "AddOrUpdateCollaborator", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -229,15 +229,15 @@ func DeleteCollaborator(ctx *context.APIContext) {
|
||||||
collaborator, err := user_model.GetUserByName(ctx, ctx.PathParam("collaborator"))
|
collaborator, err := user_model.GetUserByName(ctx, ctx.PathParam("collaborator"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if user_model.IsErrUserNotExist(err) {
|
if user_model.IsErrUserNotExist(err) {
|
||||||
ctx.Error(http.StatusUnprocessableEntity, "", err)
|
ctx.APIError(http.StatusUnprocessableEntity, err)
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetUserByName", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := repo_service.DeleteCollaboration(ctx, ctx.Repo.Repository, collaborator); err != nil {
|
if err := repo_service.DeleteCollaboration(ctx, ctx.Repo.Repository, collaborator); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "DeleteCollaboration", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.Status(http.StatusNoContent)
|
ctx.Status(http.StatusNoContent)
|
||||||
|
@ -275,23 +275,23 @@ func GetRepoPermissions(ctx *context.APIContext) {
|
||||||
// "$ref": "#/responses/forbidden"
|
// "$ref": "#/responses/forbidden"
|
||||||
|
|
||||||
if !ctx.Doer.IsAdmin && ctx.Doer.LoginName != ctx.PathParam("collaborator") && !ctx.IsUserRepoAdmin() {
|
if !ctx.Doer.IsAdmin && ctx.Doer.LoginName != ctx.PathParam("collaborator") && !ctx.IsUserRepoAdmin() {
|
||||||
ctx.Error(http.StatusForbidden, "User", "Only admins can query all permissions, repo admins can query all repo permissions, collaborators can query only their own")
|
ctx.APIError(http.StatusForbidden, "Only admins can query all permissions, repo admins can query all repo permissions, collaborators can query only their own")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
collaborator, err := user_model.GetUserByName(ctx, ctx.PathParam("collaborator"))
|
collaborator, err := user_model.GetUserByName(ctx, ctx.PathParam("collaborator"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if user_model.IsErrUserNotExist(err) {
|
if user_model.IsErrUserNotExist(err) {
|
||||||
ctx.Error(http.StatusNotFound, "GetUserByName", err)
|
ctx.APIError(http.StatusNotFound, err)
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetUserByName", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
permission, err := access_model.GetUserRepoPermission(ctx, ctx.Repo.Repository, collaborator)
|
permission, err := access_model.GetUserRepoPermission(ctx, ctx.Repo.Repository, collaborator)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetUserRepoPermission", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -324,13 +324,13 @@ func GetReviewers(ctx *context.APIContext) {
|
||||||
|
|
||||||
canChooseReviewer := issue_service.CanDoerChangeReviewRequests(ctx, ctx.Doer, ctx.Repo.Repository, 0)
|
canChooseReviewer := issue_service.CanDoerChangeReviewRequests(ctx, ctx.Doer, ctx.Repo.Repository, 0)
|
||||||
if !canChooseReviewer {
|
if !canChooseReviewer {
|
||||||
ctx.Error(http.StatusForbidden, "GetReviewers", errors.New("doer has no permission to get reviewers"))
|
ctx.APIError(http.StatusForbidden, errors.New("doer has no permission to get reviewers"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
reviewers, err := pull_service.GetReviewers(ctx, ctx.Repo.Repository, ctx.Doer.ID, 0)
|
reviewers, err := pull_service.GetReviewers(ctx, ctx.Repo.Repository, ctx.Doer.ID, 0)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "ListCollaborators", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.JSON(http.StatusOK, convert.ToUsers(ctx, ctx.Doer, reviewers))
|
ctx.JSON(http.StatusOK, convert.ToUsers(ctx, ctx.Doer, reviewers))
|
||||||
|
@ -362,7 +362,7 @@ func GetAssignees(ctx *context.APIContext) {
|
||||||
|
|
||||||
assignees, err := repo_model.GetRepoAssignees(ctx, ctx.Repo.Repository)
|
assignees, err := repo_model.GetRepoAssignees(ctx, ctx.Repo.Repository)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "ListCollaborators", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.JSON(http.StatusOK, convert.ToUsers(ctx, ctx.Doer, assignees))
|
ctx.JSON(http.StatusOK, convert.ToUsers(ctx, ctx.Doer, assignees))
|
||||||
|
|
|
@ -65,7 +65,7 @@ func GetSingleCommit(ctx *context.APIContext) {
|
||||||
|
|
||||||
sha := ctx.PathParam("sha")
|
sha := ctx.PathParam("sha")
|
||||||
if !git.IsValidRefPattern(sha) {
|
if !git.IsValidRefPattern(sha) {
|
||||||
ctx.Error(http.StatusUnprocessableEntity, "no valid ref or sha", fmt.Sprintf("no valid ref or sha: %s", sha))
|
ctx.APIError(http.StatusUnprocessableEntity, fmt.Sprintf("no valid ref or sha: %s", sha))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -76,16 +76,16 @@ func getCommit(ctx *context.APIContext, identifier string, toCommitOpts convert.
|
||||||
commit, err := ctx.Repo.GitRepo.GetCommit(identifier)
|
commit, err := ctx.Repo.GitRepo.GetCommit(identifier)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if git.IsErrNotExist(err) {
|
if git.IsErrNotExist(err) {
|
||||||
ctx.NotFound(identifier)
|
ctx.APIErrorNotFound(identifier)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.Error(http.StatusInternalServerError, "gitRepo.GetCommit", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
json, err := convert.ToCommit(ctx, ctx.Repo.Repository, ctx.Repo.GitRepo, commit, nil, toCommitOpts)
|
json, err := convert.ToCommit(ctx, ctx.Repo.Repository, ctx.Repo.GitRepo, commit, nil, toCommitOpts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "toCommit", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.JSON(http.StatusOK, json)
|
ctx.JSON(http.StatusOK, json)
|
||||||
|
@ -182,13 +182,13 @@ func GetAllCommits(ctx *context.APIContext) {
|
||||||
// no sha supplied - use default branch
|
// no sha supplied - use default branch
|
||||||
head, err := ctx.Repo.GitRepo.GetHEADBranch()
|
head, err := ctx.Repo.GitRepo.GetHEADBranch()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetHEADBranch", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
baseCommit, err = ctx.Repo.GitRepo.GetBranchCommit(head.Name)
|
baseCommit, err = ctx.Repo.GitRepo.GetBranchCommit(head.Name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetCommit", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -207,14 +207,14 @@ func GetAllCommits(ctx *context.APIContext) {
|
||||||
Revision: []string{baseCommit.ID.String()},
|
Revision: []string{baseCommit.ID.String()},
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetCommitsCount", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Query commits
|
// Query commits
|
||||||
commits, err = baseCommit.CommitsByRange(listOptions.Page, listOptions.PageSize, not)
|
commits, err = baseCommit.CommitsByRange(listOptions.Page, listOptions.PageSize, not)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "CommitsByRange", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -231,10 +231,10 @@ func GetAllCommits(ctx *context.APIContext) {
|
||||||
})
|
})
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "FileCommitsCount", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
} else if commitsCountTotal == 0 {
|
} else if commitsCountTotal == 0 {
|
||||||
ctx.NotFound("FileCommitsCount", nil)
|
ctx.APIErrorNotFound("FileCommitsCount", nil)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -246,7 +246,7 @@ func GetAllCommits(ctx *context.APIContext) {
|
||||||
Page: listOptions.Page,
|
Page: listOptions.Page,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "CommitsByFileAndRange", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -259,7 +259,7 @@ func GetAllCommits(ctx *context.APIContext) {
|
||||||
// Create json struct
|
// Create json struct
|
||||||
apiCommits[i], err = convert.ToCommit(ctx, ctx.Repo.Repository, ctx.Repo.GitRepo, commit, userCache, convert.ParseCommitOptions(ctx))
|
apiCommits[i], err = convert.ToCommit(ctx, ctx.Repo.Repository, ctx.Repo.GitRepo, commit, userCache, convert.ParseCommitOptions(ctx))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "toCommit", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -317,10 +317,10 @@ func DownloadCommitDiffOrPatch(ctx *context.APIContext) {
|
||||||
|
|
||||||
if err := git.GetRawDiff(ctx.Repo.GitRepo, sha, diffType, ctx.Resp); err != nil {
|
if err := git.GetRawDiff(ctx.Repo.GitRepo, sha, diffType, ctx.Resp); err != nil {
|
||||||
if git.IsErrNotExist(err) {
|
if git.IsErrNotExist(err) {
|
||||||
ctx.NotFound(sha)
|
ctx.APIErrorNotFound(sha)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.Error(http.StatusInternalServerError, "DownloadCommitDiffOrPatch", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -357,19 +357,19 @@ func GetCommitPullRequest(ctx *context.APIContext) {
|
||||||
pr, err := issues_model.GetPullRequestByMergedCommit(ctx, ctx.Repo.Repository.ID, ctx.PathParam("sha"))
|
pr, err := issues_model.GetPullRequestByMergedCommit(ctx, ctx.Repo.Repository.ID, ctx.PathParam("sha"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if issues_model.IsErrPullRequestNotExist(err) {
|
if issues_model.IsErrPullRequestNotExist(err) {
|
||||||
ctx.Error(http.StatusNotFound, "GetPullRequestByMergedCommit", err)
|
ctx.APIError(http.StatusNotFound, err)
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetPullRequestByIndex", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = pr.LoadBaseRepo(ctx); err != nil {
|
if err = pr.LoadBaseRepo(ctx); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "LoadBaseRepo", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if err = pr.LoadHeadRepo(ctx); err != nil {
|
if err = pr.LoadHeadRepo(ctx); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "LoadHeadRepo", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.JSON(http.StatusOK, convert.ToAPIPullRequest(ctx, pr, ctx.Doer))
|
ctx.JSON(http.StatusOK, convert.ToAPIPullRequest(ctx, pr, ctx.Doer))
|
||||||
|
|
|
@ -47,7 +47,7 @@ func CompareDiff(ctx *context.APIContext) {
|
||||||
var err error
|
var err error
|
||||||
ctx.Repo.GitRepo, err = gitrepo.RepositoryFromRequestContextOrOpen(ctx, ctx.Repo.Repository)
|
ctx.Repo.GitRepo, err = gitrepo.RepositoryFromRequestContextOrOpen(ctx, ctx.Repo.Repository)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "OpenRepository", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -82,7 +82,7 @@ func CompareDiff(ctx *context.APIContext) {
|
||||||
Files: files,
|
Files: files,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.ServerError("toCommit", err)
|
ctx.APIErrorInternal(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
apiCommits = append(apiCommits, apiCommit)
|
apiCommits = append(apiCommits, apiCommit)
|
||||||
|
|
|
@ -23,7 +23,7 @@ func DownloadArchive(ctx *context.APIContext) {
|
||||||
case "bundle":
|
case "bundle":
|
||||||
tp = git.ArchiveBundle
|
tp = git.ArchiveBundle
|
||||||
default:
|
default:
|
||||||
ctx.Error(http.StatusBadRequest, "", fmt.Sprintf("Unknown archive type: %s", ballType))
|
ctx.APIError(http.StatusBadRequest, fmt.Sprintf("Unknown archive type: %s", ballType))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,20 +31,20 @@ func DownloadArchive(ctx *context.APIContext) {
|
||||||
var err error
|
var err error
|
||||||
ctx.Repo.GitRepo, err = gitrepo.RepositoryFromRequestContextOrOpen(ctx, ctx.Repo.Repository)
|
ctx.Repo.GitRepo, err = gitrepo.RepositoryFromRequestContextOrOpen(ctx, ctx.Repo.Repository)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "OpenRepository", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
r, err := archiver_service.NewRequest(ctx.Repo.Repository.ID, ctx.Repo.GitRepo, ctx.PathParam("*")+"."+tp.String())
|
r, err := archiver_service.NewRequest(ctx.Repo.Repository.ID, ctx.Repo.GitRepo, ctx.PathParam("*")+"."+tp.String())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.ServerError("NewRequest", err)
|
ctx.APIErrorInternal(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
archive, err := r.Await(ctx)
|
archive, err := r.Await(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.ServerError("archive.Await", err)
|
ctx.APIErrorInternal(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -72,7 +72,7 @@ func GetRawFile(ctx *context.APIContext) {
|
||||||
// "$ref": "#/responses/notFound"
|
// "$ref": "#/responses/notFound"
|
||||||
|
|
||||||
if ctx.Repo.Repository.IsEmpty {
|
if ctx.Repo.Repository.IsEmpty {
|
||||||
ctx.NotFound()
|
ctx.APIErrorNotFound()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -84,7 +84,7 @@ func GetRawFile(ctx *context.APIContext) {
|
||||||
ctx.RespHeader().Set(giteaObjectTypeHeader, string(files_service.GetObjectTypeFromTreeEntry(entry)))
|
ctx.RespHeader().Set(giteaObjectTypeHeader, string(files_service.GetObjectTypeFromTreeEntry(entry)))
|
||||||
|
|
||||||
if err := common.ServeBlob(ctx.Base, ctx.Repo.TreePath, blob, lastModified); err != nil {
|
if err := common.ServeBlob(ctx.Base, ctx.Repo.TreePath, blob, lastModified); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "ServeBlob", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -125,7 +125,7 @@ func GetRawFileOrLFS(ctx *context.APIContext) {
|
||||||
// "$ref": "#/responses/notFound"
|
// "$ref": "#/responses/notFound"
|
||||||
|
|
||||||
if ctx.Repo.Repository.IsEmpty {
|
if ctx.Repo.Repository.IsEmpty {
|
||||||
ctx.NotFound()
|
ctx.APIErrorNotFound()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -145,7 +145,7 @@ func GetRawFileOrLFS(ctx *context.APIContext) {
|
||||||
|
|
||||||
// OK not cached - serve!
|
// OK not cached - serve!
|
||||||
if err := common.ServeBlob(ctx.Base, ctx.Repo.TreePath, blob, lastModified); err != nil {
|
if err := common.ServeBlob(ctx.Base, ctx.Repo.TreePath, blob, lastModified); err != nil {
|
||||||
ctx.ServerError("ServeBlob", err)
|
ctx.APIErrorInternal(err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -153,7 +153,7 @@ func GetRawFileOrLFS(ctx *context.APIContext) {
|
||||||
// OK, now the blob is known to have at most 1024 bytes we can simply read this in one go (This saves reading it twice)
|
// OK, now the blob is known to have at most 1024 bytes we can simply read this in one go (This saves reading it twice)
|
||||||
dataRc, err := blob.DataAsync()
|
dataRc, err := blob.DataAsync()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.ServerError("DataAsync", err)
|
ctx.APIErrorInternal(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -161,7 +161,7 @@ func GetRawFileOrLFS(ctx *context.APIContext) {
|
||||||
buf, err := io.ReadAll(dataRc)
|
buf, err := io.ReadAll(dataRc)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
_ = dataRc.Close()
|
_ = dataRc.Close()
|
||||||
ctx.ServerError("DataAsync", err)
|
ctx.APIErrorInternal(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -197,7 +197,7 @@ func GetRawFileOrLFS(ctx *context.APIContext) {
|
||||||
common.ServeContentByReader(ctx.Base, ctx.Repo.TreePath, blob.Size(), bytes.NewReader(buf))
|
common.ServeContentByReader(ctx.Base, ctx.Repo.TreePath, blob.Size(), bytes.NewReader(buf))
|
||||||
return
|
return
|
||||||
} else if err != nil {
|
} else if err != nil {
|
||||||
ctx.ServerError("GetLFSMetaObjectByOid", err)
|
ctx.APIErrorInternal(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -217,7 +217,7 @@ func GetRawFileOrLFS(ctx *context.APIContext) {
|
||||||
|
|
||||||
lfsDataRc, err := lfs.ReadMetaObject(meta.Pointer)
|
lfsDataRc, err := lfs.ReadMetaObject(meta.Pointer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.ServerError("ReadMetaObject", err)
|
ctx.APIErrorInternal(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
defer lfsDataRc.Close()
|
defer lfsDataRc.Close()
|
||||||
|
@ -229,21 +229,21 @@ func getBlobForEntry(ctx *context.APIContext) (blob *git.Blob, entry *git.TreeEn
|
||||||
entry, err := ctx.Repo.Commit.GetTreeEntryByPath(ctx.Repo.TreePath)
|
entry, err := ctx.Repo.Commit.GetTreeEntryByPath(ctx.Repo.TreePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if git.IsErrNotExist(err) {
|
if git.IsErrNotExist(err) {
|
||||||
ctx.NotFound()
|
ctx.APIErrorNotFound()
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetTreeEntryByPath", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
return nil, nil, nil
|
return nil, nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if entry.IsDir() || entry.IsSubModule() {
|
if entry.IsDir() || entry.IsSubModule() {
|
||||||
ctx.NotFound("getBlobForEntry", nil)
|
ctx.APIErrorNotFound("getBlobForEntry", nil)
|
||||||
return nil, nil, nil
|
return nil, nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
latestCommit, err := ctx.Repo.GitRepo.GetTreePathLatestCommit(ctx.Repo.Commit.ID.String(), ctx.Repo.TreePath)
|
latestCommit, err := ctx.Repo.GitRepo.GetTreePathLatestCommit(ctx.Repo.Commit.ID.String(), ctx.Repo.TreePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetTreePathLatestCommit", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return nil, nil, nil
|
return nil, nil, nil
|
||||||
}
|
}
|
||||||
when := &latestCommit.Committer.When
|
when := &latestCommit.Committer.When
|
||||||
|
@ -284,7 +284,7 @@ func GetArchive(ctx *context.APIContext) {
|
||||||
var err error
|
var err error
|
||||||
ctx.Repo.GitRepo, err = gitrepo.RepositoryFromRequestContextOrOpen(ctx, ctx.Repo.Repository)
|
ctx.Repo.GitRepo, err = gitrepo.RepositoryFromRequestContextOrOpen(ctx, ctx.Repo.Repository)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "OpenRepository", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -296,18 +296,18 @@ func archiveDownload(ctx *context.APIContext) {
|
||||||
aReq, err := archiver_service.NewRequest(ctx.Repo.Repository.ID, ctx.Repo.GitRepo, ctx.PathParam("*"))
|
aReq, err := archiver_service.NewRequest(ctx.Repo.Repository.ID, ctx.Repo.GitRepo, ctx.PathParam("*"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if errors.Is(err, archiver_service.ErrUnknownArchiveFormat{}) {
|
if errors.Is(err, archiver_service.ErrUnknownArchiveFormat{}) {
|
||||||
ctx.Error(http.StatusBadRequest, "unknown archive format", err)
|
ctx.APIError(http.StatusBadRequest, err)
|
||||||
} else if errors.Is(err, archiver_service.RepoRefNotFoundError{}) {
|
} else if errors.Is(err, archiver_service.RepoRefNotFoundError{}) {
|
||||||
ctx.Error(http.StatusNotFound, "unrecognized reference", err)
|
ctx.APIError(http.StatusNotFound, err)
|
||||||
} else {
|
} else {
|
||||||
ctx.ServerError("archiver_service.NewRequest", err)
|
ctx.APIErrorInternal(err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
archiver, err := aReq.Await(ctx)
|
archiver, err := aReq.Await(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.ServerError("archiver.Await", err)
|
ctx.APIErrorInternal(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -339,7 +339,7 @@ func download(ctx *context.APIContext, archiveName string, archiver *repo_model.
|
||||||
// If we have matched and access to release or issue
|
// If we have matched and access to release or issue
|
||||||
fr, err := storage.RepoArchives.Open(rPath)
|
fr, err := storage.RepoArchives.Open(rPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.ServerError("Open", err)
|
ctx.APIErrorInternal(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
defer fr.Close()
|
defer fr.Close()
|
||||||
|
@ -387,9 +387,9 @@ func GetEditorconfig(ctx *context.APIContext) {
|
||||||
ec, _, err := ctx.Repo.GetEditorconfig(ctx.Repo.Commit)
|
ec, _, err := ctx.Repo.GetEditorconfig(ctx.Repo.Commit)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if git.IsErrNotExist(err) {
|
if git.IsErrNotExist(err) {
|
||||||
ctx.NotFound(err)
|
ctx.APIErrorNotFound(err)
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetEditorconfig", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -397,7 +397,7 @@ func GetEditorconfig(ctx *context.APIContext) {
|
||||||
fileName := ctx.PathParam("filename")
|
fileName := ctx.PathParam("filename")
|
||||||
def, err := ec.GetDefinitionForFilename(fileName)
|
def, err := ec.GetDefinitionForFilename(fileName)
|
||||||
if def == nil {
|
if def == nil {
|
||||||
ctx.NotFound(err)
|
ctx.APIErrorNotFound(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.JSON(http.StatusOK, def)
|
ctx.JSON(http.StatusOK, def)
|
||||||
|
@ -470,7 +470,7 @@ func ChangeFiles(ctx *context.APIContext) {
|
||||||
for _, file := range apiOpts.Files {
|
for _, file := range apiOpts.Files {
|
||||||
contentReader, err := base64Reader(file.ContentBase64)
|
contentReader, err := base64Reader(file.ContentBase64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusUnprocessableEntity, "Invalid base64 content", err)
|
ctx.APIError(http.StatusUnprocessableEntity, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
changeRepoFile := &files_service.ChangeRepoFile{
|
changeRepoFile := &files_service.ChangeRepoFile{
|
||||||
|
@ -570,7 +570,7 @@ func CreateFile(ctx *context.APIContext) {
|
||||||
|
|
||||||
contentReader, err := base64Reader(apiOpts.ContentBase64)
|
contentReader, err := base64Reader(apiOpts.ContentBase64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusUnprocessableEntity, "Invalid base64 content", err)
|
ctx.APIError(http.StatusUnprocessableEntity, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -661,7 +661,7 @@ func UpdateFile(ctx *context.APIContext) {
|
||||||
// "$ref": "#/responses/repoArchivedError"
|
// "$ref": "#/responses/repoArchivedError"
|
||||||
apiOpts := web.GetForm(ctx).(*api.UpdateFileOptions)
|
apiOpts := web.GetForm(ctx).(*api.UpdateFileOptions)
|
||||||
if ctx.Repo.Repository.IsEmpty {
|
if ctx.Repo.Repository.IsEmpty {
|
||||||
ctx.Error(http.StatusUnprocessableEntity, "RepoIsEmpty", fmt.Errorf("repo is empty"))
|
ctx.APIError(http.StatusUnprocessableEntity, fmt.Errorf("repo is empty"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -671,7 +671,7 @@ func UpdateFile(ctx *context.APIContext) {
|
||||||
|
|
||||||
contentReader, err := base64Reader(apiOpts.ContentBase64)
|
contentReader, err := base64Reader(apiOpts.ContentBase64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusUnprocessableEntity, "Invalid base64 content", err)
|
ctx.APIError(http.StatusUnprocessableEntity, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -723,20 +723,20 @@ func UpdateFile(ctx *context.APIContext) {
|
||||||
|
|
||||||
func handleCreateOrUpdateFileError(ctx *context.APIContext, err error) {
|
func handleCreateOrUpdateFileError(ctx *context.APIContext, err error) {
|
||||||
if files_service.IsErrUserCannotCommit(err) || pull_service.IsErrFilePathProtected(err) {
|
if files_service.IsErrUserCannotCommit(err) || pull_service.IsErrFilePathProtected(err) {
|
||||||
ctx.Error(http.StatusForbidden, "Access", err)
|
ctx.APIError(http.StatusForbidden, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if git_model.IsErrBranchAlreadyExists(err) || files_service.IsErrFilenameInvalid(err) || pull_service.IsErrSHADoesNotMatch(err) ||
|
if git_model.IsErrBranchAlreadyExists(err) || files_service.IsErrFilenameInvalid(err) || pull_service.IsErrSHADoesNotMatch(err) ||
|
||||||
files_service.IsErrFilePathInvalid(err) || files_service.IsErrRepoFileAlreadyExists(err) {
|
files_service.IsErrFilePathInvalid(err) || files_service.IsErrRepoFileAlreadyExists(err) {
|
||||||
ctx.Error(http.StatusUnprocessableEntity, "Invalid", err)
|
ctx.APIError(http.StatusUnprocessableEntity, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if git_model.IsErrBranchNotExist(err) || git.IsErrBranchNotExist(err) {
|
if git_model.IsErrBranchNotExist(err) || git.IsErrBranchNotExist(err) {
|
||||||
ctx.Error(http.StatusNotFound, "BranchDoesNotExist", err)
|
ctx.APIError(http.StatusNotFound, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.Error(http.StatusInternalServerError, "UpdateFile", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Called from both CreateFile or UpdateFile to handle both
|
// Called from both CreateFile or UpdateFile to handle both
|
||||||
|
@ -825,7 +825,7 @@ func DeleteFile(ctx *context.APIContext) {
|
||||||
|
|
||||||
apiOpts := web.GetForm(ctx).(*api.DeleteFileOptions)
|
apiOpts := web.GetForm(ctx).(*api.DeleteFileOptions)
|
||||||
if !canWriteFiles(ctx, apiOpts.BranchName) {
|
if !canWriteFiles(ctx, apiOpts.BranchName) {
|
||||||
ctx.Error(http.StatusForbidden, "DeleteFile", repo_model.ErrUserDoesNotHaveAccessToRepo{
|
ctx.APIError(http.StatusForbidden, repo_model.ErrUserDoesNotHaveAccessToRepo{
|
||||||
UserID: ctx.Doer.ID,
|
UserID: ctx.Doer.ID,
|
||||||
RepoName: ctx.Repo.Repository.LowerName,
|
RepoName: ctx.Repo.Repository.LowerName,
|
||||||
})
|
})
|
||||||
|
@ -874,20 +874,20 @@ func DeleteFile(ctx *context.APIContext) {
|
||||||
|
|
||||||
if filesResponse, err := files_service.ChangeRepoFiles(ctx, ctx.Repo.Repository, ctx.Doer, opts); err != nil {
|
if filesResponse, err := files_service.ChangeRepoFiles(ctx, ctx.Repo.Repository, ctx.Doer, opts); err != nil {
|
||||||
if git.IsErrBranchNotExist(err) || files_service.IsErrRepoFileDoesNotExist(err) || git.IsErrNotExist(err) {
|
if git.IsErrBranchNotExist(err) || files_service.IsErrRepoFileDoesNotExist(err) || git.IsErrNotExist(err) {
|
||||||
ctx.Error(http.StatusNotFound, "DeleteFile", err)
|
ctx.APIError(http.StatusNotFound, err)
|
||||||
return
|
return
|
||||||
} else if git_model.IsErrBranchAlreadyExists(err) ||
|
} else if git_model.IsErrBranchAlreadyExists(err) ||
|
||||||
files_service.IsErrFilenameInvalid(err) ||
|
files_service.IsErrFilenameInvalid(err) ||
|
||||||
pull_service.IsErrSHADoesNotMatch(err) ||
|
pull_service.IsErrSHADoesNotMatch(err) ||
|
||||||
files_service.IsErrCommitIDDoesNotMatch(err) ||
|
files_service.IsErrCommitIDDoesNotMatch(err) ||
|
||||||
files_service.IsErrSHAOrCommitIDNotProvided(err) {
|
files_service.IsErrSHAOrCommitIDNotProvided(err) {
|
||||||
ctx.Error(http.StatusBadRequest, "DeleteFile", err)
|
ctx.APIError(http.StatusBadRequest, err)
|
||||||
return
|
return
|
||||||
} else if files_service.IsErrUserCannotCommit(err) {
|
} else if files_service.IsErrUserCannotCommit(err) {
|
||||||
ctx.Error(http.StatusForbidden, "DeleteFile", err)
|
ctx.APIError(http.StatusForbidden, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.Error(http.StatusInternalServerError, "DeleteFile", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
} else {
|
} else {
|
||||||
fileResponse := files_service.GetFileResponseFromFilesResponse(filesResponse, 0)
|
fileResponse := files_service.GetFileResponseFromFilesResponse(filesResponse, 0)
|
||||||
ctx.JSON(http.StatusOK, fileResponse) // FIXME on APIv2: return http.StatusNoContent
|
ctx.JSON(http.StatusOK, fileResponse) // FIXME on APIv2: return http.StatusNoContent
|
||||||
|
@ -929,7 +929,7 @@ func GetContents(ctx *context.APIContext) {
|
||||||
// "$ref": "#/responses/notFound"
|
// "$ref": "#/responses/notFound"
|
||||||
|
|
||||||
if !canReadFiles(ctx.Repo) {
|
if !canReadFiles(ctx.Repo) {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetContentsOrList", repo_model.ErrUserDoesNotHaveAccessToRepo{
|
ctx.APIError(http.StatusInternalServerError, repo_model.ErrUserDoesNotHaveAccessToRepo{
|
||||||
UserID: ctx.Doer.ID,
|
UserID: ctx.Doer.ID,
|
||||||
RepoName: ctx.Repo.Repository.LowerName,
|
RepoName: ctx.Repo.Repository.LowerName,
|
||||||
})
|
})
|
||||||
|
@ -941,10 +941,10 @@ func GetContents(ctx *context.APIContext) {
|
||||||
|
|
||||||
if fileList, err := files_service.GetContentsOrList(ctx, ctx.Repo.Repository, treePath, ref); err != nil {
|
if fileList, err := files_service.GetContentsOrList(ctx, ctx.Repo.Repository, treePath, ref); err != nil {
|
||||||
if git.IsErrNotExist(err) {
|
if git.IsErrNotExist(err) {
|
||||||
ctx.NotFound("GetContentsOrList", err)
|
ctx.APIErrorNotFound("GetContentsOrList", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.Error(http.StatusInternalServerError, "GetContentsOrList", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
} else {
|
} else {
|
||||||
ctx.JSON(http.StatusOK, fileList)
|
ctx.JSON(http.StatusOK, fileList)
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,15 +57,15 @@ func ListForks(ctx *context.APIContext) {
|
||||||
|
|
||||||
forks, total, err := repo_service.FindForks(ctx, ctx.Repo.Repository, ctx.Doer, utils.GetListOptions(ctx))
|
forks, total, err := repo_service.FindForks(ctx, ctx.Repo.Repository, ctx.Doer, utils.GetListOptions(ctx))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "FindForks", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if err := repo_model.RepositoryList(forks).LoadOwners(ctx); err != nil {
|
if err := repo_model.RepositoryList(forks).LoadOwners(ctx); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "LoadOwners", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if err := repo_model.RepositoryList(forks).LoadUnits(ctx); err != nil {
|
if err := repo_model.RepositoryList(forks).LoadUnits(ctx); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "LoadUnits", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -73,7 +73,7 @@ func ListForks(ctx *context.APIContext) {
|
||||||
for i, fork := range forks {
|
for i, fork := range forks {
|
||||||
permission, err := access_model.GetUserRepoPermission(ctx, fork, ctx.Doer)
|
permission, err := access_model.GetUserRepoPermission(ctx, fork, ctx.Doer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetUserRepoPermission", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
apiForks[i] = convert.ToRepo(ctx, fork, permission)
|
apiForks[i] = convert.ToRepo(ctx, fork, permission)
|
||||||
|
@ -126,19 +126,19 @@ func CreateFork(ctx *context.APIContext) {
|
||||||
org, err := organization.GetOrgByName(ctx, *form.Organization)
|
org, err := organization.GetOrgByName(ctx, *form.Organization)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if organization.IsErrOrgNotExist(err) {
|
if organization.IsErrOrgNotExist(err) {
|
||||||
ctx.Error(http.StatusUnprocessableEntity, "", err)
|
ctx.APIError(http.StatusUnprocessableEntity, err)
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetOrgByName", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if !ctx.Doer.IsAdmin {
|
if !ctx.Doer.IsAdmin {
|
||||||
isMember, err := org.IsOrgMember(ctx, ctx.Doer.ID)
|
isMember, err := org.IsOrgMember(ctx, ctx.Doer.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "IsOrgMember", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
} else if !isMember {
|
} else if !isMember {
|
||||||
ctx.Error(http.StatusForbidden, "isMemberNot", fmt.Sprintf("User is no Member of Organisation '%s'", org.Name))
|
ctx.APIError(http.StatusForbidden, fmt.Sprintf("User is no Member of Organisation '%s'", org.Name))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -159,11 +159,11 @@ func CreateFork(ctx *context.APIContext) {
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if errors.Is(err, util.ErrAlreadyExist) || repo_model.IsErrReachLimitOfRepo(err) {
|
if errors.Is(err, util.ErrAlreadyExist) || repo_model.IsErrReachLimitOfRepo(err) {
|
||||||
ctx.Error(http.StatusConflict, "ForkRepository", err)
|
ctx.APIError(http.StatusConflict, err)
|
||||||
} else if errors.Is(err, user_model.ErrBlockedUser) {
|
} else if errors.Is(err, user_model.ErrBlockedUser) {
|
||||||
ctx.Error(http.StatusForbidden, "ForkRepository", err)
|
ctx.APIError(http.StatusForbidden, err)
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "ForkRepository", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,7 +40,7 @@ func ListGitHooks(ctx *context.APIContext) {
|
||||||
|
|
||||||
hooks, err := ctx.Repo.GitRepo.Hooks()
|
hooks, err := ctx.Repo.GitRepo.Hooks()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "Hooks", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -84,9 +84,9 @@ func GetGitHook(ctx *context.APIContext) {
|
||||||
hook, err := ctx.Repo.GitRepo.GetHook(hookID)
|
hook, err := ctx.Repo.GitRepo.GetHook(hookID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if errors.Is(err, git.ErrNotValidHook) {
|
if errors.Is(err, git.ErrNotValidHook) {
|
||||||
ctx.NotFound()
|
ctx.APIErrorNotFound()
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetHook", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -131,16 +131,16 @@ func EditGitHook(ctx *context.APIContext) {
|
||||||
hook, err := ctx.Repo.GitRepo.GetHook(hookID)
|
hook, err := ctx.Repo.GitRepo.GetHook(hookID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if errors.Is(err, git.ErrNotValidHook) {
|
if errors.Is(err, git.ErrNotValidHook) {
|
||||||
ctx.NotFound()
|
ctx.APIErrorNotFound()
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetHook", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
hook.Content = form.Content
|
hook.Content = form.Content
|
||||||
if err = hook.Update(); err != nil {
|
if err = hook.Update(); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "hook.Update", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -180,16 +180,16 @@ func DeleteGitHook(ctx *context.APIContext) {
|
||||||
hook, err := ctx.Repo.GitRepo.GetHook(hookID)
|
hook, err := ctx.Repo.GitRepo.GetHook(hookID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if errors.Is(err, git.ErrNotValidHook) {
|
if errors.Is(err, git.ErrNotValidHook) {
|
||||||
ctx.NotFound()
|
ctx.APIErrorNotFound()
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetHook", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
hook.Content = ""
|
hook.Content = ""
|
||||||
if err = hook.Update(); err != nil {
|
if err = hook.Update(); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "hook.Update", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
package repo
|
package repo
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
|
||||||
|
@ -77,12 +78,12 @@ func GetGitRefs(ctx *context.APIContext) {
|
||||||
func getGitRefsInternal(ctx *context.APIContext, filter string) {
|
func getGitRefsInternal(ctx *context.APIContext, filter string) {
|
||||||
refs, lastMethodName, err := utils.GetGitRefs(ctx, filter)
|
refs, lastMethodName, err := utils.GetGitRefs(ctx, filter)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, lastMethodName, err)
|
ctx.APIError(http.StatusInternalServerError, fmt.Errorf("%s: %w", lastMethodName, err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(refs) == 0 {
|
if len(refs) == 0 {
|
||||||
ctx.NotFound()
|
ctx.APIErrorNotFound()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -61,7 +61,7 @@ func ListHooks(ctx *context.APIContext) {
|
||||||
|
|
||||||
hooks, count, err := db.FindAndCount[webhook.Webhook](ctx, opts)
|
hooks, count, err := db.FindAndCount[webhook.Webhook](ctx, opts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.InternalServerError(err)
|
ctx.APIErrorInternal(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -69,7 +69,7 @@ func ListHooks(ctx *context.APIContext) {
|
||||||
for i := range hooks {
|
for i := range hooks {
|
||||||
apiHooks[i], err = webhook_service.ToHook(ctx.Repo.RepoLink, hooks[i])
|
apiHooks[i], err = webhook_service.ToHook(ctx.Repo.RepoLink, hooks[i])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.InternalServerError(err)
|
ctx.APIErrorInternal(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -116,7 +116,7 @@ func GetHook(ctx *context.APIContext) {
|
||||||
}
|
}
|
||||||
apiHook, err := webhook_service.ToHook(repo.RepoLink, hook)
|
apiHook, err := webhook_service.ToHook(repo.RepoLink, hook)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.InternalServerError(err)
|
ctx.APIErrorInternal(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.JSON(http.StatusOK, apiHook)
|
ctx.JSON(http.StatusOK, apiHook)
|
||||||
|
@ -189,7 +189,7 @@ func TestHook(ctx *context.APIContext) {
|
||||||
Pusher: convert.ToUserWithAccessMode(ctx, ctx.Doer, perm.AccessModeNone),
|
Pusher: convert.ToUserWithAccessMode(ctx, ctx.Doer, perm.AccessModeNone),
|
||||||
Sender: convert.ToUserWithAccessMode(ctx, ctx.Doer, perm.AccessModeNone),
|
Sender: convert.ToUserWithAccessMode(ctx, ctx.Doer, perm.AccessModeNone),
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "PrepareWebhook: ", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -298,9 +298,9 @@ func DeleteHook(ctx *context.APIContext) {
|
||||||
// "$ref": "#/responses/notFound"
|
// "$ref": "#/responses/notFound"
|
||||||
if err := webhook.DeleteWebhookByRepoID(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("id")); err != nil {
|
if err := webhook.DeleteWebhookByRepoID(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("id")); err != nil {
|
||||||
if webhook.IsErrWebhookNotExist(err) {
|
if webhook.IsErrWebhookNotExist(err) {
|
||||||
ctx.NotFound()
|
ctx.APIErrorNotFound()
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "DeleteWebhookByRepoID", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -132,7 +132,7 @@ func SearchIssues(ctx *context.APIContext) {
|
||||||
|
|
||||||
before, since, err := context.GetQueryBeforeSince(ctx.Base)
|
before, since, err := context.GetQueryBeforeSince(ctx.Base)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusUnprocessableEntity, "GetQueryBeforeSince", err)
|
ctx.APIError(http.StatusUnprocessableEntity, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -170,9 +170,9 @@ func SearchIssues(ctx *context.APIContext) {
|
||||||
owner, err := user_model.GetUserByName(ctx, ctx.FormString("owner"))
|
owner, err := user_model.GetUserByName(ctx, ctx.FormString("owner"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if user_model.IsErrUserNotExist(err) {
|
if user_model.IsErrUserNotExist(err) {
|
||||||
ctx.Error(http.StatusBadRequest, "Owner not found", err)
|
ctx.APIError(http.StatusBadRequest, err)
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetUserByName", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -183,15 +183,15 @@ func SearchIssues(ctx *context.APIContext) {
|
||||||
}
|
}
|
||||||
if ctx.FormString("team") != "" {
|
if ctx.FormString("team") != "" {
|
||||||
if ctx.FormString("owner") == "" {
|
if ctx.FormString("owner") == "" {
|
||||||
ctx.Error(http.StatusBadRequest, "", "Owner organisation is required for filtering on team")
|
ctx.APIError(http.StatusBadRequest, "Owner organisation is required for filtering on team")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
team, err := organization.GetTeam(ctx, opts.OwnerID, ctx.FormString("team"))
|
team, err := organization.GetTeam(ctx, opts.OwnerID, ctx.FormString("team"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if organization.IsErrTeamNotExist(err) {
|
if organization.IsErrTeamNotExist(err) {
|
||||||
ctx.Error(http.StatusBadRequest, "Team not found", err)
|
ctx.APIError(http.StatusBadRequest, err)
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetUserByName", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -204,7 +204,7 @@ func SearchIssues(ctx *context.APIContext) {
|
||||||
}
|
}
|
||||||
repoIDs, _, err = repo_model.SearchRepositoryIDs(ctx, opts)
|
repoIDs, _, err = repo_model.SearchRepositoryIDs(ctx, opts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "SearchRepositoryIDs", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if len(repoIDs) == 0 {
|
if len(repoIDs) == 0 {
|
||||||
|
@ -237,7 +237,7 @@ func SearchIssues(ctx *context.APIContext) {
|
||||||
}
|
}
|
||||||
includedAnyLabels, err = issues_model.GetLabelIDsByNames(ctx, includedLabelNames)
|
includedAnyLabels, err = issues_model.GetLabelIDsByNames(ctx, includedLabelNames)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetLabelIDsByNames", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -251,7 +251,7 @@ func SearchIssues(ctx *context.APIContext) {
|
||||||
}
|
}
|
||||||
includedMilestones, err = issues_model.GetMilestoneIDsByNames(ctx, includedMilestoneNames)
|
includedMilestones, err = issues_model.GetMilestoneIDsByNames(ctx, includedMilestoneNames)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetMilestoneIDsByNames", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -312,12 +312,12 @@ func SearchIssues(ctx *context.APIContext) {
|
||||||
|
|
||||||
ids, total, err := issue_indexer.SearchIssues(ctx, searchOpt)
|
ids, total, err := issue_indexer.SearchIssues(ctx, searchOpt)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "SearchIssues", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
issues, err := issues_model.GetIssuesByIDs(ctx, ids, true)
|
issues, err := issues_model.GetIssuesByIDs(ctx, ids, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "FindIssuesByIDs", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -405,7 +405,7 @@ func ListIssues(ctx *context.APIContext) {
|
||||||
// "$ref": "#/responses/notFound"
|
// "$ref": "#/responses/notFound"
|
||||||
before, since, err := context.GetQueryBeforeSince(ctx.Base)
|
before, since, err := context.GetQueryBeforeSince(ctx.Base)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusUnprocessableEntity, "GetQueryBeforeSince", err)
|
ctx.APIError(http.StatusUnprocessableEntity, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -428,7 +428,7 @@ func ListIssues(ctx *context.APIContext) {
|
||||||
if splitted := strings.Split(ctx.FormString("labels"), ","); len(splitted) > 0 {
|
if splitted := strings.Split(ctx.FormString("labels"), ","); len(splitted) > 0 {
|
||||||
labelIDs, err = issues_model.GetLabelIDsInRepoByNames(ctx, ctx.Repo.Repository.ID, splitted)
|
labelIDs, err = issues_model.GetLabelIDsInRepoByNames(ctx, ctx.Repo.Repository.ID, splitted)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetLabelIDsInRepoByNames", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -444,7 +444,7 @@ func ListIssues(ctx *context.APIContext) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if !issues_model.IsErrMilestoneNotExist(err) {
|
if !issues_model.IsErrMilestoneNotExist(err) {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetMilestoneByRepoIDANDName", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
id, err := strconv.ParseInt(part[i], 10, 64)
|
id, err := strconv.ParseInt(part[i], 10, 64)
|
||||||
|
@ -459,7 +459,7 @@ func ListIssues(ctx *context.APIContext) {
|
||||||
if issues_model.IsErrMilestoneNotExist(err) {
|
if issues_model.IsErrMilestoneNotExist(err) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
ctx.Error(http.StatusInternalServerError, "GetMilestoneByRepoID", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -474,7 +474,7 @@ func ListIssues(ctx *context.APIContext) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if isPull.Has() && !ctx.Repo.CanReadIssuesOrPulls(isPull.Value()) {
|
if isPull.Has() && !ctx.Repo.CanReadIssuesOrPulls(isPull.Value()) {
|
||||||
ctx.NotFound()
|
ctx.APIErrorNotFound()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -482,7 +482,7 @@ func ListIssues(ctx *context.APIContext) {
|
||||||
canReadIssues := ctx.Repo.CanRead(unit.TypeIssues)
|
canReadIssues := ctx.Repo.CanRead(unit.TypeIssues)
|
||||||
canReadPulls := ctx.Repo.CanRead(unit.TypePullRequests)
|
canReadPulls := ctx.Repo.CanRead(unit.TypePullRequests)
|
||||||
if !canReadIssues && !canReadPulls {
|
if !canReadIssues && !canReadPulls {
|
||||||
ctx.NotFound()
|
ctx.APIErrorNotFound()
|
||||||
return
|
return
|
||||||
} else if !canReadIssues {
|
} else if !canReadIssues {
|
||||||
isPull = optional.Some(true)
|
isPull = optional.Some(true)
|
||||||
|
@ -549,12 +549,12 @@ func ListIssues(ctx *context.APIContext) {
|
||||||
|
|
||||||
ids, total, err := issue_indexer.SearchIssues(ctx, searchOpt)
|
ids, total, err := issue_indexer.SearchIssues(ctx, searchOpt)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "SearchIssues", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
issues, err := issues_model.GetIssuesByIDs(ctx, ids, true)
|
issues, err := issues_model.GetIssuesByIDs(ctx, ids, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "FindIssuesByIDs", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -571,12 +571,12 @@ func getUserIDForFilter(ctx *context.APIContext, queryName string) int64 {
|
||||||
|
|
||||||
user, err := user_model.GetUserByName(ctx, userName)
|
user, err := user_model.GetUserByName(ctx, userName)
|
||||||
if user_model.IsErrUserNotExist(err) {
|
if user_model.IsErrUserNotExist(err) {
|
||||||
ctx.NotFound(err)
|
ctx.APIErrorNotFound(err)
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.InternalServerError(err)
|
ctx.APIErrorInternal(err)
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -616,14 +616,14 @@ func GetIssue(ctx *context.APIContext) {
|
||||||
issue, err := issues_model.GetIssueWithAttrsByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("index"))
|
issue, err := issues_model.GetIssueWithAttrsByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("index"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if issues_model.IsErrIssueNotExist(err) {
|
if issues_model.IsErrIssueNotExist(err) {
|
||||||
ctx.NotFound()
|
ctx.APIErrorNotFound()
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetIssueByIndex", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if !ctx.Repo.CanReadIssuesOrPulls(issue.IsPull) {
|
if !ctx.Repo.CanReadIssuesOrPulls(issue.IsPull) {
|
||||||
ctx.NotFound()
|
ctx.APIErrorNotFound()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.JSON(http.StatusOK, convert.ToAPIIssue(ctx, ctx.Doer, issue))
|
ctx.JSON(http.StatusOK, convert.ToAPIIssue(ctx, ctx.Doer, issue))
|
||||||
|
@ -691,9 +691,9 @@ func CreateIssue(ctx *context.APIContext) {
|
||||||
assigneeIDs, err = issues_model.MakeIDsFromAPIAssigneesToAdd(ctx, form.Assignee, form.Assignees)
|
assigneeIDs, err = issues_model.MakeIDsFromAPIAssigneesToAdd(ctx, form.Assignee, form.Assignees)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if user_model.IsErrUserNotExist(err) {
|
if user_model.IsErrUserNotExist(err) {
|
||||||
ctx.Error(http.StatusUnprocessableEntity, "", fmt.Sprintf("Assignee does not exist: [name: %s]", err))
|
ctx.APIError(http.StatusUnprocessableEntity, fmt.Sprintf("Assignee does not exist: [name: %s]", err))
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "AddAssigneeByName", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -702,17 +702,17 @@ func CreateIssue(ctx *context.APIContext) {
|
||||||
for _, aID := range assigneeIDs {
|
for _, aID := range assigneeIDs {
|
||||||
assignee, err := user_model.GetUserByID(ctx, aID)
|
assignee, err := user_model.GetUserByID(ctx, aID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetUserByID", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
valid, err := access_model.CanBeAssigned(ctx, assignee, ctx.Repo.Repository, false)
|
valid, err := access_model.CanBeAssigned(ctx, assignee, ctx.Repo.Repository, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "canBeAssigned", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if !valid {
|
if !valid {
|
||||||
ctx.Error(http.StatusUnprocessableEntity, "canBeAssigned", repo_model.ErrUserDoesNotHaveAccessToRepo{UserID: aID, RepoName: ctx.Repo.Repository.Name})
|
ctx.APIError(http.StatusUnprocessableEntity, repo_model.ErrUserDoesNotHaveAccessToRepo{UserID: aID, RepoName: ctx.Repo.Repository.Name})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -723,11 +723,11 @@ func CreateIssue(ctx *context.APIContext) {
|
||||||
|
|
||||||
if err := issue_service.NewIssue(ctx, ctx.Repo.Repository, issue, form.Labels, nil, assigneeIDs, 0); err != nil {
|
if err := issue_service.NewIssue(ctx, ctx.Repo.Repository, issue, form.Labels, nil, assigneeIDs, 0); err != nil {
|
||||||
if repo_model.IsErrUserDoesNotHaveAccessToRepo(err) {
|
if repo_model.IsErrUserDoesNotHaveAccessToRepo(err) {
|
||||||
ctx.Error(http.StatusBadRequest, "UserDoesNotHaveAccessToRepo", err)
|
ctx.APIError(http.StatusBadRequest, err)
|
||||||
} else if errors.Is(err, user_model.ErrBlockedUser) {
|
} else if errors.Is(err, user_model.ErrBlockedUser) {
|
||||||
ctx.Error(http.StatusForbidden, "NewIssue", err)
|
ctx.APIError(http.StatusForbidden, err)
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "NewIssue", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -735,10 +735,10 @@ func CreateIssue(ctx *context.APIContext) {
|
||||||
if form.Closed {
|
if form.Closed {
|
||||||
if err := issue_service.CloseIssue(ctx, issue, ctx.Doer, ""); err != nil {
|
if err := issue_service.CloseIssue(ctx, issue, ctx.Doer, ""); err != nil {
|
||||||
if issues_model.IsErrDependenciesLeft(err) {
|
if issues_model.IsErrDependenciesLeft(err) {
|
||||||
ctx.Error(http.StatusPreconditionFailed, "DependenciesLeft", "cannot close this issue because it still has open dependencies")
|
ctx.APIError(http.StatusPreconditionFailed, "cannot close this issue because it still has open dependencies")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.Error(http.StatusInternalServerError, "ChangeStatus", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -746,7 +746,7 @@ func CreateIssue(ctx *context.APIContext) {
|
||||||
// Refetch from database to assign some automatic values
|
// Refetch from database to assign some automatic values
|
||||||
issue, err = issues_model.GetIssueByID(ctx, issue.ID)
|
issue, err = issues_model.GetIssueByID(ctx, issue.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetIssueByID", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.JSON(http.StatusCreated, convert.ToAPIIssue(ctx, ctx.Doer, issue))
|
ctx.JSON(http.StatusCreated, convert.ToAPIIssue(ctx, ctx.Doer, issue))
|
||||||
|
@ -796,9 +796,9 @@ func EditIssue(ctx *context.APIContext) {
|
||||||
issue, err := issues_model.GetIssueByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("index"))
|
issue, err := issues_model.GetIssueByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("index"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if issues_model.IsErrIssueNotExist(err) {
|
if issues_model.IsErrIssueNotExist(err) {
|
||||||
ctx.NotFound()
|
ctx.APIErrorNotFound()
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetIssueByIndex", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -807,7 +807,7 @@ func EditIssue(ctx *context.APIContext) {
|
||||||
|
|
||||||
err = issue.LoadAttributes(ctx)
|
err = issue.LoadAttributes(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "LoadAttributes", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -819,7 +819,7 @@ func EditIssue(ctx *context.APIContext) {
|
||||||
if len(form.Title) > 0 {
|
if len(form.Title) > 0 {
|
||||||
err = issue_service.ChangeTitle(ctx, issue, ctx.Doer, form.Title)
|
err = issue_service.ChangeTitle(ctx, issue, ctx.Doer, form.Title)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "ChangeTitle", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -827,18 +827,18 @@ func EditIssue(ctx *context.APIContext) {
|
||||||
err = issue_service.ChangeContent(ctx, issue, ctx.Doer, *form.Body, issue.ContentVersion)
|
err = issue_service.ChangeContent(ctx, issue, ctx.Doer, *form.Body, issue.ContentVersion)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if errors.Is(err, issues_model.ErrIssueAlreadyChanged) {
|
if errors.Is(err, issues_model.ErrIssueAlreadyChanged) {
|
||||||
ctx.Error(http.StatusBadRequest, "ChangeContent", err)
|
ctx.APIError(http.StatusBadRequest, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.Error(http.StatusInternalServerError, "ChangeContent", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if form.Ref != nil {
|
if form.Ref != nil {
|
||||||
err = issue_service.ChangeIssueRef(ctx, issue, ctx.Doer, *form.Ref)
|
err = issue_service.ChangeIssueRef(ctx, issue, ctx.Doer, *form.Ref)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "UpdateRef", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -849,7 +849,7 @@ func EditIssue(ctx *context.APIContext) {
|
||||||
|
|
||||||
if form.RemoveDeadline == nil || !*form.RemoveDeadline {
|
if form.RemoveDeadline == nil || !*form.RemoveDeadline {
|
||||||
if form.Deadline == nil {
|
if form.Deadline == nil {
|
||||||
ctx.Error(http.StatusBadRequest, "", "The due_date cannot be empty")
|
ctx.APIError(http.StatusBadRequest, "The due_date cannot be empty")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if !form.Deadline.IsZero() {
|
if !form.Deadline.IsZero() {
|
||||||
|
@ -860,7 +860,7 @@ func EditIssue(ctx *context.APIContext) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := issues_model.UpdateIssueDeadline(ctx, issue, deadlineUnix, ctx.Doer); err != nil {
|
if err := issues_model.UpdateIssueDeadline(ctx, issue, deadlineUnix, ctx.Doer); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "UpdateIssueDeadline", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
issue.DeadlineUnix = deadlineUnix
|
issue.DeadlineUnix = deadlineUnix
|
||||||
|
@ -883,9 +883,9 @@ func EditIssue(ctx *context.APIContext) {
|
||||||
err = issue_service.UpdateAssignees(ctx, issue, oneAssignee, form.Assignees, ctx.Doer)
|
err = issue_service.UpdateAssignees(ctx, issue, oneAssignee, form.Assignees, ctx.Doer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if errors.Is(err, user_model.ErrBlockedUser) {
|
if errors.Is(err, user_model.ErrBlockedUser) {
|
||||||
ctx.Error(http.StatusForbidden, "UpdateAssignees", err)
|
ctx.APIError(http.StatusForbidden, err)
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "UpdateAssignees", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -896,18 +896,18 @@ func EditIssue(ctx *context.APIContext) {
|
||||||
oldMilestoneID := issue.MilestoneID
|
oldMilestoneID := issue.MilestoneID
|
||||||
issue.MilestoneID = *form.Milestone
|
issue.MilestoneID = *form.Milestone
|
||||||
if err = issue_service.ChangeMilestoneAssign(ctx, issue, ctx.Doer, oldMilestoneID); err != nil {
|
if err = issue_service.ChangeMilestoneAssign(ctx, issue, ctx.Doer, oldMilestoneID); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "ChangeMilestoneAssign", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if form.State != nil {
|
if form.State != nil {
|
||||||
if issue.IsPull {
|
if issue.IsPull {
|
||||||
if err := issue.LoadPullRequest(ctx); err != nil {
|
if err := issue.LoadPullRequest(ctx); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetPullRequest", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if issue.PullRequest.HasMerged {
|
if issue.PullRequest.HasMerged {
|
||||||
ctx.Error(http.StatusPreconditionFailed, "MergedPRState", "cannot change state of this pull request, it was already merged")
|
ctx.APIError(http.StatusPreconditionFailed, "cannot change state of this pull request, it was already merged")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -922,11 +922,11 @@ func EditIssue(ctx *context.APIContext) {
|
||||||
// Refetch from database to assign some automatic values
|
// Refetch from database to assign some automatic values
|
||||||
issue, err = issues_model.GetIssueByID(ctx, issue.ID)
|
issue, err = issues_model.GetIssueByID(ctx, issue.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.InternalServerError(err)
|
ctx.APIErrorInternal(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if err = issue.LoadMilestone(ctx); err != nil {
|
if err = issue.LoadMilestone(ctx); err != nil {
|
||||||
ctx.InternalServerError(err)
|
ctx.APIErrorInternal(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.JSON(http.StatusCreated, convert.ToAPIIssue(ctx, ctx.Doer, issue))
|
ctx.JSON(http.StatusCreated, convert.ToAPIIssue(ctx, ctx.Doer, issue))
|
||||||
|
@ -963,15 +963,15 @@ func DeleteIssue(ctx *context.APIContext) {
|
||||||
issue, err := issues_model.GetIssueByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("index"))
|
issue, err := issues_model.GetIssueByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("index"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if issues_model.IsErrIssueNotExist(err) {
|
if issues_model.IsErrIssueNotExist(err) {
|
||||||
ctx.NotFound(err)
|
ctx.APIErrorNotFound(err)
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetIssueByID", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = issue_service.DeleteIssue(ctx, ctx.Doer, ctx.Repo.GitRepo, issue); err != nil {
|
if err = issue_service.DeleteIssue(ctx, ctx.Doer, ctx.Repo.GitRepo, issue); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "DeleteIssueByID", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1019,21 +1019,21 @@ func UpdateIssueDeadline(ctx *context.APIContext) {
|
||||||
issue, err := issues_model.GetIssueByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("index"))
|
issue, err := issues_model.GetIssueByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("index"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if issues_model.IsErrIssueNotExist(err) {
|
if issues_model.IsErrIssueNotExist(err) {
|
||||||
ctx.NotFound()
|
ctx.APIErrorNotFound()
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetIssueByIndex", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if !ctx.Repo.CanWriteIssuesOrPulls(issue.IsPull) {
|
if !ctx.Repo.CanWriteIssuesOrPulls(issue.IsPull) {
|
||||||
ctx.Error(http.StatusForbidden, "", "Not repo writer")
|
ctx.APIError(http.StatusForbidden, "Not repo writer")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
deadlineUnix, _ := common.ParseAPIDeadlineToEndOfDay(form.Deadline)
|
deadlineUnix, _ := common.ParseAPIDeadlineToEndOfDay(form.Deadline)
|
||||||
if err := issues_model.UpdateIssueDeadline(ctx, issue, deadlineUnix, ctx.Doer); err != nil {
|
if err := issues_model.UpdateIssueDeadline(ctx, issue, deadlineUnix, ctx.Doer); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "UpdateIssueDeadline", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1042,22 +1042,22 @@ func UpdateIssueDeadline(ctx *context.APIContext) {
|
||||||
|
|
||||||
func closeOrReopenIssue(ctx *context.APIContext, issue *issues_model.Issue, state api.StateType) {
|
func closeOrReopenIssue(ctx *context.APIContext, issue *issues_model.Issue, state api.StateType) {
|
||||||
if state != api.StateOpen && state != api.StateClosed {
|
if state != api.StateOpen && state != api.StateClosed {
|
||||||
ctx.Error(http.StatusPreconditionFailed, "UnknownIssueStateError", fmt.Sprintf("unknown state: %s", state))
|
ctx.APIError(http.StatusPreconditionFailed, fmt.Sprintf("unknown state: %s", state))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if state == api.StateClosed && !issue.IsClosed {
|
if state == api.StateClosed && !issue.IsClosed {
|
||||||
if err := issue_service.CloseIssue(ctx, issue, ctx.Doer, ""); err != nil {
|
if err := issue_service.CloseIssue(ctx, issue, ctx.Doer, ""); err != nil {
|
||||||
if issues_model.IsErrDependenciesLeft(err) {
|
if issues_model.IsErrDependenciesLeft(err) {
|
||||||
ctx.Error(http.StatusPreconditionFailed, "DependenciesLeft", "cannot close this issue or pull request because it still has open dependencies")
|
ctx.APIError(http.StatusPreconditionFailed, "cannot close this issue or pull request because it still has open dependencies")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.Error(http.StatusInternalServerError, "CloseIssue", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
} else if state == api.StateOpen && issue.IsClosed {
|
} else if state == api.StateOpen && issue.IsClosed {
|
||||||
if err := issue_service.ReopenIssue(ctx, issue, ctx.Doer, ""); err != nil {
|
if err := issue_service.ReopenIssue(ctx, issue, ctx.Doer, ""); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "ReopenIssue", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -104,7 +104,7 @@ func ListIssueAttachments(ctx *context.APIContext) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := issue.LoadAttributes(ctx); err != nil {
|
if err := issue.LoadAttributes(ctx); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "LoadAttributes", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -171,7 +171,7 @@ func CreateIssueAttachment(ctx *context.APIContext) {
|
||||||
// Get uploaded file from request
|
// Get uploaded file from request
|
||||||
file, header, err := ctx.Req.FormFile("attachment")
|
file, header, err := ctx.Req.FormFile("attachment")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "FormFile", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
defer file.Close()
|
defer file.Close()
|
||||||
|
@ -189,9 +189,9 @@ func CreateIssueAttachment(ctx *context.APIContext) {
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if upload.IsErrFileTypeForbidden(err) {
|
if upload.IsErrFileTypeForbidden(err) {
|
||||||
ctx.Error(http.StatusUnprocessableEntity, "", err)
|
ctx.APIError(http.StatusUnprocessableEntity, err)
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "UploadAttachment", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -199,7 +199,7 @@ func CreateIssueAttachment(ctx *context.APIContext) {
|
||||||
issue.Attachments = append(issue.Attachments, attachment)
|
issue.Attachments = append(issue.Attachments, attachment)
|
||||||
|
|
||||||
if err := issue_service.ChangeContent(ctx, issue, ctx.Doer, issue.Content, issue.ContentVersion); err != nil {
|
if err := issue_service.ChangeContent(ctx, issue, ctx.Doer, issue.Content, issue.ContentVersion); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "ChangeContent", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -265,10 +265,10 @@ func EditIssueAttachment(ctx *context.APIContext) {
|
||||||
|
|
||||||
if err := attachment_service.UpdateAttachment(ctx, setting.Attachment.AllowedTypes, attachment); err != nil {
|
if err := attachment_service.UpdateAttachment(ctx, setting.Attachment.AllowedTypes, attachment); err != nil {
|
||||||
if upload.IsErrFileTypeForbidden(err) {
|
if upload.IsErrFileTypeForbidden(err) {
|
||||||
ctx.Error(http.StatusUnprocessableEntity, "", err)
|
ctx.APIError(http.StatusUnprocessableEntity, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.Error(http.StatusInternalServerError, "UpdateAttachment", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -319,7 +319,7 @@ func DeleteIssueAttachment(ctx *context.APIContext) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := repo_model.DeleteAttachment(ctx, attachment, true); err != nil {
|
if err := repo_model.DeleteAttachment(ctx, attachment, true); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "DeleteAttachment", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -366,7 +366,7 @@ func getIssueAttachmentSafeRead(ctx *context.APIContext, issue *issues_model.Iss
|
||||||
func canUserWriteIssueAttachment(ctx *context.APIContext, issue *issues_model.Issue) bool {
|
func canUserWriteIssueAttachment(ctx *context.APIContext, issue *issues_model.Issue) bool {
|
||||||
canEditIssue := ctx.IsSigned && (ctx.Doer.ID == issue.PosterID || ctx.IsUserRepoAdmin() || ctx.IsUserSiteAdmin() || ctx.Repo.CanWriteIssuesOrPulls(issue.IsPull))
|
canEditIssue := ctx.IsSigned && (ctx.Doer.ID == issue.PosterID || ctx.IsUserRepoAdmin() || ctx.IsUserSiteAdmin() || ctx.Repo.CanWriteIssuesOrPulls(issue.IsPull))
|
||||||
if !canEditIssue {
|
if !canEditIssue {
|
||||||
ctx.Error(http.StatusForbidden, "", "user should have permission to write issue")
|
ctx.APIError(http.StatusForbidden, "user should have permission to write issue")
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -376,16 +376,16 @@ func canUserWriteIssueAttachment(ctx *context.APIContext, issue *issues_model.Is
|
||||||
func attachmentBelongsToRepoOrIssue(ctx *context.APIContext, attachment *repo_model.Attachment, issue *issues_model.Issue) bool {
|
func attachmentBelongsToRepoOrIssue(ctx *context.APIContext, attachment *repo_model.Attachment, issue *issues_model.Issue) bool {
|
||||||
if attachment.RepoID != ctx.Repo.Repository.ID {
|
if attachment.RepoID != ctx.Repo.Repository.ID {
|
||||||
log.Debug("Requested attachment[%d] does not belong to repo[%-v].", attachment.ID, ctx.Repo.Repository)
|
log.Debug("Requested attachment[%d] does not belong to repo[%-v].", attachment.ID, ctx.Repo.Repository)
|
||||||
ctx.NotFound("no such attachment in repo")
|
ctx.APIErrorNotFound("no such attachment in repo")
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
if attachment.IssueID == 0 {
|
if attachment.IssueID == 0 {
|
||||||
log.Debug("Requested attachment[%d] is not in an issue.", attachment.ID)
|
log.Debug("Requested attachment[%d] is not in an issue.", attachment.ID)
|
||||||
ctx.NotFound("no such attachment in issue")
|
ctx.APIErrorNotFound("no such attachment in issue")
|
||||||
return false
|
return false
|
||||||
} else if issue != nil && attachment.IssueID != issue.ID {
|
} else if issue != nil && attachment.IssueID != issue.ID {
|
||||||
log.Debug("Requested attachment[%d] does not belong to issue[%d, #%d].", attachment.ID, issue.ID, issue.Index)
|
log.Debug("Requested attachment[%d] does not belong to issue[%d, #%d].", attachment.ID, issue.ID, issue.Index)
|
||||||
ctx.NotFound("no such attachment in issue")
|
ctx.APIErrorNotFound("no such attachment in issue")
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
|
|
|
@ -65,16 +65,16 @@ func ListIssueComments(ctx *context.APIContext) {
|
||||||
|
|
||||||
before, since, err := context.GetQueryBeforeSince(ctx.Base)
|
before, since, err := context.GetQueryBeforeSince(ctx.Base)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusUnprocessableEntity, "GetQueryBeforeSince", err)
|
ctx.APIError(http.StatusUnprocessableEntity, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
issue, err := issues_model.GetIssueByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("index"))
|
issue, err := issues_model.GetIssueByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("index"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetRawIssueByIndex", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if !ctx.Repo.CanReadIssuesOrPulls(issue.IsPull) {
|
if !ctx.Repo.CanReadIssuesOrPulls(issue.IsPull) {
|
||||||
ctx.NotFound()
|
ctx.APIErrorNotFound()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -89,23 +89,23 @@ func ListIssueComments(ctx *context.APIContext) {
|
||||||
|
|
||||||
comments, err := issues_model.FindComments(ctx, opts)
|
comments, err := issues_model.FindComments(ctx, opts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "FindComments", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
totalCount, err := issues_model.CountComments(ctx, opts)
|
totalCount, err := issues_model.CountComments(ctx, opts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.InternalServerError(err)
|
ctx.APIErrorInternal(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := comments.LoadPosters(ctx); err != nil {
|
if err := comments.LoadPosters(ctx); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "LoadPosters", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := comments.LoadAttachments(ctx); err != nil {
|
if err := comments.LoadAttachments(ctx); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "LoadAttachments", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -169,12 +169,12 @@ func ListIssueCommentsAndTimeline(ctx *context.APIContext) {
|
||||||
|
|
||||||
before, since, err := context.GetQueryBeforeSince(ctx.Base)
|
before, since, err := context.GetQueryBeforeSince(ctx.Base)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusUnprocessableEntity, "GetQueryBeforeSince", err)
|
ctx.APIError(http.StatusUnprocessableEntity, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
issue, err := issues_model.GetIssueByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("index"))
|
issue, err := issues_model.GetIssueByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("index"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetRawIssueByIndex", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
issue.Repo = ctx.Repo.Repository
|
issue.Repo = ctx.Repo.Repository
|
||||||
|
@ -189,12 +189,12 @@ func ListIssueCommentsAndTimeline(ctx *context.APIContext) {
|
||||||
|
|
||||||
comments, err := issues_model.FindComments(ctx, opts)
|
comments, err := issues_model.FindComments(ctx, opts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "FindComments", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := comments.LoadPosters(ctx); err != nil {
|
if err := comments.LoadPosters(ctx); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "LoadPosters", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -274,7 +274,7 @@ func ListRepoIssueComments(ctx *context.APIContext) {
|
||||||
|
|
||||||
before, since, err := context.GetQueryBeforeSince(ctx.Base)
|
before, since, err := context.GetQueryBeforeSince(ctx.Base)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusUnprocessableEntity, "GetQueryBeforeSince", err)
|
ctx.APIError(http.StatusUnprocessableEntity, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -288,7 +288,7 @@ func ListRepoIssueComments(ctx *context.APIContext) {
|
||||||
} else if canReadPull {
|
} else if canReadPull {
|
||||||
isPull = optional.Some(true)
|
isPull = optional.Some(true)
|
||||||
} else {
|
} else {
|
||||||
ctx.NotFound()
|
ctx.APIErrorNotFound()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -303,32 +303,32 @@ func ListRepoIssueComments(ctx *context.APIContext) {
|
||||||
|
|
||||||
comments, err := issues_model.FindComments(ctx, opts)
|
comments, err := issues_model.FindComments(ctx, opts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "FindComments", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
totalCount, err := issues_model.CountComments(ctx, opts)
|
totalCount, err := issues_model.CountComments(ctx, opts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.InternalServerError(err)
|
ctx.APIErrorInternal(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = comments.LoadPosters(ctx); err != nil {
|
if err = comments.LoadPosters(ctx); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "LoadPosters", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
apiComments := make([]*api.Comment, len(comments))
|
apiComments := make([]*api.Comment, len(comments))
|
||||||
if err := comments.LoadIssues(ctx); err != nil {
|
if err := comments.LoadIssues(ctx); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "LoadIssues", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if err := comments.LoadAttachments(ctx); err != nil {
|
if err := comments.LoadAttachments(ctx); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "LoadAttachments", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if _, err := comments.Issues().LoadRepositories(ctx); err != nil {
|
if _, err := comments.Issues().LoadRepositories(ctx); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "LoadRepositories", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
for i := range comments {
|
for i := range comments {
|
||||||
|
@ -382,26 +382,26 @@ func CreateIssueComment(ctx *context.APIContext) {
|
||||||
form := web.GetForm(ctx).(*api.CreateIssueCommentOption)
|
form := web.GetForm(ctx).(*api.CreateIssueCommentOption)
|
||||||
issue, err := issues_model.GetIssueByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("index"))
|
issue, err := issues_model.GetIssueByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("index"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetIssueByIndex", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if !ctx.Repo.CanReadIssuesOrPulls(issue.IsPull) {
|
if !ctx.Repo.CanReadIssuesOrPulls(issue.IsPull) {
|
||||||
ctx.NotFound()
|
ctx.APIErrorNotFound()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if issue.IsLocked && !ctx.Repo.CanWriteIssuesOrPulls(issue.IsPull) && !ctx.Doer.IsAdmin {
|
if issue.IsLocked && !ctx.Repo.CanWriteIssuesOrPulls(issue.IsPull) && !ctx.Doer.IsAdmin {
|
||||||
ctx.Error(http.StatusForbidden, "CreateIssueComment", errors.New(ctx.Locale.TrString("repo.issues.comment_on_locked")))
|
ctx.APIError(http.StatusForbidden, errors.New(ctx.Locale.TrString("repo.issues.comment_on_locked")))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
comment, err := issue_service.CreateIssueComment(ctx, ctx.Doer, ctx.Repo.Repository, issue, form.Body, nil)
|
comment, err := issue_service.CreateIssueComment(ctx, ctx.Doer, ctx.Repo.Repository, issue, form.Body, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if errors.Is(err, user_model.ErrBlockedUser) {
|
if errors.Is(err, user_model.ErrBlockedUser) {
|
||||||
ctx.Error(http.StatusForbidden, "CreateIssueComment", err)
|
ctx.APIError(http.StatusForbidden, err)
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "CreateIssueComment", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -448,15 +448,15 @@ func GetIssueComment(ctx *context.APIContext) {
|
||||||
comment, err := issues_model.GetCommentByID(ctx, ctx.PathParamInt64("id"))
|
comment, err := issues_model.GetCommentByID(ctx, ctx.PathParamInt64("id"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if issues_model.IsErrCommentNotExist(err) {
|
if issues_model.IsErrCommentNotExist(err) {
|
||||||
ctx.NotFound(err)
|
ctx.APIErrorNotFound(err)
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetCommentByID", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = comment.LoadIssue(ctx); err != nil {
|
if err = comment.LoadIssue(ctx); err != nil {
|
||||||
ctx.InternalServerError(err)
|
ctx.APIErrorInternal(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if comment.Issue.RepoID != ctx.Repo.Repository.ID {
|
if comment.Issue.RepoID != ctx.Repo.Repository.ID {
|
||||||
|
@ -465,7 +465,7 @@ func GetIssueComment(ctx *context.APIContext) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if !ctx.Repo.CanReadIssuesOrPulls(comment.Issue.IsPull) {
|
if !ctx.Repo.CanReadIssuesOrPulls(comment.Issue.IsPull) {
|
||||||
ctx.NotFound()
|
ctx.APIErrorNotFound()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -475,7 +475,7 @@ func GetIssueComment(ctx *context.APIContext) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := comment.LoadPoster(ctx); err != nil {
|
if err := comment.LoadPoster(ctx); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "comment.LoadPoster", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -582,15 +582,15 @@ func editIssueComment(ctx *context.APIContext, form api.EditIssueCommentOption)
|
||||||
comment, err := issues_model.GetCommentByID(ctx, ctx.PathParamInt64("id"))
|
comment, err := issues_model.GetCommentByID(ctx, ctx.PathParamInt64("id"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if issues_model.IsErrCommentNotExist(err) {
|
if issues_model.IsErrCommentNotExist(err) {
|
||||||
ctx.NotFound(err)
|
ctx.APIErrorNotFound(err)
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetCommentByID", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := comment.LoadIssue(ctx); err != nil {
|
if err := comment.LoadIssue(ctx); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "LoadIssue", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -613,9 +613,9 @@ func editIssueComment(ctx *context.APIContext, form api.EditIssueCommentOption)
|
||||||
comment.Content = form.Body
|
comment.Content = form.Body
|
||||||
if err := issue_service.UpdateComment(ctx, comment, comment.ContentVersion, ctx.Doer, oldContent); err != nil {
|
if err := issue_service.UpdateComment(ctx, comment, comment.ContentVersion, ctx.Doer, oldContent); err != nil {
|
||||||
if errors.Is(err, user_model.ErrBlockedUser) {
|
if errors.Is(err, user_model.ErrBlockedUser) {
|
||||||
ctx.Error(http.StatusForbidden, "UpdateComment", err)
|
ctx.APIError(http.StatusForbidden, err)
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "UpdateComment", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -699,15 +699,15 @@ func deleteIssueComment(ctx *context.APIContext) {
|
||||||
comment, err := issues_model.GetCommentByID(ctx, ctx.PathParamInt64("id"))
|
comment, err := issues_model.GetCommentByID(ctx, ctx.PathParamInt64("id"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if issues_model.IsErrCommentNotExist(err) {
|
if issues_model.IsErrCommentNotExist(err) {
|
||||||
ctx.NotFound(err)
|
ctx.APIErrorNotFound(err)
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetCommentByID", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := comment.LoadIssue(ctx); err != nil {
|
if err := comment.LoadIssue(ctx); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "LoadIssue", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -725,7 +725,7 @@ func deleteIssueComment(ctx *context.APIContext) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = issue_service.DeleteComment(ctx, ctx.Doer, comment); err != nil {
|
if err = issue_service.DeleteComment(ctx, ctx.Doer, comment); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "DeleteCommentByID", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -67,7 +67,7 @@ func GetIssueCommentAttachment(ctx *context.APIContext) {
|
||||||
}
|
}
|
||||||
if attachment.CommentID != comment.ID {
|
if attachment.CommentID != comment.ID {
|
||||||
log.Debug("User requested attachment[%d] is not in comment[%d].", attachment.ID, comment.ID)
|
log.Debug("User requested attachment[%d] is not in comment[%d].", attachment.ID, comment.ID)
|
||||||
ctx.NotFound("attachment not in comment")
|
ctx.APIErrorNotFound("attachment not in comment")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -109,7 +109,7 @@ func ListIssueCommentAttachments(ctx *context.APIContext) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := comment.LoadAttachments(ctx); err != nil {
|
if err := comment.LoadAttachments(ctx); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "LoadAttachments", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -179,7 +179,7 @@ func CreateIssueCommentAttachment(ctx *context.APIContext) {
|
||||||
// Get uploaded file from request
|
// Get uploaded file from request
|
||||||
file, header, err := ctx.Req.FormFile("attachment")
|
file, header, err := ctx.Req.FormFile("attachment")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "FormFile", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
defer file.Close()
|
defer file.Close()
|
||||||
|
@ -198,23 +198,23 @@ func CreateIssueCommentAttachment(ctx *context.APIContext) {
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if upload.IsErrFileTypeForbidden(err) {
|
if upload.IsErrFileTypeForbidden(err) {
|
||||||
ctx.Error(http.StatusUnprocessableEntity, "", err)
|
ctx.APIError(http.StatusUnprocessableEntity, err)
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "UploadAttachment", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := comment.LoadAttachments(ctx); err != nil {
|
if err := comment.LoadAttachments(ctx); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "LoadAttachments", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = issue_service.UpdateComment(ctx, comment, comment.ContentVersion, ctx.Doer, comment.Content); err != nil {
|
if err = issue_service.UpdateComment(ctx, comment, comment.ContentVersion, ctx.Doer, comment.Content); err != nil {
|
||||||
if errors.Is(err, user_model.ErrBlockedUser) {
|
if errors.Is(err, user_model.ErrBlockedUser) {
|
||||||
ctx.Error(http.StatusForbidden, "UpdateComment", err)
|
ctx.APIError(http.StatusForbidden, err)
|
||||||
} else {
|
} else {
|
||||||
ctx.ServerError("UpdateComment", err)
|
ctx.APIErrorInternal(err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -279,10 +279,10 @@ func EditIssueCommentAttachment(ctx *context.APIContext) {
|
||||||
|
|
||||||
if err := attachment_service.UpdateAttachment(ctx, setting.Attachment.AllowedTypes, attach); err != nil {
|
if err := attachment_service.UpdateAttachment(ctx, setting.Attachment.AllowedTypes, attach); err != nil {
|
||||||
if upload.IsErrFileTypeForbidden(err) {
|
if upload.IsErrFileTypeForbidden(err) {
|
||||||
ctx.Error(http.StatusUnprocessableEntity, "", err)
|
ctx.APIError(http.StatusUnprocessableEntity, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.Error(http.StatusInternalServerError, "UpdateAttachment", attach)
|
ctx.APIError(http.StatusInternalServerError, attach)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.JSON(http.StatusCreated, convert.ToAPIAttachment(ctx.Repo.Repository, attach))
|
ctx.JSON(http.StatusCreated, convert.ToAPIAttachment(ctx.Repo.Repository, attach))
|
||||||
|
@ -331,7 +331,7 @@ func DeleteIssueCommentAttachment(ctx *context.APIContext) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := repo_model.DeleteAttachment(ctx, attach, true); err != nil {
|
if err := repo_model.DeleteAttachment(ctx, attach, true); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "DeleteAttachment", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.Status(http.StatusNoContent)
|
ctx.Status(http.StatusNoContent)
|
||||||
|
@ -344,11 +344,11 @@ func getIssueCommentSafe(ctx *context.APIContext) *issues_model.Comment {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
if err := comment.LoadIssue(ctx); err != nil {
|
if err := comment.LoadIssue(ctx); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "comment.LoadIssue", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
if comment.Issue == nil || comment.Issue.RepoID != ctx.Repo.Repository.ID {
|
if comment.Issue == nil || comment.Issue.RepoID != ctx.Repo.Repository.ID {
|
||||||
ctx.Error(http.StatusNotFound, "", "no matching issue comment found")
|
ctx.APIError(http.StatusNotFound, "no matching issue comment found")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -375,7 +375,7 @@ func getIssueCommentAttachmentSafeWrite(ctx *context.APIContext) *repo_model.Att
|
||||||
func canUserWriteIssueCommentAttachment(ctx *context.APIContext, comment *issues_model.Comment) bool {
|
func canUserWriteIssueCommentAttachment(ctx *context.APIContext, comment *issues_model.Comment) bool {
|
||||||
canEditComment := ctx.IsSigned && (ctx.Doer.ID == comment.PosterID || ctx.IsUserRepoAdmin() || ctx.IsUserSiteAdmin()) && ctx.Repo.CanWriteIssuesOrPulls(comment.Issue.IsPull)
|
canEditComment := ctx.IsSigned && (ctx.Doer.ID == comment.PosterID || ctx.IsUserRepoAdmin() || ctx.IsUserSiteAdmin()) && ctx.Repo.CanWriteIssuesOrPulls(comment.Issue.IsPull)
|
||||||
if !canEditComment {
|
if !canEditComment {
|
||||||
ctx.Error(http.StatusForbidden, "", "user should have permission to edit comment")
|
ctx.APIError(http.StatusForbidden, "user should have permission to edit comment")
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -397,17 +397,17 @@ func getIssueCommentAttachmentSafeRead(ctx *context.APIContext, comment *issues_
|
||||||
func attachmentBelongsToRepoOrComment(ctx *context.APIContext, attachment *repo_model.Attachment, comment *issues_model.Comment) bool {
|
func attachmentBelongsToRepoOrComment(ctx *context.APIContext, attachment *repo_model.Attachment, comment *issues_model.Comment) bool {
|
||||||
if attachment.RepoID != ctx.Repo.Repository.ID {
|
if attachment.RepoID != ctx.Repo.Repository.ID {
|
||||||
log.Debug("Requested attachment[%d] does not belong to repo[%-v].", attachment.ID, ctx.Repo.Repository)
|
log.Debug("Requested attachment[%d] does not belong to repo[%-v].", attachment.ID, ctx.Repo.Repository)
|
||||||
ctx.NotFound("no such attachment in repo")
|
ctx.APIErrorNotFound("no such attachment in repo")
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
if attachment.IssueID == 0 || attachment.CommentID == 0 {
|
if attachment.IssueID == 0 || attachment.CommentID == 0 {
|
||||||
log.Debug("Requested attachment[%d] is not in a comment.", attachment.ID)
|
log.Debug("Requested attachment[%d] is not in a comment.", attachment.ID)
|
||||||
ctx.NotFound("no such attachment in comment")
|
ctx.APIErrorNotFound("no such attachment in comment")
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
if comment != nil && attachment.CommentID != comment.ID {
|
if comment != nil && attachment.CommentID != comment.ID {
|
||||||
log.Debug("Requested attachment[%d] does not belong to comment[%d].", attachment.ID, comment.ID)
|
log.Debug("Requested attachment[%d] does not belong to comment[%d].", attachment.ID, comment.ID)
|
||||||
ctx.NotFound("no such attachment in comment")
|
ctx.APIErrorNotFound("no such attachment in comment")
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
|
|
|
@ -57,23 +57,23 @@ func GetIssueDependencies(ctx *context.APIContext) {
|
||||||
|
|
||||||
// If this issue's repository does not enable dependencies then there can be no dependencies by default
|
// If this issue's repository does not enable dependencies then there can be no dependencies by default
|
||||||
if !ctx.Repo.Repository.IsDependenciesEnabled(ctx) {
|
if !ctx.Repo.Repository.IsDependenciesEnabled(ctx) {
|
||||||
ctx.NotFound()
|
ctx.APIErrorNotFound()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
issue, err := issues_model.GetIssueByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("index"))
|
issue, err := issues_model.GetIssueByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("index"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if issues_model.IsErrIssueNotExist(err) {
|
if issues_model.IsErrIssueNotExist(err) {
|
||||||
ctx.NotFound("IsErrIssueNotExist", err)
|
ctx.APIErrorNotFound("IsErrIssueNotExist", err)
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetIssueByIndex", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// 1. We must be able to read this issue
|
// 1. We must be able to read this issue
|
||||||
if !ctx.Repo.Permission.CanReadIssuesOrPulls(issue.IsPull) {
|
if !ctx.Repo.Permission.CanReadIssuesOrPulls(issue.IsPull) {
|
||||||
ctx.NotFound()
|
ctx.APIErrorNotFound()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -98,7 +98,7 @@ func GetIssueDependencies(ctx *context.APIContext) {
|
||||||
PageSize: limit,
|
PageSize: limit,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "BlockedByDependencies", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -116,7 +116,7 @@ func GetIssueDependencies(ctx *context.APIContext) {
|
||||||
var err error
|
var err error
|
||||||
perm, err = access_model.GetUserRepoPermission(ctx, &blocker.Repository, ctx.Doer)
|
perm, err = access_model.GetUserRepoPermission(ctx, &blocker.Repository, ctx.Doer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.ServerError("GetUserRepoPermission", err)
|
ctx.APIErrorInternal(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
repoPerms[blocker.RepoID] = perm
|
repoPerms[blocker.RepoID] = perm
|
||||||
|
@ -324,7 +324,7 @@ func GetIssueBlocks(ctx *context.APIContext) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if !ctx.Repo.Permission.CanReadIssuesOrPulls(issue.IsPull) {
|
if !ctx.Repo.Permission.CanReadIssuesOrPulls(issue.IsPull) {
|
||||||
ctx.NotFound()
|
ctx.APIErrorNotFound()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -342,7 +342,7 @@ func GetIssueBlocks(ctx *context.APIContext) {
|
||||||
|
|
||||||
deps, err := issue.BlockingDependencies(ctx)
|
deps, err := issue.BlockingDependencies(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "BlockingDependencies", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -367,7 +367,7 @@ func GetIssueBlocks(ctx *context.APIContext) {
|
||||||
var err error
|
var err error
|
||||||
perm, err = access_model.GetUserRepoPermission(ctx, &depMeta.Repository, ctx.Doer)
|
perm, err = access_model.GetUserRepoPermission(ctx, &depMeta.Repository, ctx.Doer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.ServerError("GetUserRepoPermission", err)
|
ctx.APIErrorInternal(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
repoPerms[depMeta.RepoID] = perm
|
repoPerms[depMeta.RepoID] = perm
|
||||||
|
@ -502,9 +502,9 @@ func getParamsIssue(ctx *context.APIContext) *issues_model.Issue {
|
||||||
issue, err := issues_model.GetIssueByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("index"))
|
issue, err := issues_model.GetIssueByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("index"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if issues_model.IsErrIssueNotExist(err) {
|
if issues_model.IsErrIssueNotExist(err) {
|
||||||
ctx.NotFound("IsErrIssueNotExist", err)
|
ctx.APIErrorNotFound("IsErrIssueNotExist", err)
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetIssueByIndex", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -523,9 +523,9 @@ func getFormIssue(ctx *context.APIContext, form *api.IssueMeta) *issues_model.Is
|
||||||
repo, err = repo_model.GetRepositoryByOwnerAndName(ctx, form.Owner, form.Name)
|
repo, err = repo_model.GetRepositoryByOwnerAndName(ctx, form.Owner, form.Name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if repo_model.IsErrRepoNotExist(err) {
|
if repo_model.IsErrRepoNotExist(err) {
|
||||||
ctx.NotFound("IsErrRepoNotExist", err)
|
ctx.APIErrorNotFound("IsErrRepoNotExist", err)
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetRepositoryByOwnerAndName", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -536,9 +536,9 @@ func getFormIssue(ctx *context.APIContext, form *api.IssueMeta) *issues_model.Is
|
||||||
issue, err := issues_model.GetIssueByIndex(ctx, repo.ID, form.Index)
|
issue, err := issues_model.GetIssueByIndex(ctx, repo.ID, form.Index)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if issues_model.IsErrIssueNotExist(err) {
|
if issues_model.IsErrIssueNotExist(err) {
|
||||||
ctx.NotFound("IsErrIssueNotExist", err)
|
ctx.APIErrorNotFound("IsErrIssueNotExist", err)
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetIssueByIndex", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -553,7 +553,7 @@ func getPermissionForRepo(ctx *context.APIContext, repo *repo_model.Repository)
|
||||||
|
|
||||||
perm, err := access_model.GetUserRepoPermission(ctx, repo, ctx.Doer)
|
perm, err := access_model.GetUserRepoPermission(ctx, repo, ctx.Doer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetUserRepoPermission", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -563,25 +563,25 @@ func getPermissionForRepo(ctx *context.APIContext, repo *repo_model.Repository)
|
||||||
func createIssueDependency(ctx *context.APIContext, target, dependency *issues_model.Issue, targetPerm, dependencyPerm access_model.Permission) {
|
func createIssueDependency(ctx *context.APIContext, target, dependency *issues_model.Issue, targetPerm, dependencyPerm access_model.Permission) {
|
||||||
if target.Repo.IsArchived || !target.Repo.IsDependenciesEnabled(ctx) {
|
if target.Repo.IsArchived || !target.Repo.IsDependenciesEnabled(ctx) {
|
||||||
// The target's repository doesn't have dependencies enabled
|
// The target's repository doesn't have dependencies enabled
|
||||||
ctx.NotFound()
|
ctx.APIErrorNotFound()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if !targetPerm.CanWriteIssuesOrPulls(target.IsPull) {
|
if !targetPerm.CanWriteIssuesOrPulls(target.IsPull) {
|
||||||
// We can't write to the target
|
// We can't write to the target
|
||||||
ctx.NotFound()
|
ctx.APIErrorNotFound()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if !dependencyPerm.CanReadIssuesOrPulls(dependency.IsPull) {
|
if !dependencyPerm.CanReadIssuesOrPulls(dependency.IsPull) {
|
||||||
// We can't read the dependency
|
// We can't read the dependency
|
||||||
ctx.NotFound()
|
ctx.APIErrorNotFound()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
err := issues_model.CreateIssueDependency(ctx, ctx.Doer, target, dependency)
|
err := issues_model.CreateIssueDependency(ctx, ctx.Doer, target, dependency)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "CreateIssueDependency", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -589,25 +589,25 @@ func createIssueDependency(ctx *context.APIContext, target, dependency *issues_m
|
||||||
func removeIssueDependency(ctx *context.APIContext, target, dependency *issues_model.Issue, targetPerm, dependencyPerm access_model.Permission) {
|
func removeIssueDependency(ctx *context.APIContext, target, dependency *issues_model.Issue, targetPerm, dependencyPerm access_model.Permission) {
|
||||||
if target.Repo.IsArchived || !target.Repo.IsDependenciesEnabled(ctx) {
|
if target.Repo.IsArchived || !target.Repo.IsDependenciesEnabled(ctx) {
|
||||||
// The target's repository doesn't have dependencies enabled
|
// The target's repository doesn't have dependencies enabled
|
||||||
ctx.NotFound()
|
ctx.APIErrorNotFound()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if !targetPerm.CanWriteIssuesOrPulls(target.IsPull) {
|
if !targetPerm.CanWriteIssuesOrPulls(target.IsPull) {
|
||||||
// We can't write to the target
|
// We can't write to the target
|
||||||
ctx.NotFound()
|
ctx.APIErrorNotFound()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if !dependencyPerm.CanReadIssuesOrPulls(dependency.IsPull) {
|
if !dependencyPerm.CanReadIssuesOrPulls(dependency.IsPull) {
|
||||||
// We can't read the dependency
|
// We can't read the dependency
|
||||||
ctx.NotFound()
|
ctx.APIErrorNotFound()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
err := issues_model.RemoveIssueDependency(ctx, ctx.Doer, target, dependency, issues_model.DependencyTypeBlockedBy)
|
err := issues_model.RemoveIssueDependency(ctx, ctx.Doer, target, dependency, issues_model.DependencyTypeBlockedBy)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "CreateIssueDependency", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,15 +50,15 @@ func ListIssueLabels(ctx *context.APIContext) {
|
||||||
issue, err := issues_model.GetIssueByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("index"))
|
issue, err := issues_model.GetIssueByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("index"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if issues_model.IsErrIssueNotExist(err) {
|
if issues_model.IsErrIssueNotExist(err) {
|
||||||
ctx.NotFound()
|
ctx.APIErrorNotFound()
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetIssueByIndex", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := issue.LoadAttributes(ctx); err != nil {
|
if err := issue.LoadAttributes(ctx); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "LoadAttributes", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -110,13 +110,13 @@ func AddIssueLabels(ctx *context.APIContext) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = issue_service.AddLabels(ctx, issue, ctx.Doer, labels); err != nil {
|
if err = issue_service.AddLabels(ctx, issue, ctx.Doer, labels); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "AddLabels", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
labels, err = issues_model.GetLabelsByIssueID(ctx, issue.ID)
|
labels, err = issues_model.GetLabelsByIssueID(ctx, issue.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetLabelsByIssueID", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -166,9 +166,9 @@ func DeleteIssueLabel(ctx *context.APIContext) {
|
||||||
issue, err := issues_model.GetIssueByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("index"))
|
issue, err := issues_model.GetIssueByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("index"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if issues_model.IsErrIssueNotExist(err) {
|
if issues_model.IsErrIssueNotExist(err) {
|
||||||
ctx.NotFound()
|
ctx.APIErrorNotFound()
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetIssueByIndex", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -181,15 +181,15 @@ func DeleteIssueLabel(ctx *context.APIContext) {
|
||||||
label, err := issues_model.GetLabelByID(ctx, ctx.PathParamInt64("id"))
|
label, err := issues_model.GetLabelByID(ctx, ctx.PathParamInt64("id"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if issues_model.IsErrLabelNotExist(err) {
|
if issues_model.IsErrLabelNotExist(err) {
|
||||||
ctx.Error(http.StatusUnprocessableEntity, "", err)
|
ctx.APIError(http.StatusUnprocessableEntity, err)
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetLabelByID", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := issue_service.RemoveLabel(ctx, issue, ctx.Doer, label); err != nil {
|
if err := issue_service.RemoveLabel(ctx, issue, ctx.Doer, label); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "DeleteIssueLabel", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -240,13 +240,13 @@ func ReplaceIssueLabels(ctx *context.APIContext) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := issue_service.ReplaceLabels(ctx, issue, ctx.Doer, labels); err != nil {
|
if err := issue_service.ReplaceLabels(ctx, issue, ctx.Doer, labels); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "ReplaceLabels", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
labels, err = issues_model.GetLabelsByIssueID(ctx, issue.ID)
|
labels, err = issues_model.GetLabelsByIssueID(ctx, issue.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetLabelsByIssueID", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -288,9 +288,9 @@ func ClearIssueLabels(ctx *context.APIContext) {
|
||||||
issue, err := issues_model.GetIssueByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("index"))
|
issue, err := issues_model.GetIssueByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("index"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if issues_model.IsErrIssueNotExist(err) {
|
if issues_model.IsErrIssueNotExist(err) {
|
||||||
ctx.NotFound()
|
ctx.APIErrorNotFound()
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetIssueByIndex", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -301,7 +301,7 @@ func ClearIssueLabels(ctx *context.APIContext) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := issue_service.ClearLabels(ctx, issue, ctx.Doer); err != nil {
|
if err := issue_service.ClearLabels(ctx, issue, ctx.Doer); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "ClearLabels", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -312,15 +312,15 @@ func prepareForReplaceOrAdd(ctx *context.APIContext, form api.IssueLabelsOption)
|
||||||
issue, err := issues_model.GetIssueByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("index"))
|
issue, err := issues_model.GetIssueByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("index"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if issues_model.IsErrIssueNotExist(err) {
|
if issues_model.IsErrIssueNotExist(err) {
|
||||||
ctx.NotFound()
|
ctx.APIErrorNotFound()
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetIssueByIndex", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if !ctx.Repo.CanWriteIssuesOrPulls(issue.IsPull) {
|
if !ctx.Repo.CanWriteIssuesOrPulls(issue.IsPull) {
|
||||||
ctx.Error(http.StatusForbidden, "CanWriteIssuesOrPulls", "write permission is required")
|
ctx.APIError(http.StatusForbidden, "write permission is required")
|
||||||
return nil, nil, fmt.Errorf("permission denied")
|
return nil, nil, fmt.Errorf("permission denied")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -336,25 +336,25 @@ func prepareForReplaceOrAdd(ctx *context.APIContext, form api.IssueLabelsOption)
|
||||||
case reflect.String:
|
case reflect.String:
|
||||||
labelNames = append(labelNames, rv.String())
|
labelNames = append(labelNames, rv.String())
|
||||||
default:
|
default:
|
||||||
ctx.Error(http.StatusBadRequest, "InvalidLabel", "a label must be an integer or a string")
|
ctx.APIError(http.StatusBadRequest, "a label must be an integer or a string")
|
||||||
return nil, nil, fmt.Errorf("invalid label")
|
return nil, nil, fmt.Errorf("invalid label")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if len(labelIDs) > 0 && len(labelNames) > 0 {
|
if len(labelIDs) > 0 && len(labelNames) > 0 {
|
||||||
ctx.Error(http.StatusBadRequest, "InvalidLabels", "labels should be an array of strings or integers")
|
ctx.APIError(http.StatusBadRequest, "labels should be an array of strings or integers")
|
||||||
return nil, nil, fmt.Errorf("invalid labels")
|
return nil, nil, fmt.Errorf("invalid labels")
|
||||||
}
|
}
|
||||||
if len(labelNames) > 0 {
|
if len(labelNames) > 0 {
|
||||||
repoLabelIDs, err := issues_model.GetLabelIDsInRepoByNames(ctx, ctx.Repo.Repository.ID, labelNames)
|
repoLabelIDs, err := issues_model.GetLabelIDsInRepoByNames(ctx, ctx.Repo.Repository.ID, labelNames)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetLabelIDsInRepoByNames", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
labelIDs = append(labelIDs, repoLabelIDs...)
|
labelIDs = append(labelIDs, repoLabelIDs...)
|
||||||
if ctx.Repo.Owner.IsOrganization() {
|
if ctx.Repo.Owner.IsOrganization() {
|
||||||
orgLabelIDs, err := issues_model.GetLabelIDsInOrgByNames(ctx, ctx.Repo.Owner.ID, labelNames)
|
orgLabelIDs, err := issues_model.GetLabelIDsInOrgByNames(ctx, ctx.Repo.Owner.ID, labelNames)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetLabelIDsInOrgByNames", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
labelIDs = append(labelIDs, orgLabelIDs...)
|
labelIDs = append(labelIDs, orgLabelIDs...)
|
||||||
|
@ -363,7 +363,7 @@ func prepareForReplaceOrAdd(ctx *context.APIContext, form api.IssueLabelsOption)
|
||||||
|
|
||||||
labels, err := issues_model.GetLabelsByIDs(ctx, labelIDs, "id", "repo_id", "org_id", "name", "exclusive")
|
labels, err := issues_model.GetLabelsByIDs(ctx, labelIDs, "id", "repo_id", "org_id", "name", "exclusive")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetLabelsByIDs", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -44,11 +44,11 @@ func PinIssue(ctx *context.APIContext) {
|
||||||
issue, err := issues_model.GetIssueByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("index"))
|
issue, err := issues_model.GetIssueByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("index"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if issues_model.IsErrIssueNotExist(err) {
|
if issues_model.IsErrIssueNotExist(err) {
|
||||||
ctx.NotFound()
|
ctx.APIErrorNotFound()
|
||||||
} else if issues_model.IsErrIssueMaxPinReached(err) {
|
} else if issues_model.IsErrIssueMaxPinReached(err) {
|
||||||
ctx.Error(http.StatusBadRequest, "MaxPinReached", err)
|
ctx.APIError(http.StatusBadRequest, err)
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetIssueByIndex", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -56,13 +56,13 @@ func PinIssue(ctx *context.APIContext) {
|
||||||
// If we don't do this, it will crash when trying to add the pin event to the comment history
|
// If we don't do this, it will crash when trying to add the pin event to the comment history
|
||||||
err = issue.LoadRepo(ctx)
|
err = issue.LoadRepo(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "LoadRepo", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
err = issue.Pin(ctx, ctx.Doer)
|
err = issue.Pin(ctx, ctx.Doer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "PinIssue", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -101,9 +101,9 @@ func UnpinIssue(ctx *context.APIContext) {
|
||||||
issue, err := issues_model.GetIssueByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("index"))
|
issue, err := issues_model.GetIssueByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("index"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if issues_model.IsErrIssueNotExist(err) {
|
if issues_model.IsErrIssueNotExist(err) {
|
||||||
ctx.NotFound()
|
ctx.APIErrorNotFound()
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetIssueByIndex", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -111,13 +111,13 @@ func UnpinIssue(ctx *context.APIContext) {
|
||||||
// If we don't do this, it will crash when trying to add the unpin event to the comment history
|
// If we don't do this, it will crash when trying to add the unpin event to the comment history
|
||||||
err = issue.LoadRepo(ctx)
|
err = issue.LoadRepo(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "LoadRepo", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
err = issue.Unpin(ctx, ctx.Doer)
|
err = issue.Unpin(ctx, ctx.Doer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "UnpinIssue", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -162,16 +162,16 @@ func MoveIssuePin(ctx *context.APIContext) {
|
||||||
issue, err := issues_model.GetIssueByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("index"))
|
issue, err := issues_model.GetIssueByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("index"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if issues_model.IsErrIssueNotExist(err) {
|
if issues_model.IsErrIssueNotExist(err) {
|
||||||
ctx.NotFound()
|
ctx.APIErrorNotFound()
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetIssueByIndex", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
err = issue.MovePin(ctx, int(ctx.PathParamInt64("position")))
|
err = issue.MovePin(ctx, int(ctx.PathParamInt64("position")))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "MovePin", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -203,7 +203,7 @@ func ListPinnedIssues(ctx *context.APIContext) {
|
||||||
// "$ref": "#/responses/notFound"
|
// "$ref": "#/responses/notFound"
|
||||||
issues, err := issues_model.GetPinnedIssues(ctx, ctx.Repo.Repository.ID, false)
|
issues, err := issues_model.GetPinnedIssues(ctx, ctx.Repo.Repository.ID, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "LoadPinnedIssues", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -235,29 +235,29 @@ func ListPinnedPullRequests(ctx *context.APIContext) {
|
||||||
// "$ref": "#/responses/notFound"
|
// "$ref": "#/responses/notFound"
|
||||||
issues, err := issues_model.GetPinnedIssues(ctx, ctx.Repo.Repository.ID, true)
|
issues, err := issues_model.GetPinnedIssues(ctx, ctx.Repo.Repository.ID, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "LoadPinnedPullRequests", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
apiPrs := make([]*api.PullRequest, len(issues))
|
apiPrs := make([]*api.PullRequest, len(issues))
|
||||||
if err := issues.LoadPullRequests(ctx); err != nil {
|
if err := issues.LoadPullRequests(ctx); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "LoadPullRequests", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
for i, currentIssue := range issues {
|
for i, currentIssue := range issues {
|
||||||
pr := currentIssue.PullRequest
|
pr := currentIssue.PullRequest
|
||||||
if err = pr.LoadAttributes(ctx); err != nil {
|
if err = pr.LoadAttributes(ctx); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "LoadAttributes", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = pr.LoadBaseRepo(ctx); err != nil {
|
if err = pr.LoadBaseRepo(ctx); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "LoadBaseRepo", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = pr.LoadHeadRepo(ctx); err != nil {
|
if err = pr.LoadHeadRepo(ctx); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "LoadHeadRepo", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -295,13 +295,13 @@ func AreNewIssuePinsAllowed(ctx *context.APIContext) {
|
||||||
|
|
||||||
pinsAllowed.Issues, err = issues_model.IsNewPinAllowed(ctx, ctx.Repo.Repository.ID, false)
|
pinsAllowed.Issues, err = issues_model.IsNewPinAllowed(ctx, ctx.Repo.Repository.ID, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "IsNewIssuePinAllowed", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
pinsAllowed.PullRequests, err = issues_model.IsNewPinAllowed(ctx, ctx.Repo.Repository.ID, true)
|
pinsAllowed.PullRequests, err = issues_model.IsNewPinAllowed(ctx, ctx.Repo.Repository.ID, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "IsNewPullRequestPinAllowed", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -54,36 +54,36 @@ func GetIssueCommentReactions(ctx *context.APIContext) {
|
||||||
comment, err := issues_model.GetCommentByID(ctx, ctx.PathParamInt64("id"))
|
comment, err := issues_model.GetCommentByID(ctx, ctx.PathParamInt64("id"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if issues_model.IsErrCommentNotExist(err) {
|
if issues_model.IsErrCommentNotExist(err) {
|
||||||
ctx.NotFound(err)
|
ctx.APIErrorNotFound(err)
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetCommentByID", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := comment.LoadIssue(ctx); err != nil {
|
if err := comment.LoadIssue(ctx); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "comment.LoadIssue", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if comment.Issue.RepoID != ctx.Repo.Repository.ID {
|
if comment.Issue.RepoID != ctx.Repo.Repository.ID {
|
||||||
ctx.NotFound()
|
ctx.APIErrorNotFound()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if !ctx.Repo.CanReadIssuesOrPulls(comment.Issue.IsPull) {
|
if !ctx.Repo.CanReadIssuesOrPulls(comment.Issue.IsPull) {
|
||||||
ctx.Error(http.StatusForbidden, "GetIssueCommentReactions", errors.New("no permission to get reactions"))
|
ctx.APIError(http.StatusForbidden, errors.New("no permission to get reactions"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
reactions, _, err := issues_model.FindCommentReactions(ctx, comment.IssueID, comment.ID)
|
reactions, _, err := issues_model.FindCommentReactions(ctx, comment.IssueID, comment.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "FindCommentReactions", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
_, err = reactions.LoadUsers(ctx, ctx.Repo.Repository)
|
_, err = reactions.LoadUsers(ctx, ctx.Repo.Repository)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "ReactionList.LoadUsers()", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -191,30 +191,30 @@ func changeIssueCommentReaction(ctx *context.APIContext, form api.EditReactionOp
|
||||||
comment, err := issues_model.GetCommentByID(ctx, ctx.PathParamInt64("id"))
|
comment, err := issues_model.GetCommentByID(ctx, ctx.PathParamInt64("id"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if issues_model.IsErrCommentNotExist(err) {
|
if issues_model.IsErrCommentNotExist(err) {
|
||||||
ctx.NotFound(err)
|
ctx.APIErrorNotFound(err)
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetCommentByID", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = comment.LoadIssue(ctx); err != nil {
|
if err = comment.LoadIssue(ctx); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "comment.LoadIssue() failed", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if comment.Issue.RepoID != ctx.Repo.Repository.ID {
|
if comment.Issue.RepoID != ctx.Repo.Repository.ID {
|
||||||
ctx.NotFound()
|
ctx.APIErrorNotFound()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if !ctx.Repo.CanReadIssuesOrPulls(comment.Issue.IsPull) {
|
if !ctx.Repo.CanReadIssuesOrPulls(comment.Issue.IsPull) {
|
||||||
ctx.NotFound()
|
ctx.APIErrorNotFound()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if comment.Issue.IsLocked && !ctx.Repo.CanWriteIssuesOrPulls(comment.Issue.IsPull) {
|
if comment.Issue.IsLocked && !ctx.Repo.CanWriteIssuesOrPulls(comment.Issue.IsPull) {
|
||||||
ctx.Error(http.StatusForbidden, "ChangeIssueCommentReaction", errors.New("no permission to change reaction"))
|
ctx.APIError(http.StatusForbidden, errors.New("no permission to change reaction"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -223,7 +223,7 @@ func changeIssueCommentReaction(ctx *context.APIContext, form api.EditReactionOp
|
||||||
reaction, err := issue_service.CreateCommentReaction(ctx, ctx.Doer, comment, form.Reaction)
|
reaction, err := issue_service.CreateCommentReaction(ctx, ctx.Doer, comment, form.Reaction)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if issues_model.IsErrForbiddenIssueReaction(err) || errors.Is(err, user_model.ErrBlockedUser) {
|
if issues_model.IsErrForbiddenIssueReaction(err) || errors.Is(err, user_model.ErrBlockedUser) {
|
||||||
ctx.Error(http.StatusForbidden, err.Error(), err)
|
ctx.APIError(http.StatusForbidden, err)
|
||||||
} else if issues_model.IsErrReactionAlreadyExist(err) {
|
} else if issues_model.IsErrReactionAlreadyExist(err) {
|
||||||
ctx.JSON(http.StatusOK, api.Reaction{
|
ctx.JSON(http.StatusOK, api.Reaction{
|
||||||
User: convert.ToUser(ctx, ctx.Doer, ctx.Doer),
|
User: convert.ToUser(ctx, ctx.Doer, ctx.Doer),
|
||||||
|
@ -231,7 +231,7 @@ func changeIssueCommentReaction(ctx *context.APIContext, form api.EditReactionOp
|
||||||
Created: reaction.CreatedUnix.AsTime(),
|
Created: reaction.CreatedUnix.AsTime(),
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "CreateCommentReaction", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -245,7 +245,7 @@ func changeIssueCommentReaction(ctx *context.APIContext, form api.EditReactionOp
|
||||||
// DeleteIssueCommentReaction part
|
// DeleteIssueCommentReaction part
|
||||||
err = issues_model.DeleteCommentReaction(ctx, ctx.Doer.ID, comment.Issue.ID, comment.ID, form.Reaction)
|
err = issues_model.DeleteCommentReaction(ctx, ctx.Doer.ID, comment.Issue.ID, comment.ID, form.Reaction)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "DeleteCommentReaction", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// ToDo respond 204
|
// ToDo respond 204
|
||||||
|
@ -298,26 +298,26 @@ func GetIssueReactions(ctx *context.APIContext) {
|
||||||
issue, err := issues_model.GetIssueWithAttrsByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("index"))
|
issue, err := issues_model.GetIssueWithAttrsByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("index"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if issues_model.IsErrIssueNotExist(err) {
|
if issues_model.IsErrIssueNotExist(err) {
|
||||||
ctx.NotFound()
|
ctx.APIErrorNotFound()
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetIssueByIndex", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if !ctx.Repo.CanReadIssuesOrPulls(issue.IsPull) {
|
if !ctx.Repo.CanReadIssuesOrPulls(issue.IsPull) {
|
||||||
ctx.Error(http.StatusForbidden, "GetIssueReactions", errors.New("no permission to get reactions"))
|
ctx.APIError(http.StatusForbidden, errors.New("no permission to get reactions"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
reactions, count, err := issues_model.FindIssueReactions(ctx, issue.ID, utils.GetListOptions(ctx))
|
reactions, count, err := issues_model.FindIssueReactions(ctx, issue.ID, utils.GetListOptions(ctx))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "FindIssueReactions", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
_, err = reactions.LoadUsers(ctx, ctx.Repo.Repository)
|
_, err = reactions.LoadUsers(ctx, ctx.Repo.Repository)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "ReactionList.LoadUsers()", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -422,15 +422,15 @@ func changeIssueReaction(ctx *context.APIContext, form api.EditReactionOption, i
|
||||||
issue, err := issues_model.GetIssueWithAttrsByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("index"))
|
issue, err := issues_model.GetIssueWithAttrsByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("index"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if issues_model.IsErrIssueNotExist(err) {
|
if issues_model.IsErrIssueNotExist(err) {
|
||||||
ctx.NotFound()
|
ctx.APIErrorNotFound()
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetIssueByIndex", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if issue.IsLocked && !ctx.Repo.CanWriteIssuesOrPulls(issue.IsPull) {
|
if issue.IsLocked && !ctx.Repo.CanWriteIssuesOrPulls(issue.IsPull) {
|
||||||
ctx.Error(http.StatusForbidden, "ChangeIssueCommentReaction", errors.New("no permission to change reaction"))
|
ctx.APIError(http.StatusForbidden, errors.New("no permission to change reaction"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -439,7 +439,7 @@ func changeIssueReaction(ctx *context.APIContext, form api.EditReactionOption, i
|
||||||
reaction, err := issue_service.CreateIssueReaction(ctx, ctx.Doer, issue, form.Reaction)
|
reaction, err := issue_service.CreateIssueReaction(ctx, ctx.Doer, issue, form.Reaction)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if issues_model.IsErrForbiddenIssueReaction(err) || errors.Is(err, user_model.ErrBlockedUser) {
|
if issues_model.IsErrForbiddenIssueReaction(err) || errors.Is(err, user_model.ErrBlockedUser) {
|
||||||
ctx.Error(http.StatusForbidden, err.Error(), err)
|
ctx.APIError(http.StatusForbidden, err)
|
||||||
} else if issues_model.IsErrReactionAlreadyExist(err) {
|
} else if issues_model.IsErrReactionAlreadyExist(err) {
|
||||||
ctx.JSON(http.StatusOK, api.Reaction{
|
ctx.JSON(http.StatusOK, api.Reaction{
|
||||||
User: convert.ToUser(ctx, ctx.Doer, ctx.Doer),
|
User: convert.ToUser(ctx, ctx.Doer, ctx.Doer),
|
||||||
|
@ -447,7 +447,7 @@ func changeIssueReaction(ctx *context.APIContext, form api.EditReactionOption, i
|
||||||
Created: reaction.CreatedUnix.AsTime(),
|
Created: reaction.CreatedUnix.AsTime(),
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "CreateIssueReaction", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -461,7 +461,7 @@ func changeIssueReaction(ctx *context.APIContext, form api.EditReactionOption, i
|
||||||
// DeleteIssueReaction part
|
// DeleteIssueReaction part
|
||||||
err = issues_model.DeleteIssueReaction(ctx, ctx.Doer.ID, issue.ID, form.Reaction)
|
err = issues_model.DeleteIssueReaction(ctx, ctx.Doer.ID, issue.ID, form.Reaction)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "DeleteIssueReaction", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// ToDo respond 204
|
// ToDo respond 204
|
||||||
|
|
|
@ -55,7 +55,7 @@ func StartIssueStopwatch(ctx *context.APIContext) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := issues_model.CreateIssueStopwatch(ctx, ctx.Doer, issue); err != nil {
|
if err := issues_model.CreateIssueStopwatch(ctx, ctx.Doer, issue); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "CreateOrStopIssueStopwatch", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -104,7 +104,7 @@ func StopIssueStopwatch(ctx *context.APIContext) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := issues_model.FinishIssueStopwatch(ctx, ctx.Doer, issue); err != nil {
|
if err := issues_model.FinishIssueStopwatch(ctx, ctx.Doer, issue); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "CreateOrStopIssueStopwatch", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -153,7 +153,7 @@ func DeleteIssueStopwatch(ctx *context.APIContext) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := issues_model.CancelStopwatch(ctx, ctx.Doer, issue); err != nil {
|
if err := issues_model.CancelStopwatch(ctx, ctx.Doer, issue); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "CancelStopwatch", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -164,9 +164,9 @@ func prepareIssueStopwatch(ctx *context.APIContext, shouldExist bool) (*issues_m
|
||||||
issue, err := issues_model.GetIssueByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("index"))
|
issue, err := issues_model.GetIssueByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("index"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if issues_model.IsErrIssueNotExist(err) {
|
if issues_model.IsErrIssueNotExist(err) {
|
||||||
ctx.NotFound()
|
ctx.APIErrorNotFound()
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetIssueByIndex", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -184,10 +184,10 @@ func prepareIssueStopwatch(ctx *context.APIContext, shouldExist bool) (*issues_m
|
||||||
|
|
||||||
if issues_model.StopwatchExists(ctx, ctx.Doer.ID, issue.ID) != shouldExist {
|
if issues_model.StopwatchExists(ctx, ctx.Doer.ID, issue.ID) != shouldExist {
|
||||||
if shouldExist {
|
if shouldExist {
|
||||||
ctx.Error(http.StatusConflict, "StopwatchExists", "cannot stop/cancel a non existent stopwatch")
|
ctx.APIError(http.StatusConflict, "cannot stop/cancel a non existent stopwatch")
|
||||||
err = errors.New("cannot stop/cancel a non existent stopwatch")
|
err = errors.New("cannot stop/cancel a non existent stopwatch")
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusConflict, "StopwatchExists", "cannot start a stopwatch again if it already exists")
|
ctx.APIError(http.StatusConflict, "cannot start a stopwatch again if it already exists")
|
||||||
err = errors.New("cannot start a stopwatch again if it already exists")
|
err = errors.New("cannot start a stopwatch again if it already exists")
|
||||||
}
|
}
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -220,19 +220,19 @@ func GetStopwatches(ctx *context.APIContext) {
|
||||||
|
|
||||||
sws, err := issues_model.GetUserStopwatches(ctx, ctx.Doer.ID, utils.GetListOptions(ctx))
|
sws, err := issues_model.GetUserStopwatches(ctx, ctx.Doer.ID, utils.GetListOptions(ctx))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetUserStopwatches", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
count, err := issues_model.CountUserStopwatches(ctx, ctx.Doer.ID)
|
count, err := issues_model.CountUserStopwatches(ctx, ctx.Doer.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.InternalServerError(err)
|
ctx.APIErrorInternal(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
apiSWs, err := convert.ToStopWatches(ctx, sws)
|
apiSWs, err := convert.ToStopWatches(ctx, sws)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "APIFormat", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -107,9 +107,9 @@ func setIssueSubscription(ctx *context.APIContext, watch bool) {
|
||||||
issue, err := issues_model.GetIssueByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("index"))
|
issue, err := issues_model.GetIssueByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("index"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if issues_model.IsErrIssueNotExist(err) {
|
if issues_model.IsErrIssueNotExist(err) {
|
||||||
ctx.NotFound()
|
ctx.APIErrorNotFound()
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetIssueByIndex", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
@ -118,9 +118,9 @@ func setIssueSubscription(ctx *context.APIContext, watch bool) {
|
||||||
user, err := user_model.GetUserByName(ctx, ctx.PathParam("user"))
|
user, err := user_model.GetUserByName(ctx, ctx.PathParam("user"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if user_model.IsErrUserNotExist(err) {
|
if user_model.IsErrUserNotExist(err) {
|
||||||
ctx.NotFound()
|
ctx.APIErrorNotFound()
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetUserByName", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
@ -128,13 +128,13 @@ func setIssueSubscription(ctx *context.APIContext, watch bool) {
|
||||||
|
|
||||||
// only admin and user for itself can change subscription
|
// only admin and user for itself can change subscription
|
||||||
if user.ID != ctx.Doer.ID && !ctx.Doer.IsAdmin {
|
if user.ID != ctx.Doer.ID && !ctx.Doer.IsAdmin {
|
||||||
ctx.Error(http.StatusForbidden, "User", fmt.Errorf("%s is not permitted to change subscriptions for %s", ctx.Doer.Name, user.Name))
|
ctx.APIError(http.StatusForbidden, fmt.Errorf("%s is not permitted to change subscriptions for %s", ctx.Doer.Name, user.Name))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
current, err := issues_model.CheckIssueWatch(ctx, user, issue)
|
current, err := issues_model.CheckIssueWatch(ctx, user, issue)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "CheckIssueWatch", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -146,7 +146,7 @@ func setIssueSubscription(ctx *context.APIContext, watch bool) {
|
||||||
|
|
||||||
// Update watch state
|
// Update watch state
|
||||||
if err := issues_model.CreateOrUpdateIssueWatch(ctx, user.ID, issue.ID, watch); err != nil {
|
if err := issues_model.CreateOrUpdateIssueWatch(ctx, user.ID, issue.ID, watch); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "CreateOrUpdateIssueWatch", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -188,9 +188,9 @@ func CheckIssueSubscription(ctx *context.APIContext) {
|
||||||
issue, err := issues_model.GetIssueByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("index"))
|
issue, err := issues_model.GetIssueByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("index"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if issues_model.IsErrIssueNotExist(err) {
|
if issues_model.IsErrIssueNotExist(err) {
|
||||||
ctx.NotFound()
|
ctx.APIErrorNotFound()
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetIssueByIndex", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
@ -198,7 +198,7 @@ func CheckIssueSubscription(ctx *context.APIContext) {
|
||||||
|
|
||||||
watching, err := issues_model.CheckIssueWatch(ctx, ctx.Doer, issue)
|
watching, err := issues_model.CheckIssueWatch(ctx, ctx.Doer, issue)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.InternalServerError(err)
|
ctx.APIErrorInternal(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.JSON(http.StatusOK, api.WatchInfo{
|
ctx.JSON(http.StatusOK, api.WatchInfo{
|
||||||
|
@ -254,9 +254,9 @@ func GetIssueSubscribers(ctx *context.APIContext) {
|
||||||
issue, err := issues_model.GetIssueByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("index"))
|
issue, err := issues_model.GetIssueByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("index"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if issues_model.IsErrIssueNotExist(err) {
|
if issues_model.IsErrIssueNotExist(err) {
|
||||||
ctx.NotFound()
|
ctx.APIErrorNotFound()
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetIssueByIndex", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
@ -264,7 +264,7 @@ func GetIssueSubscribers(ctx *context.APIContext) {
|
||||||
|
|
||||||
iwl, err := issues_model.GetIssueWatchers(ctx, issue.ID, utils.GetListOptions(ctx))
|
iwl, err := issues_model.GetIssueWatchers(ctx, issue.ID, utils.GetListOptions(ctx))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetIssueWatchers", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -275,7 +275,7 @@ func GetIssueSubscribers(ctx *context.APIContext) {
|
||||||
|
|
||||||
users, err := user_model.GetUsersByIDs(ctx, userIDs)
|
users, err := user_model.GetUsersByIDs(ctx, userIDs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetUsersByIDs", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
apiUsers := make([]*api.User, 0, len(users))
|
apiUsers := make([]*api.User, 0, len(users))
|
||||||
|
@ -285,7 +285,7 @@ func GetIssueSubscribers(ctx *context.APIContext) {
|
||||||
|
|
||||||
count, err := issues_model.CountIssueWatchers(ctx, issue.ID)
|
count, err := issues_model.CountIssueWatchers(ctx, issue.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "CountIssueWatchers", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -72,15 +72,15 @@ func ListTrackedTimes(ctx *context.APIContext) {
|
||||||
// "$ref": "#/responses/notFound"
|
// "$ref": "#/responses/notFound"
|
||||||
|
|
||||||
if !ctx.Repo.Repository.IsTimetrackerEnabled(ctx) {
|
if !ctx.Repo.Repository.IsTimetrackerEnabled(ctx) {
|
||||||
ctx.NotFound("Timetracker is disabled")
|
ctx.APIErrorNotFound("Timetracker is disabled")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
issue, err := issues_model.GetIssueByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("index"))
|
issue, err := issues_model.GetIssueByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("index"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if issues_model.IsErrIssueNotExist(err) {
|
if issues_model.IsErrIssueNotExist(err) {
|
||||||
ctx.NotFound(err)
|
ctx.APIErrorNotFound(err)
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetIssueByIndex", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -95,16 +95,16 @@ func ListTrackedTimes(ctx *context.APIContext) {
|
||||||
if qUser != "" {
|
if qUser != "" {
|
||||||
user, err := user_model.GetUserByName(ctx, qUser)
|
user, err := user_model.GetUserByName(ctx, qUser)
|
||||||
if user_model.IsErrUserNotExist(err) {
|
if user_model.IsErrUserNotExist(err) {
|
||||||
ctx.Error(http.StatusNotFound, "User does not exist", err)
|
ctx.APIError(http.StatusNotFound, err)
|
||||||
} else if err != nil {
|
} else if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetUserByName", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
opts.UserID = user.ID
|
opts.UserID = user.ID
|
||||||
}
|
}
|
||||||
|
|
||||||
if opts.CreatedBeforeUnix, opts.CreatedAfterUnix, err = context.GetQueryBeforeSince(ctx.Base); err != nil {
|
if opts.CreatedBeforeUnix, opts.CreatedAfterUnix, err = context.GetQueryBeforeSince(ctx.Base); err != nil {
|
||||||
ctx.Error(http.StatusUnprocessableEntity, "GetQueryBeforeSince", err)
|
ctx.APIError(http.StatusUnprocessableEntity, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -116,24 +116,24 @@ func ListTrackedTimes(ctx *context.APIContext) {
|
||||||
if opts.UserID == 0 {
|
if opts.UserID == 0 {
|
||||||
opts.UserID = ctx.Doer.ID
|
opts.UserID = ctx.Doer.ID
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusForbidden, "", fmt.Errorf("query by user not allowed; not enough rights"))
|
ctx.APIError(http.StatusForbidden, fmt.Errorf("query by user not allowed; not enough rights"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
count, err := issues_model.CountTrackedTimes(ctx, opts)
|
count, err := issues_model.CountTrackedTimes(ctx, opts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.InternalServerError(err)
|
ctx.APIErrorInternal(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
trackedTimes, err := issues_model.GetTrackedTimes(ctx, opts)
|
trackedTimes, err := issues_model.GetTrackedTimes(ctx, opts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetTrackedTimes", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if err = trackedTimes.LoadAttributes(ctx); err != nil {
|
if err = trackedTimes.LoadAttributes(ctx); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "LoadAttributes", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -184,16 +184,16 @@ func AddTime(ctx *context.APIContext) {
|
||||||
issue, err := issues_model.GetIssueByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("index"))
|
issue, err := issues_model.GetIssueByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("index"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if issues_model.IsErrIssueNotExist(err) {
|
if issues_model.IsErrIssueNotExist(err) {
|
||||||
ctx.NotFound(err)
|
ctx.APIErrorNotFound(err)
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetIssueByIndex", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if !ctx.Repo.CanUseTimetracker(ctx, issue, ctx.Doer) {
|
if !ctx.Repo.CanUseTimetracker(ctx, issue, ctx.Doer) {
|
||||||
if !ctx.Repo.Repository.IsTimetrackerEnabled(ctx) {
|
if !ctx.Repo.Repository.IsTimetrackerEnabled(ctx) {
|
||||||
ctx.Error(http.StatusBadRequest, "", "time tracking disabled")
|
ctx.APIError(http.StatusBadRequest, "time tracking disabled")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.Status(http.StatusForbidden)
|
ctx.Status(http.StatusForbidden)
|
||||||
|
@ -206,7 +206,7 @@ func AddTime(ctx *context.APIContext) {
|
||||||
// allow only RepoAdmin, Admin and User to add time
|
// allow only RepoAdmin, Admin and User to add time
|
||||||
user, err = user_model.GetUserByName(ctx, form.User)
|
user, err = user_model.GetUserByName(ctx, form.User)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetUserByName", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -218,11 +218,11 @@ func AddTime(ctx *context.APIContext) {
|
||||||
|
|
||||||
trackedTime, err := issues_model.AddTime(ctx, user, issue, form.Time, created)
|
trackedTime, err := issues_model.AddTime(ctx, user, issue, form.Time, created)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "AddTime", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if err = trackedTime.LoadAttributes(ctx); err != nil {
|
if err = trackedTime.LoadAttributes(ctx); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "LoadAttributes", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.JSON(http.StatusOK, convert.ToTrackedTime(ctx, user, trackedTime))
|
ctx.JSON(http.StatusOK, convert.ToTrackedTime(ctx, user, trackedTime))
|
||||||
|
@ -267,9 +267,9 @@ func ResetIssueTime(ctx *context.APIContext) {
|
||||||
issue, err := issues_model.GetIssueByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("index"))
|
issue, err := issues_model.GetIssueByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("index"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if issues_model.IsErrIssueNotExist(err) {
|
if issues_model.IsErrIssueNotExist(err) {
|
||||||
ctx.NotFound(err)
|
ctx.APIErrorNotFound(err)
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetIssueByIndex", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -286,9 +286,9 @@ func ResetIssueTime(ctx *context.APIContext) {
|
||||||
err = issues_model.DeleteIssueUserTimes(ctx, issue, ctx.Doer)
|
err = issues_model.DeleteIssueUserTimes(ctx, issue, ctx.Doer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if db.IsErrNotExist(err) {
|
if db.IsErrNotExist(err) {
|
||||||
ctx.Error(http.StatusNotFound, "DeleteIssueUserTimes", err)
|
ctx.APIError(http.StatusNotFound, err)
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "DeleteIssueUserTimes", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -340,9 +340,9 @@ func DeleteTime(ctx *context.APIContext) {
|
||||||
issue, err := issues_model.GetIssueByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("index"))
|
issue, err := issues_model.GetIssueByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("index"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if issues_model.IsErrIssueNotExist(err) {
|
if issues_model.IsErrIssueNotExist(err) {
|
||||||
ctx.NotFound(err)
|
ctx.APIErrorNotFound(err)
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetIssueByIndex", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -359,14 +359,14 @@ func DeleteTime(ctx *context.APIContext) {
|
||||||
time, err := issues_model.GetTrackedTimeByID(ctx, ctx.PathParamInt64("id"))
|
time, err := issues_model.GetTrackedTimeByID(ctx, ctx.PathParamInt64("id"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if db.IsErrNotExist(err) {
|
if db.IsErrNotExist(err) {
|
||||||
ctx.NotFound(err)
|
ctx.APIErrorNotFound(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.Error(http.StatusInternalServerError, "GetTrackedTimeByID", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if time.Deleted {
|
if time.Deleted {
|
||||||
ctx.NotFound(fmt.Errorf("tracked time [%d] already deleted", time.ID))
|
ctx.APIErrorNotFound(fmt.Errorf("tracked time [%d] already deleted", time.ID))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -378,7 +378,7 @@ func DeleteTime(ctx *context.APIContext) {
|
||||||
|
|
||||||
err = issues_model.DeleteTime(ctx, time)
|
err = issues_model.DeleteTime(ctx, time)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "DeleteTime", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.Status(http.StatusNoContent)
|
ctx.Status(http.StatusNoContent)
|
||||||
|
@ -419,25 +419,25 @@ func ListTrackedTimesByUser(ctx *context.APIContext) {
|
||||||
// "$ref": "#/responses/notFound"
|
// "$ref": "#/responses/notFound"
|
||||||
|
|
||||||
if !ctx.Repo.Repository.IsTimetrackerEnabled(ctx) {
|
if !ctx.Repo.Repository.IsTimetrackerEnabled(ctx) {
|
||||||
ctx.Error(http.StatusBadRequest, "", "time tracking disabled")
|
ctx.APIError(http.StatusBadRequest, "time tracking disabled")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
user, err := user_model.GetUserByName(ctx, ctx.PathParam("timetrackingusername"))
|
user, err := user_model.GetUserByName(ctx, ctx.PathParam("timetrackingusername"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if user_model.IsErrUserNotExist(err) {
|
if user_model.IsErrUserNotExist(err) {
|
||||||
ctx.NotFound(err)
|
ctx.APIErrorNotFound(err)
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetUserByName", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if user == nil {
|
if user == nil {
|
||||||
ctx.NotFound()
|
ctx.APIErrorNotFound()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if !ctx.IsUserRepoAdmin() && !ctx.Doer.IsAdmin && ctx.Doer.ID != user.ID {
|
if !ctx.IsUserRepoAdmin() && !ctx.Doer.IsAdmin && ctx.Doer.ID != user.ID {
|
||||||
ctx.Error(http.StatusForbidden, "", fmt.Errorf("query by user not allowed; not enough rights"))
|
ctx.APIError(http.StatusForbidden, fmt.Errorf("query by user not allowed; not enough rights"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -448,11 +448,11 @@ func ListTrackedTimesByUser(ctx *context.APIContext) {
|
||||||
|
|
||||||
trackedTimes, err := issues_model.GetTrackedTimes(ctx, opts)
|
trackedTimes, err := issues_model.GetTrackedTimes(ctx, opts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetTrackedTimes", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if err = trackedTimes.LoadAttributes(ctx); err != nil {
|
if err = trackedTimes.LoadAttributes(ctx); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "LoadAttributes", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.JSON(http.StatusOK, convert.ToTrackedTimeList(ctx, ctx.Doer, trackedTimes))
|
ctx.JSON(http.StatusOK, convert.ToTrackedTimeList(ctx, ctx.Doer, trackedTimes))
|
||||||
|
@ -509,7 +509,7 @@ func ListTrackedTimesByRepository(ctx *context.APIContext) {
|
||||||
// "$ref": "#/responses/notFound"
|
// "$ref": "#/responses/notFound"
|
||||||
|
|
||||||
if !ctx.Repo.Repository.IsTimetrackerEnabled(ctx) {
|
if !ctx.Repo.Repository.IsTimetrackerEnabled(ctx) {
|
||||||
ctx.Error(http.StatusBadRequest, "", "time tracking disabled")
|
ctx.APIError(http.StatusBadRequest, "time tracking disabled")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -523,9 +523,9 @@ func ListTrackedTimesByRepository(ctx *context.APIContext) {
|
||||||
if qUser != "" {
|
if qUser != "" {
|
||||||
user, err := user_model.GetUserByName(ctx, qUser)
|
user, err := user_model.GetUserByName(ctx, qUser)
|
||||||
if user_model.IsErrUserNotExist(err) {
|
if user_model.IsErrUserNotExist(err) {
|
||||||
ctx.Error(http.StatusNotFound, "User does not exist", err)
|
ctx.APIError(http.StatusNotFound, err)
|
||||||
} else if err != nil {
|
} else if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetUserByName", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
opts.UserID = user.ID
|
opts.UserID = user.ID
|
||||||
|
@ -533,7 +533,7 @@ func ListTrackedTimesByRepository(ctx *context.APIContext) {
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
if opts.CreatedBeforeUnix, opts.CreatedAfterUnix, err = context.GetQueryBeforeSince(ctx.Base); err != nil {
|
if opts.CreatedBeforeUnix, opts.CreatedAfterUnix, err = context.GetQueryBeforeSince(ctx.Base); err != nil {
|
||||||
ctx.Error(http.StatusUnprocessableEntity, "GetQueryBeforeSince", err)
|
ctx.APIError(http.StatusUnprocessableEntity, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -545,24 +545,24 @@ func ListTrackedTimesByRepository(ctx *context.APIContext) {
|
||||||
if opts.UserID == 0 {
|
if opts.UserID == 0 {
|
||||||
opts.UserID = ctx.Doer.ID
|
opts.UserID = ctx.Doer.ID
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusForbidden, "", fmt.Errorf("query by user not allowed; not enough rights"))
|
ctx.APIError(http.StatusForbidden, fmt.Errorf("query by user not allowed; not enough rights"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
count, err := issues_model.CountTrackedTimes(ctx, opts)
|
count, err := issues_model.CountTrackedTimes(ctx, opts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.InternalServerError(err)
|
ctx.APIErrorInternal(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
trackedTimes, err := issues_model.GetTrackedTimes(ctx, opts)
|
trackedTimes, err := issues_model.GetTrackedTimes(ctx, opts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetTrackedTimes", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if err = trackedTimes.LoadAttributes(ctx); err != nil {
|
if err = trackedTimes.LoadAttributes(ctx); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "LoadAttributes", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -607,24 +607,24 @@ func ListMyTrackedTimes(ctx *context.APIContext) {
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
if opts.CreatedBeforeUnix, opts.CreatedAfterUnix, err = context.GetQueryBeforeSince(ctx.Base); err != nil {
|
if opts.CreatedBeforeUnix, opts.CreatedAfterUnix, err = context.GetQueryBeforeSince(ctx.Base); err != nil {
|
||||||
ctx.Error(http.StatusUnprocessableEntity, "GetQueryBeforeSince", err)
|
ctx.APIError(http.StatusUnprocessableEntity, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
count, err := issues_model.CountTrackedTimes(ctx, opts)
|
count, err := issues_model.CountTrackedTimes(ctx, opts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.InternalServerError(err)
|
ctx.APIErrorInternal(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
trackedTimes, err := issues_model.GetTrackedTimes(ctx, opts)
|
trackedTimes, err := issues_model.GetTrackedTimes(ctx, opts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetTrackedTimesByUser", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = trackedTimes.LoadAttributes(ctx); err != nil {
|
if err = trackedTimes.LoadAttributes(ctx); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "LoadAttributes", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -92,7 +92,7 @@ func ListDeployKeys(ctx *context.APIContext) {
|
||||||
|
|
||||||
keys, count, err := db.FindAndCount[asymkey_model.DeployKey](ctx, opts)
|
keys, count, err := db.FindAndCount[asymkey_model.DeployKey](ctx, opts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.InternalServerError(err)
|
ctx.APIErrorInternal(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -100,7 +100,7 @@ func ListDeployKeys(ctx *context.APIContext) {
|
||||||
apiKeys := make([]*api.DeployKey, len(keys))
|
apiKeys := make([]*api.DeployKey, len(keys))
|
||||||
for i := range keys {
|
for i := range keys {
|
||||||
if err := keys[i].GetContent(ctx); err != nil {
|
if err := keys[i].GetContent(ctx); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetContent", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
apiKeys[i] = convert.ToDeployKey(apiLink, keys[i])
|
apiKeys[i] = convert.ToDeployKey(apiLink, keys[i])
|
||||||
|
@ -146,21 +146,21 @@ func GetDeployKey(ctx *context.APIContext) {
|
||||||
key, err := asymkey_model.GetDeployKeyByID(ctx, ctx.PathParamInt64("id"))
|
key, err := asymkey_model.GetDeployKeyByID(ctx, ctx.PathParamInt64("id"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if asymkey_model.IsErrDeployKeyNotExist(err) {
|
if asymkey_model.IsErrDeployKeyNotExist(err) {
|
||||||
ctx.NotFound()
|
ctx.APIErrorNotFound()
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetDeployKeyByID", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// this check make it more consistent
|
// this check make it more consistent
|
||||||
if key.RepoID != ctx.Repo.Repository.ID {
|
if key.RepoID != ctx.Repo.Repository.ID {
|
||||||
ctx.NotFound()
|
ctx.APIErrorNotFound()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = key.GetContent(ctx); err != nil {
|
if err = key.GetContent(ctx); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetContent", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -175,11 +175,11 @@ func GetDeployKey(ctx *context.APIContext) {
|
||||||
// HandleCheckKeyStringError handle check key error
|
// HandleCheckKeyStringError handle check key error
|
||||||
func HandleCheckKeyStringError(ctx *context.APIContext, err error) {
|
func HandleCheckKeyStringError(ctx *context.APIContext, err error) {
|
||||||
if db.IsErrSSHDisabled(err) {
|
if db.IsErrSSHDisabled(err) {
|
||||||
ctx.Error(http.StatusUnprocessableEntity, "", "SSH is disabled")
|
ctx.APIError(http.StatusUnprocessableEntity, "SSH is disabled")
|
||||||
} else if asymkey_model.IsErrKeyUnableVerify(err) {
|
} else if asymkey_model.IsErrKeyUnableVerify(err) {
|
||||||
ctx.Error(http.StatusUnprocessableEntity, "", "Unable to verify key content")
|
ctx.APIError(http.StatusUnprocessableEntity, "Unable to verify key content")
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusUnprocessableEntity, "", fmt.Errorf("Invalid key content: %w", err))
|
ctx.APIError(http.StatusUnprocessableEntity, fmt.Errorf("Invalid key content: %w", err))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -187,15 +187,15 @@ func HandleCheckKeyStringError(ctx *context.APIContext, err error) {
|
||||||
func HandleAddKeyError(ctx *context.APIContext, err error) {
|
func HandleAddKeyError(ctx *context.APIContext, err error) {
|
||||||
switch {
|
switch {
|
||||||
case asymkey_model.IsErrDeployKeyAlreadyExist(err):
|
case asymkey_model.IsErrDeployKeyAlreadyExist(err):
|
||||||
ctx.Error(http.StatusUnprocessableEntity, "", "This key has already been added to this repository")
|
ctx.APIError(http.StatusUnprocessableEntity, "This key has already been added to this repository")
|
||||||
case asymkey_model.IsErrKeyAlreadyExist(err):
|
case asymkey_model.IsErrKeyAlreadyExist(err):
|
||||||
ctx.Error(http.StatusUnprocessableEntity, "", "Key content has been used as non-deploy key")
|
ctx.APIError(http.StatusUnprocessableEntity, "Key content has been used as non-deploy key")
|
||||||
case asymkey_model.IsErrKeyNameAlreadyUsed(err):
|
case asymkey_model.IsErrKeyNameAlreadyUsed(err):
|
||||||
ctx.Error(http.StatusUnprocessableEntity, "", "Key title has been used")
|
ctx.APIError(http.StatusUnprocessableEntity, "Key title has been used")
|
||||||
case asymkey_model.IsErrDeployKeyNameAlreadyUsed(err):
|
case asymkey_model.IsErrDeployKeyNameAlreadyUsed(err):
|
||||||
ctx.Error(http.StatusUnprocessableEntity, "", "A key with the same name already exists")
|
ctx.APIError(http.StatusUnprocessableEntity, "A key with the same name already exists")
|
||||||
default:
|
default:
|
||||||
ctx.Error(http.StatusInternalServerError, "AddKey", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -281,9 +281,9 @@ func DeleteDeploykey(ctx *context.APIContext) {
|
||||||
|
|
||||||
if err := asymkey_service.DeleteDeployKey(ctx, ctx.Repo.Repository, ctx.PathParamInt64("id")); err != nil {
|
if err := asymkey_service.DeleteDeployKey(ctx, ctx.Repo.Repository, ctx.PathParamInt64("id")); err != nil {
|
||||||
if asymkey_model.IsErrKeyAccessDenied(err) {
|
if asymkey_model.IsErrKeyAccessDenied(err) {
|
||||||
ctx.Error(http.StatusForbidden, "", "You do not have access to this key")
|
ctx.APIError(http.StatusForbidden, "You do not have access to this key")
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "DeleteDeployKey", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,13 +51,13 @@ func ListLabels(ctx *context.APIContext) {
|
||||||
|
|
||||||
labels, err := issues_model.GetLabelsByRepoID(ctx, ctx.Repo.Repository.ID, ctx.FormString("sort"), utils.GetListOptions(ctx))
|
labels, err := issues_model.GetLabelsByRepoID(ctx, ctx.Repo.Repository.ID, ctx.FormString("sort"), utils.GetListOptions(ctx))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetLabelsByRepoID", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
count, err := issues_model.CountLabelsByRepoID(ctx, ctx.Repo.Repository.ID)
|
count, err := issues_model.CountLabelsByRepoID(ctx, ctx.Repo.Repository.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.InternalServerError(err)
|
ctx.APIErrorInternal(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -107,9 +107,9 @@ func GetLabel(ctx *context.APIContext) {
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if issues_model.IsErrRepoLabelNotExist(err) {
|
if issues_model.IsErrRepoLabelNotExist(err) {
|
||||||
ctx.NotFound()
|
ctx.APIErrorNotFound()
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetLabelByRepoID", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -153,7 +153,7 @@ func CreateLabel(ctx *context.APIContext) {
|
||||||
|
|
||||||
color, err := label.NormalizeColor(form.Color)
|
color, err := label.NormalizeColor(form.Color)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusUnprocessableEntity, "StringToColor", err)
|
ctx.APIError(http.StatusUnprocessableEntity, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
form.Color = color
|
form.Color = color
|
||||||
|
@ -166,7 +166,7 @@ func CreateLabel(ctx *context.APIContext) {
|
||||||
}
|
}
|
||||||
l.SetArchived(form.IsArchived)
|
l.SetArchived(form.IsArchived)
|
||||||
if err := issues_model.NewLabel(ctx, l); err != nil {
|
if err := issues_model.NewLabel(ctx, l); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "NewLabel", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -215,9 +215,9 @@ func EditLabel(ctx *context.APIContext) {
|
||||||
l, err := issues_model.GetLabelInRepoByID(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("id"))
|
l, err := issues_model.GetLabelInRepoByID(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("id"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if issues_model.IsErrRepoLabelNotExist(err) {
|
if issues_model.IsErrRepoLabelNotExist(err) {
|
||||||
ctx.NotFound()
|
ctx.APIErrorNotFound()
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetLabelByRepoID", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -231,7 +231,7 @@ func EditLabel(ctx *context.APIContext) {
|
||||||
if form.Color != nil {
|
if form.Color != nil {
|
||||||
color, err := label.NormalizeColor(*form.Color)
|
color, err := label.NormalizeColor(*form.Color)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusUnprocessableEntity, "StringToColor", err)
|
ctx.APIError(http.StatusUnprocessableEntity, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
l.Color = color
|
l.Color = color
|
||||||
|
@ -241,7 +241,7 @@ func EditLabel(ctx *context.APIContext) {
|
||||||
}
|
}
|
||||||
l.SetArchived(form.IsArchived != nil && *form.IsArchived)
|
l.SetArchived(form.IsArchived != nil && *form.IsArchived)
|
||||||
if err := issues_model.UpdateLabel(ctx, l); err != nil {
|
if err := issues_model.UpdateLabel(ctx, l); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "UpdateLabel", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -277,7 +277,7 @@ func DeleteLabel(ctx *context.APIContext) {
|
||||||
// "$ref": "#/responses/notFound"
|
// "$ref": "#/responses/notFound"
|
||||||
|
|
||||||
if err := issues_model.DeleteLabel(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("id")); err != nil {
|
if err := issues_model.DeleteLabel(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("id")); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "DeleteLabel", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -70,7 +70,7 @@ func GetLanguages(ctx *context.APIContext) {
|
||||||
langs, err := repo_model.GetLanguageStats(ctx, ctx.Repo.Repository)
|
langs, err := repo_model.GetLanguageStats(ctx, ctx.Repo.Repository)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("GetLanguageStats failed: %v", err)
|
log.Error("GetLanguageStats failed: %v", err)
|
||||||
ctx.InternalServerError(err)
|
ctx.APIErrorInternal(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -38,7 +38,7 @@ func GetLicenses(ctx *context.APIContext) {
|
||||||
licenses, err := repo_model.GetRepoLicenses(ctx, ctx.Repo.Repository)
|
licenses, err := repo_model.GetRepoLicenses(ctx, ctx.Repo.Repository)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("GetRepoLicenses failed: %v", err)
|
log.Error("GetRepoLicenses failed: %v", err)
|
||||||
ctx.InternalServerError(err)
|
ctx.APIErrorInternal(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -72,21 +72,21 @@ func Migrate(ctx *context.APIContext) {
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if user_model.IsErrUserNotExist(err) {
|
if user_model.IsErrUserNotExist(err) {
|
||||||
ctx.Error(http.StatusUnprocessableEntity, "", err)
|
ctx.APIError(http.StatusUnprocessableEntity, err)
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetUser", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if ctx.HasAPIError() {
|
if ctx.HasAPIError() {
|
||||||
ctx.Error(http.StatusUnprocessableEntity, "", ctx.GetErrMsg())
|
ctx.APIError(http.StatusUnprocessableEntity, ctx.GetErrMsg())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if !ctx.Doer.IsAdmin {
|
if !ctx.Doer.IsAdmin {
|
||||||
if !repoOwner.IsOrganization() && ctx.Doer.ID != repoOwner.ID {
|
if !repoOwner.IsOrganization() && ctx.Doer.ID != repoOwner.ID {
|
||||||
ctx.Error(http.StatusForbidden, "", "Given user is not an organization.")
|
ctx.APIError(http.StatusForbidden, "Given user is not an organization.")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -94,10 +94,10 @@ func Migrate(ctx *context.APIContext) {
|
||||||
// Check ownership of organization.
|
// Check ownership of organization.
|
||||||
isOwner, err := organization.OrgFromUser(repoOwner).IsOwnedBy(ctx, ctx.Doer.ID)
|
isOwner, err := organization.OrgFromUser(repoOwner).IsOwnedBy(ctx, ctx.Doer.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "IsOwnedBy", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
} else if !isOwner {
|
} else if !isOwner {
|
||||||
ctx.Error(http.StatusForbidden, "", "Given user is not owner of organization.")
|
ctx.APIError(http.StatusForbidden, "Given user is not owner of organization.")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -115,12 +115,12 @@ func Migrate(ctx *context.APIContext) {
|
||||||
gitServiceType := convert.ToGitServiceType(form.Service)
|
gitServiceType := convert.ToGitServiceType(form.Service)
|
||||||
|
|
||||||
if form.Mirror && setting.Mirror.DisableNewPull {
|
if form.Mirror && setting.Mirror.DisableNewPull {
|
||||||
ctx.Error(http.StatusForbidden, "MirrorsGlobalDisabled", fmt.Errorf("the site administrator has disabled the creation of new pull mirrors"))
|
ctx.APIError(http.StatusForbidden, fmt.Errorf("the site administrator has disabled the creation of new pull mirrors"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if setting.Repository.DisableMigrations {
|
if setting.Repository.DisableMigrations {
|
||||||
ctx.Error(http.StatusForbidden, "MigrationsGlobalDisabled", fmt.Errorf("the site administrator has disabled migrations"))
|
ctx.APIError(http.StatusForbidden, fmt.Errorf("the site administrator has disabled migrations"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -129,7 +129,7 @@ func Migrate(ctx *context.APIContext) {
|
||||||
if form.LFS && len(form.LFSEndpoint) > 0 {
|
if form.LFS && len(form.LFSEndpoint) > 0 {
|
||||||
ep := lfs.DetermineEndpoint("", form.LFSEndpoint)
|
ep := lfs.DetermineEndpoint("", form.LFSEndpoint)
|
||||||
if ep == nil {
|
if ep == nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "", ctx.Tr("repo.migrate.invalid_lfs_endpoint"))
|
ctx.APIError(http.StatusInternalServerError, ctx.Tr("repo.migrate.invalid_lfs_endpoint"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
err = migrations.IsMigrateURLAllowed(ep.String(), ctx.Doer)
|
err = migrations.IsMigrateURLAllowed(ep.String(), ctx.Doer)
|
||||||
|
@ -221,35 +221,35 @@ func Migrate(ctx *context.APIContext) {
|
||||||
func handleMigrateError(ctx *context.APIContext, repoOwner *user_model.User, err error) {
|
func handleMigrateError(ctx *context.APIContext, repoOwner *user_model.User, err error) {
|
||||||
switch {
|
switch {
|
||||||
case repo_model.IsErrRepoAlreadyExist(err):
|
case repo_model.IsErrRepoAlreadyExist(err):
|
||||||
ctx.Error(http.StatusConflict, "", "The repository with the same name already exists.")
|
ctx.APIError(http.StatusConflict, "The repository with the same name already exists.")
|
||||||
case repo_model.IsErrRepoFilesAlreadyExist(err):
|
case repo_model.IsErrRepoFilesAlreadyExist(err):
|
||||||
ctx.Error(http.StatusConflict, "", "Files already exist for this repository. Adopt them or delete them.")
|
ctx.APIError(http.StatusConflict, "Files already exist for this repository. Adopt them or delete them.")
|
||||||
case migrations.IsRateLimitError(err):
|
case migrations.IsRateLimitError(err):
|
||||||
ctx.Error(http.StatusUnprocessableEntity, "", "Remote visit addressed rate limitation.")
|
ctx.APIError(http.StatusUnprocessableEntity, "Remote visit addressed rate limitation.")
|
||||||
case migrations.IsTwoFactorAuthError(err):
|
case migrations.IsTwoFactorAuthError(err):
|
||||||
ctx.Error(http.StatusUnprocessableEntity, "", "Remote visit required two factors authentication.")
|
ctx.APIError(http.StatusUnprocessableEntity, "Remote visit required two factors authentication.")
|
||||||
case repo_model.IsErrReachLimitOfRepo(err):
|
case repo_model.IsErrReachLimitOfRepo(err):
|
||||||
ctx.Error(http.StatusUnprocessableEntity, "", fmt.Sprintf("You have already reached your limit of %d repositories.", repoOwner.MaxCreationLimit()))
|
ctx.APIError(http.StatusUnprocessableEntity, fmt.Sprintf("You have already reached your limit of %d repositories.", repoOwner.MaxCreationLimit()))
|
||||||
case db.IsErrNameReserved(err):
|
case db.IsErrNameReserved(err):
|
||||||
ctx.Error(http.StatusUnprocessableEntity, "", fmt.Sprintf("The username '%s' is reserved.", err.(db.ErrNameReserved).Name))
|
ctx.APIError(http.StatusUnprocessableEntity, fmt.Sprintf("The username '%s' is reserved.", err.(db.ErrNameReserved).Name))
|
||||||
case db.IsErrNameCharsNotAllowed(err):
|
case db.IsErrNameCharsNotAllowed(err):
|
||||||
ctx.Error(http.StatusUnprocessableEntity, "", fmt.Sprintf("The username '%s' contains invalid characters.", err.(db.ErrNameCharsNotAllowed).Name))
|
ctx.APIError(http.StatusUnprocessableEntity, fmt.Sprintf("The username '%s' contains invalid characters.", err.(db.ErrNameCharsNotAllowed).Name))
|
||||||
case db.IsErrNamePatternNotAllowed(err):
|
case db.IsErrNamePatternNotAllowed(err):
|
||||||
ctx.Error(http.StatusUnprocessableEntity, "", fmt.Sprintf("The pattern '%s' is not allowed in a username.", err.(db.ErrNamePatternNotAllowed).Pattern))
|
ctx.APIError(http.StatusUnprocessableEntity, fmt.Sprintf("The pattern '%s' is not allowed in a username.", err.(db.ErrNamePatternNotAllowed).Pattern))
|
||||||
case git.IsErrInvalidCloneAddr(err):
|
case git.IsErrInvalidCloneAddr(err):
|
||||||
ctx.Error(http.StatusUnprocessableEntity, "", err)
|
ctx.APIError(http.StatusUnprocessableEntity, err)
|
||||||
case base.IsErrNotSupported(err):
|
case base.IsErrNotSupported(err):
|
||||||
ctx.Error(http.StatusUnprocessableEntity, "", err)
|
ctx.APIError(http.StatusUnprocessableEntity, err)
|
||||||
default:
|
default:
|
||||||
err = util.SanitizeErrorCredentialURLs(err)
|
err = util.SanitizeErrorCredentialURLs(err)
|
||||||
if strings.Contains(err.Error(), "Authentication failed") ||
|
if strings.Contains(err.Error(), "Authentication failed") ||
|
||||||
strings.Contains(err.Error(), "Bad credentials") ||
|
strings.Contains(err.Error(), "Bad credentials") ||
|
||||||
strings.Contains(err.Error(), "could not read Username") {
|
strings.Contains(err.Error(), "could not read Username") {
|
||||||
ctx.Error(http.StatusUnprocessableEntity, "", fmt.Sprintf("Authentication failed: %v.", err))
|
ctx.APIError(http.StatusUnprocessableEntity, fmt.Sprintf("Authentication failed: %v.", err))
|
||||||
} else if strings.Contains(err.Error(), "fatal:") {
|
} else if strings.Contains(err.Error(), "fatal:") {
|
||||||
ctx.Error(http.StatusUnprocessableEntity, "", fmt.Sprintf("Migration failed: %v.", err))
|
ctx.APIError(http.StatusUnprocessableEntity, fmt.Sprintf("Migration failed: %v.", err))
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "MigrateRepository", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -259,19 +259,19 @@ func handleRemoteAddrError(ctx *context.APIContext, err error) {
|
||||||
addrErr := err.(*git.ErrInvalidCloneAddr)
|
addrErr := err.(*git.ErrInvalidCloneAddr)
|
||||||
switch {
|
switch {
|
||||||
case addrErr.IsURLError:
|
case addrErr.IsURLError:
|
||||||
ctx.Error(http.StatusUnprocessableEntity, "", err)
|
ctx.APIError(http.StatusUnprocessableEntity, err)
|
||||||
case addrErr.IsPermissionDenied:
|
case addrErr.IsPermissionDenied:
|
||||||
if addrErr.LocalPath {
|
if addrErr.LocalPath {
|
||||||
ctx.Error(http.StatusUnprocessableEntity, "", "You are not allowed to import local repositories.")
|
ctx.APIError(http.StatusUnprocessableEntity, "You are not allowed to import local repositories.")
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusUnprocessableEntity, "", "You can not import from disallowed hosts.")
|
ctx.APIError(http.StatusUnprocessableEntity, "You can not import from disallowed hosts.")
|
||||||
}
|
}
|
||||||
case addrErr.IsInvalidPath:
|
case addrErr.IsInvalidPath:
|
||||||
ctx.Error(http.StatusUnprocessableEntity, "", "Invalid local path, it does not exist or not a directory.")
|
ctx.APIError(http.StatusUnprocessableEntity, "Invalid local path, it does not exist or not a directory.")
|
||||||
default:
|
default:
|
||||||
ctx.Error(http.StatusInternalServerError, "ParseRemoteAddr", "Unknown error type (ErrInvalidCloneAddr): "+err.Error())
|
ctx.APIError(http.StatusInternalServerError, "Unknown error type (ErrInvalidCloneAddr): "+err.Error())
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "ParseRemoteAddr", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -74,7 +74,7 @@ func ListMilestones(ctx *context.APIContext) {
|
||||||
Name: ctx.FormString("name"),
|
Name: ctx.FormString("name"),
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "db.FindAndCount[issues_model.Milestone]", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -173,7 +173,7 @@ func CreateMilestone(ctx *context.APIContext) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := issues_model.NewMilestone(ctx, milestone); err != nil {
|
if err := issues_model.NewMilestone(ctx, milestone); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "NewMilestone", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.JSON(http.StatusCreated, convert.ToAPIMilestone(milestone))
|
ctx.JSON(http.StatusCreated, convert.ToAPIMilestone(milestone))
|
||||||
|
@ -233,7 +233,7 @@ func EditMilestone(ctx *context.APIContext) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := issues_model.UpdateMilestone(ctx, milestone, oldIsClosed); err != nil {
|
if err := issues_model.UpdateMilestone(ctx, milestone, oldIsClosed); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "UpdateMilestone", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.JSON(http.StatusOK, convert.ToAPIMilestone(milestone))
|
ctx.JSON(http.StatusOK, convert.ToAPIMilestone(milestone))
|
||||||
|
@ -272,7 +272,7 @@ func DeleteMilestone(ctx *context.APIContext) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := issues_model.DeleteMilestoneByRepoID(ctx, ctx.Repo.Repository.ID, m.ID); err != nil {
|
if err := issues_model.DeleteMilestoneByRepoID(ctx, ctx.Repo.Repository.ID, m.ID); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "DeleteMilestoneByRepoID", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.Status(http.StatusNoContent)
|
ctx.Status(http.StatusNoContent)
|
||||||
|
@ -288,7 +288,7 @@ func getMilestoneByIDOrName(ctx *context.APIContext) *issues_model.Milestone {
|
||||||
if err == nil {
|
if err == nil {
|
||||||
return milestone
|
return milestone
|
||||||
} else if !issues_model.IsErrMilestoneNotExist(err) {
|
} else if !issues_model.IsErrMilestoneNotExist(err) {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetMilestoneByRepoID", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -296,10 +296,10 @@ func getMilestoneByIDOrName(ctx *context.APIContext) *issues_model.Milestone {
|
||||||
milestone, err := issues_model.GetMilestoneByRepoIDANDName(ctx, ctx.Repo.Repository.ID, mile)
|
milestone, err := issues_model.GetMilestoneByRepoIDANDName(ctx, ctx.Repo.Repository.ID, mile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if issues_model.IsErrMilestoneNotExist(err) {
|
if issues_model.IsErrMilestoneNotExist(err) {
|
||||||
ctx.NotFound()
|
ctx.APIErrorNotFound()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
ctx.Error(http.StatusInternalServerError, "GetMilestoneByRepoID", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -53,20 +53,20 @@ func MirrorSync(ctx *context.APIContext) {
|
||||||
repo := ctx.Repo.Repository
|
repo := ctx.Repo.Repository
|
||||||
|
|
||||||
if !ctx.Repo.CanWrite(unit.TypeCode) {
|
if !ctx.Repo.CanWrite(unit.TypeCode) {
|
||||||
ctx.Error(http.StatusForbidden, "MirrorSync", "Must have write access")
|
ctx.APIError(http.StatusForbidden, "Must have write access")
|
||||||
}
|
}
|
||||||
|
|
||||||
if !setting.Mirror.Enabled {
|
if !setting.Mirror.Enabled {
|
||||||
ctx.Error(http.StatusBadRequest, "MirrorSync", "Mirror feature is disabled")
|
ctx.APIError(http.StatusBadRequest, "Mirror feature is disabled")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := repo_model.GetMirrorByRepoID(ctx, repo.ID); err != nil {
|
if _, err := repo_model.GetMirrorByRepoID(ctx, repo.ID); err != nil {
|
||||||
if errors.Is(err, repo_model.ErrMirrorNotExist) {
|
if errors.Is(err, repo_model.ErrMirrorNotExist) {
|
||||||
ctx.Error(http.StatusBadRequest, "MirrorSync", "Repository is not a mirror")
|
ctx.APIError(http.StatusBadRequest, "Repository is not a mirror")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.Error(http.StatusInternalServerError, "MirrorSync", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -104,19 +104,19 @@ func PushMirrorSync(ctx *context.APIContext) {
|
||||||
// "$ref": "#/responses/notFound"
|
// "$ref": "#/responses/notFound"
|
||||||
|
|
||||||
if !setting.Mirror.Enabled {
|
if !setting.Mirror.Enabled {
|
||||||
ctx.Error(http.StatusBadRequest, "PushMirrorSync", "Mirror feature is disabled")
|
ctx.APIError(http.StatusBadRequest, "Mirror feature is disabled")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// Get All push mirrors of a specific repo
|
// Get All push mirrors of a specific repo
|
||||||
pushMirrors, _, err := repo_model.GetPushMirrorsByRepoID(ctx, ctx.Repo.Repository.ID, db.ListOptions{})
|
pushMirrors, _, err := repo_model.GetPushMirrorsByRepoID(ctx, ctx.Repo.Repository.ID, db.ListOptions{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusNotFound, "PushMirrorSync", err)
|
ctx.APIError(http.StatusNotFound, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
for _, mirror := range pushMirrors {
|
for _, mirror := range pushMirrors {
|
||||||
ok := mirror_service.SyncPushMirror(ctx, mirror.ID)
|
ok := mirror_service.SyncPushMirror(ctx, mirror.ID)
|
||||||
if !ok {
|
if !ok {
|
||||||
ctx.Error(http.StatusInternalServerError, "PushMirrorSync", "error occurred when syncing push mirror "+mirror.RemoteName)
|
ctx.APIError(http.StatusInternalServerError, "error occurred when syncing push mirror "+mirror.RemoteName)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -161,7 +161,7 @@ func ListPushMirrors(ctx *context.APIContext) {
|
||||||
// "$ref": "#/responses/notFound"
|
// "$ref": "#/responses/notFound"
|
||||||
|
|
||||||
if !setting.Mirror.Enabled {
|
if !setting.Mirror.Enabled {
|
||||||
ctx.Error(http.StatusBadRequest, "GetPushMirrorsByRepoID", "Mirror feature is disabled")
|
ctx.APIError(http.StatusBadRequest, "Mirror feature is disabled")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -169,7 +169,7 @@ func ListPushMirrors(ctx *context.APIContext) {
|
||||||
// Get all push mirrors for the specified repository.
|
// Get all push mirrors for the specified repository.
|
||||||
pushMirrors, count, err := repo_model.GetPushMirrorsByRepoID(ctx, repo.ID, utils.GetListOptions(ctx))
|
pushMirrors, count, err := repo_model.GetPushMirrorsByRepoID(ctx, repo.ID, utils.GetListOptions(ctx))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusNotFound, "GetPushMirrorsByRepoID", err)
|
ctx.APIError(http.StatusNotFound, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -219,7 +219,7 @@ func GetPushMirrorByName(ctx *context.APIContext) {
|
||||||
// "$ref": "#/responses/notFound"
|
// "$ref": "#/responses/notFound"
|
||||||
|
|
||||||
if !setting.Mirror.Enabled {
|
if !setting.Mirror.Enabled {
|
||||||
ctx.Error(http.StatusBadRequest, "GetPushMirrorByRemoteName", "Mirror feature is disabled")
|
ctx.APIError(http.StatusBadRequest, "Mirror feature is disabled")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -230,16 +230,16 @@ func GetPushMirrorByName(ctx *context.APIContext) {
|
||||||
RemoteName: mirrorName,
|
RemoteName: mirrorName,
|
||||||
}.ToConds())
|
}.ToConds())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetPushMirrors", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
} else if !exist {
|
} else if !exist {
|
||||||
ctx.Error(http.StatusNotFound, "GetPushMirrors", nil)
|
ctx.APIError(http.StatusNotFound, nil)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
m, err := convert.ToPushMirror(ctx, pushMirror)
|
m, err := convert.ToPushMirror(ctx, pushMirror)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.ServerError("GetPushMirrorByRemoteName", err)
|
ctx.APIErrorInternal(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.JSON(http.StatusOK, m)
|
ctx.JSON(http.StatusOK, m)
|
||||||
|
@ -280,7 +280,7 @@ func AddPushMirror(ctx *context.APIContext) {
|
||||||
// "$ref": "#/responses/notFound"
|
// "$ref": "#/responses/notFound"
|
||||||
|
|
||||||
if !setting.Mirror.Enabled {
|
if !setting.Mirror.Enabled {
|
||||||
ctx.Error(http.StatusBadRequest, "AddPushMirror", "Mirror feature is disabled")
|
ctx.APIError(http.StatusBadRequest, "Mirror feature is disabled")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -320,7 +320,7 @@ func DeletePushMirrorByRemoteName(ctx *context.APIContext) {
|
||||||
// "$ref": "#/responses/error"
|
// "$ref": "#/responses/error"
|
||||||
|
|
||||||
if !setting.Mirror.Enabled {
|
if !setting.Mirror.Enabled {
|
||||||
ctx.Error(http.StatusBadRequest, "DeletePushMirrorByName", "Mirror feature is disabled")
|
ctx.APIError(http.StatusBadRequest, "Mirror feature is disabled")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -328,7 +328,7 @@ func DeletePushMirrorByRemoteName(ctx *context.APIContext) {
|
||||||
// Delete push mirror on repo by name.
|
// Delete push mirror on repo by name.
|
||||||
err := repo_model.DeletePushMirrors(ctx, repo_model.PushMirrorOptions{RepoID: ctx.Repo.Repository.ID, RemoteName: remoteName})
|
err := repo_model.DeletePushMirrors(ctx, repo_model.PushMirrorOptions{RepoID: ctx.Repo.Repository.ID, RemoteName: remoteName})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusNotFound, "DeletePushMirrors", err)
|
ctx.APIError(http.StatusNotFound, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.Status(http.StatusNoContent)
|
ctx.Status(http.StatusNoContent)
|
||||||
|
@ -339,7 +339,7 @@ func CreatePushMirror(ctx *context.APIContext, mirrorOption *api.CreatePushMirro
|
||||||
|
|
||||||
interval, err := time.ParseDuration(mirrorOption.Interval)
|
interval, err := time.ParseDuration(mirrorOption.Interval)
|
||||||
if err != nil || (interval != 0 && interval < setting.Mirror.MinInterval) {
|
if err != nil || (interval != 0 && interval < setting.Mirror.MinInterval) {
|
||||||
ctx.Error(http.StatusBadRequest, "CreatePushMirror", err)
|
ctx.APIError(http.StatusBadRequest, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -354,13 +354,13 @@ func CreatePushMirror(ctx *context.APIContext, mirrorOption *api.CreatePushMirro
|
||||||
|
|
||||||
remoteSuffix, err := util.CryptoRandomString(10)
|
remoteSuffix, err := util.CryptoRandomString(10)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.ServerError("CryptoRandomString", err)
|
ctx.APIErrorInternal(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
remoteAddress, err := util.SanitizeURL(mirrorOption.RemoteAddress)
|
remoteAddress, err := util.SanitizeURL(mirrorOption.RemoteAddress)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.ServerError("SanitizeURL", err)
|
ctx.APIErrorInternal(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -374,22 +374,22 @@ func CreatePushMirror(ctx *context.APIContext, mirrorOption *api.CreatePushMirro
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = db.Insert(ctx, pushMirror); err != nil {
|
if err = db.Insert(ctx, pushMirror); err != nil {
|
||||||
ctx.ServerError("InsertPushMirror", err)
|
ctx.APIErrorInternal(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// if the registration of the push mirrorOption fails remove it from the database
|
// if the registration of the push mirrorOption fails remove it from the database
|
||||||
if err = mirror_service.AddPushMirrorRemote(ctx, pushMirror, address); err != nil {
|
if err = mirror_service.AddPushMirrorRemote(ctx, pushMirror, address); err != nil {
|
||||||
if err := repo_model.DeletePushMirrors(ctx, repo_model.PushMirrorOptions{ID: pushMirror.ID, RepoID: pushMirror.RepoID}); err != nil {
|
if err := repo_model.DeletePushMirrors(ctx, repo_model.PushMirrorOptions{ID: pushMirror.ID, RepoID: pushMirror.RepoID}); err != nil {
|
||||||
ctx.ServerError("DeletePushMirrors", err)
|
ctx.APIErrorInternal(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.ServerError("AddPushMirrorRemote", err)
|
ctx.APIErrorInternal(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
m, err := convert.ToPushMirror(ctx, pushMirror)
|
m, err := convert.ToPushMirror(ctx, pushMirror)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.ServerError("ToPushMirror", err)
|
ctx.APIErrorInternal(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.JSON(http.StatusOK, m)
|
ctx.JSON(http.StatusOK, m)
|
||||||
|
@ -400,13 +400,13 @@ func HandleRemoteAddressError(ctx *context.APIContext, err error) {
|
||||||
addrErr := err.(*git.ErrInvalidCloneAddr)
|
addrErr := err.(*git.ErrInvalidCloneAddr)
|
||||||
switch {
|
switch {
|
||||||
case addrErr.IsProtocolInvalid:
|
case addrErr.IsProtocolInvalid:
|
||||||
ctx.Error(http.StatusBadRequest, "CreatePushMirror", "Invalid mirror protocol")
|
ctx.APIError(http.StatusBadRequest, "Invalid mirror protocol")
|
||||||
case addrErr.IsURLError:
|
case addrErr.IsURLError:
|
||||||
ctx.Error(http.StatusBadRequest, "CreatePushMirror", "Invalid Url ")
|
ctx.APIError(http.StatusBadRequest, "Invalid Url ")
|
||||||
case addrErr.IsPermissionDenied:
|
case addrErr.IsPermissionDenied:
|
||||||
ctx.Error(http.StatusUnauthorized, "CreatePushMirror", "Permission denied")
|
ctx.APIError(http.StatusUnauthorized, "Permission denied")
|
||||||
default:
|
default:
|
||||||
ctx.Error(http.StatusBadRequest, "CreatePushMirror", "Unknown error")
|
ctx.APIError(http.StatusBadRequest, "Unknown error")
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,7 +54,7 @@ func GetNote(ctx *context.APIContext) {
|
||||||
|
|
||||||
sha := ctx.PathParam("sha")
|
sha := ctx.PathParam("sha")
|
||||||
if !git.IsValidRefPattern(sha) {
|
if !git.IsValidRefPattern(sha) {
|
||||||
ctx.Error(http.StatusUnprocessableEntity, "no valid ref or sha", fmt.Sprintf("no valid ref or sha: %s", sha))
|
ctx.APIError(http.StatusUnprocessableEntity, fmt.Sprintf("no valid ref or sha: %s", sha))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
getNote(ctx, sha)
|
getNote(ctx, sha)
|
||||||
|
@ -62,16 +62,16 @@ func GetNote(ctx *context.APIContext) {
|
||||||
|
|
||||||
func getNote(ctx *context.APIContext, identifier string) {
|
func getNote(ctx *context.APIContext, identifier string) {
|
||||||
if ctx.Repo.GitRepo == nil {
|
if ctx.Repo.GitRepo == nil {
|
||||||
ctx.InternalServerError(fmt.Errorf("no open git repo"))
|
ctx.APIErrorInternal(fmt.Errorf("no open git repo"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
commitID, err := ctx.Repo.GitRepo.ConvertToGitID(identifier)
|
commitID, err := ctx.Repo.GitRepo.ConvertToGitID(identifier)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if git.IsErrNotExist(err) {
|
if git.IsErrNotExist(err) {
|
||||||
ctx.NotFound(err)
|
ctx.APIErrorNotFound(err)
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "ConvertToSHA1", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -79,10 +79,10 @@ func getNote(ctx *context.APIContext, identifier string) {
|
||||||
var note git.Note
|
var note git.Note
|
||||||
if err := git.GetNote(ctx, ctx.Repo.GitRepo, commitID.String(), ¬e); err != nil {
|
if err := git.GetNote(ctx, ctx.Repo.GitRepo, commitID.String(), ¬e); err != nil {
|
||||||
if git.IsErrNotExist(err) {
|
if git.IsErrNotExist(err) {
|
||||||
ctx.NotFound(identifier)
|
ctx.APIErrorNotFound(identifier)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.Error(http.StatusInternalServerError, "GetNote", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -96,7 +96,7 @@ func getNote(ctx *context.APIContext, identifier string) {
|
||||||
Files: files,
|
Files: files,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "ToCommit", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
apiNote := api.Note{Message: string(note.Message), Commit: cmt}
|
apiNote := api.Note{Message: string(note.Message), Commit: cmt}
|
||||||
|
|
|
@ -83,7 +83,7 @@ func ApplyDiffPatch(ctx *context.APIContext) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if !canWriteFiles(ctx, apiOpts.BranchName) {
|
if !canWriteFiles(ctx, apiOpts.BranchName) {
|
||||||
ctx.Error(http.StatusInternalServerError, "ApplyPatch", repo_model.ErrUserDoesNotHaveAccessToRepo{
|
ctx.APIError(http.StatusInternalServerError, repo_model.ErrUserDoesNotHaveAccessToRepo{
|
||||||
UserID: ctx.Doer.ID,
|
UserID: ctx.Doer.ID,
|
||||||
RepoName: ctx.Repo.Repository.LowerName,
|
RepoName: ctx.Repo.Repository.LowerName,
|
||||||
})
|
})
|
||||||
|
@ -93,19 +93,19 @@ func ApplyDiffPatch(ctx *context.APIContext) {
|
||||||
fileResponse, err := files.ApplyDiffPatch(ctx, ctx.Repo.Repository, ctx.Doer, opts)
|
fileResponse, err := files.ApplyDiffPatch(ctx, ctx.Repo.Repository, ctx.Doer, opts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if files.IsErrUserCannotCommit(err) || pull_service.IsErrFilePathProtected(err) {
|
if files.IsErrUserCannotCommit(err) || pull_service.IsErrFilePathProtected(err) {
|
||||||
ctx.Error(http.StatusForbidden, "Access", err)
|
ctx.APIError(http.StatusForbidden, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if git_model.IsErrBranchAlreadyExists(err) || files.IsErrFilenameInvalid(err) || pull_service.IsErrSHADoesNotMatch(err) ||
|
if git_model.IsErrBranchAlreadyExists(err) || files.IsErrFilenameInvalid(err) || pull_service.IsErrSHADoesNotMatch(err) ||
|
||||||
files.IsErrFilePathInvalid(err) || files.IsErrRepoFileAlreadyExists(err) {
|
files.IsErrFilePathInvalid(err) || files.IsErrRepoFileAlreadyExists(err) {
|
||||||
ctx.Error(http.StatusUnprocessableEntity, "Invalid", err)
|
ctx.APIError(http.StatusUnprocessableEntity, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if git_model.IsErrBranchNotExist(err) || git.IsErrBranchNotExist(err) {
|
if git_model.IsErrBranchNotExist(err) || git.IsErrBranchNotExist(err) {
|
||||||
ctx.Error(http.StatusNotFound, "BranchDoesNotExist", err)
|
ctx.APIError(http.StatusNotFound, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.Error(http.StatusInternalServerError, "ApplyPatch", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
} else {
|
} else {
|
||||||
ctx.JSON(http.StatusCreated, fileResponse)
|
ctx.JSON(http.StatusCreated, fileResponse)
|
||||||
}
|
}
|
||||||
|
|
|
@ -108,7 +108,7 @@ func ListPullRequests(ctx *context.APIContext) {
|
||||||
|
|
||||||
labelIDs, err := base.StringsToInt64s(ctx.FormStrings("labels"))
|
labelIDs, err := base.StringsToInt64s(ctx.FormStrings("labels"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "PullRequests", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
var posterID int64
|
var posterID int64
|
||||||
|
@ -116,9 +116,9 @@ func ListPullRequests(ctx *context.APIContext) {
|
||||||
poster, err := user_model.GetUserByName(ctx, posterStr)
|
poster, err := user_model.GetUserByName(ctx, posterStr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if user_model.IsErrUserNotExist(err) {
|
if user_model.IsErrUserNotExist(err) {
|
||||||
ctx.Error(http.StatusBadRequest, "Poster not found", err)
|
ctx.APIError(http.StatusBadRequest, err)
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetUserByName", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -134,13 +134,13 @@ func ListPullRequests(ctx *context.APIContext) {
|
||||||
PosterID: posterID,
|
PosterID: posterID,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "PullRequests", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
apiPrs, err := convert.ToAPIPullRequests(ctx, ctx.Repo.Repository, prs, ctx.Doer)
|
apiPrs, err := convert.ToAPIPullRequests(ctx, ctx.Repo.Repository, prs, ctx.Doer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "ToAPIPullRequests", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -182,19 +182,19 @@ func GetPullRequest(ctx *context.APIContext) {
|
||||||
pr, err := issues_model.GetPullRequestByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("index"))
|
pr, err := issues_model.GetPullRequestByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("index"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if issues_model.IsErrPullRequestNotExist(err) {
|
if issues_model.IsErrPullRequestNotExist(err) {
|
||||||
ctx.NotFound()
|
ctx.APIErrorNotFound()
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetPullRequestByIndex", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = pr.LoadBaseRepo(ctx); err != nil {
|
if err = pr.LoadBaseRepo(ctx); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "LoadBaseRepo", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if err = pr.LoadHeadRepo(ctx); err != nil {
|
if err = pr.LoadHeadRepo(ctx); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "LoadHeadRepo", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.JSON(http.StatusOK, convert.ToAPIPullRequest(ctx, pr, ctx.Doer))
|
ctx.JSON(http.StatusOK, convert.ToAPIPullRequest(ctx, pr, ctx.Doer))
|
||||||
|
@ -252,9 +252,9 @@ func GetPullRequestByBaseHead(ctx *context.APIContext) {
|
||||||
repo, err := repo_model.GetRepositoryByOwnerAndName(ctx, owner, name)
|
repo, err := repo_model.GetRepositoryByOwnerAndName(ctx, owner, name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if repo_model.IsErrRepoNotExist(err) {
|
if repo_model.IsErrRepoNotExist(err) {
|
||||||
ctx.NotFound()
|
ctx.APIErrorNotFound()
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetRepositoryByOwnerName", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -267,19 +267,19 @@ func GetPullRequestByBaseHead(ctx *context.APIContext) {
|
||||||
pr, err := issues_model.GetPullRequestByBaseHeadInfo(ctx, ctx.Repo.Repository.ID, headRepoID, ctx.PathParam("base"), headBranch)
|
pr, err := issues_model.GetPullRequestByBaseHeadInfo(ctx, ctx.Repo.Repository.ID, headRepoID, ctx.PathParam("base"), headBranch)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if issues_model.IsErrPullRequestNotExist(err) {
|
if issues_model.IsErrPullRequestNotExist(err) {
|
||||||
ctx.NotFound()
|
ctx.APIErrorNotFound()
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetPullRequestByBaseHeadInfo", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = pr.LoadBaseRepo(ctx); err != nil {
|
if err = pr.LoadBaseRepo(ctx); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "LoadBaseRepo", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if err = pr.LoadHeadRepo(ctx); err != nil {
|
if err = pr.LoadHeadRepo(ctx); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "LoadHeadRepo", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.JSON(http.StatusOK, convert.ToAPIPullRequest(ctx, pr, ctx.Doer))
|
ctx.JSON(http.StatusOK, convert.ToAPIPullRequest(ctx, pr, ctx.Doer))
|
||||||
|
@ -327,9 +327,9 @@ func DownloadPullDiffOrPatch(ctx *context.APIContext) {
|
||||||
pr, err := issues_model.GetPullRequestByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("index"))
|
pr, err := issues_model.GetPullRequestByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("index"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if issues_model.IsErrPullRequestNotExist(err) {
|
if issues_model.IsErrPullRequestNotExist(err) {
|
||||||
ctx.NotFound()
|
ctx.APIErrorNotFound()
|
||||||
} else {
|
} else {
|
||||||
ctx.InternalServerError(err)
|
ctx.APIErrorInternal(err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -343,7 +343,7 @@ func DownloadPullDiffOrPatch(ctx *context.APIContext) {
|
||||||
binary := ctx.FormBool("binary")
|
binary := ctx.FormBool("binary")
|
||||||
|
|
||||||
if err := pull_service.DownloadDiffOrPatch(ctx, pr, ctx, patch, binary); err != nil {
|
if err := pull_service.DownloadDiffOrPatch(ctx, pr, ctx, patch, binary); err != nil {
|
||||||
ctx.InternalServerError(err)
|
ctx.APIErrorInternal(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -388,7 +388,7 @@ func CreatePullRequest(ctx *context.APIContext) {
|
||||||
|
|
||||||
form := *web.GetForm(ctx).(*api.CreatePullRequestOption)
|
form := *web.GetForm(ctx).(*api.CreatePullRequestOption)
|
||||||
if form.Head == form.Base {
|
if form.Head == form.Base {
|
||||||
ctx.Error(http.StatusUnprocessableEntity, "BaseHeadSame", "Invalid PullRequest: There are no changes between the head and the base")
|
ctx.APIError(http.StatusUnprocessableEntity, "Invalid PullRequest: There are no changes between the head and the base")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -406,7 +406,7 @@ func CreatePullRequest(ctx *context.APIContext) {
|
||||||
defer closer()
|
defer closer()
|
||||||
|
|
||||||
if !compareResult.baseRef.IsBranch() || !compareResult.headRef.IsBranch() {
|
if !compareResult.baseRef.IsBranch() || !compareResult.headRef.IsBranch() {
|
||||||
ctx.Error(http.StatusUnprocessableEntity, "BaseHeadInvalidRefType", "Invalid PullRequest: base and head must be branches")
|
ctx.APIError(http.StatusUnprocessableEntity, "Invalid PullRequest: base and head must be branches")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -417,7 +417,7 @@ func CreatePullRequest(ctx *context.APIContext) {
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if !issues_model.IsErrPullRequestNotExist(err) {
|
if !issues_model.IsErrPullRequestNotExist(err) {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetUnmergedPullRequest", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -429,14 +429,14 @@ func CreatePullRequest(ctx *context.APIContext) {
|
||||||
HeadBranch: existingPr.HeadBranch,
|
HeadBranch: existingPr.HeadBranch,
|
||||||
BaseBranch: existingPr.BaseBranch,
|
BaseBranch: existingPr.BaseBranch,
|
||||||
}
|
}
|
||||||
ctx.Error(http.StatusConflict, "GetUnmergedPullRequest", err)
|
ctx.APIError(http.StatusConflict, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(form.Labels) > 0 {
|
if len(form.Labels) > 0 {
|
||||||
labels, err := issues_model.GetLabelsInRepoByIDs(ctx, ctx.Repo.Repository.ID, form.Labels)
|
labels, err := issues_model.GetLabelsInRepoByIDs(ctx, ctx.Repo.Repository.ID, form.Labels)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetLabelsInRepoByIDs", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -448,7 +448,7 @@ func CreatePullRequest(ctx *context.APIContext) {
|
||||||
if ctx.Repo.Owner.IsOrganization() {
|
if ctx.Repo.Owner.IsOrganization() {
|
||||||
orgLabels, err := issues_model.GetLabelsInOrgByIDs(ctx, ctx.Repo.Owner.ID, form.Labels)
|
orgLabels, err := issues_model.GetLabelsInOrgByIDs(ctx, ctx.Repo.Owner.ID, form.Labels)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetLabelsInOrgByIDs", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -464,9 +464,9 @@ func CreatePullRequest(ctx *context.APIContext) {
|
||||||
milestone, err := issues_model.GetMilestoneByRepoID(ctx, ctx.Repo.Repository.ID, form.Milestone)
|
milestone, err := issues_model.GetMilestoneByRepoID(ctx, ctx.Repo.Repository.ID, form.Milestone)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if issues_model.IsErrMilestoneNotExist(err) {
|
if issues_model.IsErrMilestoneNotExist(err) {
|
||||||
ctx.NotFound()
|
ctx.APIErrorNotFound()
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetMilestoneByRepoID", err)
|
ctx.APIError(http.StatusInternalServerError, fmt.Errorf("GetMilestoneByRepoID: %w", err))
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -504,9 +504,9 @@ func CreatePullRequest(ctx *context.APIContext) {
|
||||||
assigneeIDs, err := issues_model.MakeIDsFromAPIAssigneesToAdd(ctx, form.Assignee, form.Assignees)
|
assigneeIDs, err := issues_model.MakeIDsFromAPIAssigneesToAdd(ctx, form.Assignee, form.Assignees)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if user_model.IsErrUserNotExist(err) {
|
if user_model.IsErrUserNotExist(err) {
|
||||||
ctx.Error(http.StatusUnprocessableEntity, "", fmt.Sprintf("Assignee does not exist: [name: %s]", err))
|
ctx.APIError(http.StatusUnprocessableEntity, fmt.Sprintf("Assignee does not exist: [name: %s]", err))
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "AddAssigneeByName", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -514,17 +514,17 @@ func CreatePullRequest(ctx *context.APIContext) {
|
||||||
for _, aID := range assigneeIDs {
|
for _, aID := range assigneeIDs {
|
||||||
assignee, err := user_model.GetUserByID(ctx, aID)
|
assignee, err := user_model.GetUserByID(ctx, aID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetUserByID", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
valid, err := access_model.CanBeAssigned(ctx, assignee, repo, true)
|
valid, err := access_model.CanBeAssigned(ctx, assignee, repo, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "canBeAssigned", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if !valid {
|
if !valid {
|
||||||
ctx.Error(http.StatusUnprocessableEntity, "canBeAssigned", repo_model.ErrUserDoesNotHaveAccessToRepo{UserID: aID, RepoName: repo.Name})
|
ctx.APIError(http.StatusUnprocessableEntity, repo_model.ErrUserDoesNotHaveAccessToRepo{UserID: aID, RepoName: repo.Name})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -543,13 +543,13 @@ func CreatePullRequest(ctx *context.APIContext) {
|
||||||
|
|
||||||
if err := pull_service.NewPullRequest(ctx, prOpts); err != nil {
|
if err := pull_service.NewPullRequest(ctx, prOpts); err != nil {
|
||||||
if repo_model.IsErrUserDoesNotHaveAccessToRepo(err) {
|
if repo_model.IsErrUserDoesNotHaveAccessToRepo(err) {
|
||||||
ctx.Error(http.StatusBadRequest, "UserDoesNotHaveAccessToRepo", err)
|
ctx.APIError(http.StatusBadRequest, err)
|
||||||
} else if errors.Is(err, user_model.ErrBlockedUser) {
|
} else if errors.Is(err, user_model.ErrBlockedUser) {
|
||||||
ctx.Error(http.StatusForbidden, "BlockedUser", err)
|
ctx.APIError(http.StatusForbidden, err)
|
||||||
} else if errors.Is(err, issues_model.ErrMustCollaborator) {
|
} else if errors.Is(err, issues_model.ErrMustCollaborator) {
|
||||||
ctx.Error(http.StatusForbidden, "MustCollaborator", err)
|
ctx.APIError(http.StatusForbidden, err)
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "NewPullRequest", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -606,23 +606,23 @@ func EditPullRequest(ctx *context.APIContext) {
|
||||||
pr, err := issues_model.GetPullRequestByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("index"))
|
pr, err := issues_model.GetPullRequestByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("index"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if issues_model.IsErrPullRequestNotExist(err) {
|
if issues_model.IsErrPullRequestNotExist(err) {
|
||||||
ctx.NotFound()
|
ctx.APIErrorNotFound()
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetPullRequestByIndex", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
err = pr.LoadIssue(ctx)
|
err = pr.LoadIssue(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "LoadIssue", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
issue := pr.Issue
|
issue := pr.Issue
|
||||||
issue.Repo = ctx.Repo.Repository
|
issue.Repo = ctx.Repo.Repository
|
||||||
|
|
||||||
if err := issue.LoadAttributes(ctx); err != nil {
|
if err := issue.LoadAttributes(ctx); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "LoadAttributes", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -634,7 +634,7 @@ func EditPullRequest(ctx *context.APIContext) {
|
||||||
if len(form.Title) > 0 {
|
if len(form.Title) > 0 {
|
||||||
err = issue_service.ChangeTitle(ctx, issue, ctx.Doer, form.Title)
|
err = issue_service.ChangeTitle(ctx, issue, ctx.Doer, form.Title)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "ChangeTitle", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -642,11 +642,11 @@ func EditPullRequest(ctx *context.APIContext) {
|
||||||
err = issue_service.ChangeContent(ctx, issue, ctx.Doer, *form.Body, issue.ContentVersion)
|
err = issue_service.ChangeContent(ctx, issue, ctx.Doer, *form.Body, issue.ContentVersion)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if errors.Is(err, issues_model.ErrIssueAlreadyChanged) {
|
if errors.Is(err, issues_model.ErrIssueAlreadyChanged) {
|
||||||
ctx.Error(http.StatusBadRequest, "ChangeContent", err)
|
ctx.APIError(http.StatusBadRequest, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.Error(http.StatusInternalServerError, "ChangeContent", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -661,7 +661,7 @@ func EditPullRequest(ctx *context.APIContext) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := issues_model.UpdateIssueDeadline(ctx, issue, deadlineUnix, ctx.Doer); err != nil {
|
if err := issues_model.UpdateIssueDeadline(ctx, issue, deadlineUnix, ctx.Doer); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "UpdateIssueDeadline", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
issue.DeadlineUnix = deadlineUnix
|
issue.DeadlineUnix = deadlineUnix
|
||||||
|
@ -679,11 +679,11 @@ func EditPullRequest(ctx *context.APIContext) {
|
||||||
err = issue_service.UpdateAssignees(ctx, issue, form.Assignee, form.Assignees, ctx.Doer)
|
err = issue_service.UpdateAssignees(ctx, issue, form.Assignee, form.Assignees, ctx.Doer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if user_model.IsErrUserNotExist(err) {
|
if user_model.IsErrUserNotExist(err) {
|
||||||
ctx.Error(http.StatusUnprocessableEntity, "", fmt.Sprintf("Assignee does not exist: [name: %s]", err))
|
ctx.APIError(http.StatusUnprocessableEntity, fmt.Sprintf("Assignee does not exist: [name: %s]", err))
|
||||||
} else if errors.Is(err, user_model.ErrBlockedUser) {
|
} else if errors.Is(err, user_model.ErrBlockedUser) {
|
||||||
ctx.Error(http.StatusForbidden, "UpdateAssignees", err)
|
ctx.APIError(http.StatusForbidden, err)
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "UpdateAssignees", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -694,7 +694,7 @@ func EditPullRequest(ctx *context.APIContext) {
|
||||||
oldMilestoneID := issue.MilestoneID
|
oldMilestoneID := issue.MilestoneID
|
||||||
issue.MilestoneID = form.Milestone
|
issue.MilestoneID = form.Milestone
|
||||||
if err = issue_service.ChangeMilestoneAssign(ctx, issue, ctx.Doer, oldMilestoneID); err != nil {
|
if err = issue_service.ChangeMilestoneAssign(ctx, issue, ctx.Doer, oldMilestoneID); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "ChangeMilestoneAssign", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -702,14 +702,14 @@ func EditPullRequest(ctx *context.APIContext) {
|
||||||
if ctx.Repo.CanWrite(unit.TypePullRequests) && form.Labels != nil {
|
if ctx.Repo.CanWrite(unit.TypePullRequests) && form.Labels != nil {
|
||||||
labels, err := issues_model.GetLabelsInRepoByIDs(ctx, ctx.Repo.Repository.ID, form.Labels)
|
labels, err := issues_model.GetLabelsInRepoByIDs(ctx, ctx.Repo.Repository.ID, form.Labels)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetLabelsInRepoByIDsError", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if ctx.Repo.Owner.IsOrganization() {
|
if ctx.Repo.Owner.IsOrganization() {
|
||||||
orgLabels, err := issues_model.GetLabelsInOrgByIDs(ctx, ctx.Repo.Owner.ID, form.Labels)
|
orgLabels, err := issues_model.GetLabelsInOrgByIDs(ctx, ctx.Repo.Owner.ID, form.Labels)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetLabelsInOrgByIDs", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -717,14 +717,14 @@ func EditPullRequest(ctx *context.APIContext) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = issues_model.ReplaceIssueLabels(ctx, issue, labels, ctx.Doer); err != nil {
|
if err = issues_model.ReplaceIssueLabels(ctx, issue, labels, ctx.Doer); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "ReplaceLabelsError", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if form.State != nil {
|
if form.State != nil {
|
||||||
if pr.HasMerged {
|
if pr.HasMerged {
|
||||||
ctx.Error(http.StatusPreconditionFailed, "MergedPRState", "cannot change state of this pull request, it was already merged")
|
ctx.APIError(http.StatusPreconditionFailed, "cannot change state of this pull request, it was already merged")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -738,21 +738,21 @@ func EditPullRequest(ctx *context.APIContext) {
|
||||||
// change pull target branch
|
// change pull target branch
|
||||||
if !pr.HasMerged && len(form.Base) != 0 && form.Base != pr.BaseBranch {
|
if !pr.HasMerged && len(form.Base) != 0 && form.Base != pr.BaseBranch {
|
||||||
if !ctx.Repo.GitRepo.IsBranchExist(form.Base) {
|
if !ctx.Repo.GitRepo.IsBranchExist(form.Base) {
|
||||||
ctx.Error(http.StatusNotFound, "NewBaseBranchNotExist", fmt.Errorf("new base '%s' not exist", form.Base))
|
ctx.APIError(http.StatusNotFound, fmt.Errorf("new base '%s' not exist", form.Base))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if err := pull_service.ChangeTargetBranch(ctx, pr, ctx.Doer, form.Base); err != nil {
|
if err := pull_service.ChangeTargetBranch(ctx, pr, ctx.Doer, form.Base); err != nil {
|
||||||
if issues_model.IsErrPullRequestAlreadyExists(err) {
|
if issues_model.IsErrPullRequestAlreadyExists(err) {
|
||||||
ctx.Error(http.StatusConflict, "IsErrPullRequestAlreadyExists", err)
|
ctx.APIError(http.StatusConflict, err)
|
||||||
return
|
return
|
||||||
} else if issues_model.IsErrIssueIsClosed(err) {
|
} else if issues_model.IsErrIssueIsClosed(err) {
|
||||||
ctx.Error(http.StatusUnprocessableEntity, "IsErrIssueIsClosed", err)
|
ctx.APIError(http.StatusUnprocessableEntity, err)
|
||||||
return
|
return
|
||||||
} else if pull_service.IsErrPullRequestHasMerged(err) {
|
} else if pull_service.IsErrPullRequestHasMerged(err) {
|
||||||
ctx.Error(http.StatusConflict, "IsErrPullRequestHasMerged", err)
|
ctx.APIError(http.StatusConflict, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.InternalServerError(err)
|
ctx.APIErrorInternal(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
notify_service.PullRequestChangeTargetBranch(ctx, ctx.Doer, pr, form.Base)
|
notify_service.PullRequestChangeTargetBranch(ctx, ctx.Doer, pr, form.Base)
|
||||||
|
@ -762,10 +762,10 @@ func EditPullRequest(ctx *context.APIContext) {
|
||||||
if form.AllowMaintainerEdit != nil {
|
if form.AllowMaintainerEdit != nil {
|
||||||
if err := pull_service.SetAllowEdits(ctx, ctx.Doer, pr, *form.AllowMaintainerEdit); err != nil {
|
if err := pull_service.SetAllowEdits(ctx, ctx.Doer, pr, *form.AllowMaintainerEdit); err != nil {
|
||||||
if errors.Is(err, pull_service.ErrUserHasNoPermissionForAction) {
|
if errors.Is(err, pull_service.ErrUserHasNoPermissionForAction) {
|
||||||
ctx.Error(http.StatusForbidden, "SetAllowEdits", fmt.Sprintf("SetAllowEdits: %s", err))
|
ctx.APIError(http.StatusForbidden, fmt.Sprintf("SetAllowEdits: %s", err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.ServerError("SetAllowEdits", err)
|
ctx.APIErrorInternal(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -774,9 +774,9 @@ func EditPullRequest(ctx *context.APIContext) {
|
||||||
pr, err = issues_model.GetPullRequestByIndex(ctx, ctx.Repo.Repository.ID, pr.Index)
|
pr, err = issues_model.GetPullRequestByIndex(ctx, ctx.Repo.Repository.ID, pr.Index)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if issues_model.IsErrPullRequestNotExist(err) {
|
if issues_model.IsErrPullRequestNotExist(err) {
|
||||||
ctx.NotFound()
|
ctx.APIErrorNotFound()
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetPullRequestByIndex", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -818,9 +818,9 @@ func IsPullRequestMerged(ctx *context.APIContext) {
|
||||||
pr, err := issues_model.GetPullRequestByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("index"))
|
pr, err := issues_model.GetPullRequestByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("index"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if issues_model.IsErrPullRequestNotExist(err) {
|
if issues_model.IsErrPullRequestNotExist(err) {
|
||||||
ctx.NotFound()
|
ctx.APIErrorNotFound()
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetPullRequestByIndex", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -828,7 +828,7 @@ func IsPullRequestMerged(ctx *context.APIContext) {
|
||||||
if pr.HasMerged {
|
if pr.HasMerged {
|
||||||
ctx.Status(http.StatusNoContent)
|
ctx.Status(http.StatusNoContent)
|
||||||
}
|
}
|
||||||
ctx.NotFound()
|
ctx.APIErrorNotFound()
|
||||||
}
|
}
|
||||||
|
|
||||||
// MergePullRequest merges a PR given an index
|
// MergePullRequest merges a PR given an index
|
||||||
|
@ -876,20 +876,20 @@ func MergePullRequest(ctx *context.APIContext) {
|
||||||
pr, err := issues_model.GetPullRequestByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("index"))
|
pr, err := issues_model.GetPullRequestByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("index"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if issues_model.IsErrPullRequestNotExist(err) {
|
if issues_model.IsErrPullRequestNotExist(err) {
|
||||||
ctx.NotFound("GetPullRequestByIndex", err)
|
ctx.APIErrorNotFound("GetPullRequestByIndex", err)
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetPullRequestByIndex", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := pr.LoadHeadRepo(ctx); err != nil {
|
if err := pr.LoadHeadRepo(ctx); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "LoadHeadRepo", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := pr.LoadIssue(ctx); err != nil {
|
if err := pr.LoadIssue(ctx); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "LoadIssue", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
pr.Issue.Repo = ctx.Repo.Repository
|
pr.Issue.Repo = ctx.Repo.Repository
|
||||||
|
@ -897,7 +897,7 @@ func MergePullRequest(ctx *context.APIContext) {
|
||||||
if ctx.IsSigned {
|
if ctx.IsSigned {
|
||||||
// Update issue-user.
|
// Update issue-user.
|
||||||
if err = activities_model.SetIssueReadBy(ctx, pr.Issue.ID, ctx.Doer.ID); err != nil {
|
if err = activities_model.SetIssueReadBy(ctx, pr.Issue.ID, ctx.Doer.ID); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "ReadBy", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -915,21 +915,21 @@ func MergePullRequest(ctx *context.APIContext) {
|
||||||
// start with merging by checking
|
// start with merging by checking
|
||||||
if err := pull_service.CheckPullMergeable(ctx, ctx.Doer, &ctx.Repo.Permission, pr, mergeCheckType, form.ForceMerge); err != nil {
|
if err := pull_service.CheckPullMergeable(ctx, ctx.Doer, &ctx.Repo.Permission, pr, mergeCheckType, form.ForceMerge); err != nil {
|
||||||
if errors.Is(err, pull_service.ErrIsClosed) {
|
if errors.Is(err, pull_service.ErrIsClosed) {
|
||||||
ctx.NotFound()
|
ctx.APIErrorNotFound()
|
||||||
} else if errors.Is(err, pull_service.ErrUserNotAllowedToMerge) {
|
} else if errors.Is(err, pull_service.ErrUserNotAllowedToMerge) {
|
||||||
ctx.Error(http.StatusMethodNotAllowed, "Merge", "User not allowed to merge PR")
|
ctx.APIError(http.StatusMethodNotAllowed, "User not allowed to merge PR")
|
||||||
} else if errors.Is(err, pull_service.ErrHasMerged) {
|
} else if errors.Is(err, pull_service.ErrHasMerged) {
|
||||||
ctx.Error(http.StatusMethodNotAllowed, "PR already merged", "")
|
ctx.APIError(http.StatusMethodNotAllowed, "")
|
||||||
} else if errors.Is(err, pull_service.ErrIsWorkInProgress) {
|
} else if errors.Is(err, pull_service.ErrIsWorkInProgress) {
|
||||||
ctx.Error(http.StatusMethodNotAllowed, "PR is a work in progress", "Work in progress PRs cannot be merged")
|
ctx.APIError(http.StatusMethodNotAllowed, "Work in progress PRs cannot be merged")
|
||||||
} else if errors.Is(err, pull_service.ErrNotMergeableState) {
|
} else if errors.Is(err, pull_service.ErrNotMergeableState) {
|
||||||
ctx.Error(http.StatusMethodNotAllowed, "PR not in mergeable state", "Please try again later")
|
ctx.APIError(http.StatusMethodNotAllowed, "Please try again later")
|
||||||
} else if pull_service.IsErrDisallowedToMerge(err) {
|
} else if pull_service.IsErrDisallowedToMerge(err) {
|
||||||
ctx.Error(http.StatusMethodNotAllowed, "PR is not ready to be merged", err)
|
ctx.APIError(http.StatusMethodNotAllowed, err)
|
||||||
} else if asymkey_service.IsErrWontSign(err) {
|
} else if asymkey_service.IsErrWontSign(err) {
|
||||||
ctx.Error(http.StatusMethodNotAllowed, fmt.Sprintf("Protected branch %s requires signed commits but this merge would not be signed", pr.BaseBranch), err)
|
ctx.APIError(http.StatusMethodNotAllowed, err)
|
||||||
} else {
|
} else {
|
||||||
ctx.InternalServerError(err)
|
ctx.APIErrorInternal(err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -938,14 +938,14 @@ func MergePullRequest(ctx *context.APIContext) {
|
||||||
if manuallyMerged {
|
if manuallyMerged {
|
||||||
if err := pull_service.MergedManually(ctx, pr, ctx.Doer, ctx.Repo.GitRepo, form.MergeCommitID); err != nil {
|
if err := pull_service.MergedManually(ctx, pr, ctx.Doer, ctx.Repo.GitRepo, form.MergeCommitID); err != nil {
|
||||||
if pull_service.IsErrInvalidMergeStyle(err) {
|
if pull_service.IsErrInvalidMergeStyle(err) {
|
||||||
ctx.Error(http.StatusMethodNotAllowed, "Invalid merge style", fmt.Errorf("%s is not allowed an allowed merge style for this repository", repo_model.MergeStyle(form.Do)))
|
ctx.APIError(http.StatusMethodNotAllowed, fmt.Errorf("%s is not allowed an allowed merge style for this repository", repo_model.MergeStyle(form.Do)))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if strings.Contains(err.Error(), "Wrong commit ID") {
|
if strings.Contains(err.Error(), "Wrong commit ID") {
|
||||||
ctx.JSON(http.StatusConflict, err)
|
ctx.JSON(http.StatusConflict, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.Error(http.StatusInternalServerError, "Manually-Merged", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.Status(http.StatusOK)
|
ctx.Status(http.StatusOK)
|
||||||
|
@ -960,7 +960,7 @@ func MergePullRequest(ctx *context.APIContext) {
|
||||||
if len(message) == 0 {
|
if len(message) == 0 {
|
||||||
message, _, err = pull_service.GetDefaultMergeMessage(ctx, ctx.Repo.GitRepo, pr, repo_model.MergeStyle(form.Do))
|
message, _, err = pull_service.GetDefaultMergeMessage(ctx, ctx.Repo.GitRepo, pr, repo_model.MergeStyle(form.Do))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetDefaultMergeMessage", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -974,10 +974,10 @@ func MergePullRequest(ctx *context.APIContext) {
|
||||||
scheduled, err := automerge.ScheduleAutoMerge(ctx, ctx.Doer, pr, repo_model.MergeStyle(form.Do), message, form.DeleteBranchAfterMerge)
|
scheduled, err := automerge.ScheduleAutoMerge(ctx, ctx.Doer, pr, repo_model.MergeStyle(form.Do), message, form.DeleteBranchAfterMerge)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if pull_model.IsErrAlreadyScheduledToAutoMerge(err) {
|
if pull_model.IsErrAlreadyScheduledToAutoMerge(err) {
|
||||||
ctx.Error(http.StatusConflict, "ScheduleAutoMerge", err)
|
ctx.APIError(http.StatusConflict, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.Error(http.StatusInternalServerError, "ScheduleAutoMerge", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
} else if scheduled {
|
} else if scheduled {
|
||||||
// nothing more to do ...
|
// nothing more to do ...
|
||||||
|
@ -988,7 +988,7 @@ func MergePullRequest(ctx *context.APIContext) {
|
||||||
|
|
||||||
if err := pull_service.Merge(ctx, pr, ctx.Doer, ctx.Repo.GitRepo, repo_model.MergeStyle(form.Do), form.HeadCommitID, message, false); err != nil {
|
if err := pull_service.Merge(ctx, pr, ctx.Doer, ctx.Repo.GitRepo, repo_model.MergeStyle(form.Do), form.HeadCommitID, message, false); err != nil {
|
||||||
if pull_service.IsErrInvalidMergeStyle(err) {
|
if pull_service.IsErrInvalidMergeStyle(err) {
|
||||||
ctx.Error(http.StatusMethodNotAllowed, "Invalid merge style", fmt.Errorf("%s is not allowed an allowed merge style for this repository", repo_model.MergeStyle(form.Do)))
|
ctx.APIError(http.StatusMethodNotAllowed, fmt.Errorf("%s is not allowed an allowed merge style for this repository", repo_model.MergeStyle(form.Do)))
|
||||||
} else if pull_service.IsErrMergeConflicts(err) {
|
} else if pull_service.IsErrMergeConflicts(err) {
|
||||||
conflictError := err.(pull_service.ErrMergeConflicts)
|
conflictError := err.(pull_service.ErrMergeConflicts)
|
||||||
ctx.JSON(http.StatusConflict, conflictError)
|
ctx.JSON(http.StatusConflict, conflictError)
|
||||||
|
@ -999,18 +999,18 @@ func MergePullRequest(ctx *context.APIContext) {
|
||||||
conflictError := err.(pull_service.ErrMergeUnrelatedHistories)
|
conflictError := err.(pull_service.ErrMergeUnrelatedHistories)
|
||||||
ctx.JSON(http.StatusConflict, conflictError)
|
ctx.JSON(http.StatusConflict, conflictError)
|
||||||
} else if git.IsErrPushOutOfDate(err) {
|
} else if git.IsErrPushOutOfDate(err) {
|
||||||
ctx.Error(http.StatusConflict, "Merge", "merge push out of date")
|
ctx.APIError(http.StatusConflict, "merge push out of date")
|
||||||
} else if pull_service.IsErrSHADoesNotMatch(err) {
|
} else if pull_service.IsErrSHADoesNotMatch(err) {
|
||||||
ctx.Error(http.StatusConflict, "Merge", "head out of date")
|
ctx.APIError(http.StatusConflict, "head out of date")
|
||||||
} else if git.IsErrPushRejected(err) {
|
} else if git.IsErrPushRejected(err) {
|
||||||
errPushRej := err.(*git.ErrPushRejected)
|
errPushRej := err.(*git.ErrPushRejected)
|
||||||
if len(errPushRej.Message) == 0 {
|
if len(errPushRej.Message) == 0 {
|
||||||
ctx.Error(http.StatusConflict, "Merge", "PushRejected without remote error message")
|
ctx.APIError(http.StatusConflict, "PushRejected without remote error message")
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusConflict, "Merge", "PushRejected with remote message: "+errPushRej.Message)
|
ctx.APIError(http.StatusConflict, "PushRejected with remote message: "+errPushRej.Message)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "Merge", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -1024,7 +1024,7 @@ func MergePullRequest(ctx *context.APIContext) {
|
||||||
// Don't cleanup when there are other PR's that use this branch as head branch.
|
// Don't cleanup when there are other PR's that use this branch as head branch.
|
||||||
exist, err := issues_model.HasUnmergedPullRequestsByHeadInfo(ctx, pr.HeadRepoID, pr.HeadBranch)
|
exist, err := issues_model.HasUnmergedPullRequestsByHeadInfo(ctx, pr.HeadRepoID, pr.HeadBranch)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.ServerError("HasUnmergedPullRequestsByHeadInfo", err)
|
ctx.APIErrorInternal(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if exist {
|
if exist {
|
||||||
|
@ -1038,7 +1038,7 @@ func MergePullRequest(ctx *context.APIContext) {
|
||||||
} else {
|
} else {
|
||||||
headRepo, err = gitrepo.OpenRepository(ctx, pr.HeadRepo)
|
headRepo, err = gitrepo.OpenRepository(ctx, pr.HeadRepo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.ServerError(fmt.Sprintf("OpenRepository[%s]", pr.HeadRepo.FullName()), err)
|
ctx.APIErrorInternal(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
defer headRepo.Close()
|
defer headRepo.Close()
|
||||||
|
@ -1047,13 +1047,13 @@ func MergePullRequest(ctx *context.APIContext) {
|
||||||
if err := repo_service.DeleteBranch(ctx, ctx.Doer, pr.HeadRepo, headRepo, pr.HeadBranch, pr); err != nil {
|
if err := repo_service.DeleteBranch(ctx, ctx.Doer, pr.HeadRepo, headRepo, pr.HeadBranch, pr); err != nil {
|
||||||
switch {
|
switch {
|
||||||
case git.IsErrBranchNotExist(err):
|
case git.IsErrBranchNotExist(err):
|
||||||
ctx.NotFound(err)
|
ctx.APIErrorNotFound(err)
|
||||||
case errors.Is(err, repo_service.ErrBranchIsDefault):
|
case errors.Is(err, repo_service.ErrBranchIsDefault):
|
||||||
ctx.Error(http.StatusForbidden, "DefaultBranch", fmt.Errorf("can not delete default branch"))
|
ctx.APIError(http.StatusForbidden, fmt.Errorf("can not delete default branch"))
|
||||||
case errors.Is(err, git_model.ErrBranchIsProtected):
|
case errors.Is(err, git_model.ErrBranchIsProtected):
|
||||||
ctx.Error(http.StatusForbidden, "IsProtectedBranch", fmt.Errorf("branch protected"))
|
ctx.APIError(http.StatusForbidden, fmt.Errorf("branch protected"))
|
||||||
default:
|
default:
|
||||||
ctx.Error(http.StatusInternalServerError, "DeleteBranch", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -1092,14 +1092,14 @@ func parseCompareInfo(ctx *context.APIContext, form api.CreatePullRequestOption)
|
||||||
headUser, err = user_model.GetUserByName(ctx, headInfos[0])
|
headUser, err = user_model.GetUserByName(ctx, headInfos[0])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if user_model.IsErrUserNotExist(err) {
|
if user_model.IsErrUserNotExist(err) {
|
||||||
ctx.NotFound("GetUserByName")
|
ctx.APIErrorNotFound("GetUserByName")
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetUserByName", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
ctx.NotFound()
|
ctx.APIErrorNotFound()
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1110,14 +1110,14 @@ func parseCompareInfo(ctx *context.APIContext, form api.CreatePullRequestOption)
|
||||||
if headRepo == nil && !isSameRepo {
|
if headRepo == nil && !isSameRepo {
|
||||||
err = baseRepo.GetBaseRepo(ctx)
|
err = baseRepo.GetBaseRepo(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetBaseRepo", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if baseRepo's base repository is the same as headUser's repository.
|
// Check if baseRepo's base repository is the same as headUser's repository.
|
||||||
if baseRepo.BaseRepo == nil || baseRepo.BaseRepo.OwnerID != headUser.ID {
|
if baseRepo.BaseRepo == nil || baseRepo.BaseRepo.OwnerID != headUser.ID {
|
||||||
log.Trace("parseCompareInfo[%d]: does not have fork or in same repository", baseRepo.ID)
|
log.Trace("parseCompareInfo[%d]: does not have fork or in same repository", baseRepo.ID)
|
||||||
ctx.NotFound("GetBaseRepo")
|
ctx.APIErrorNotFound("GetBaseRepo")
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
// Assign headRepo so it can be used below.
|
// Assign headRepo so it can be used below.
|
||||||
|
@ -1132,7 +1132,7 @@ func parseCompareInfo(ctx *context.APIContext, form api.CreatePullRequestOption)
|
||||||
} else {
|
} else {
|
||||||
headGitRepo, err = gitrepo.OpenRepository(ctx, headRepo)
|
headGitRepo, err = gitrepo.OpenRepository(ctx, headRepo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "OpenRepository", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
closer = func() { _ = headGitRepo.Close() }
|
closer = func() { _ = headGitRepo.Close() }
|
||||||
|
@ -1146,13 +1146,13 @@ func parseCompareInfo(ctx *context.APIContext, form api.CreatePullRequestOption)
|
||||||
// user should have permission to read baseRepo's codes and pulls, NOT headRepo's
|
// user should have permission to read baseRepo's codes and pulls, NOT headRepo's
|
||||||
permBase, err := access_model.GetUserRepoPermission(ctx, baseRepo, ctx.Doer)
|
permBase, err := access_model.GetUserRepoPermission(ctx, baseRepo, ctx.Doer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetUserRepoPermission", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if !permBase.CanReadIssuesOrPulls(true) || !permBase.CanRead(unit.TypeCode) {
|
if !permBase.CanReadIssuesOrPulls(true) || !permBase.CanRead(unit.TypeCode) {
|
||||||
log.Trace("Permission Denied: User %-v cannot create/read pull requests or cannot read code in Repo %-v\nUser in baseRepo has Permissions: %-+v", ctx.Doer, baseRepo, permBase)
|
log.Trace("Permission Denied: User %-v cannot create/read pull requests or cannot read code in Repo %-v\nUser in baseRepo has Permissions: %-+v", ctx.Doer, baseRepo, permBase)
|
||||||
ctx.NotFound("Can't read pulls or can't read UnitTypeCode")
|
ctx.APIErrorNotFound("Can't read pulls or can't read UnitTypeCode")
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1160,12 +1160,12 @@ func parseCompareInfo(ctx *context.APIContext, form api.CreatePullRequestOption)
|
||||||
// TODO: could the logic be simplified if the headRepo is the same as the baseRepo? Need to think more about it.
|
// TODO: could the logic be simplified if the headRepo is the same as the baseRepo? Need to think more about it.
|
||||||
permHead, err := access_model.GetUserRepoPermission(ctx, headRepo, ctx.Doer)
|
permHead, err := access_model.GetUserRepoPermission(ctx, headRepo, ctx.Doer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetUserRepoPermission", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
if !permHead.CanRead(unit.TypeCode) {
|
if !permHead.CanRead(unit.TypeCode) {
|
||||||
log.Trace("Permission Denied: User: %-v cannot read code in Repo: %-v\nUser in headRepo has Permissions: %-+v", ctx.Doer, headRepo, permHead)
|
log.Trace("Permission Denied: User: %-v cannot read code in Repo: %-v\nUser in headRepo has Permissions: %-+v", ctx.Doer, headRepo, permHead)
|
||||||
ctx.NotFound("Can't read headRepo UnitTypeCode")
|
ctx.APIErrorNotFound("Can't read headRepo UnitTypeCode")
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1178,13 +1178,13 @@ func parseCompareInfo(ctx *context.APIContext, form api.CreatePullRequestOption)
|
||||||
headRefValid := headRef.IsBranch() || headRef.IsTag() || git.IsStringLikelyCommitID(git.ObjectFormatFromName(headRepo.ObjectFormatName), headRef.ShortName())
|
headRefValid := headRef.IsBranch() || headRef.IsTag() || git.IsStringLikelyCommitID(git.ObjectFormatFromName(headRepo.ObjectFormatName), headRef.ShortName())
|
||||||
// Check if base&head ref are valid.
|
// Check if base&head ref are valid.
|
||||||
if !baseRefValid || !headRefValid {
|
if !baseRefValid || !headRefValid {
|
||||||
ctx.NotFound()
|
ctx.APIErrorNotFound()
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
compareInfo, err := headGitRepo.GetCompareInfo(repo_model.RepoPath(baseRepo.Owner.Name, baseRepo.Name), baseRef.ShortName(), headRef.ShortName(), false, false)
|
compareInfo, err := headGitRepo.GetCompareInfo(repo_model.RepoPath(baseRepo.Owner.Name, baseRepo.Name), baseRef.ShortName(), headRef.ShortName(), false, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetCompareInfo", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1236,34 +1236,34 @@ func UpdatePullRequest(ctx *context.APIContext) {
|
||||||
pr, err := issues_model.GetPullRequestByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("index"))
|
pr, err := issues_model.GetPullRequestByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("index"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if issues_model.IsErrPullRequestNotExist(err) {
|
if issues_model.IsErrPullRequestNotExist(err) {
|
||||||
ctx.NotFound()
|
ctx.APIErrorNotFound()
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetPullRequestByIndex", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if pr.HasMerged {
|
if pr.HasMerged {
|
||||||
ctx.Error(http.StatusUnprocessableEntity, "UpdatePullRequest", err)
|
ctx.APIError(http.StatusUnprocessableEntity, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = pr.LoadIssue(ctx); err != nil {
|
if err = pr.LoadIssue(ctx); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "LoadIssue", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if pr.Issue.IsClosed {
|
if pr.Issue.IsClosed {
|
||||||
ctx.Error(http.StatusUnprocessableEntity, "UpdatePullRequest", err)
|
ctx.APIError(http.StatusUnprocessableEntity, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = pr.LoadBaseRepo(ctx); err != nil {
|
if err = pr.LoadBaseRepo(ctx); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "LoadBaseRepo", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if err = pr.LoadHeadRepo(ctx); err != nil {
|
if err = pr.LoadHeadRepo(ctx); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "LoadHeadRepo", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1271,7 +1271,7 @@ func UpdatePullRequest(ctx *context.APIContext) {
|
||||||
|
|
||||||
allowedUpdateByMerge, allowedUpdateByRebase, err := pull_service.IsUserAllowedToUpdate(ctx, pr, ctx.Doer)
|
allowedUpdateByMerge, allowedUpdateByRebase, err := pull_service.IsUserAllowedToUpdate(ctx, pr, ctx.Doer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "IsUserAllowedToMerge", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1285,13 +1285,13 @@ func UpdatePullRequest(ctx *context.APIContext) {
|
||||||
|
|
||||||
if err = pull_service.Update(ctx, pr, ctx.Doer, message, rebase); err != nil {
|
if err = pull_service.Update(ctx, pr, ctx.Doer, message, rebase); err != nil {
|
||||||
if pull_service.IsErrMergeConflicts(err) {
|
if pull_service.IsErrMergeConflicts(err) {
|
||||||
ctx.Error(http.StatusConflict, "Update", "merge failed because of conflict")
|
ctx.APIError(http.StatusConflict, "merge failed because of conflict")
|
||||||
return
|
return
|
||||||
} else if pull_service.IsErrRebaseConflicts(err) {
|
} else if pull_service.IsErrRebaseConflicts(err) {
|
||||||
ctx.Error(http.StatusConflict, "Update", "rebase failed because of conflict")
|
ctx.APIError(http.StatusConflict, "rebase failed because of conflict")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.Error(http.StatusInternalServerError, "pull_service.Update", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1336,37 +1336,37 @@ func CancelScheduledAutoMerge(ctx *context.APIContext) {
|
||||||
pull, err := issues_model.GetPullRequestByIndex(ctx, ctx.Repo.Repository.ID, pullIndex)
|
pull, err := issues_model.GetPullRequestByIndex(ctx, ctx.Repo.Repository.ID, pullIndex)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if issues_model.IsErrPullRequestNotExist(err) {
|
if issues_model.IsErrPullRequestNotExist(err) {
|
||||||
ctx.NotFound()
|
ctx.APIErrorNotFound()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.InternalServerError(err)
|
ctx.APIErrorInternal(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
exist, autoMerge, err := pull_model.GetScheduledMergeByPullID(ctx, pull.ID)
|
exist, autoMerge, err := pull_model.GetScheduledMergeByPullID(ctx, pull.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.InternalServerError(err)
|
ctx.APIErrorInternal(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if !exist {
|
if !exist {
|
||||||
ctx.NotFound()
|
ctx.APIErrorNotFound()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if ctx.Doer.ID != autoMerge.DoerID {
|
if ctx.Doer.ID != autoMerge.DoerID {
|
||||||
allowed, err := access_model.IsUserRepoAdmin(ctx, ctx.Repo.Repository, ctx.Doer)
|
allowed, err := access_model.IsUserRepoAdmin(ctx, ctx.Repo.Repository, ctx.Doer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.InternalServerError(err)
|
ctx.APIErrorInternal(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if !allowed {
|
if !allowed {
|
||||||
ctx.Error(http.StatusForbidden, "No permission to cancel", "user has no permission to cancel the scheduled auto merge")
|
ctx.APIError(http.StatusForbidden, "user has no permission to cancel the scheduled auto merge")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := automerge.RemoveScheduledAutoMerge(ctx, ctx.Doer, pull); err != nil {
|
if err := automerge.RemoveScheduledAutoMerge(ctx, ctx.Doer, pull); err != nil {
|
||||||
ctx.InternalServerError(err)
|
ctx.APIErrorInternal(err)
|
||||||
} else {
|
} else {
|
||||||
ctx.Status(http.StatusNoContent)
|
ctx.Status(http.StatusNoContent)
|
||||||
}
|
}
|
||||||
|
@ -1421,22 +1421,22 @@ func GetPullRequestCommits(ctx *context.APIContext) {
|
||||||
pr, err := issues_model.GetPullRequestByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("index"))
|
pr, err := issues_model.GetPullRequestByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("index"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if issues_model.IsErrPullRequestNotExist(err) {
|
if issues_model.IsErrPullRequestNotExist(err) {
|
||||||
ctx.NotFound()
|
ctx.APIErrorNotFound()
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetPullRequestByIndex", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := pr.LoadBaseRepo(ctx); err != nil {
|
if err := pr.LoadBaseRepo(ctx); err != nil {
|
||||||
ctx.InternalServerError(err)
|
ctx.APIErrorInternal(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
var prInfo *git.CompareInfo
|
var prInfo *git.CompareInfo
|
||||||
baseGitRepo, closer, err := gitrepo.RepositoryFromContextOrOpen(ctx, pr.BaseRepo)
|
baseGitRepo, closer, err := gitrepo.RepositoryFromContextOrOpen(ctx, pr.BaseRepo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.ServerError("OpenRepository", err)
|
ctx.APIErrorInternal(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
defer closer.Close()
|
defer closer.Close()
|
||||||
|
@ -1447,7 +1447,7 @@ func GetPullRequestCommits(ctx *context.APIContext) {
|
||||||
prInfo, err = baseGitRepo.GetCompareInfo(pr.BaseRepo.RepoPath(), pr.BaseBranch, pr.GetGitRefName(), false, false)
|
prInfo, err = baseGitRepo.GetCompareInfo(pr.BaseRepo.RepoPath(), pr.BaseBranch, pr.GetGitRefName(), false, false)
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.ServerError("GetCompareInfo", err)
|
ctx.APIErrorInternal(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
commits := prInfo.Commits
|
commits := prInfo.Commits
|
||||||
|
@ -1476,7 +1476,7 @@ func GetPullRequestCommits(ctx *context.APIContext) {
|
||||||
Files: files,
|
Files: files,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.ServerError("toCommit", err)
|
ctx.APIErrorInternal(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
apiCommits = append(apiCommits, apiCommit)
|
apiCommits = append(apiCommits, apiCommit)
|
||||||
|
@ -1544,20 +1544,20 @@ func GetPullRequestFiles(ctx *context.APIContext) {
|
||||||
pr, err := issues_model.GetPullRequestByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("index"))
|
pr, err := issues_model.GetPullRequestByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("index"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if issues_model.IsErrPullRequestNotExist(err) {
|
if issues_model.IsErrPullRequestNotExist(err) {
|
||||||
ctx.NotFound()
|
ctx.APIErrorNotFound()
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetPullRequestByIndex", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := pr.LoadBaseRepo(ctx); err != nil {
|
if err := pr.LoadBaseRepo(ctx); err != nil {
|
||||||
ctx.InternalServerError(err)
|
ctx.APIErrorInternal(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := pr.LoadHeadRepo(ctx); err != nil {
|
if err := pr.LoadHeadRepo(ctx); err != nil {
|
||||||
ctx.InternalServerError(err)
|
ctx.APIErrorInternal(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1570,13 +1570,13 @@ func GetPullRequestFiles(ctx *context.APIContext) {
|
||||||
prInfo, err = baseGitRepo.GetCompareInfo(pr.BaseRepo.RepoPath(), pr.BaseBranch, pr.GetGitRefName(), true, false)
|
prInfo, err = baseGitRepo.GetCompareInfo(pr.BaseRepo.RepoPath(), pr.BaseBranch, pr.GetGitRefName(), true, false)
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.ServerError("GetCompareInfo", err)
|
ctx.APIErrorInternal(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
headCommitID, err := baseGitRepo.GetRefCommitID(pr.GetGitRefName())
|
headCommitID, err := baseGitRepo.GetRefCommitID(pr.GetGitRefName())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.ServerError("GetRefCommitID", err)
|
ctx.APIErrorInternal(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1597,7 +1597,7 @@ func GetPullRequestFiles(ctx *context.APIContext) {
|
||||||
WhitespaceBehavior: gitdiff.GetWhitespaceFlag(ctx.FormString("whitespace")),
|
WhitespaceBehavior: gitdiff.GetWhitespaceFlag(ctx.FormString("whitespace")),
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.ServerError("GetDiff", err)
|
ctx.APIErrorInternal(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -64,20 +64,20 @@ func ListPullReviews(ctx *context.APIContext) {
|
||||||
pr, err := issues_model.GetPullRequestByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("index"))
|
pr, err := issues_model.GetPullRequestByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("index"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if issues_model.IsErrPullRequestNotExist(err) {
|
if issues_model.IsErrPullRequestNotExist(err) {
|
||||||
ctx.NotFound("GetPullRequestByIndex", err)
|
ctx.APIErrorNotFound("GetPullRequestByIndex", err)
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetPullRequestByIndex", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = pr.LoadIssue(ctx); err != nil {
|
if err = pr.LoadIssue(ctx); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "LoadIssue", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = pr.Issue.LoadRepo(ctx); err != nil {
|
if err = pr.Issue.LoadRepo(ctx); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "LoadRepo", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -88,19 +88,19 @@ func ListPullReviews(ctx *context.APIContext) {
|
||||||
|
|
||||||
allReviews, err := issues_model.FindReviews(ctx, opts)
|
allReviews, err := issues_model.FindReviews(ctx, opts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.InternalServerError(err)
|
ctx.APIErrorInternal(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
count, err := issues_model.CountReviews(ctx, opts)
|
count, err := issues_model.CountReviews(ctx, opts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.InternalServerError(err)
|
ctx.APIErrorInternal(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
apiReviews, err := convert.ToPullReviewList(ctx, allReviews, ctx.Doer)
|
apiReviews, err := convert.ToPullReviewList(ctx, allReviews, ctx.Doer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "convertToPullReviewList", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -151,7 +151,7 @@ func GetPullReview(ctx *context.APIContext) {
|
||||||
|
|
||||||
apiReview, err := convert.ToPullReview(ctx, review, ctx.Doer)
|
apiReview, err := convert.ToPullReview(ctx, review, ctx.Doer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "convertToPullReview", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -201,7 +201,7 @@ func GetPullReviewComments(ctx *context.APIContext) {
|
||||||
|
|
||||||
apiComments, err := convert.ToPullReviewCommentList(ctx, review, ctx.Doer)
|
apiComments, err := convert.ToPullReviewCommentList(ctx, review, ctx.Doer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "convertToPullReviewCommentList", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -252,16 +252,16 @@ func DeletePullReview(ctx *context.APIContext) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if ctx.Doer == nil {
|
if ctx.Doer == nil {
|
||||||
ctx.NotFound()
|
ctx.APIErrorNotFound()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if !ctx.Doer.IsAdmin && ctx.Doer.ID != review.ReviewerID {
|
if !ctx.Doer.IsAdmin && ctx.Doer.ID != review.ReviewerID {
|
||||||
ctx.Error(http.StatusForbidden, "only admin and user itself can delete a review", nil)
|
ctx.APIError(http.StatusForbidden, nil)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := issues_model.DeleteReview(ctx, review); err != nil {
|
if err := issues_model.DeleteReview(ctx, review); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "DeleteReview", fmt.Errorf("can not delete ReviewID: %d", review.ID))
|
ctx.APIError(http.StatusInternalServerError, fmt.Errorf("can not delete ReviewID: %d", review.ID))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -309,9 +309,9 @@ func CreatePullReview(ctx *context.APIContext) {
|
||||||
pr, err := issues_model.GetPullRequestByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("index"))
|
pr, err := issues_model.GetPullRequestByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("index"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if issues_model.IsErrPullRequestNotExist(err) {
|
if issues_model.IsErrPullRequestNotExist(err) {
|
||||||
ctx.NotFound("GetPullRequestByIndex", err)
|
ctx.APIErrorNotFound("GetPullRequestByIndex", err)
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetPullRequestByIndex", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -323,7 +323,7 @@ func CreatePullReview(ctx *context.APIContext) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := pr.Issue.LoadRepo(ctx); err != nil {
|
if err := pr.Issue.LoadRepo(ctx); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "pr.Issue.LoadRepo", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -331,14 +331,14 @@ func CreatePullReview(ctx *context.APIContext) {
|
||||||
if opts.CommitID == "" {
|
if opts.CommitID == "" {
|
||||||
gitRepo, closer, err := gitrepo.RepositoryFromContextOrOpen(ctx, pr.Issue.Repo)
|
gitRepo, closer, err := gitrepo.RepositoryFromContextOrOpen(ctx, pr.Issue.Repo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "git.OpenRepository", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
defer closer.Close()
|
defer closer.Close()
|
||||||
|
|
||||||
headCommitID, err := gitRepo.GetRefCommitID(pr.GetGitRefName())
|
headCommitID, err := gitRepo.GetRefCommitID(pr.GetGitRefName())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetRefCommitID", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -364,7 +364,7 @@ func CreatePullReview(ctx *context.APIContext) {
|
||||||
opts.CommitID,
|
opts.CommitID,
|
||||||
nil,
|
nil,
|
||||||
); err != nil {
|
); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "CreateCodeComment", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -373,9 +373,9 @@ func CreatePullReview(ctx *context.APIContext) {
|
||||||
review, _, err := pull_service.SubmitReview(ctx, ctx.Doer, ctx.Repo.GitRepo, pr.Issue, reviewType, opts.Body, opts.CommitID, nil)
|
review, _, err := pull_service.SubmitReview(ctx, ctx.Doer, ctx.Repo.GitRepo, pr.Issue, reviewType, opts.Body, opts.CommitID, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if errors.Is(err, pull_service.ErrSubmitReviewOnClosedPR) {
|
if errors.Is(err, pull_service.ErrSubmitReviewOnClosedPR) {
|
||||||
ctx.Error(http.StatusUnprocessableEntity, "", err)
|
ctx.APIError(http.StatusUnprocessableEntity, err)
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "SubmitReview", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -383,7 +383,7 @@ func CreatePullReview(ctx *context.APIContext) {
|
||||||
// convert response
|
// convert response
|
||||||
apiReview, err := convert.ToPullReview(ctx, review, ctx.Doer)
|
apiReview, err := convert.ToPullReview(ctx, review, ctx.Doer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "convertToPullReview", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.JSON(http.StatusOK, apiReview)
|
ctx.JSON(http.StatusOK, apiReview)
|
||||||
|
@ -439,7 +439,7 @@ func SubmitPullReview(ctx *context.APIContext) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if review.Type != issues_model.ReviewTypePending {
|
if review.Type != issues_model.ReviewTypePending {
|
||||||
ctx.Error(http.StatusUnprocessableEntity, "", fmt.Errorf("only a pending review can be submitted"))
|
ctx.APIError(http.StatusUnprocessableEntity, fmt.Errorf("only a pending review can be submitted"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -451,13 +451,13 @@ func SubmitPullReview(ctx *context.APIContext) {
|
||||||
|
|
||||||
// if review stay pending return
|
// if review stay pending return
|
||||||
if reviewType == issues_model.ReviewTypePending {
|
if reviewType == issues_model.ReviewTypePending {
|
||||||
ctx.Error(http.StatusUnprocessableEntity, "", fmt.Errorf("review stay pending"))
|
ctx.APIError(http.StatusUnprocessableEntity, fmt.Errorf("review stay pending"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
headCommitID, err := ctx.Repo.GitRepo.GetRefCommitID(pr.GetGitRefName())
|
headCommitID, err := ctx.Repo.GitRepo.GetRefCommitID(pr.GetGitRefName())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "GitRepo: GetRefCommitID", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -465,9 +465,9 @@ func SubmitPullReview(ctx *context.APIContext) {
|
||||||
review, _, err = pull_service.SubmitReview(ctx, ctx.Doer, ctx.Repo.GitRepo, pr.Issue, reviewType, opts.Body, headCommitID, nil)
|
review, _, err = pull_service.SubmitReview(ctx, ctx.Doer, ctx.Repo.GitRepo, pr.Issue, reviewType, opts.Body, headCommitID, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if errors.Is(err, pull_service.ErrSubmitReviewOnClosedPR) {
|
if errors.Is(err, pull_service.ErrSubmitReviewOnClosedPR) {
|
||||||
ctx.Error(http.StatusUnprocessableEntity, "", err)
|
ctx.APIError(http.StatusUnprocessableEntity, err)
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "SubmitReview", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -475,7 +475,7 @@ func SubmitPullReview(ctx *context.APIContext) {
|
||||||
// convert response
|
// convert response
|
||||||
apiReview, err := convert.ToPullReview(ctx, review, ctx.Doer)
|
apiReview, err := convert.ToPullReview(ctx, review, ctx.Doer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "convertToPullReview", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.JSON(http.StatusOK, apiReview)
|
ctx.JSON(http.StatusOK, apiReview)
|
||||||
|
@ -484,7 +484,7 @@ func SubmitPullReview(ctx *context.APIContext) {
|
||||||
// preparePullReviewType return ReviewType and false or nil and true if an error happen
|
// preparePullReviewType return ReviewType and false or nil and true if an error happen
|
||||||
func preparePullReviewType(ctx *context.APIContext, pr *issues_model.PullRequest, event api.ReviewStateType, body string, hasComments bool) (issues_model.ReviewType, bool) {
|
func preparePullReviewType(ctx *context.APIContext, pr *issues_model.PullRequest, event api.ReviewStateType, body string, hasComments bool) (issues_model.ReviewType, bool) {
|
||||||
if err := pr.LoadIssue(ctx); err != nil {
|
if err := pr.LoadIssue(ctx); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "LoadIssue", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return -1, true
|
return -1, true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -496,7 +496,7 @@ func preparePullReviewType(ctx *context.APIContext, pr *issues_model.PullRequest
|
||||||
case api.ReviewStateApproved:
|
case api.ReviewStateApproved:
|
||||||
// can not approve your own PR
|
// can not approve your own PR
|
||||||
if pr.Issue.IsPoster(ctx.Doer.ID) {
|
if pr.Issue.IsPoster(ctx.Doer.ID) {
|
||||||
ctx.Error(http.StatusUnprocessableEntity, "", fmt.Errorf("approve your own pull is not allowed"))
|
ctx.APIError(http.StatusUnprocessableEntity, fmt.Errorf("approve your own pull is not allowed"))
|
||||||
return -1, true
|
return -1, true
|
||||||
}
|
}
|
||||||
reviewType = issues_model.ReviewTypeApprove
|
reviewType = issues_model.ReviewTypeApprove
|
||||||
|
@ -505,7 +505,7 @@ func preparePullReviewType(ctx *context.APIContext, pr *issues_model.PullRequest
|
||||||
case api.ReviewStateRequestChanges:
|
case api.ReviewStateRequestChanges:
|
||||||
// can not reject your own PR
|
// can not reject your own PR
|
||||||
if pr.Issue.IsPoster(ctx.Doer.ID) {
|
if pr.Issue.IsPoster(ctx.Doer.ID) {
|
||||||
ctx.Error(http.StatusUnprocessableEntity, "", fmt.Errorf("reject your own pull is not allowed"))
|
ctx.APIError(http.StatusUnprocessableEntity, fmt.Errorf("reject your own pull is not allowed"))
|
||||||
return -1, true
|
return -1, true
|
||||||
}
|
}
|
||||||
reviewType = issues_model.ReviewTypeReject
|
reviewType = issues_model.ReviewTypeReject
|
||||||
|
@ -515,7 +515,7 @@ func preparePullReviewType(ctx *context.APIContext, pr *issues_model.PullRequest
|
||||||
needsBody = false
|
needsBody = false
|
||||||
// if there is no body we need to ensure that there are comments
|
// if there is no body we need to ensure that there are comments
|
||||||
if !hasBody && !hasComments {
|
if !hasBody && !hasComments {
|
||||||
ctx.Error(http.StatusUnprocessableEntity, "", fmt.Errorf("review event %s requires a body or a comment", event))
|
ctx.APIError(http.StatusUnprocessableEntity, fmt.Errorf("review event %s requires a body or a comment", event))
|
||||||
return -1, true
|
return -1, true
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
|
@ -524,7 +524,7 @@ func preparePullReviewType(ctx *context.APIContext, pr *issues_model.PullRequest
|
||||||
|
|
||||||
// reject reviews with empty body if a body is required for this call
|
// reject reviews with empty body if a body is required for this call
|
||||||
if needsBody && !hasBody {
|
if needsBody && !hasBody {
|
||||||
ctx.Error(http.StatusUnprocessableEntity, "", fmt.Errorf("review event %s requires a body", event))
|
ctx.APIError(http.StatusUnprocessableEntity, fmt.Errorf("review event %s requires a body", event))
|
||||||
return -1, true
|
return -1, true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -536,9 +536,9 @@ func prepareSingleReview(ctx *context.APIContext) (*issues_model.Review, *issues
|
||||||
pr, err := issues_model.GetPullRequestByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("index"))
|
pr, err := issues_model.GetPullRequestByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("index"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if issues_model.IsErrPullRequestNotExist(err) {
|
if issues_model.IsErrPullRequestNotExist(err) {
|
||||||
ctx.NotFound("GetPullRequestByIndex", err)
|
ctx.APIErrorNotFound("GetPullRequestByIndex", err)
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetPullRequestByIndex", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
return nil, nil, true
|
return nil, nil, true
|
||||||
}
|
}
|
||||||
|
@ -546,27 +546,27 @@ func prepareSingleReview(ctx *context.APIContext) (*issues_model.Review, *issues
|
||||||
review, err := issues_model.GetReviewByID(ctx, ctx.PathParamInt64("id"))
|
review, err := issues_model.GetReviewByID(ctx, ctx.PathParamInt64("id"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if issues_model.IsErrReviewNotExist(err) {
|
if issues_model.IsErrReviewNotExist(err) {
|
||||||
ctx.NotFound("GetReviewByID", err)
|
ctx.APIErrorNotFound("GetReviewByID", err)
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetReviewByID", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
return nil, nil, true
|
return nil, nil, true
|
||||||
}
|
}
|
||||||
|
|
||||||
// validate the review is for the given PR
|
// validate the review is for the given PR
|
||||||
if review.IssueID != pr.IssueID {
|
if review.IssueID != pr.IssueID {
|
||||||
ctx.NotFound("ReviewNotInPR")
|
ctx.APIErrorNotFound("ReviewNotInPR")
|
||||||
return nil, nil, true
|
return nil, nil, true
|
||||||
}
|
}
|
||||||
|
|
||||||
// make sure that the user has access to this review if it is pending
|
// make sure that the user has access to this review if it is pending
|
||||||
if review.Type == issues_model.ReviewTypePending && review.ReviewerID != ctx.Doer.ID && !ctx.Doer.IsAdmin {
|
if review.Type == issues_model.ReviewTypePending && review.ReviewerID != ctx.Doer.ID && !ctx.Doer.IsAdmin {
|
||||||
ctx.NotFound("GetReviewByID")
|
ctx.APIErrorNotFound("GetReviewByID")
|
||||||
return nil, nil, true
|
return nil, nil, true
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := review.LoadAttributes(ctx); err != nil && !user_model.IsErrUserNotExist(err) {
|
if err := review.LoadAttributes(ctx); err != nil && !user_model.IsErrUserNotExist(err) {
|
||||||
ctx.Error(http.StatusInternalServerError, "ReviewLoadAttributes", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return nil, nil, true
|
return nil, nil, true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -668,10 +668,10 @@ func parseReviewersByNames(ctx *context.APIContext, reviewerNames, teamReviewerN
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if user_model.IsErrUserNotExist(err) {
|
if user_model.IsErrUserNotExist(err) {
|
||||||
ctx.NotFound("UserNotExist", fmt.Sprintf("User '%s' not exist", r))
|
ctx.APIErrorNotFound("UserNotExist", fmt.Sprintf("User '%s' not exist", r))
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
ctx.Error(http.StatusInternalServerError, "GetUser", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -684,10 +684,10 @@ func parseReviewersByNames(ctx *context.APIContext, reviewerNames, teamReviewerN
|
||||||
teamReviewer, err = organization.GetTeam(ctx, ctx.Repo.Owner.ID, t)
|
teamReviewer, err = organization.GetTeam(ctx, ctx.Repo.Owner.ID, t)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if organization.IsErrTeamNotExist(err) {
|
if organization.IsErrTeamNotExist(err) {
|
||||||
ctx.NotFound("TeamNotExist", fmt.Sprintf("Team '%s' not exist", t))
|
ctx.APIErrorNotFound("TeamNotExist", fmt.Sprintf("Team '%s' not exist", t))
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
ctx.Error(http.StatusInternalServerError, "ReviewRequest", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -701,21 +701,21 @@ func apiReviewRequest(ctx *context.APIContext, opts api.PullReviewRequestOptions
|
||||||
pr, err := issues_model.GetPullRequestByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("index"))
|
pr, err := issues_model.GetPullRequestByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("index"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if issues_model.IsErrPullRequestNotExist(err) {
|
if issues_model.IsErrPullRequestNotExist(err) {
|
||||||
ctx.NotFound("GetPullRequestByIndex", err)
|
ctx.APIErrorNotFound("GetPullRequestByIndex", err)
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetPullRequestByIndex", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := pr.Issue.LoadRepo(ctx); err != nil {
|
if err := pr.Issue.LoadRepo(ctx); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "pr.Issue.LoadRepo", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
permDoer, err := access_model.GetUserRepoPermission(ctx, pr.Issue.Repo, ctx.Doer)
|
permDoer, err := access_model.GetUserRepoPermission(ctx, pr.Issue.Repo, ctx.Doer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetUserRepoPermission", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -733,20 +733,20 @@ func apiReviewRequest(ctx *context.APIContext, opts api.PullReviewRequestOptions
|
||||||
comment, err := issue_service.ReviewRequest(ctx, pr.Issue, ctx.Doer, &permDoer, reviewer, isAdd)
|
comment, err := issue_service.ReviewRequest(ctx, pr.Issue, ctx.Doer, &permDoer, reviewer, isAdd)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if issues_model.IsErrReviewRequestOnClosedPR(err) {
|
if issues_model.IsErrReviewRequestOnClosedPR(err) {
|
||||||
ctx.Error(http.StatusForbidden, "", err)
|
ctx.APIError(http.StatusForbidden, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if issues_model.IsErrNotValidReviewRequest(err) {
|
if issues_model.IsErrNotValidReviewRequest(err) {
|
||||||
ctx.Error(http.StatusUnprocessableEntity, "", err)
|
ctx.APIError(http.StatusUnprocessableEntity, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.Error(http.StatusInternalServerError, "ReviewRequest", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if comment != nil && isAdd {
|
if comment != nil && isAdd {
|
||||||
if err = comment.LoadReview(ctx); err != nil {
|
if err = comment.LoadReview(ctx); err != nil {
|
||||||
ctx.ServerError("ReviewRequest", err)
|
ctx.APIErrorInternal(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
reviews = append(reviews, comment.Review)
|
reviews = append(reviews, comment.Review)
|
||||||
|
@ -758,20 +758,20 @@ func apiReviewRequest(ctx *context.APIContext, opts api.PullReviewRequestOptions
|
||||||
comment, err := issue_service.TeamReviewRequest(ctx, pr.Issue, ctx.Doer, teamReviewer, isAdd)
|
comment, err := issue_service.TeamReviewRequest(ctx, pr.Issue, ctx.Doer, teamReviewer, isAdd)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if issues_model.IsErrReviewRequestOnClosedPR(err) {
|
if issues_model.IsErrReviewRequestOnClosedPR(err) {
|
||||||
ctx.Error(http.StatusForbidden, "", err)
|
ctx.APIError(http.StatusForbidden, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if issues_model.IsErrNotValidReviewRequest(err) {
|
if issues_model.IsErrNotValidReviewRequest(err) {
|
||||||
ctx.Error(http.StatusUnprocessableEntity, "", err)
|
ctx.APIError(http.StatusUnprocessableEntity, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.ServerError("TeamReviewRequest", err)
|
ctx.APIErrorInternal(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if comment != nil && isAdd {
|
if comment != nil && isAdd {
|
||||||
if err = comment.LoadReview(ctx); err != nil {
|
if err = comment.LoadReview(ctx); err != nil {
|
||||||
ctx.ServerError("ReviewRequest", err)
|
ctx.APIErrorInternal(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
reviews = append(reviews, comment.Review)
|
reviews = append(reviews, comment.Review)
|
||||||
|
@ -782,7 +782,7 @@ func apiReviewRequest(ctx *context.APIContext, opts api.PullReviewRequestOptions
|
||||||
if isAdd {
|
if isAdd {
|
||||||
apiReviews, err := convert.ToPullReviewList(ctx, reviews, ctx.Doer)
|
apiReviews, err := convert.ToPullReviewList(ctx, reviews, ctx.Doer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "convertToPullReviewList", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.JSON(http.StatusCreated, apiReviews)
|
ctx.JSON(http.StatusCreated, apiReviews)
|
||||||
|
@ -884,7 +884,7 @@ func UnDismissPullReview(ctx *context.APIContext) {
|
||||||
|
|
||||||
func dismissReview(ctx *context.APIContext, msg string, isDismiss, dismissPriors bool) {
|
func dismissReview(ctx *context.APIContext, msg string, isDismiss, dismissPriors bool) {
|
||||||
if !ctx.Repo.IsAdmin() {
|
if !ctx.Repo.IsAdmin() {
|
||||||
ctx.Error(http.StatusForbidden, "", "Must be repo admin")
|
ctx.APIError(http.StatusForbidden, "Must be repo admin")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
review, _, isWrong := prepareSingleReview(ctx)
|
review, _, isWrong := prepareSingleReview(ctx)
|
||||||
|
@ -893,29 +893,29 @@ func dismissReview(ctx *context.APIContext, msg string, isDismiss, dismissPriors
|
||||||
}
|
}
|
||||||
|
|
||||||
if review.Type != issues_model.ReviewTypeApprove && review.Type != issues_model.ReviewTypeReject {
|
if review.Type != issues_model.ReviewTypeApprove && review.Type != issues_model.ReviewTypeReject {
|
||||||
ctx.Error(http.StatusForbidden, "", "not need to dismiss this review because it's type is not Approve or change request")
|
ctx.APIError(http.StatusForbidden, "not need to dismiss this review because it's type is not Approve or change request")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err := pull_service.DismissReview(ctx, review.ID, ctx.Repo.Repository.ID, msg, ctx.Doer, isDismiss, dismissPriors)
|
_, err := pull_service.DismissReview(ctx, review.ID, ctx.Repo.Repository.ID, msg, ctx.Doer, isDismiss, dismissPriors)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if pull_service.IsErrDismissRequestOnClosedPR(err) {
|
if pull_service.IsErrDismissRequestOnClosedPR(err) {
|
||||||
ctx.Error(http.StatusForbidden, "", err)
|
ctx.APIError(http.StatusForbidden, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.Error(http.StatusInternalServerError, "pull_service.DismissReview", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if review, err = issues_model.GetReviewByID(ctx, review.ID); err != nil {
|
if review, err = issues_model.GetReviewByID(ctx, review.ID); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetReviewByID", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// convert response
|
// convert response
|
||||||
apiReview, err := convert.ToPullReview(ctx, review, ctx.Doer)
|
apiReview, err := convert.ToPullReview(ctx, review, ctx.Doer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "convertToPullReview", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.JSON(http.StatusOK, apiReview)
|
ctx.JSON(http.StatusOK, apiReview)
|
||||||
|
|
|
@ -53,16 +53,16 @@ func GetRelease(ctx *context.APIContext) {
|
||||||
id := ctx.PathParamInt64("id")
|
id := ctx.PathParamInt64("id")
|
||||||
release, err := repo_model.GetReleaseForRepoByID(ctx, ctx.Repo.Repository.ID, id)
|
release, err := repo_model.GetReleaseForRepoByID(ctx, ctx.Repo.Repository.ID, id)
|
||||||
if err != nil && !repo_model.IsErrReleaseNotExist(err) {
|
if err != nil && !repo_model.IsErrReleaseNotExist(err) {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetReleaseForRepoByID", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if err != nil && repo_model.IsErrReleaseNotExist(err) || release.IsTag {
|
if err != nil && repo_model.IsErrReleaseNotExist(err) || release.IsTag {
|
||||||
ctx.NotFound()
|
ctx.APIErrorNotFound()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := release.LoadAttributes(ctx); err != nil {
|
if err := release.LoadAttributes(ctx); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "LoadAttributes", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.JSON(http.StatusOK, convert.ToAPIRelease(ctx, ctx.Repo.Repository, release))
|
ctx.JSON(http.StatusOK, convert.ToAPIRelease(ctx, ctx.Repo.Repository, release))
|
||||||
|
@ -93,17 +93,17 @@ func GetLatestRelease(ctx *context.APIContext) {
|
||||||
// "$ref": "#/responses/notFound"
|
// "$ref": "#/responses/notFound"
|
||||||
release, err := repo_model.GetLatestReleaseByRepoID(ctx, ctx.Repo.Repository.ID)
|
release, err := repo_model.GetLatestReleaseByRepoID(ctx, ctx.Repo.Repository.ID)
|
||||||
if err != nil && !repo_model.IsErrReleaseNotExist(err) {
|
if err != nil && !repo_model.IsErrReleaseNotExist(err) {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetLatestRelease", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if err != nil && repo_model.IsErrReleaseNotExist(err) ||
|
if err != nil && repo_model.IsErrReleaseNotExist(err) ||
|
||||||
release.IsTag || release.RepoID != ctx.Repo.Repository.ID {
|
release.IsTag || release.RepoID != ctx.Repo.Repository.ID {
|
||||||
ctx.NotFound()
|
ctx.APIErrorNotFound()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := release.LoadAttributes(ctx); err != nil {
|
if err := release.LoadAttributes(ctx); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "LoadAttributes", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.JSON(http.StatusOK, convert.ToAPIRelease(ctx, ctx.Repo.Repository, release))
|
ctx.JSON(http.StatusOK, convert.ToAPIRelease(ctx, ctx.Repo.Repository, release))
|
||||||
|
@ -161,13 +161,13 @@ func ListReleases(ctx *context.APIContext) {
|
||||||
|
|
||||||
releases, err := db.Find[repo_model.Release](ctx, opts)
|
releases, err := db.Find[repo_model.Release](ctx, opts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetReleasesByRepoID", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
rels := make([]*api.Release, len(releases))
|
rels := make([]*api.Release, len(releases))
|
||||||
for i, release := range releases {
|
for i, release := range releases {
|
||||||
if err := release.LoadAttributes(ctx); err != nil {
|
if err := release.LoadAttributes(ctx); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "LoadAttributes", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
rels[i] = convert.ToAPIRelease(ctx, ctx.Repo.Repository, release)
|
rels[i] = convert.ToAPIRelease(ctx, ctx.Repo.Repository, release)
|
||||||
|
@ -175,7 +175,7 @@ func ListReleases(ctx *context.APIContext) {
|
||||||
|
|
||||||
filteredCount, err := db.Count[repo_model.Release](ctx, opts)
|
filteredCount, err := db.Count[repo_model.Release](ctx, opts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.InternalServerError(err)
|
ctx.APIErrorInternal(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -220,13 +220,13 @@ func CreateRelease(ctx *context.APIContext) {
|
||||||
|
|
||||||
form := web.GetForm(ctx).(*api.CreateReleaseOption)
|
form := web.GetForm(ctx).(*api.CreateReleaseOption)
|
||||||
if ctx.Repo.Repository.IsEmpty {
|
if ctx.Repo.Repository.IsEmpty {
|
||||||
ctx.Error(http.StatusUnprocessableEntity, "RepoIsEmpty", fmt.Errorf("repo is empty"))
|
ctx.APIError(http.StatusUnprocessableEntity, fmt.Errorf("repo is empty"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
rel, err := repo_model.GetRelease(ctx, ctx.Repo.Repository.ID, form.TagName)
|
rel, err := repo_model.GetRelease(ctx, ctx.Repo.Repository.ID, form.TagName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if !repo_model.IsErrReleaseNotExist(err) {
|
if !repo_model.IsErrReleaseNotExist(err) {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetRelease", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// If target is not provided use default branch
|
// If target is not provided use default branch
|
||||||
|
@ -248,19 +248,19 @@ func CreateRelease(ctx *context.APIContext) {
|
||||||
}
|
}
|
||||||
if err := release_service.CreateRelease(ctx.Repo.GitRepo, rel, nil, ""); err != nil {
|
if err := release_service.CreateRelease(ctx.Repo.GitRepo, rel, nil, ""); err != nil {
|
||||||
if repo_model.IsErrReleaseAlreadyExist(err) {
|
if repo_model.IsErrReleaseAlreadyExist(err) {
|
||||||
ctx.Error(http.StatusConflict, "ReleaseAlreadyExist", err)
|
ctx.APIError(http.StatusConflict, err)
|
||||||
} else if release_service.IsErrProtectedTagName(err) {
|
} else if release_service.IsErrProtectedTagName(err) {
|
||||||
ctx.Error(http.StatusUnprocessableEntity, "ProtectedTagName", err)
|
ctx.APIError(http.StatusUnprocessableEntity, err)
|
||||||
} else if git.IsErrNotExist(err) {
|
} else if git.IsErrNotExist(err) {
|
||||||
ctx.Error(http.StatusNotFound, "ErrNotExist", fmt.Errorf("target \"%v\" not found: %w", rel.Target, err))
|
ctx.APIError(http.StatusNotFound, fmt.Errorf("target \"%v\" not found: %w", rel.Target, err))
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "CreateRelease", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if !rel.IsTag {
|
if !rel.IsTag {
|
||||||
ctx.Error(http.StatusConflict, "GetRelease", "Release is has no Tag")
|
ctx.APIError(http.StatusConflict, "Release is has no Tag")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -275,7 +275,7 @@ func CreateRelease(ctx *context.APIContext) {
|
||||||
rel.Target = form.Target
|
rel.Target = form.Target
|
||||||
|
|
||||||
if err = release_service.UpdateRelease(ctx, ctx.Doer, ctx.Repo.GitRepo, rel, nil, nil, nil); err != nil {
|
if err = release_service.UpdateRelease(ctx, ctx.Doer, ctx.Repo.GitRepo, rel, nil, nil, nil); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "UpdateRelease", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -322,11 +322,11 @@ func EditRelease(ctx *context.APIContext) {
|
||||||
id := ctx.PathParamInt64("id")
|
id := ctx.PathParamInt64("id")
|
||||||
rel, err := repo_model.GetReleaseForRepoByID(ctx, ctx.Repo.Repository.ID, id)
|
rel, err := repo_model.GetReleaseForRepoByID(ctx, ctx.Repo.Repository.ID, id)
|
||||||
if err != nil && !repo_model.IsErrReleaseNotExist(err) {
|
if err != nil && !repo_model.IsErrReleaseNotExist(err) {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetReleaseForRepoByID", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if err != nil && repo_model.IsErrReleaseNotExist(err) || rel.IsTag {
|
if err != nil && repo_model.IsErrReleaseNotExist(err) || rel.IsTag {
|
||||||
ctx.NotFound()
|
ctx.APIErrorNotFound()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -349,18 +349,18 @@ func EditRelease(ctx *context.APIContext) {
|
||||||
rel.IsPrerelease = *form.IsPrerelease
|
rel.IsPrerelease = *form.IsPrerelease
|
||||||
}
|
}
|
||||||
if err := release_service.UpdateRelease(ctx, ctx.Doer, ctx.Repo.GitRepo, rel, nil, nil, nil); err != nil {
|
if err := release_service.UpdateRelease(ctx, ctx.Doer, ctx.Repo.GitRepo, rel, nil, nil, nil); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "UpdateRelease", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// reload data from database
|
// reload data from database
|
||||||
rel, err = repo_model.GetReleaseByID(ctx, id)
|
rel, err = repo_model.GetReleaseByID(ctx, id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetReleaseByID", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if err := rel.LoadAttributes(ctx); err != nil {
|
if err := rel.LoadAttributes(ctx); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "LoadAttributes", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.JSON(http.StatusOK, convert.ToAPIRelease(ctx, ctx.Repo.Repository, rel))
|
ctx.JSON(http.StatusOK, convert.ToAPIRelease(ctx, ctx.Repo.Repository, rel))
|
||||||
|
@ -399,19 +399,19 @@ func DeleteRelease(ctx *context.APIContext) {
|
||||||
id := ctx.PathParamInt64("id")
|
id := ctx.PathParamInt64("id")
|
||||||
rel, err := repo_model.GetReleaseForRepoByID(ctx, ctx.Repo.Repository.ID, id)
|
rel, err := repo_model.GetReleaseForRepoByID(ctx, ctx.Repo.Repository.ID, id)
|
||||||
if err != nil && !repo_model.IsErrReleaseNotExist(err) {
|
if err != nil && !repo_model.IsErrReleaseNotExist(err) {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetReleaseForRepoByID", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if err != nil && repo_model.IsErrReleaseNotExist(err) || rel.IsTag {
|
if err != nil && repo_model.IsErrReleaseNotExist(err) || rel.IsTag {
|
||||||
ctx.NotFound()
|
ctx.APIErrorNotFound()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if err := release_service.DeleteReleaseByID(ctx, ctx.Repo.Repository, rel, ctx.Doer, false); err != nil {
|
if err := release_service.DeleteReleaseByID(ctx, ctx.Repo.Repository, rel, ctx.Doer, false); err != nil {
|
||||||
if release_service.IsErrProtectedTagName(err) {
|
if release_service.IsErrProtectedTagName(err) {
|
||||||
ctx.Error(http.StatusUnprocessableEntity, "delTag", "user not allowed to delete protected tag")
|
ctx.APIError(http.StatusUnprocessableEntity, "user not allowed to delete protected tag")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.Error(http.StatusInternalServerError, "DeleteReleaseByID", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.Status(http.StatusNoContent)
|
ctx.Status(http.StatusNoContent)
|
||||||
|
|
|
@ -23,14 +23,14 @@ func checkReleaseMatchRepo(ctx *context.APIContext, releaseID int64) bool {
|
||||||
release, err := repo_model.GetReleaseByID(ctx, releaseID)
|
release, err := repo_model.GetReleaseByID(ctx, releaseID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if repo_model.IsErrReleaseNotExist(err) {
|
if repo_model.IsErrReleaseNotExist(err) {
|
||||||
ctx.NotFound()
|
ctx.APIErrorNotFound()
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
ctx.Error(http.StatusInternalServerError, "GetReleaseByID", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
if release.RepoID != ctx.Repo.Repository.ID {
|
if release.RepoID != ctx.Repo.Repository.ID {
|
||||||
ctx.NotFound()
|
ctx.APIErrorNotFound()
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
|
@ -81,15 +81,15 @@ func GetReleaseAttachment(ctx *context.APIContext) {
|
||||||
attach, err := repo_model.GetAttachmentByID(ctx, attachID)
|
attach, err := repo_model.GetAttachmentByID(ctx, attachID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if repo_model.IsErrAttachmentNotExist(err) {
|
if repo_model.IsErrAttachmentNotExist(err) {
|
||||||
ctx.NotFound()
|
ctx.APIErrorNotFound()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.Error(http.StatusInternalServerError, "GetAttachmentByID", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if attach.ReleaseID != releaseID {
|
if attach.ReleaseID != releaseID {
|
||||||
log.Info("User requested attachment is not in release, release_id %v, attachment_id: %v", releaseID, attachID)
|
log.Info("User requested attachment is not in release, release_id %v, attachment_id: %v", releaseID, attachID)
|
||||||
ctx.NotFound()
|
ctx.APIErrorNotFound()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// FIXME Should prove the existence of the given repo, but results in unnecessary database requests
|
// FIXME Should prove the existence of the given repo, but results in unnecessary database requests
|
||||||
|
@ -130,18 +130,18 @@ func ListReleaseAttachments(ctx *context.APIContext) {
|
||||||
release, err := repo_model.GetReleaseByID(ctx, releaseID)
|
release, err := repo_model.GetReleaseByID(ctx, releaseID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if repo_model.IsErrReleaseNotExist(err) {
|
if repo_model.IsErrReleaseNotExist(err) {
|
||||||
ctx.NotFound()
|
ctx.APIErrorNotFound()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.Error(http.StatusInternalServerError, "GetReleaseByID", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if release.RepoID != ctx.Repo.Repository.ID {
|
if release.RepoID != ctx.Repo.Repository.ID {
|
||||||
ctx.NotFound()
|
ctx.APIErrorNotFound()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if err := release.LoadAttributes(ctx); err != nil {
|
if err := release.LoadAttributes(ctx); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "LoadAttributes", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.JSON(http.StatusOK, convert.ToAPIRelease(ctx, ctx.Repo.Repository, release).Attachments)
|
ctx.JSON(http.StatusOK, convert.ToAPIRelease(ctx, ctx.Repo.Repository, release).Attachments)
|
||||||
|
@ -194,7 +194,7 @@ func CreateReleaseAttachment(ctx *context.APIContext) {
|
||||||
|
|
||||||
// Check if attachments are enabled
|
// Check if attachments are enabled
|
||||||
if !setting.Attachment.Enabled {
|
if !setting.Attachment.Enabled {
|
||||||
ctx.NotFound("Attachment is not enabled")
|
ctx.APIErrorNotFound("Attachment is not enabled")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -212,7 +212,7 @@ func CreateReleaseAttachment(ctx *context.APIContext) {
|
||||||
if strings.HasPrefix(strings.ToLower(ctx.Req.Header.Get("Content-Type")), "multipart/form-data") {
|
if strings.HasPrefix(strings.ToLower(ctx.Req.Header.Get("Content-Type")), "multipart/form-data") {
|
||||||
file, header, err := ctx.Req.FormFile("attachment")
|
file, header, err := ctx.Req.FormFile("attachment")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetFile", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
defer file.Close()
|
defer file.Close()
|
||||||
|
@ -229,7 +229,7 @@ func CreateReleaseAttachment(ctx *context.APIContext) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if filename == "" {
|
if filename == "" {
|
||||||
ctx.Error(http.StatusBadRequest, "CreateReleaseAttachment", "Could not determine name of attachment.")
|
ctx.APIError(http.StatusBadRequest, "Could not determine name of attachment.")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -242,10 +242,10 @@ func CreateReleaseAttachment(ctx *context.APIContext) {
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if upload.IsErrFileTypeForbidden(err) {
|
if upload.IsErrFileTypeForbidden(err) {
|
||||||
ctx.Error(http.StatusBadRequest, "DetectContentType", err)
|
ctx.APIError(http.StatusBadRequest, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.Error(http.StatusInternalServerError, "NewAttachment", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -308,15 +308,15 @@ func EditReleaseAttachment(ctx *context.APIContext) {
|
||||||
attach, err := repo_model.GetAttachmentByID(ctx, attachID)
|
attach, err := repo_model.GetAttachmentByID(ctx, attachID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if repo_model.IsErrAttachmentNotExist(err) {
|
if repo_model.IsErrAttachmentNotExist(err) {
|
||||||
ctx.NotFound()
|
ctx.APIErrorNotFound()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.Error(http.StatusInternalServerError, "GetAttachmentByID", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if attach.ReleaseID != releaseID {
|
if attach.ReleaseID != releaseID {
|
||||||
log.Info("User requested attachment is not in release, release_id %v, attachment_id: %v", releaseID, attachID)
|
log.Info("User requested attachment is not in release, release_id %v, attachment_id: %v", releaseID, attachID)
|
||||||
ctx.NotFound()
|
ctx.APIErrorNotFound()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// FIXME Should prove the existence of the given repo, but results in unnecessary database requests
|
// FIXME Should prove the existence of the given repo, but results in unnecessary database requests
|
||||||
|
@ -326,10 +326,10 @@ func EditReleaseAttachment(ctx *context.APIContext) {
|
||||||
|
|
||||||
if err := attachment_service.UpdateAttachment(ctx, setting.Repository.Release.AllowedTypes, attach); err != nil {
|
if err := attachment_service.UpdateAttachment(ctx, setting.Repository.Release.AllowedTypes, attach); err != nil {
|
||||||
if upload.IsErrFileTypeForbidden(err) {
|
if upload.IsErrFileTypeForbidden(err) {
|
||||||
ctx.Error(http.StatusUnprocessableEntity, "", err)
|
ctx.APIError(http.StatusUnprocessableEntity, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.Error(http.StatusInternalServerError, "UpdateAttachment", attach)
|
ctx.APIError(http.StatusInternalServerError, attach)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.JSON(http.StatusCreated, convert.ToAPIAttachment(ctx.Repo.Repository, attach))
|
ctx.JSON(http.StatusCreated, convert.ToAPIAttachment(ctx.Repo.Repository, attach))
|
||||||
|
@ -381,21 +381,21 @@ func DeleteReleaseAttachment(ctx *context.APIContext) {
|
||||||
attach, err := repo_model.GetAttachmentByID(ctx, attachID)
|
attach, err := repo_model.GetAttachmentByID(ctx, attachID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if repo_model.IsErrAttachmentNotExist(err) {
|
if repo_model.IsErrAttachmentNotExist(err) {
|
||||||
ctx.NotFound()
|
ctx.APIErrorNotFound()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.Error(http.StatusInternalServerError, "GetAttachmentByID", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if attach.ReleaseID != releaseID {
|
if attach.ReleaseID != releaseID {
|
||||||
log.Info("User requested attachment is not in release, release_id %v, attachment_id: %v", releaseID, attachID)
|
log.Info("User requested attachment is not in release, release_id %v, attachment_id: %v", releaseID, attachID)
|
||||||
ctx.NotFound()
|
ctx.APIErrorNotFound()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// FIXME Should prove the existence of the given repo, but results in unnecessary database requests
|
// FIXME Should prove the existence of the given repo, but results in unnecessary database requests
|
||||||
|
|
||||||
if err := repo_model.DeleteAttachment(ctx, attach, true); err != nil {
|
if err := repo_model.DeleteAttachment(ctx, attach, true); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "DeleteAttachment", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.Status(http.StatusNoContent)
|
ctx.Status(http.StatusNoContent)
|
||||||
|
|
|
@ -46,20 +46,20 @@ func GetReleaseByTag(ctx *context.APIContext) {
|
||||||
release, err := repo_model.GetRelease(ctx, ctx.Repo.Repository.ID, tag)
|
release, err := repo_model.GetRelease(ctx, ctx.Repo.Repository.ID, tag)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if repo_model.IsErrReleaseNotExist(err) {
|
if repo_model.IsErrReleaseNotExist(err) {
|
||||||
ctx.NotFound()
|
ctx.APIErrorNotFound()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.Error(http.StatusInternalServerError, "GetRelease", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if release.IsTag {
|
if release.IsTag {
|
||||||
ctx.NotFound()
|
ctx.APIErrorNotFound()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = release.LoadAttributes(ctx); err != nil {
|
if err = release.LoadAttributes(ctx); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "LoadAttributes", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.JSON(http.StatusOK, convert.ToAPIRelease(ctx, ctx.Repo.Repository, release))
|
ctx.JSON(http.StatusOK, convert.ToAPIRelease(ctx, ctx.Repo.Repository, release))
|
||||||
|
@ -99,24 +99,24 @@ func DeleteReleaseByTag(ctx *context.APIContext) {
|
||||||
release, err := repo_model.GetRelease(ctx, ctx.Repo.Repository.ID, tag)
|
release, err := repo_model.GetRelease(ctx, ctx.Repo.Repository.ID, tag)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if repo_model.IsErrReleaseNotExist(err) {
|
if repo_model.IsErrReleaseNotExist(err) {
|
||||||
ctx.NotFound()
|
ctx.APIErrorNotFound()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.Error(http.StatusInternalServerError, "GetRelease", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if release.IsTag {
|
if release.IsTag {
|
||||||
ctx.NotFound()
|
ctx.APIErrorNotFound()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = release_service.DeleteReleaseByID(ctx, ctx.Repo.Repository, release, ctx.Doer, false); err != nil {
|
if err = release_service.DeleteReleaseByID(ctx, ctx.Repo.Repository, release, ctx.Doer, false); err != nil {
|
||||||
if release_service.IsErrProtectedTagName(err) {
|
if release_service.IsErrProtectedTagName(err) {
|
||||||
ctx.Error(http.StatusUnprocessableEntity, "delTag", "user not allowed to delete protected tag")
|
ctx.APIError(http.StatusUnprocessableEntity, "user not allowed to delete protected tag")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.Error(http.StatusInternalServerError, "DeleteReleaseByID", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -171,7 +171,7 @@ func Search(ctx *context.APIContext) {
|
||||||
opts.Collaborate = optional.Some(true)
|
opts.Collaborate = optional.Some(true)
|
||||||
case "":
|
case "":
|
||||||
default:
|
default:
|
||||||
ctx.Error(http.StatusUnprocessableEntity, "", fmt.Errorf("Invalid search mode: \"%s\"", mode))
|
ctx.APIError(http.StatusUnprocessableEntity, fmt.Errorf("Invalid search mode: \"%s\"", mode))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -193,11 +193,11 @@ func Search(ctx *context.APIContext) {
|
||||||
if orderBy, ok := searchModeMap[sortMode]; ok {
|
if orderBy, ok := searchModeMap[sortMode]; ok {
|
||||||
opts.OrderBy = orderBy
|
opts.OrderBy = orderBy
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusUnprocessableEntity, "", fmt.Errorf("Invalid sort mode: \"%s\"", sortMode))
|
ctx.APIError(http.StatusUnprocessableEntity, fmt.Errorf("Invalid sort mode: \"%s\"", sortMode))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusUnprocessableEntity, "", fmt.Errorf("Invalid sort order: \"%s\"", sortOrder))
|
ctx.APIError(http.StatusUnprocessableEntity, fmt.Errorf("Invalid sort order: \"%s\"", sortOrder))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -245,7 +245,7 @@ func CreateUserRepo(ctx *context.APIContext, owner *user_model.User, opt api.Cre
|
||||||
|
|
||||||
// If the readme template does not exist, a 400 will be returned.
|
// If the readme template does not exist, a 400 will be returned.
|
||||||
if opt.AutoInit && len(opt.Readme) > 0 && !slices.Contains(repo_module.Readmes, opt.Readme) {
|
if opt.AutoInit && len(opt.Readme) > 0 && !slices.Contains(repo_module.Readmes, opt.Readme) {
|
||||||
ctx.Error(http.StatusBadRequest, "", fmt.Errorf("readme template does not exist, available templates: %v", repo_module.Readmes))
|
ctx.APIError(http.StatusBadRequest, fmt.Errorf("readme template does not exist, available templates: %v", repo_module.Readmes))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -265,13 +265,13 @@ func CreateUserRepo(ctx *context.APIContext, owner *user_model.User, opt api.Cre
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if repo_model.IsErrRepoAlreadyExist(err) {
|
if repo_model.IsErrRepoAlreadyExist(err) {
|
||||||
ctx.Error(http.StatusConflict, "", "The repository with the same name already exists.")
|
ctx.APIError(http.StatusConflict, "The repository with the same name already exists.")
|
||||||
} else if db.IsErrNameReserved(err) ||
|
} else if db.IsErrNameReserved(err) ||
|
||||||
db.IsErrNamePatternNotAllowed(err) ||
|
db.IsErrNamePatternNotAllowed(err) ||
|
||||||
label.IsErrTemplateLoad(err) {
|
label.IsErrTemplateLoad(err) {
|
||||||
ctx.Error(http.StatusUnprocessableEntity, "", err)
|
ctx.APIError(http.StatusUnprocessableEntity, err)
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "CreateRepository", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -279,7 +279,7 @@ func CreateUserRepo(ctx *context.APIContext, owner *user_model.User, opt api.Cre
|
||||||
// reload repo from db to get a real state after creation
|
// reload repo from db to get a real state after creation
|
||||||
repo, err = repo_model.GetRepositoryByID(ctx, repo.ID)
|
repo, err = repo_model.GetRepositoryByID(ctx, repo.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetRepositoryByID", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.JSON(http.StatusCreated, convert.ToRepo(ctx, repo, access_model.Permission{AccessMode: perm.AccessModeOwner}))
|
ctx.JSON(http.StatusCreated, convert.ToRepo(ctx, repo, access_model.Permission{AccessMode: perm.AccessModeOwner}))
|
||||||
|
@ -311,7 +311,7 @@ func Create(ctx *context.APIContext) {
|
||||||
opt := web.GetForm(ctx).(*api.CreateRepoOption)
|
opt := web.GetForm(ctx).(*api.CreateRepoOption)
|
||||||
if ctx.Doer.IsOrganization() {
|
if ctx.Doer.IsOrganization() {
|
||||||
// Shouldn't reach this condition, but just in case.
|
// Shouldn't reach this condition, but just in case.
|
||||||
ctx.Error(http.StatusUnprocessableEntity, "", "not allowed creating repository for organization")
|
ctx.APIError(http.StatusUnprocessableEntity, "not allowed creating repository for organization")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
CreateUserRepo(ctx, ctx.Doer, *opt)
|
CreateUserRepo(ctx, ctx.Doer, *opt)
|
||||||
|
@ -355,12 +355,12 @@ func Generate(ctx *context.APIContext) {
|
||||||
form := web.GetForm(ctx).(*api.GenerateRepoOption)
|
form := web.GetForm(ctx).(*api.GenerateRepoOption)
|
||||||
|
|
||||||
if !ctx.Repo.Repository.IsTemplate {
|
if !ctx.Repo.Repository.IsTemplate {
|
||||||
ctx.Error(http.StatusUnprocessableEntity, "", "this is not a template repo")
|
ctx.APIError(http.StatusUnprocessableEntity, "this is not a template repo")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if ctx.Doer.IsOrganization() {
|
if ctx.Doer.IsOrganization() {
|
||||||
ctx.Error(http.StatusUnprocessableEntity, "", "not allowed creating repository for organization")
|
ctx.APIError(http.StatusUnprocessableEntity, "not allowed creating repository for organization")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -379,7 +379,7 @@ func Generate(ctx *context.APIContext) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if !opts.IsValid() {
|
if !opts.IsValid() {
|
||||||
ctx.Error(http.StatusUnprocessableEntity, "", "must select at least one template item")
|
ctx.APIError(http.StatusUnprocessableEntity, "must select at least one template item")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -395,22 +395,22 @@ func Generate(ctx *context.APIContext) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.Error(http.StatusInternalServerError, "GetUserByName", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if !ctx.Doer.IsAdmin && !ctxUser.IsOrganization() {
|
if !ctx.Doer.IsAdmin && !ctxUser.IsOrganization() {
|
||||||
ctx.Error(http.StatusForbidden, "", "Only admin can generate repository for other user.")
|
ctx.APIError(http.StatusForbidden, "Only admin can generate repository for other user.")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if !ctx.Doer.IsAdmin {
|
if !ctx.Doer.IsAdmin {
|
||||||
canCreate, err := organization.OrgFromUser(ctxUser).CanCreateOrgRepo(ctx, ctx.Doer.ID)
|
canCreate, err := organization.OrgFromUser(ctxUser).CanCreateOrgRepo(ctx, ctx.Doer.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.ServerError("CanCreateOrgRepo", err)
|
ctx.APIErrorInternal(err)
|
||||||
return
|
return
|
||||||
} else if !canCreate {
|
} else if !canCreate {
|
||||||
ctx.Error(http.StatusForbidden, "", "Given user is not allowed to create repository in organization.")
|
ctx.APIError(http.StatusForbidden, "Given user is not allowed to create repository in organization.")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -419,12 +419,12 @@ func Generate(ctx *context.APIContext) {
|
||||||
repo, err := repo_service.GenerateRepository(ctx, ctx.Doer, ctxUser, ctx.Repo.Repository, opts)
|
repo, err := repo_service.GenerateRepository(ctx, ctx.Doer, ctxUser, ctx.Repo.Repository, opts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if repo_model.IsErrRepoAlreadyExist(err) {
|
if repo_model.IsErrRepoAlreadyExist(err) {
|
||||||
ctx.Error(http.StatusConflict, "", "The repository with the same name already exists.")
|
ctx.APIError(http.StatusConflict, "The repository with the same name already exists.")
|
||||||
} else if db.IsErrNameReserved(err) ||
|
} else if db.IsErrNameReserved(err) ||
|
||||||
db.IsErrNamePatternNotAllowed(err) {
|
db.IsErrNamePatternNotAllowed(err) {
|
||||||
ctx.Error(http.StatusUnprocessableEntity, "", err)
|
ctx.APIError(http.StatusUnprocessableEntity, err)
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "CreateRepository", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -498,25 +498,25 @@ func CreateOrgRepo(ctx *context.APIContext) {
|
||||||
org, err := organization.GetOrgByName(ctx, ctx.PathParam("org"))
|
org, err := organization.GetOrgByName(ctx, ctx.PathParam("org"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if organization.IsErrOrgNotExist(err) {
|
if organization.IsErrOrgNotExist(err) {
|
||||||
ctx.Error(http.StatusUnprocessableEntity, "", err)
|
ctx.APIError(http.StatusUnprocessableEntity, err)
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetOrgByName", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if !organization.HasOrgOrUserVisible(ctx, org.AsUser(), ctx.Doer) {
|
if !organization.HasOrgOrUserVisible(ctx, org.AsUser(), ctx.Doer) {
|
||||||
ctx.NotFound("HasOrgOrUserVisible", nil)
|
ctx.APIErrorNotFound("HasOrgOrUserVisible", nil)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if !ctx.Doer.IsAdmin {
|
if !ctx.Doer.IsAdmin {
|
||||||
canCreate, err := org.CanCreateOrgRepo(ctx, ctx.Doer.ID)
|
canCreate, err := org.CanCreateOrgRepo(ctx, ctx.Doer.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "CanCreateOrgRepo", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
} else if !canCreate {
|
} else if !canCreate {
|
||||||
ctx.Error(http.StatusForbidden, "", "Given user is not allowed to create repository in organization.")
|
ctx.APIError(http.StatusForbidden, "Given user is not allowed to create repository in organization.")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -548,7 +548,7 @@ func Get(ctx *context.APIContext) {
|
||||||
// "$ref": "#/responses/notFound"
|
// "$ref": "#/responses/notFound"
|
||||||
|
|
||||||
if err := ctx.Repo.Repository.LoadAttributes(ctx); err != nil {
|
if err := ctx.Repo.Repository.LoadAttributes(ctx); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "Repository.LoadAttributes", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -578,19 +578,19 @@ func GetByID(ctx *context.APIContext) {
|
||||||
repo, err := repo_model.GetRepositoryByID(ctx, ctx.PathParamInt64("id"))
|
repo, err := repo_model.GetRepositoryByID(ctx, ctx.PathParamInt64("id"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if repo_model.IsErrRepoNotExist(err) {
|
if repo_model.IsErrRepoNotExist(err) {
|
||||||
ctx.NotFound()
|
ctx.APIErrorNotFound()
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetRepositoryByID", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
permission, err := access_model.GetUserRepoPermission(ctx, repo, ctx.Doer)
|
permission, err := access_model.GetUserRepoPermission(ctx, repo, ctx.Doer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetUserRepoPermission", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
} else if !permission.HasAnyUnitAccess() {
|
} else if !permission.HasAnyUnitAccess() {
|
||||||
ctx.NotFound()
|
ctx.APIErrorNotFound()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.JSON(http.StatusOK, convert.ToRepo(ctx, repo, permission))
|
ctx.JSON(http.StatusOK, convert.ToRepo(ctx, repo, permission))
|
||||||
|
@ -653,7 +653,7 @@ func Edit(ctx *context.APIContext) {
|
||||||
|
|
||||||
repo, err := repo_model.GetRepositoryByID(ctx, ctx.Repo.Repository.ID)
|
repo, err := repo_model.GetRepositoryByID(ctx, ctx.Repo.Repository.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.InternalServerError(err)
|
ctx.APIErrorInternal(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -673,13 +673,13 @@ func updateBasicProperties(ctx *context.APIContext, opts api.EditRepoOption) err
|
||||||
if err := repo_service.ChangeRepositoryName(ctx, ctx.Doer, repo, newRepoName); err != nil {
|
if err := repo_service.ChangeRepositoryName(ctx, ctx.Doer, repo, newRepoName); err != nil {
|
||||||
switch {
|
switch {
|
||||||
case repo_model.IsErrRepoAlreadyExist(err):
|
case repo_model.IsErrRepoAlreadyExist(err):
|
||||||
ctx.Error(http.StatusUnprocessableEntity, fmt.Sprintf("repo name is already taken [name: %s]", newRepoName), err)
|
ctx.APIError(http.StatusUnprocessableEntity, err)
|
||||||
case db.IsErrNameReserved(err):
|
case db.IsErrNameReserved(err):
|
||||||
ctx.Error(http.StatusUnprocessableEntity, fmt.Sprintf("repo name is reserved [name: %s]", newRepoName), err)
|
ctx.APIError(http.StatusUnprocessableEntity, err)
|
||||||
case db.IsErrNamePatternNotAllowed(err):
|
case db.IsErrNamePatternNotAllowed(err):
|
||||||
ctx.Error(http.StatusUnprocessableEntity, fmt.Sprintf("repo name's pattern is not allowed [name: %s, pattern: %s]", newRepoName, err.(db.ErrNamePatternNotAllowed).Pattern), err)
|
ctx.APIError(http.StatusUnprocessableEntity, err)
|
||||||
default:
|
default:
|
||||||
ctx.Error(http.StatusUnprocessableEntity, "ChangeRepositoryName", err)
|
ctx.APIError(http.StatusUnprocessableEntity, fmt.Errorf("ChangeRepositoryName: %w", err))
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -703,7 +703,7 @@ func updateBasicProperties(ctx *context.APIContext, opts api.EditRepoOption) err
|
||||||
// Visibility of forked repository is forced sync with base repository.
|
// Visibility of forked repository is forced sync with base repository.
|
||||||
if repo.IsFork {
|
if repo.IsFork {
|
||||||
if err := repo.GetBaseRepo(ctx); err != nil {
|
if err := repo.GetBaseRepo(ctx); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "Unable to load base repository", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
*opts.Private = repo.BaseRepo.IsPrivate
|
*opts.Private = repo.BaseRepo.IsPrivate
|
||||||
|
@ -713,7 +713,7 @@ func updateBasicProperties(ctx *context.APIContext, opts api.EditRepoOption) err
|
||||||
// when ForcePrivate enabled, you could change public repo to private, but only admin users can change private to public
|
// when ForcePrivate enabled, you could change public repo to private, but only admin users can change private to public
|
||||||
if visibilityChanged && setting.Repository.ForcePrivate && !*opts.Private && !ctx.Doer.IsAdmin {
|
if visibilityChanged && setting.Repository.ForcePrivate && !*opts.Private && !ctx.Doer.IsAdmin {
|
||||||
err := fmt.Errorf("cannot change private repository to public")
|
err := fmt.Errorf("cannot change private repository to public")
|
||||||
ctx.Error(http.StatusUnprocessableEntity, "Force Private enabled", err)
|
ctx.APIError(http.StatusUnprocessableEntity, err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -728,7 +728,7 @@ func updateBasicProperties(ctx *context.APIContext, opts api.EditRepoOption) err
|
||||||
var err error
|
var err error
|
||||||
ctx.Repo.GitRepo, err = gitrepo.RepositoryFromRequestContextOrOpen(ctx, repo)
|
ctx.Repo.GitRepo, err = gitrepo.RepositoryFromRequestContextOrOpen(ctx, repo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "Unable to OpenRepository", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -738,7 +738,7 @@ func updateBasicProperties(ctx *context.APIContext, opts api.EditRepoOption) err
|
||||||
if opts.DefaultBranch != nil && repo.DefaultBranch != *opts.DefaultBranch && (repo.IsEmpty || ctx.Repo.GitRepo.IsBranchExist(*opts.DefaultBranch)) {
|
if opts.DefaultBranch != nil && repo.DefaultBranch != *opts.DefaultBranch && (repo.IsEmpty || ctx.Repo.GitRepo.IsBranchExist(*opts.DefaultBranch)) {
|
||||||
if !repo.IsEmpty {
|
if !repo.IsEmpty {
|
||||||
if err := gitrepo.SetDefaultBranch(ctx, ctx.Repo.Repository, *opts.DefaultBranch); err != nil {
|
if err := gitrepo.SetDefaultBranch(ctx, ctx.Repo.Repository, *opts.DefaultBranch); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "SetDefaultBranch", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
updateRepoLicense = true
|
updateRepoLicense = true
|
||||||
|
@ -747,7 +747,7 @@ func updateBasicProperties(ctx *context.APIContext, opts api.EditRepoOption) err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := repo_service.UpdateRepository(ctx, repo, visibilityChanged); err != nil {
|
if err := repo_service.UpdateRepository(ctx, repo, visibilityChanged); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "UpdateRepository", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -755,7 +755,7 @@ func updateBasicProperties(ctx *context.APIContext, opts api.EditRepoOption) err
|
||||||
if err := repo_service.AddRepoToLicenseUpdaterQueue(&repo_service.LicenseUpdaterOptions{
|
if err := repo_service.AddRepoToLicenseUpdaterQueue(&repo_service.LicenseUpdaterOptions{
|
||||||
RepoID: ctx.Repo.Repository.ID,
|
RepoID: ctx.Repo.Repository.ID,
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "AddRepoToLicenseUpdaterQueue", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -782,12 +782,12 @@ func updateRepoUnits(ctx *context.APIContext, opts api.EditRepoOption) error {
|
||||||
// Check that values are valid
|
// Check that values are valid
|
||||||
if !validation.IsValidExternalURL(opts.ExternalTracker.ExternalTrackerURL) {
|
if !validation.IsValidExternalURL(opts.ExternalTracker.ExternalTrackerURL) {
|
||||||
err := fmt.Errorf("External tracker URL not valid")
|
err := fmt.Errorf("External tracker URL not valid")
|
||||||
ctx.Error(http.StatusUnprocessableEntity, "Invalid external tracker URL", err)
|
ctx.APIError(http.StatusUnprocessableEntity, err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if len(opts.ExternalTracker.ExternalTrackerFormat) != 0 && !validation.IsValidExternalTrackerURLFormat(opts.ExternalTracker.ExternalTrackerFormat) {
|
if len(opts.ExternalTracker.ExternalTrackerFormat) != 0 && !validation.IsValidExternalTrackerURLFormat(opts.ExternalTracker.ExternalTrackerFormat) {
|
||||||
err := fmt.Errorf("External tracker URL format not valid")
|
err := fmt.Errorf("External tracker URL format not valid")
|
||||||
ctx.Error(http.StatusUnprocessableEntity, "Invalid external tracker URL format", err)
|
ctx.APIError(http.StatusUnprocessableEntity, err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -849,7 +849,7 @@ func updateRepoUnits(ctx *context.APIContext, opts api.EditRepoOption) error {
|
||||||
// Check that values are valid
|
// Check that values are valid
|
||||||
if !validation.IsValidExternalURL(opts.ExternalWiki.ExternalWikiURL) {
|
if !validation.IsValidExternalURL(opts.ExternalWiki.ExternalWikiURL) {
|
||||||
err := fmt.Errorf("External wiki URL not valid")
|
err := fmt.Errorf("External wiki URL not valid")
|
||||||
ctx.Error(http.StatusUnprocessableEntity, "", "Invalid external wiki URL")
|
ctx.APIError(http.StatusUnprocessableEntity, "Invalid external wiki URL")
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1024,7 +1024,7 @@ func updateRepoUnits(ctx *context.APIContext, opts api.EditRepoOption) error {
|
||||||
|
|
||||||
if len(units)+len(deleteUnitTypes) > 0 {
|
if len(units)+len(deleteUnitTypes) > 0 {
|
||||||
if err := repo_service.UpdateRepositoryUnits(ctx, repo, units, deleteUnitTypes); err != nil {
|
if err := repo_service.UpdateRepositoryUnits(ctx, repo, units, deleteUnitTypes); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "UpdateRepositoryUnits", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1040,13 +1040,13 @@ func updateRepoArchivedState(ctx *context.APIContext, opts api.EditRepoOption) e
|
||||||
if opts.Archived != nil {
|
if opts.Archived != nil {
|
||||||
if repo.IsMirror {
|
if repo.IsMirror {
|
||||||
err := fmt.Errorf("repo is a mirror, cannot archive/un-archive")
|
err := fmt.Errorf("repo is a mirror, cannot archive/un-archive")
|
||||||
ctx.Error(http.StatusUnprocessableEntity, err.Error(), err)
|
ctx.APIError(http.StatusUnprocessableEntity, err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if *opts.Archived {
|
if *opts.Archived {
|
||||||
if err := repo_model.SetArchiveRepoState(ctx, repo, *opts.Archived); err != nil {
|
if err := repo_model.SetArchiveRepoState(ctx, repo, *opts.Archived); err != nil {
|
||||||
log.Error("Tried to archive a repo: %s", err)
|
log.Error("Tried to archive a repo: %s", err)
|
||||||
ctx.Error(http.StatusInternalServerError, "ArchiveRepoState", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err := actions_model.CleanRepoScheduleTasks(ctx, repo); err != nil {
|
if err := actions_model.CleanRepoScheduleTasks(ctx, repo); err != nil {
|
||||||
|
@ -1056,7 +1056,7 @@ func updateRepoArchivedState(ctx *context.APIContext, opts api.EditRepoOption) e
|
||||||
} else {
|
} else {
|
||||||
if err := repo_model.SetArchiveRepoState(ctx, repo, *opts.Archived); err != nil {
|
if err := repo_model.SetArchiveRepoState(ctx, repo, *opts.Archived); err != nil {
|
||||||
log.Error("Tried to un-archive a repo: %s", err)
|
log.Error("Tried to un-archive a repo: %s", err)
|
||||||
ctx.Error(http.StatusInternalServerError, "ArchiveRepoState", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if ctx.Repo.Repository.UnitEnabled(ctx, unit_model.TypeActions) {
|
if ctx.Repo.Repository.UnitEnabled(ctx, unit_model.TypeActions) {
|
||||||
|
@ -1084,7 +1084,7 @@ func updateMirror(ctx *context.APIContext, opts api.EditRepoOption) error {
|
||||||
mirror, err := repo_model.GetMirrorByRepoID(ctx, repo.ID)
|
mirror, err := repo_model.GetMirrorByRepoID(ctx, repo.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("Failed to get mirror: %s", err)
|
log.Error("Failed to get mirror: %s", err)
|
||||||
ctx.Error(http.StatusInternalServerError, "MirrorInterval", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1094,14 +1094,14 @@ func updateMirror(ctx *context.APIContext, opts api.EditRepoOption) error {
|
||||||
interval, err := time.ParseDuration(*opts.MirrorInterval)
|
interval, err := time.ParseDuration(*opts.MirrorInterval)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("Wrong format for MirrorInternal Sent: %s", err)
|
log.Error("Wrong format for MirrorInternal Sent: %s", err)
|
||||||
ctx.Error(http.StatusUnprocessableEntity, "MirrorInterval", err)
|
ctx.APIError(http.StatusUnprocessableEntity, err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ensure the provided duration is not too short
|
// Ensure the provided duration is not too short
|
||||||
if interval != 0 && interval < setting.Mirror.MinInterval {
|
if interval != 0 && interval < setting.Mirror.MinInterval {
|
||||||
err := fmt.Errorf("invalid mirror interval: %s is below minimum interval: %s", interval, setting.Mirror.MinInterval)
|
err := fmt.Errorf("invalid mirror interval: %s is below minimum interval: %s", interval, setting.Mirror.MinInterval)
|
||||||
ctx.Error(http.StatusUnprocessableEntity, "MirrorInterval", err)
|
ctx.APIError(http.StatusUnprocessableEntity, err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1120,7 +1120,7 @@ func updateMirror(ctx *context.APIContext, opts api.EditRepoOption) error {
|
||||||
// finally update the mirror in the DB
|
// finally update the mirror in the DB
|
||||||
if err := repo_model.UpdateMirror(ctx, mirror); err != nil {
|
if err := repo_model.UpdateMirror(ctx, mirror); err != nil {
|
||||||
log.Error("Failed to Set Mirror Interval: %s", err)
|
log.Error("Failed to Set Mirror Interval: %s", err)
|
||||||
ctx.Error(http.StatusUnprocessableEntity, "MirrorInterval", err)
|
ctx.APIError(http.StatusUnprocessableEntity, err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1158,10 +1158,10 @@ func Delete(ctx *context.APIContext) {
|
||||||
|
|
||||||
canDelete, err := repo_module.CanUserDelete(ctx, repo, ctx.Doer)
|
canDelete, err := repo_module.CanUserDelete(ctx, repo, ctx.Doer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "CanUserDelete", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
} else if !canDelete {
|
} else if !canDelete {
|
||||||
ctx.Error(http.StatusForbidden, "", "Given user is not owner of organization.")
|
ctx.APIError(http.StatusForbidden, "Given user is not owner of organization.")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1170,7 +1170,7 @@ func Delete(ctx *context.APIContext) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := repo_service.DeleteRepository(ctx, ctx.Doer, repo, true); err != nil {
|
if err := repo_service.DeleteRepository(ctx, ctx.Doer, repo, true); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "DeleteRepository", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1315,7 +1315,7 @@ func ListRepoActivityFeeds(ctx *context.APIContext) {
|
||||||
|
|
||||||
feeds, count, err := feed_service.GetFeeds(ctx, opts)
|
feeds, count, err := feed_service.GetFeeds(ctx, opts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetFeeds", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.SetTotalCountHeader(count)
|
ctx.SetTotalCountHeader(count)
|
||||||
|
|
|
@ -49,7 +49,7 @@ func ListStargazers(ctx *context.APIContext) {
|
||||||
|
|
||||||
stargazers, err := repo_model.GetStargazers(ctx, ctx.Repo.Repository, utils.GetListOptions(ctx))
|
stargazers, err := repo_model.GetStargazers(ctx, ctx.Repo.Repository, utils.GetListOptions(ctx))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetStargazers", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
users := make([]*api.User, len(stargazers))
|
users := make([]*api.User, len(stargazers))
|
||||||
|
|
|
@ -55,7 +55,7 @@ func NewCommitStatus(ctx *context.APIContext) {
|
||||||
form := web.GetForm(ctx).(*api.CreateStatusOption)
|
form := web.GetForm(ctx).(*api.CreateStatusOption)
|
||||||
sha := ctx.PathParam("sha")
|
sha := ctx.PathParam("sha")
|
||||||
if len(sha) == 0 {
|
if len(sha) == 0 {
|
||||||
ctx.Error(http.StatusBadRequest, "sha not given", nil)
|
ctx.APIError(http.StatusBadRequest, nil)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
status := &git_model.CommitStatus{
|
status := &git_model.CommitStatus{
|
||||||
|
@ -65,7 +65,7 @@ func NewCommitStatus(ctx *context.APIContext) {
|
||||||
Context: form.Context,
|
Context: form.Context,
|
||||||
}
|
}
|
||||||
if err := commitstatus_service.CreateCommitStatus(ctx, ctx.Repo.Repository, ctx.Doer, sha, status); err != nil {
|
if err := commitstatus_service.CreateCommitStatus(ctx, ctx.Repo.Repository, ctx.Doer, sha, status); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "CreateCommitStatus", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -187,7 +187,7 @@ func GetCommitStatusesByRef(ctx *context.APIContext) {
|
||||||
|
|
||||||
func getCommitStatuses(ctx *context.APIContext, sha string) {
|
func getCommitStatuses(ctx *context.APIContext, sha string) {
|
||||||
if len(sha) == 0 {
|
if len(sha) == 0 {
|
||||||
ctx.Error(http.StatusBadRequest, "ref/sha not given", nil)
|
ctx.APIError(http.StatusBadRequest, nil)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
sha = utils.MustConvertToSHA1(ctx.Base, ctx.Repo, sha)
|
sha = utils.MustConvertToSHA1(ctx.Base, ctx.Repo, sha)
|
||||||
|
@ -203,7 +203,7 @@ func getCommitStatuses(ctx *context.APIContext, sha string) {
|
||||||
State: ctx.FormTrim("state"),
|
State: ctx.FormTrim("state"),
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetCommitStatuses", fmt.Errorf("GetCommitStatuses[%s, %s, %d]: %w", repo.FullName(), sha, ctx.FormInt("page"), err))
|
ctx.APIError(http.StatusInternalServerError, fmt.Errorf("GetCommitStatuses[%s, %s, %d]: %w", repo.FullName(), sha, ctx.FormInt("page"), err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -266,7 +266,7 @@ func GetCombinedCommitStatusByRef(ctx *context.APIContext) {
|
||||||
|
|
||||||
statuses, count, err := git_model.GetLatestCommitStatus(ctx, repo.ID, sha, utils.GetListOptions(ctx))
|
statuses, count, err := git_model.GetLatestCommitStatus(ctx, repo.ID, sha, utils.GetListOptions(ctx))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetLatestCommitStatus", fmt.Errorf("GetLatestCommitStatus[%s, %s]: %w", repo.FullName(), sha, err))
|
ctx.APIError(http.StatusInternalServerError, fmt.Errorf("GetLatestCommitStatus[%s, %s]: %w", repo.FullName(), sha, err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -47,7 +47,7 @@ func ListSubscribers(ctx *context.APIContext) {
|
||||||
|
|
||||||
subscribers, err := repo_model.GetRepoWatchers(ctx, ctx.Repo.Repository.ID, utils.GetListOptions(ctx))
|
subscribers, err := repo_model.GetRepoWatchers(ctx, ctx.Repo.Repository.ID, utils.GetListOptions(ctx))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetRepoWatchers", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
users := make([]*api.User, len(subscribers))
|
users := make([]*api.User, len(subscribers))
|
||||||
|
|
|
@ -57,7 +57,7 @@ func ListTags(ctx *context.APIContext) {
|
||||||
|
|
||||||
tags, total, err := ctx.Repo.GitRepo.GetTagInfos(listOpts.Page, listOpts.PageSize)
|
tags, total, err := ctx.Repo.GitRepo.GetTagInfos(listOpts.Page, listOpts.PageSize)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetTags", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -103,16 +103,16 @@ func GetAnnotatedTag(ctx *context.APIContext) {
|
||||||
|
|
||||||
sha := ctx.PathParam("sha")
|
sha := ctx.PathParam("sha")
|
||||||
if len(sha) == 0 {
|
if len(sha) == 0 {
|
||||||
ctx.Error(http.StatusBadRequest, "", "SHA not provided")
|
ctx.APIError(http.StatusBadRequest, "SHA not provided")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if tag, err := ctx.Repo.GitRepo.GetAnnotatedTag(sha); err != nil {
|
if tag, err := ctx.Repo.GitRepo.GetAnnotatedTag(sha); err != nil {
|
||||||
ctx.Error(http.StatusBadRequest, "GetAnnotatedTag", err)
|
ctx.APIError(http.StatusBadRequest, err)
|
||||||
} else {
|
} else {
|
||||||
commit, err := tag.Commit(ctx.Repo.GitRepo)
|
commit, err := tag.Commit(ctx.Repo.GitRepo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusBadRequest, "GetAnnotatedTag", err)
|
ctx.APIError(http.StatusBadRequest, err)
|
||||||
}
|
}
|
||||||
ctx.JSON(http.StatusOK, convert.ToAnnotatedTag(ctx, ctx.Repo.Repository, tag, commit))
|
ctx.JSON(http.StatusOK, convert.ToAnnotatedTag(ctx, ctx.Repo.Repository, tag, commit))
|
||||||
}
|
}
|
||||||
|
@ -150,7 +150,7 @@ func GetTag(ctx *context.APIContext) {
|
||||||
|
|
||||||
tag, err := ctx.Repo.GitRepo.GetTag(tagName)
|
tag, err := ctx.Repo.GitRepo.GetTag(tagName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.NotFound(tagName)
|
ctx.APIErrorNotFound(tagName)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.JSON(http.StatusOK, convert.ToTag(ctx.Repo.Repository, tag))
|
ctx.JSON(http.StatusOK, convert.ToTag(ctx.Repo.Repository, tag))
|
||||||
|
@ -200,27 +200,27 @@ func CreateTag(ctx *context.APIContext) {
|
||||||
|
|
||||||
commit, err := ctx.Repo.GitRepo.GetCommit(form.Target)
|
commit, err := ctx.Repo.GitRepo.GetCommit(form.Target)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusNotFound, "target not found", fmt.Errorf("target not found: %w", err))
|
ctx.APIError(http.StatusNotFound, fmt.Errorf("target not found: %w", err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := release_service.CreateNewTag(ctx, ctx.Doer, ctx.Repo.Repository, commit.ID.String(), form.TagName, form.Message); err != nil {
|
if err := release_service.CreateNewTag(ctx, ctx.Doer, ctx.Repo.Repository, commit.ID.String(), form.TagName, form.Message); err != nil {
|
||||||
if release_service.IsErrTagAlreadyExists(err) {
|
if release_service.IsErrTagAlreadyExists(err) {
|
||||||
ctx.Error(http.StatusConflict, "tag exist", err)
|
ctx.APIError(http.StatusConflict, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if release_service.IsErrProtectedTagName(err) {
|
if release_service.IsErrProtectedTagName(err) {
|
||||||
ctx.Error(http.StatusUnprocessableEntity, "CreateNewTag", "user not allowed to create protected tag")
|
ctx.APIError(http.StatusUnprocessableEntity, "user not allowed to create protected tag")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.InternalServerError(err)
|
ctx.APIErrorInternal(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
tag, err := ctx.Repo.GitRepo.GetTag(form.TagName)
|
tag, err := ctx.Repo.GitRepo.GetTag(form.TagName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.InternalServerError(err)
|
ctx.APIErrorInternal(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.JSON(http.StatusCreated, convert.ToTag(ctx.Repo.Repository, tag))
|
ctx.JSON(http.StatusCreated, convert.ToTag(ctx.Repo.Repository, tag))
|
||||||
|
@ -267,24 +267,24 @@ func DeleteTag(ctx *context.APIContext) {
|
||||||
tag, err := repo_model.GetRelease(ctx, ctx.Repo.Repository.ID, tagName)
|
tag, err := repo_model.GetRelease(ctx, ctx.Repo.Repository.ID, tagName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if repo_model.IsErrReleaseNotExist(err) {
|
if repo_model.IsErrReleaseNotExist(err) {
|
||||||
ctx.NotFound()
|
ctx.APIErrorNotFound()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.Error(http.StatusInternalServerError, "GetRelease", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if !tag.IsTag {
|
if !tag.IsTag {
|
||||||
ctx.Error(http.StatusConflict, "IsTag", errors.New("a tag attached to a release cannot be deleted directly"))
|
ctx.APIError(http.StatusConflict, errors.New("a tag attached to a release cannot be deleted directly"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = release_service.DeleteReleaseByID(ctx, ctx.Repo.Repository, tag, ctx.Doer, true); err != nil {
|
if err = release_service.DeleteReleaseByID(ctx, ctx.Repo.Repository, tag, ctx.Doer, true); err != nil {
|
||||||
if release_service.IsErrProtectedTagName(err) {
|
if release_service.IsErrProtectedTagName(err) {
|
||||||
ctx.Error(http.StatusUnprocessableEntity, "delTag", "user not allowed to delete protected tag")
|
ctx.APIError(http.StatusUnprocessableEntity, "user not allowed to delete protected tag")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.Error(http.StatusInternalServerError, "DeleteReleaseByID", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -316,7 +316,7 @@ func ListTagProtection(ctx *context.APIContext) {
|
||||||
repo := ctx.Repo.Repository
|
repo := ctx.Repo.Repository
|
||||||
pts, err := git_model.GetProtectedTags(ctx, repo.ID)
|
pts, err := git_model.GetProtectedTags(ctx, repo.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetProtectedTags", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
apiPts := make([]*api.TagProtection, len(pts))
|
apiPts := make([]*api.TagProtection, len(pts))
|
||||||
|
@ -360,12 +360,12 @@ func GetTagProtection(ctx *context.APIContext) {
|
||||||
id := ctx.PathParamInt64("id")
|
id := ctx.PathParamInt64("id")
|
||||||
pt, err := git_model.GetProtectedTagByID(ctx, id)
|
pt, err := git_model.GetProtectedTagByID(ctx, id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetProtectedTagByID", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if pt == nil || repo.ID != pt.RepoID {
|
if pt == nil || repo.ID != pt.RepoID {
|
||||||
ctx.NotFound()
|
ctx.APIErrorNotFound()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -413,21 +413,21 @@ func CreateTagProtection(ctx *context.APIContext) {
|
||||||
|
|
||||||
namePattern := strings.TrimSpace(form.NamePattern)
|
namePattern := strings.TrimSpace(form.NamePattern)
|
||||||
if namePattern == "" {
|
if namePattern == "" {
|
||||||
ctx.Error(http.StatusBadRequest, "name_pattern are empty", "name_pattern are empty")
|
ctx.APIError(http.StatusBadRequest, "name_pattern are empty")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(form.WhitelistUsernames) == 0 && len(form.WhitelistTeams) == 0 {
|
if len(form.WhitelistUsernames) == 0 && len(form.WhitelistTeams) == 0 {
|
||||||
ctx.Error(http.StatusBadRequest, "both whitelist_usernames and whitelist_teams are empty", "both whitelist_usernames and whitelist_teams are empty")
|
ctx.APIError(http.StatusBadRequest, "both whitelist_usernames and whitelist_teams are empty")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
pt, err := git_model.GetProtectedTagByNamePattern(ctx, repo.ID, namePattern)
|
pt, err := git_model.GetProtectedTagByNamePattern(ctx, repo.ID, namePattern)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetProtectTagOfRepo", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
} else if pt != nil {
|
} else if pt != nil {
|
||||||
ctx.Error(http.StatusForbidden, "Create tag protection", "Tag protection already exist")
|
ctx.APIError(http.StatusForbidden, "Tag protection already exist")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -435,10 +435,10 @@ func CreateTagProtection(ctx *context.APIContext) {
|
||||||
whitelistUsers, err = user_model.GetUserIDsByNames(ctx, form.WhitelistUsernames, false)
|
whitelistUsers, err = user_model.GetUserIDsByNames(ctx, form.WhitelistUsernames, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if user_model.IsErrUserNotExist(err) {
|
if user_model.IsErrUserNotExist(err) {
|
||||||
ctx.Error(http.StatusUnprocessableEntity, "User does not exist", err)
|
ctx.APIError(http.StatusUnprocessableEntity, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.Error(http.StatusInternalServerError, "GetUserIDsByNames", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -446,10 +446,10 @@ func CreateTagProtection(ctx *context.APIContext) {
|
||||||
whitelistTeams, err = organization.GetTeamIDsByNames(ctx, repo.OwnerID, form.WhitelistTeams, false)
|
whitelistTeams, err = organization.GetTeamIDsByNames(ctx, repo.OwnerID, form.WhitelistTeams, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if organization.IsErrTeamNotExist(err) {
|
if organization.IsErrTeamNotExist(err) {
|
||||||
ctx.Error(http.StatusUnprocessableEntity, "Team does not exist", err)
|
ctx.APIError(http.StatusUnprocessableEntity, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.Error(http.StatusInternalServerError, "GetTeamIDsByNames", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -461,18 +461,18 @@ func CreateTagProtection(ctx *context.APIContext) {
|
||||||
AllowlistTeamIDs: whitelistTeams,
|
AllowlistTeamIDs: whitelistTeams,
|
||||||
}
|
}
|
||||||
if err := git_model.InsertProtectedTag(ctx, protectTag); err != nil {
|
if err := git_model.InsertProtectedTag(ctx, protectTag); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "InsertProtectedTag", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
pt, err = git_model.GetProtectedTagByID(ctx, protectTag.ID)
|
pt, err = git_model.GetProtectedTagByID(ctx, protectTag.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetProtectedTagByID", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if pt == nil || pt.RepoID != repo.ID {
|
if pt == nil || pt.RepoID != repo.ID {
|
||||||
ctx.Error(http.StatusInternalServerError, "New tag protection not found", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -524,12 +524,12 @@ func EditTagProtection(ctx *context.APIContext) {
|
||||||
id := ctx.PathParamInt64("id")
|
id := ctx.PathParamInt64("id")
|
||||||
pt, err := git_model.GetProtectedTagByID(ctx, id)
|
pt, err := git_model.GetProtectedTagByID(ctx, id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetProtectedTagByID", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if pt == nil || pt.RepoID != repo.ID {
|
if pt == nil || pt.RepoID != repo.ID {
|
||||||
ctx.NotFound()
|
ctx.APIErrorNotFound()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -543,10 +543,10 @@ func EditTagProtection(ctx *context.APIContext) {
|
||||||
whitelistTeams, err = organization.GetTeamIDsByNames(ctx, repo.OwnerID, form.WhitelistTeams, false)
|
whitelistTeams, err = organization.GetTeamIDsByNames(ctx, repo.OwnerID, form.WhitelistTeams, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if organization.IsErrTeamNotExist(err) {
|
if organization.IsErrTeamNotExist(err) {
|
||||||
ctx.Error(http.StatusUnprocessableEntity, "Team does not exist", err)
|
ctx.APIError(http.StatusUnprocessableEntity, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.Error(http.StatusInternalServerError, "GetTeamIDsByNames", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -557,10 +557,10 @@ func EditTagProtection(ctx *context.APIContext) {
|
||||||
whitelistUsers, err = user_model.GetUserIDsByNames(ctx, form.WhitelistUsernames, false)
|
whitelistUsers, err = user_model.GetUserIDsByNames(ctx, form.WhitelistUsernames, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if user_model.IsErrUserNotExist(err) {
|
if user_model.IsErrUserNotExist(err) {
|
||||||
ctx.Error(http.StatusUnprocessableEntity, "User does not exist", err)
|
ctx.APIError(http.StatusUnprocessableEntity, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.Error(http.StatusInternalServerError, "GetUserIDsByNames", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
pt.AllowlistUserIDs = whitelistUsers
|
pt.AllowlistUserIDs = whitelistUsers
|
||||||
|
@ -568,18 +568,18 @@ func EditTagProtection(ctx *context.APIContext) {
|
||||||
|
|
||||||
err = git_model.UpdateProtectedTag(ctx, pt)
|
err = git_model.UpdateProtectedTag(ctx, pt)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "UpdateProtectedTag", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
pt, err = git_model.GetProtectedTagByID(ctx, id)
|
pt, err = git_model.GetProtectedTagByID(ctx, id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetProtectedTagByID", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if pt == nil || pt.RepoID != repo.ID {
|
if pt == nil || pt.RepoID != repo.ID {
|
||||||
ctx.Error(http.StatusInternalServerError, "New tag protection not found", "New tag protection not found")
|
ctx.APIError(http.StatusInternalServerError, "New tag protection not found")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -619,18 +619,18 @@ func DeleteTagProtection(ctx *context.APIContext) {
|
||||||
id := ctx.PathParamInt64("id")
|
id := ctx.PathParamInt64("id")
|
||||||
pt, err := git_model.GetProtectedTagByID(ctx, id)
|
pt, err := git_model.GetProtectedTagByID(ctx, id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetProtectedTagByID", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if pt == nil || pt.RepoID != repo.ID {
|
if pt == nil || pt.RepoID != repo.ID {
|
||||||
ctx.NotFound()
|
ctx.APIErrorNotFound()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
err = git_model.DeleteProtectedTag(ctx, pt)
|
err = git_model.DeleteProtectedTag(ctx, pt)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "DeleteProtectedTag", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -38,19 +38,19 @@ func ListTeams(ctx *context.APIContext) {
|
||||||
// "$ref": "#/responses/notFound"
|
// "$ref": "#/responses/notFound"
|
||||||
|
|
||||||
if !ctx.Repo.Owner.IsOrganization() {
|
if !ctx.Repo.Owner.IsOrganization() {
|
||||||
ctx.Error(http.StatusMethodNotAllowed, "noOrg", "repo is not owned by an organization")
|
ctx.APIError(http.StatusMethodNotAllowed, "repo is not owned by an organization")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
teams, err := organization.GetRepoTeams(ctx, ctx.Repo.Repository.OwnerID, ctx.Repo.Repository.ID)
|
teams, err := organization.GetRepoTeams(ctx, ctx.Repo.Repository.OwnerID, ctx.Repo.Repository.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.InternalServerError(err)
|
ctx.APIErrorInternal(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
apiTeams, err := convert.ToTeams(ctx, teams, false)
|
apiTeams, err := convert.ToTeams(ctx, teams, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.InternalServerError(err)
|
ctx.APIErrorInternal(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -89,7 +89,7 @@ func IsTeam(ctx *context.APIContext) {
|
||||||
// "$ref": "#/responses/error"
|
// "$ref": "#/responses/error"
|
||||||
|
|
||||||
if !ctx.Repo.Owner.IsOrganization() {
|
if !ctx.Repo.Owner.IsOrganization() {
|
||||||
ctx.Error(http.StatusMethodNotAllowed, "noOrg", "repo is not owned by an organization")
|
ctx.APIError(http.StatusMethodNotAllowed, "repo is not owned by an organization")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -101,14 +101,14 @@ func IsTeam(ctx *context.APIContext) {
|
||||||
if repo_service.HasRepository(ctx, team, ctx.Repo.Repository.ID) {
|
if repo_service.HasRepository(ctx, team, ctx.Repo.Repository.ID) {
|
||||||
apiTeam, err := convert.ToTeam(ctx, team)
|
apiTeam, err := convert.ToTeam(ctx, team)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.InternalServerError(err)
|
ctx.APIErrorInternal(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.JSON(http.StatusOK, apiTeam)
|
ctx.JSON(http.StatusOK, apiTeam)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.NotFound()
|
ctx.APIErrorNotFound()
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddTeam add a team to a repository
|
// AddTeam add a team to a repository
|
||||||
|
@ -185,10 +185,10 @@ func DeleteTeam(ctx *context.APIContext) {
|
||||||
|
|
||||||
func changeRepoTeam(ctx *context.APIContext, add bool) {
|
func changeRepoTeam(ctx *context.APIContext, add bool) {
|
||||||
if !ctx.Repo.Owner.IsOrganization() {
|
if !ctx.Repo.Owner.IsOrganization() {
|
||||||
ctx.Error(http.StatusMethodNotAllowed, "noOrg", "repo is not owned by an organization")
|
ctx.APIError(http.StatusMethodNotAllowed, "repo is not owned by an organization")
|
||||||
}
|
}
|
||||||
if !ctx.Repo.Owner.RepoAdminChangeTeamAccess && !ctx.Repo.IsOwner() {
|
if !ctx.Repo.Owner.RepoAdminChangeTeamAccess && !ctx.Repo.IsOwner() {
|
||||||
ctx.Error(http.StatusForbidden, "noAdmin", "user is nor repo admin nor owner")
|
ctx.APIError(http.StatusForbidden, "user is nor repo admin nor owner")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -201,19 +201,19 @@ func changeRepoTeam(ctx *context.APIContext, add bool) {
|
||||||
var err error
|
var err error
|
||||||
if add {
|
if add {
|
||||||
if repoHasTeam {
|
if repoHasTeam {
|
||||||
ctx.Error(http.StatusUnprocessableEntity, "alreadyAdded", fmt.Errorf("team '%s' is already added to repo", team.Name))
|
ctx.APIError(http.StatusUnprocessableEntity, fmt.Errorf("team '%s' is already added to repo", team.Name))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
err = repo_service.TeamAddRepository(ctx, team, ctx.Repo.Repository)
|
err = repo_service.TeamAddRepository(ctx, team, ctx.Repo.Repository)
|
||||||
} else {
|
} else {
|
||||||
if !repoHasTeam {
|
if !repoHasTeam {
|
||||||
ctx.Error(http.StatusUnprocessableEntity, "notAdded", fmt.Errorf("team '%s' was not added to repo", team.Name))
|
ctx.APIError(http.StatusUnprocessableEntity, fmt.Errorf("team '%s' was not added to repo", team.Name))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
err = repo_service.RemoveRepositoryFromTeam(ctx, team, ctx.Repo.Repository.ID)
|
err = repo_service.RemoveRepositoryFromTeam(ctx, team, ctx.Repo.Repository.ID)
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.InternalServerError(err)
|
ctx.APIErrorInternal(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -224,10 +224,10 @@ func getTeamByParam(ctx *context.APIContext) *organization.Team {
|
||||||
team, err := organization.GetTeam(ctx, ctx.Repo.Owner.ID, ctx.PathParam("team"))
|
team, err := organization.GetTeam(ctx, ctx.Repo.Owner.ID, ctx.PathParam("team"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if organization.IsErrTeamNotExist(err) {
|
if organization.IsErrTeamNotExist(err) {
|
||||||
ctx.Error(http.StatusNotFound, "TeamNotExit", err)
|
ctx.APIError(http.StatusNotFound, err)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
ctx.InternalServerError(err)
|
ctx.APIErrorInternal(err)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return team
|
return team
|
||||||
|
|
|
@ -56,7 +56,7 @@ func ListTopics(ctx *context.APIContext) {
|
||||||
|
|
||||||
topics, total, err := db.FindAndCount[repo_model.Topic](ctx, opts)
|
topics, total, err := db.FindAndCount[repo_model.Topic](ctx, opts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.InternalServerError(err)
|
ctx.APIErrorInternal(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -124,7 +124,7 @@ func UpdateTopics(ctx *context.APIContext) {
|
||||||
err := repo_model.SaveTopics(ctx, ctx.Repo.Repository.ID, validTopics...)
|
err := repo_model.SaveTopics(ctx, ctx.Repo.Repository.ID, validTopics...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("SaveTopics failed: %v", err)
|
log.Error("SaveTopics failed: %v", err)
|
||||||
ctx.InternalServerError(err)
|
ctx.APIErrorInternal(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -178,7 +178,7 @@ func AddTopic(ctx *context.APIContext) {
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("CountTopics failed: %v", err)
|
log.Error("CountTopics failed: %v", err)
|
||||||
ctx.InternalServerError(err)
|
ctx.APIErrorInternal(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if count >= 25 {
|
if count >= 25 {
|
||||||
|
@ -191,7 +191,7 @@ func AddTopic(ctx *context.APIContext) {
|
||||||
_, err = repo_model.AddTopic(ctx, ctx.Repo.Repository.ID, topicName)
|
_, err = repo_model.AddTopic(ctx, ctx.Repo.Repository.ID, topicName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("AddTopic failed: %v", err)
|
log.Error("AddTopic failed: %v", err)
|
||||||
ctx.InternalServerError(err)
|
ctx.APIErrorInternal(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -242,12 +242,12 @@ func DeleteTopic(ctx *context.APIContext) {
|
||||||
topic, err := repo_model.DeleteTopic(ctx, ctx.Repo.Repository.ID, topicName)
|
topic, err := repo_model.DeleteTopic(ctx, ctx.Repo.Repository.ID, topicName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("DeleteTopic failed: %v", err)
|
log.Error("DeleteTopic failed: %v", err)
|
||||||
ctx.InternalServerError(err)
|
ctx.APIErrorInternal(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if topic == nil {
|
if topic == nil {
|
||||||
ctx.NotFound()
|
ctx.APIErrorNotFound()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -290,7 +290,7 @@ func TopicSearch(ctx *context.APIContext) {
|
||||||
|
|
||||||
topics, total, err := db.FindAndCount[repo_model.Topic](ctx, opts)
|
topics, total, err := db.FindAndCount[repo_model.Topic](ctx, opts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.InternalServerError(err)
|
ctx.APIErrorInternal(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -61,17 +61,17 @@ func Transfer(ctx *context.APIContext) {
|
||||||
newOwner, err := user_model.GetUserByName(ctx, opts.NewOwner)
|
newOwner, err := user_model.GetUserByName(ctx, opts.NewOwner)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if user_model.IsErrUserNotExist(err) {
|
if user_model.IsErrUserNotExist(err) {
|
||||||
ctx.Error(http.StatusNotFound, "", "The new owner does not exist or cannot be found")
|
ctx.APIError(http.StatusNotFound, "The new owner does not exist or cannot be found")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.InternalServerError(err)
|
ctx.APIErrorInternal(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if newOwner.Type == user_model.UserTypeOrganization {
|
if newOwner.Type == user_model.UserTypeOrganization {
|
||||||
if !ctx.Doer.IsAdmin && newOwner.Visibility == api.VisibleTypePrivate && !organization.OrgFromUser(newOwner).HasMemberWithUserID(ctx, ctx.Doer.ID) {
|
if !ctx.Doer.IsAdmin && newOwner.Visibility == api.VisibleTypePrivate && !organization.OrgFromUser(newOwner).HasMemberWithUserID(ctx, ctx.Doer.ID) {
|
||||||
// The user shouldn't know about this organization
|
// The user shouldn't know about this organization
|
||||||
ctx.Error(http.StatusNotFound, "", "The new owner does not exist or cannot be found")
|
ctx.APIError(http.StatusNotFound, "The new owner does not exist or cannot be found")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -79,7 +79,7 @@ func Transfer(ctx *context.APIContext) {
|
||||||
var teams []*organization.Team
|
var teams []*organization.Team
|
||||||
if opts.TeamIDs != nil {
|
if opts.TeamIDs != nil {
|
||||||
if !newOwner.IsOrganization() {
|
if !newOwner.IsOrganization() {
|
||||||
ctx.Error(http.StatusUnprocessableEntity, "repoTransfer", "Teams can only be added to organization-owned repositories")
|
ctx.APIError(http.StatusUnprocessableEntity, "Teams can only be added to organization-owned repositories")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -87,12 +87,12 @@ func Transfer(ctx *context.APIContext) {
|
||||||
for _, tID := range *opts.TeamIDs {
|
for _, tID := range *opts.TeamIDs {
|
||||||
team, err := organization.GetTeamByID(ctx, tID)
|
team, err := organization.GetTeamByID(ctx, tID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusUnprocessableEntity, "team", fmt.Errorf("team %d not found", tID))
|
ctx.APIError(http.StatusUnprocessableEntity, fmt.Errorf("team %d not found", tID))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if team.OrgID != org.ID {
|
if team.OrgID != org.ID {
|
||||||
ctx.Error(http.StatusForbidden, "team", fmt.Errorf("team %d belongs not to org %d", tID, org.ID))
|
ctx.APIError(http.StatusForbidden, fmt.Errorf("team %d belongs not to org %d", tID, org.ID))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -109,19 +109,19 @@ func Transfer(ctx *context.APIContext) {
|
||||||
|
|
||||||
if err := repo_service.StartRepositoryTransfer(ctx, ctx.Doer, newOwner, ctx.Repo.Repository, teams); err != nil {
|
if err := repo_service.StartRepositoryTransfer(ctx, ctx.Doer, newOwner, ctx.Repo.Repository, teams); err != nil {
|
||||||
if repo_model.IsErrRepoTransferInProgress(err) {
|
if repo_model.IsErrRepoTransferInProgress(err) {
|
||||||
ctx.Error(http.StatusConflict, "StartRepositoryTransfer", err)
|
ctx.APIError(http.StatusConflict, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if repo_model.IsErrRepoAlreadyExist(err) {
|
if repo_model.IsErrRepoAlreadyExist(err) {
|
||||||
ctx.Error(http.StatusUnprocessableEntity, "StartRepositoryTransfer", err)
|
ctx.APIError(http.StatusUnprocessableEntity, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if errors.Is(err, user_model.ErrBlockedUser) {
|
if errors.Is(err, user_model.ErrBlockedUser) {
|
||||||
ctx.Error(http.StatusForbidden, "BlockedUser", err)
|
ctx.APIError(http.StatusForbidden, err)
|
||||||
} else {
|
} else {
|
||||||
ctx.InternalServerError(err)
|
ctx.APIErrorInternal(err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -166,11 +166,11 @@ func AcceptTransfer(ctx *context.APIContext) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
switch {
|
switch {
|
||||||
case repo_model.IsErrNoPendingTransfer(err):
|
case repo_model.IsErrNoPendingTransfer(err):
|
||||||
ctx.Error(http.StatusNotFound, "AcceptTransferOwnership", err)
|
ctx.APIError(http.StatusNotFound, err)
|
||||||
case errors.Is(err, util.ErrPermissionDenied):
|
case errors.Is(err, util.ErrPermissionDenied):
|
||||||
ctx.Error(http.StatusForbidden, "AcceptTransferOwnership", err)
|
ctx.APIError(http.StatusForbidden, err)
|
||||||
default:
|
default:
|
||||||
ctx.Error(http.StatusInternalServerError, "AcceptTransferOwnership", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -208,11 +208,11 @@ func RejectTransfer(ctx *context.APIContext) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
switch {
|
switch {
|
||||||
case repo_model.IsErrNoPendingTransfer(err):
|
case repo_model.IsErrNoPendingTransfer(err):
|
||||||
ctx.Error(http.StatusNotFound, "RejectRepositoryTransfer", err)
|
ctx.APIError(http.StatusNotFound, err)
|
||||||
case errors.Is(err, util.ErrPermissionDenied):
|
case errors.Is(err, util.ErrPermissionDenied):
|
||||||
ctx.Error(http.StatusForbidden, "RejectRepositoryTransfer", err)
|
ctx.APIError(http.StatusForbidden, err)
|
||||||
default:
|
default:
|
||||||
ctx.Error(http.StatusInternalServerError, "RejectRepositoryTransfer", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,11 +58,11 @@ func GetTree(ctx *context.APIContext) {
|
||||||
|
|
||||||
sha := ctx.PathParam("sha")
|
sha := ctx.PathParam("sha")
|
||||||
if len(sha) == 0 {
|
if len(sha) == 0 {
|
||||||
ctx.Error(http.StatusBadRequest, "", "sha not provided")
|
ctx.APIError(http.StatusBadRequest, "sha not provided")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if tree, err := files_service.GetTreeBySHA(ctx, ctx.Repo.Repository, ctx.Repo.GitRepo, sha, ctx.FormInt("page"), ctx.FormInt("per_page"), ctx.FormBool("recursive")); err != nil {
|
if tree, err := files_service.GetTreeBySHA(ctx, ctx.Repo.Repository, ctx.Repo.GitRepo, sha, ctx.FormInt("page"), ctx.FormInt("per_page"), ctx.FormBool("recursive")); err != nil {
|
||||||
ctx.Error(http.StatusBadRequest, "", err.Error())
|
ctx.APIError(http.StatusBadRequest, err.Error())
|
||||||
} else {
|
} else {
|
||||||
ctx.SetTotalCountHeader(int64(tree.TotalCount))
|
ctx.SetTotalCountHeader(int64(tree.TotalCount))
|
||||||
ctx.JSON(http.StatusOK, tree)
|
ctx.JSON(http.StatusOK, tree)
|
||||||
|
|
|
@ -59,7 +59,7 @@ func NewWikiPage(ctx *context.APIContext) {
|
||||||
form := web.GetForm(ctx).(*api.CreateWikiPageOptions)
|
form := web.GetForm(ctx).(*api.CreateWikiPageOptions)
|
||||||
|
|
||||||
if util.IsEmptyString(form.Title) {
|
if util.IsEmptyString(form.Title) {
|
||||||
ctx.Error(http.StatusBadRequest, "emptyTitle", nil)
|
ctx.APIError(http.StatusBadRequest, nil)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -71,18 +71,18 @@ func NewWikiPage(ctx *context.APIContext) {
|
||||||
|
|
||||||
content, err := base64.StdEncoding.DecodeString(form.ContentBase64)
|
content, err := base64.StdEncoding.DecodeString(form.ContentBase64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusBadRequest, "invalid base64 encoding of content", err)
|
ctx.APIError(http.StatusBadRequest, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
form.ContentBase64 = string(content)
|
form.ContentBase64 = string(content)
|
||||||
|
|
||||||
if err := wiki_service.AddWikiPage(ctx, ctx.Doer, ctx.Repo.Repository, wikiName, form.ContentBase64, form.Message); err != nil {
|
if err := wiki_service.AddWikiPage(ctx, ctx.Doer, ctx.Repo.Repository, wikiName, form.ContentBase64, form.Message); err != nil {
|
||||||
if repo_model.IsErrWikiReservedName(err) {
|
if repo_model.IsErrWikiReservedName(err) {
|
||||||
ctx.Error(http.StatusBadRequest, "IsErrWikiReservedName", err)
|
ctx.APIError(http.StatusBadRequest, err)
|
||||||
} else if repo_model.IsErrWikiAlreadyExist(err) {
|
} else if repo_model.IsErrWikiAlreadyExist(err) {
|
||||||
ctx.Error(http.StatusBadRequest, "IsErrWikiAlreadyExists", err)
|
ctx.APIError(http.StatusBadRequest, err)
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "AddWikiPage", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -149,13 +149,13 @@ func EditWikiPage(ctx *context.APIContext) {
|
||||||
|
|
||||||
content, err := base64.StdEncoding.DecodeString(form.ContentBase64)
|
content, err := base64.StdEncoding.DecodeString(form.ContentBase64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusBadRequest, "invalid base64 encoding of content", err)
|
ctx.APIError(http.StatusBadRequest, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
form.ContentBase64 = string(content)
|
form.ContentBase64 = string(content)
|
||||||
|
|
||||||
if err := wiki_service.EditWikiPage(ctx, ctx.Doer, ctx.Repo.Repository, oldWikiName, newWikiName, form.ContentBase64, form.Message); err != nil {
|
if err := wiki_service.EditWikiPage(ctx, ctx.Doer, ctx.Repo.Repository, oldWikiName, newWikiName, form.ContentBase64, form.Message); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "EditWikiPage", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -198,7 +198,7 @@ func getWikiPage(ctx *context.APIContext, wikiName wiki_service.WebPath) *api.Wi
|
||||||
// Get last change information.
|
// Get last change information.
|
||||||
lastCommit, err := wikiRepo.GetCommitByPath(pageFilename)
|
lastCommit, err := wikiRepo.GetCommitByPath(pageFilename)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetCommitByPath", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -246,10 +246,10 @@ func DeleteWikiPage(ctx *context.APIContext) {
|
||||||
|
|
||||||
if err := wiki_service.DeleteWikiPage(ctx, ctx.Doer, ctx.Repo.Repository, wikiName); err != nil {
|
if err := wiki_service.DeleteWikiPage(ctx, ctx.Doer, ctx.Repo.Repository, wikiName); err != nil {
|
||||||
if err.Error() == "file does not exist" {
|
if err.Error() == "file does not exist" {
|
||||||
ctx.NotFound(err)
|
ctx.APIErrorNotFound(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.Error(http.StatusInternalServerError, "DeleteWikiPage", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -312,7 +312,7 @@ func ListWikiPages(ctx *context.APIContext) {
|
||||||
|
|
||||||
entries, err := commit.ListEntries()
|
entries, err := commit.ListEntries()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.ServerError("ListEntries", err)
|
ctx.APIErrorInternal(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
pages := make([]*api.WikiPageMetaData, 0, len(entries))
|
pages := make([]*api.WikiPageMetaData, 0, len(entries))
|
||||||
|
@ -322,7 +322,7 @@ func ListWikiPages(ctx *context.APIContext) {
|
||||||
}
|
}
|
||||||
c, err := wikiRepo.GetCommitByPath(entry.Name())
|
c, err := wikiRepo.GetCommitByPath(entry.Name())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetCommit", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
wikiName, err := wiki_service.GitPathToWebPath(entry.Name())
|
wikiName, err := wiki_service.GitPathToWebPath(entry.Name())
|
||||||
|
@ -330,7 +330,7 @@ func ListWikiPages(ctx *context.APIContext) {
|
||||||
if repo_model.IsErrWikiInvalidFileName(err) {
|
if repo_model.IsErrWikiInvalidFileName(err) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
ctx.Error(http.StatusInternalServerError, "WikiFilenameToName", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
pages = append(pages, wiki_service.ToWikiPageMetaData(wikiName, c, ctx.Repo.Repository))
|
pages = append(pages, wiki_service.ToWikiPageMetaData(wikiName, c, ctx.Repo.Repository))
|
||||||
|
@ -447,7 +447,7 @@ func ListPageRevisions(ctx *context.APIContext) {
|
||||||
Page: page,
|
Page: page,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "CommitsByFileAndRange", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -479,9 +479,9 @@ func findWikiRepoCommit(ctx *context.APIContext) (*git.Repository, *git.Commit)
|
||||||
wikiRepo, err := gitrepo.OpenWikiRepository(ctx, ctx.Repo.Repository)
|
wikiRepo, err := gitrepo.OpenWikiRepository(ctx, ctx.Repo.Repository)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if git.IsErrNotExist(err) || err.Error() == "no such file or directory" {
|
if git.IsErrNotExist(err) || err.Error() == "no such file or directory" {
|
||||||
ctx.NotFound(err)
|
ctx.APIErrorNotFound(err)
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "OpenRepository", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
@ -489,9 +489,9 @@ func findWikiRepoCommit(ctx *context.APIContext) (*git.Repository, *git.Commit)
|
||||||
commit, err := wikiRepo.GetBranchCommit("master")
|
commit, err := wikiRepo.GetBranchCommit("master")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if git.IsErrNotExist(err) {
|
if git.IsErrNotExist(err) {
|
||||||
ctx.NotFound(err)
|
ctx.APIErrorNotFound(err)
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetBranchCommit", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
return wikiRepo, nil
|
return wikiRepo, nil
|
||||||
}
|
}
|
||||||
|
@ -507,7 +507,7 @@ func wikiContentsByEntry(ctx *context.APIContext, entry *git.TreeEntry) string {
|
||||||
}
|
}
|
||||||
content, err := blob.GetBlobContentBase64()
|
content, err := blob.GetBlobContentBase64()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetBlobContentBase64", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
return content
|
return content
|
||||||
|
@ -521,10 +521,10 @@ func wikiContentsByName(ctx *context.APIContext, commit *git.Commit, wikiName wi
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if git.IsErrNotExist(err) {
|
if git.IsErrNotExist(err) {
|
||||||
if !isSidebarOrFooter {
|
if !isSidebarOrFooter {
|
||||||
ctx.NotFound()
|
ctx.APIErrorNotFound()
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
ctx.ServerError("findEntryForFile", err)
|
ctx.APIErrorInternal(err)
|
||||||
}
|
}
|
||||||
return "", ""
|
return "", ""
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,12 +21,12 @@ func ListBlocks(ctx *context.APIContext, blocker *user_model.User) {
|
||||||
BlockerID: blocker.ID,
|
BlockerID: blocker.ID,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "FindBlockings", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := user_model.BlockingList(blocks).LoadAttributes(ctx); err != nil {
|
if err := user_model.BlockingList(blocks).LoadAttributes(ctx); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "LoadAttributes", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,14 +42,14 @@ func ListBlocks(ctx *context.APIContext, blocker *user_model.User) {
|
||||||
func CheckUserBlock(ctx *context.APIContext, blocker *user_model.User) {
|
func CheckUserBlock(ctx *context.APIContext, blocker *user_model.User) {
|
||||||
blockee, err := user_model.GetUserByName(ctx, ctx.PathParam("username"))
|
blockee, err := user_model.GetUserByName(ctx, ctx.PathParam("username"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.NotFound("GetUserByName", err)
|
ctx.APIErrorNotFound("GetUserByName", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
status := http.StatusNotFound
|
status := http.StatusNotFound
|
||||||
blocking, err := user_model.GetBlocking(ctx, blocker.ID, blockee.ID)
|
blocking, err := user_model.GetBlocking(ctx, blocker.ID, blockee.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetBlocking", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if blocking != nil {
|
if blocking != nil {
|
||||||
|
@ -62,15 +62,15 @@ func CheckUserBlock(ctx *context.APIContext, blocker *user_model.User) {
|
||||||
func BlockUser(ctx *context.APIContext, blocker *user_model.User) {
|
func BlockUser(ctx *context.APIContext, blocker *user_model.User) {
|
||||||
blockee, err := user_model.GetUserByName(ctx, ctx.PathParam("username"))
|
blockee, err := user_model.GetUserByName(ctx, ctx.PathParam("username"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.NotFound("GetUserByName", err)
|
ctx.APIErrorNotFound("GetUserByName", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := user_service.BlockUser(ctx, ctx.Doer, blocker, blockee, ctx.FormString("note")); err != nil {
|
if err := user_service.BlockUser(ctx, ctx.Doer, blocker, blockee, ctx.FormString("note")); err != nil {
|
||||||
if errors.Is(err, user_model.ErrCanNotBlock) || errors.Is(err, user_model.ErrBlockOrganization) {
|
if errors.Is(err, user_model.ErrCanNotBlock) || errors.Is(err, user_model.ErrBlockOrganization) {
|
||||||
ctx.Error(http.StatusBadRequest, "BlockUser", err)
|
ctx.APIError(http.StatusBadRequest, err)
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "BlockUser", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -81,15 +81,15 @@ func BlockUser(ctx *context.APIContext, blocker *user_model.User) {
|
||||||
func UnblockUser(ctx *context.APIContext, doer, blocker *user_model.User) {
|
func UnblockUser(ctx *context.APIContext, doer, blocker *user_model.User) {
|
||||||
blockee, err := user_model.GetUserByName(ctx, ctx.PathParam("username"))
|
blockee, err := user_model.GetUserByName(ctx, ctx.PathParam("username"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.NotFound("GetUserByName", err)
|
ctx.APIErrorNotFound("GetUserByName", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := user_service.UnblockUser(ctx, doer, blocker, blockee); err != nil {
|
if err := user_service.UnblockUser(ctx, doer, blocker, blockee); err != nil {
|
||||||
if errors.Is(err, user_model.ErrCanNotUnblock) || errors.Is(err, user_model.ErrBlockOrganization) {
|
if errors.Is(err, user_model.ErrCanNotUnblock) || errors.Is(err, user_model.ErrBlockOrganization) {
|
||||||
ctx.Error(http.StatusBadRequest, "UnblockUser", err)
|
ctx.APIError(http.StatusBadRequest, err)
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "UnblockUser", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,7 +24,7 @@ func GetRegistrationToken(ctx *context.APIContext, ownerID, repoID int64) {
|
||||||
token, err = actions_model.NewRunnerToken(ctx, ownerID, repoID)
|
token, err = actions_model.NewRunnerToken(ctx, ownerID, repoID)
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.InternalServerError(err)
|
ctx.APIErrorInternal(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -52,11 +52,11 @@ func CreateOrUpdateSecret(ctx *context.APIContext) {
|
||||||
_, created, err := secret_service.CreateOrUpdateSecret(ctx, ctx.Doer.ID, 0, ctx.PathParam("secretname"), opt.Data)
|
_, created, err := secret_service.CreateOrUpdateSecret(ctx, ctx.Doer.ID, 0, ctx.PathParam("secretname"), opt.Data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if errors.Is(err, util.ErrInvalidArgument) {
|
if errors.Is(err, util.ErrInvalidArgument) {
|
||||||
ctx.Error(http.StatusBadRequest, "CreateOrUpdateSecret", err)
|
ctx.APIError(http.StatusBadRequest, err)
|
||||||
} else if errors.Is(err, util.ErrNotExist) {
|
} else if errors.Is(err, util.ErrNotExist) {
|
||||||
ctx.Error(http.StatusNotFound, "CreateOrUpdateSecret", err)
|
ctx.APIError(http.StatusNotFound, err)
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "CreateOrUpdateSecret", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -94,11 +94,11 @@ func DeleteSecret(ctx *context.APIContext) {
|
||||||
err := secret_service.DeleteSecretByName(ctx, ctx.Doer.ID, 0, ctx.PathParam("secretname"))
|
err := secret_service.DeleteSecretByName(ctx, ctx.Doer.ID, 0, ctx.PathParam("secretname"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if errors.Is(err, util.ErrInvalidArgument) {
|
if errors.Is(err, util.ErrInvalidArgument) {
|
||||||
ctx.Error(http.StatusBadRequest, "DeleteSecret", err)
|
ctx.APIError(http.StatusBadRequest, err)
|
||||||
} else if errors.Is(err, util.ErrNotExist) {
|
} else if errors.Is(err, util.ErrNotExist) {
|
||||||
ctx.Error(http.StatusNotFound, "DeleteSecret", err)
|
ctx.APIError(http.StatusNotFound, err)
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "DeleteSecret", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -145,19 +145,19 @@ func CreateVariable(ctx *context.APIContext) {
|
||||||
Name: variableName,
|
Name: variableName,
|
||||||
})
|
})
|
||||||
if err != nil && !errors.Is(err, util.ErrNotExist) {
|
if err != nil && !errors.Is(err, util.ErrNotExist) {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetVariable", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if v != nil && v.ID > 0 {
|
if v != nil && v.ID > 0 {
|
||||||
ctx.Error(http.StatusConflict, "VariableNameAlreadyExists", util.NewAlreadyExistErrorf("variable name %s already exists", variableName))
|
ctx.APIError(http.StatusConflict, util.NewAlreadyExistErrorf("variable name %s already exists", variableName))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := actions_service.CreateVariable(ctx, ownerID, 0, variableName, opt.Value); err != nil {
|
if _, err := actions_service.CreateVariable(ctx, ownerID, 0, variableName, opt.Value); err != nil {
|
||||||
if errors.Is(err, util.ErrInvalidArgument) {
|
if errors.Is(err, util.ErrInvalidArgument) {
|
||||||
ctx.Error(http.StatusBadRequest, "CreateVariable", err)
|
ctx.APIError(http.StatusBadRequest, err)
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "CreateVariable", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -202,9 +202,9 @@ func UpdateVariable(ctx *context.APIContext) {
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if errors.Is(err, util.ErrNotExist) {
|
if errors.Is(err, util.ErrNotExist) {
|
||||||
ctx.Error(http.StatusNotFound, "GetVariable", err)
|
ctx.APIError(http.StatusNotFound, err)
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetVariable", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -218,9 +218,9 @@ func UpdateVariable(ctx *context.APIContext) {
|
||||||
|
|
||||||
if _, err := actions_service.UpdateVariableNameData(ctx, v); err != nil {
|
if _, err := actions_service.UpdateVariableNameData(ctx, v); err != nil {
|
||||||
if errors.Is(err, util.ErrInvalidArgument) {
|
if errors.Is(err, util.ErrInvalidArgument) {
|
||||||
ctx.Error(http.StatusBadRequest, "UpdateVariable", err)
|
ctx.APIError(http.StatusBadRequest, err)
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "UpdateVariable", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -253,11 +253,11 @@ func DeleteVariable(ctx *context.APIContext) {
|
||||||
|
|
||||||
if err := actions_service.DeleteVariableByName(ctx, ctx.Doer.ID, 0, ctx.PathParam("variablename")); err != nil {
|
if err := actions_service.DeleteVariableByName(ctx, ctx.Doer.ID, 0, ctx.PathParam("variablename")); err != nil {
|
||||||
if errors.Is(err, util.ErrInvalidArgument) {
|
if errors.Is(err, util.ErrInvalidArgument) {
|
||||||
ctx.Error(http.StatusBadRequest, "DeleteVariableByName", err)
|
ctx.APIError(http.StatusBadRequest, err)
|
||||||
} else if errors.Is(err, util.ErrNotExist) {
|
} else if errors.Is(err, util.ErrNotExist) {
|
||||||
ctx.Error(http.StatusNotFound, "DeleteVariableByName", err)
|
ctx.APIError(http.StatusNotFound, err)
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "DeleteVariableByName", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -292,9 +292,9 @@ func GetVariable(ctx *context.APIContext) {
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if errors.Is(err, util.ErrNotExist) {
|
if errors.Is(err, util.ErrNotExist) {
|
||||||
ctx.Error(http.StatusNotFound, "GetVariable", err)
|
ctx.APIError(http.StatusNotFound, err)
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetVariable", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -338,7 +338,7 @@ func ListVariables(ctx *context.APIContext) {
|
||||||
ListOptions: utils.GetListOptions(ctx),
|
ListOptions: utils.GetListOptions(ctx),
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "FindVariables", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -51,7 +51,7 @@ func ListAccessTokens(ctx *context.APIContext) {
|
||||||
|
|
||||||
tokens, count, err := db.FindAndCount[auth_model.AccessToken](ctx, opts)
|
tokens, count, err := db.FindAndCount[auth_model.AccessToken](ctx, opts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.InternalServerError(err)
|
ctx.APIErrorInternal(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -105,27 +105,27 @@ func CreateAccessToken(ctx *context.APIContext) {
|
||||||
|
|
||||||
exist, err := auth_model.AccessTokenByNameExists(ctx, t)
|
exist, err := auth_model.AccessTokenByNameExists(ctx, t)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.InternalServerError(err)
|
ctx.APIErrorInternal(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if exist {
|
if exist {
|
||||||
ctx.Error(http.StatusBadRequest, "AccessTokenByNameExists", errors.New("access token name has been used already"))
|
ctx.APIError(http.StatusBadRequest, errors.New("access token name has been used already"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
scope, err := auth_model.AccessTokenScope(strings.Join(form.Scopes, ",")).Normalize()
|
scope, err := auth_model.AccessTokenScope(strings.Join(form.Scopes, ",")).Normalize()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusBadRequest, "AccessTokenScope.Normalize", fmt.Errorf("invalid access token scope provided: %w", err))
|
ctx.APIError(http.StatusBadRequest, fmt.Errorf("invalid access token scope provided: %w", err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if scope == "" {
|
if scope == "" {
|
||||||
ctx.Error(http.StatusBadRequest, "AccessTokenScope", "access token must have a scope")
|
ctx.APIError(http.StatusBadRequest, "access token must have a scope")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
t.Scope = scope
|
t.Scope = scope
|
||||||
|
|
||||||
if err := auth_model.NewAccessToken(ctx, t); err != nil {
|
if err := auth_model.NewAccessToken(ctx, t); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "NewAccessToken", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.JSON(http.StatusCreated, &api.AccessToken{
|
ctx.JSON(http.StatusCreated, &api.AccessToken{
|
||||||
|
@ -174,31 +174,31 @@ func DeleteAccessToken(ctx *context.APIContext) {
|
||||||
UserID: ctx.ContextUser.ID,
|
UserID: ctx.ContextUser.ID,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "ListAccessTokens", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
switch len(tokens) {
|
switch len(tokens) {
|
||||||
case 0:
|
case 0:
|
||||||
ctx.NotFound()
|
ctx.APIErrorNotFound()
|
||||||
return
|
return
|
||||||
case 1:
|
case 1:
|
||||||
tokenID = tokens[0].ID
|
tokenID = tokens[0].ID
|
||||||
default:
|
default:
|
||||||
ctx.Error(http.StatusUnprocessableEntity, "DeleteAccessTokenByID", fmt.Errorf("multiple matches for token name '%s'", token))
|
ctx.APIError(http.StatusUnprocessableEntity, fmt.Errorf("multiple matches for token name '%s'", token))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if tokenID == 0 {
|
if tokenID == 0 {
|
||||||
ctx.Error(http.StatusInternalServerError, "Invalid TokenID", nil)
|
ctx.APIError(http.StatusInternalServerError, nil)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := auth_model.DeleteAccessTokenByID(ctx, tokenID, ctx.ContextUser.ID); err != nil {
|
if err := auth_model.DeleteAccessTokenByID(ctx, tokenID, ctx.ContextUser.ID); err != nil {
|
||||||
if auth_model.IsErrAccessTokenNotExist(err) {
|
if auth_model.IsErrAccessTokenNotExist(err) {
|
||||||
ctx.NotFound()
|
ctx.APIErrorNotFound()
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "DeleteAccessTokenByID", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -235,12 +235,12 @@ func CreateOauth2Application(ctx *context.APIContext) {
|
||||||
SkipSecondaryAuthorization: data.SkipSecondaryAuthorization,
|
SkipSecondaryAuthorization: data.SkipSecondaryAuthorization,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusBadRequest, "", "error creating oauth2 application")
|
ctx.APIError(http.StatusBadRequest, "error creating oauth2 application")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
secret, err := app.GenerateClientSecret(ctx)
|
secret, err := app.GenerateClientSecret(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusBadRequest, "", "error creating application secret")
|
ctx.APIError(http.StatusBadRequest, "error creating application secret")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
app.ClientSecret = secret
|
app.ClientSecret = secret
|
||||||
|
@ -273,7 +273,7 @@ func ListOauth2Applications(ctx *context.APIContext) {
|
||||||
OwnerID: ctx.Doer.ID,
|
OwnerID: ctx.Doer.ID,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "ListOAuth2Applications", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -309,9 +309,9 @@ func DeleteOauth2Application(ctx *context.APIContext) {
|
||||||
appID := ctx.PathParamInt64("id")
|
appID := ctx.PathParamInt64("id")
|
||||||
if err := auth_model.DeleteOAuth2Application(ctx, appID, ctx.Doer.ID); err != nil {
|
if err := auth_model.DeleteOAuth2Application(ctx, appID, ctx.Doer.ID); err != nil {
|
||||||
if auth_model.IsErrOAuthApplicationNotFound(err) {
|
if auth_model.IsErrOAuthApplicationNotFound(err) {
|
||||||
ctx.NotFound()
|
ctx.APIErrorNotFound()
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "DeleteOauth2ApplicationByID", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -342,14 +342,14 @@ func GetOauth2Application(ctx *context.APIContext) {
|
||||||
app, err := auth_model.GetOAuth2ApplicationByID(ctx, appID)
|
app, err := auth_model.GetOAuth2ApplicationByID(ctx, appID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if auth_model.IsErrOauthClientIDInvalid(err) || auth_model.IsErrOAuthApplicationNotFound(err) {
|
if auth_model.IsErrOauthClientIDInvalid(err) || auth_model.IsErrOAuthApplicationNotFound(err) {
|
||||||
ctx.NotFound()
|
ctx.APIErrorNotFound()
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetOauth2ApplicationByID", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if app.UID != ctx.Doer.ID {
|
if app.UID != ctx.Doer.ID {
|
||||||
ctx.NotFound()
|
ctx.APIErrorNotFound()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -396,15 +396,15 @@ func UpdateOauth2Application(ctx *context.APIContext) {
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if auth_model.IsErrOauthClientIDInvalid(err) || auth_model.IsErrOAuthApplicationNotFound(err) {
|
if auth_model.IsErrOauthClientIDInvalid(err) || auth_model.IsErrOAuthApplicationNotFound(err) {
|
||||||
ctx.NotFound()
|
ctx.APIErrorNotFound()
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "UpdateOauth2ApplicationByID", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
app.ClientSecret, err = app.GenerateClientSecret(ctx)
|
app.ClientSecret, err = app.GenerateClientSecret(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusBadRequest, "", "error updating application secret")
|
ctx.APIError(http.StatusBadRequest, "error updating application secret")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -32,13 +32,13 @@ func UpdateAvatar(ctx *context.APIContext) {
|
||||||
|
|
||||||
content, err := base64.StdEncoding.DecodeString(form.Image)
|
content, err := base64.StdEncoding.DecodeString(form.Image)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusBadRequest, "DecodeImage", err)
|
ctx.APIError(http.StatusBadRequest, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
err = user_service.UploadAvatar(ctx, ctx.Doer, content)
|
err = user_service.UploadAvatar(ctx, ctx.Doer, content)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "UploadAvatar", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,7 +57,7 @@ func DeleteAvatar(ctx *context.APIContext) {
|
||||||
// "$ref": "#/responses/empty"
|
// "$ref": "#/responses/empty"
|
||||||
err := user_service.DeleteAvatar(ctx, ctx.Doer)
|
err := user_service.DeleteAvatar(ctx, ctx.Doer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "DeleteAvatar", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -29,7 +29,7 @@ func ListEmails(ctx *context.APIContext) {
|
||||||
|
|
||||||
emails, err := user_model.GetEmailAddresses(ctx, ctx.Doer.ID)
|
emails, err := user_model.GetEmailAddresses(ctx, ctx.Doer.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetEmailAddresses", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
apiEmails := make([]*api.Email, len(emails))
|
apiEmails := make([]*api.Email, len(emails))
|
||||||
|
@ -59,13 +59,13 @@ func AddEmail(ctx *context.APIContext) {
|
||||||
|
|
||||||
form := web.GetForm(ctx).(*api.CreateEmailOption)
|
form := web.GetForm(ctx).(*api.CreateEmailOption)
|
||||||
if len(form.Emails) == 0 {
|
if len(form.Emails) == 0 {
|
||||||
ctx.Error(http.StatusUnprocessableEntity, "", "Email list empty")
|
ctx.APIError(http.StatusUnprocessableEntity, "Email list empty")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := user_service.AddEmailAddresses(ctx, ctx.Doer, form.Emails); err != nil {
|
if err := user_service.AddEmailAddresses(ctx, ctx.Doer, form.Emails); err != nil {
|
||||||
if user_model.IsErrEmailAlreadyUsed(err) {
|
if user_model.IsErrEmailAlreadyUsed(err) {
|
||||||
ctx.Error(http.StatusUnprocessableEntity, "", "Email address has been used: "+err.(user_model.ErrEmailAlreadyUsed).Email)
|
ctx.APIError(http.StatusUnprocessableEntity, "Email address has been used: "+err.(user_model.ErrEmailAlreadyUsed).Email)
|
||||||
} else if user_model.IsErrEmailCharIsNotSupported(err) || user_model.IsErrEmailInvalid(err) {
|
} else if user_model.IsErrEmailCharIsNotSupported(err) || user_model.IsErrEmailInvalid(err) {
|
||||||
email := ""
|
email := ""
|
||||||
if typedError, ok := err.(user_model.ErrEmailInvalid); ok {
|
if typedError, ok := err.(user_model.ErrEmailInvalid); ok {
|
||||||
|
@ -76,16 +76,16 @@ func AddEmail(ctx *context.APIContext) {
|
||||||
}
|
}
|
||||||
|
|
||||||
errMsg := fmt.Sprintf("Email address %q invalid", email)
|
errMsg := fmt.Sprintf("Email address %q invalid", email)
|
||||||
ctx.Error(http.StatusUnprocessableEntity, "", errMsg)
|
ctx.APIError(http.StatusUnprocessableEntity, errMsg)
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "AddEmailAddresses", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
emails, err := user_model.GetEmailAddresses(ctx, ctx.Doer.ID)
|
emails, err := user_model.GetEmailAddresses(ctx, ctx.Doer.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetEmailAddresses", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -122,9 +122,9 @@ func DeleteEmail(ctx *context.APIContext) {
|
||||||
|
|
||||||
if err := user_service.DeleteEmailAddresses(ctx, ctx.Doer, form.Emails); err != nil {
|
if err := user_service.DeleteEmailAddresses(ctx, ctx.Doer, form.Emails); err != nil {
|
||||||
if user_model.IsErrEmailAddressNotExist(err) {
|
if user_model.IsErrEmailAddressNotExist(err) {
|
||||||
ctx.Error(http.StatusNotFound, "DeleteEmailAddresses", err)
|
ctx.APIError(http.StatusNotFound, err)
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "DeleteEmailAddresses", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,7 +26,7 @@ func responseAPIUsers(ctx *context.APIContext, users []*user_model.User) {
|
||||||
func listUserFollowers(ctx *context.APIContext, u *user_model.User) {
|
func listUserFollowers(ctx *context.APIContext, u *user_model.User) {
|
||||||
users, count, err := user_model.GetUserFollowers(ctx, u, ctx.Doer, utils.GetListOptions(ctx))
|
users, count, err := user_model.GetUserFollowers(ctx, u, ctx.Doer, utils.GetListOptions(ctx))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetUserFollowers", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -90,7 +90,7 @@ func ListFollowers(ctx *context.APIContext) {
|
||||||
func listUserFollowing(ctx *context.APIContext, u *user_model.User) {
|
func listUserFollowing(ctx *context.APIContext, u *user_model.User) {
|
||||||
users, count, err := user_model.GetUserFollowing(ctx, u, ctx.Doer, utils.GetListOptions(ctx))
|
users, count, err := user_model.GetUserFollowing(ctx, u, ctx.Doer, utils.GetListOptions(ctx))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetUserFollowing", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -155,7 +155,7 @@ func checkUserFollowing(ctx *context.APIContext, u *user_model.User, followID in
|
||||||
if user_model.IsFollowing(ctx, u.ID, followID) {
|
if user_model.IsFollowing(ctx, u.ID, followID) {
|
||||||
ctx.Status(http.StatusNoContent)
|
ctx.Status(http.StatusNoContent)
|
||||||
} else {
|
} else {
|
||||||
ctx.NotFound()
|
ctx.APIErrorNotFound()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -229,9 +229,9 @@ func Follow(ctx *context.APIContext) {
|
||||||
|
|
||||||
if err := user_model.FollowUser(ctx, ctx.Doer, ctx.ContextUser); err != nil {
|
if err := user_model.FollowUser(ctx, ctx.Doer, ctx.ContextUser); err != nil {
|
||||||
if errors.Is(err, user_model.ErrBlockedUser) {
|
if errors.Is(err, user_model.ErrBlockedUser) {
|
||||||
ctx.Error(http.StatusForbidden, "FollowUser", err)
|
ctx.APIError(http.StatusForbidden, err)
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "FollowUser", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -256,7 +256,7 @@ func Unfollow(ctx *context.APIContext) {
|
||||||
// "$ref": "#/responses/notFound"
|
// "$ref": "#/responses/notFound"
|
||||||
|
|
||||||
if err := user_model.UnfollowUser(ctx, ctx.Doer.ID, ctx.ContextUser.ID); err != nil {
|
if err := user_model.UnfollowUser(ctx, ctx.Doer.ID, ctx.ContextUser.ID); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "UnfollowUser", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.Status(http.StatusNoContent)
|
ctx.Status(http.StatusNoContent)
|
||||||
|
|
|
@ -25,12 +25,12 @@ func listGPGKeys(ctx *context.APIContext, uid int64, listOptions db.ListOptions)
|
||||||
OwnerID: uid,
|
OwnerID: uid,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "ListGPGKeys", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := asymkey_model.GPGKeyList(keys).LoadSubKeys(ctx); err != nil {
|
if err := asymkey_model.GPGKeyList(keys).LoadSubKeys(ctx); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "ListGPGKeys", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -119,14 +119,14 @@ func GetGPGKey(ctx *context.APIContext) {
|
||||||
key, err := asymkey_model.GetGPGKeyForUserByID(ctx, ctx.Doer.ID, ctx.PathParamInt64("id"))
|
key, err := asymkey_model.GetGPGKeyForUserByID(ctx, ctx.Doer.ID, ctx.PathParamInt64("id"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if asymkey_model.IsErrGPGKeyNotExist(err) {
|
if asymkey_model.IsErrGPGKeyNotExist(err) {
|
||||||
ctx.NotFound()
|
ctx.APIErrorNotFound()
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetGPGKeyByID", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if err := key.LoadSubKeys(ctx); err != nil {
|
if err := key.LoadSubKeys(ctx); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "LoadSubKeys", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.JSON(http.StatusOK, convert.ToGPGKey(key))
|
ctx.JSON(http.StatusOK, convert.ToGPGKey(key))
|
||||||
|
@ -135,7 +135,7 @@ func GetGPGKey(ctx *context.APIContext) {
|
||||||
// CreateUserGPGKey creates new GPG key to given user by ID.
|
// CreateUserGPGKey creates new GPG key to given user by ID.
|
||||||
func CreateUserGPGKey(ctx *context.APIContext, form api.CreateGPGKeyOption, uid int64) {
|
func CreateUserGPGKey(ctx *context.APIContext, form api.CreateGPGKeyOption, uid int64) {
|
||||||
if user_model.IsFeatureDisabledWithLoginType(ctx.Doer, setting.UserFeatureManageGPGKeys) {
|
if user_model.IsFeatureDisabledWithLoginType(ctx.Doer, setting.UserFeatureManageGPGKeys) {
|
||||||
ctx.NotFound("Not Found", fmt.Errorf("gpg keys setting is not allowed to be visited"))
|
ctx.APIErrorNotFound("Not Found", fmt.Errorf("gpg keys setting is not allowed to be visited"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -194,7 +194,7 @@ func VerifyUserGPGKey(ctx *context.APIContext) {
|
||||||
|
|
||||||
form.KeyID = strings.TrimLeft(form.KeyID, "0")
|
form.KeyID = strings.TrimLeft(form.KeyID, "0")
|
||||||
if form.KeyID == "" {
|
if form.KeyID == "" {
|
||||||
ctx.NotFound()
|
ctx.APIErrorNotFound()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -205,10 +205,10 @@ func VerifyUserGPGKey(ctx *context.APIContext) {
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if asymkey_model.IsErrGPGInvalidTokenSignature(err) {
|
if asymkey_model.IsErrGPGInvalidTokenSignature(err) {
|
||||||
ctx.Error(http.StatusUnprocessableEntity, "GPGInvalidSignature", fmt.Sprintf("The provided GPG key, signature and token do not match or token is out of date. Provide a valid signature for the token: %s", token))
|
ctx.APIError(http.StatusUnprocessableEntity, fmt.Sprintf("The provided GPG key, signature and token do not match or token is out of date. Provide a valid signature for the token: %s", token))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.Error(http.StatusInternalServerError, "VerifyUserGPGKey", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
keys, err := db.Find[asymkey_model.GPGKey](ctx, asymkey_model.FindGPGKeyOptions{
|
keys, err := db.Find[asymkey_model.GPGKey](ctx, asymkey_model.FindGPGKeyOptions{
|
||||||
|
@ -217,9 +217,9 @@ func VerifyUserGPGKey(ctx *context.APIContext) {
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if asymkey_model.IsErrGPGKeyNotExist(err) {
|
if asymkey_model.IsErrGPGKeyNotExist(err) {
|
||||||
ctx.NotFound()
|
ctx.APIErrorNotFound()
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetGPGKeysByKeyID", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -276,15 +276,15 @@ func DeleteGPGKey(ctx *context.APIContext) {
|
||||||
// "$ref": "#/responses/notFound"
|
// "$ref": "#/responses/notFound"
|
||||||
|
|
||||||
if user_model.IsFeatureDisabledWithLoginType(ctx.Doer, setting.UserFeatureManageGPGKeys) {
|
if user_model.IsFeatureDisabledWithLoginType(ctx.Doer, setting.UserFeatureManageGPGKeys) {
|
||||||
ctx.NotFound("Not Found", fmt.Errorf("gpg keys setting is not allowed to be visited"))
|
ctx.APIErrorNotFound("Not Found", fmt.Errorf("gpg keys setting is not allowed to be visited"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := asymkey_model.DeleteGPGKey(ctx, ctx.Doer, ctx.PathParamInt64("id")); err != nil {
|
if err := asymkey_model.DeleteGPGKey(ctx, ctx.Doer, ctx.PathParamInt64("id")); err != nil {
|
||||||
if asymkey_model.IsErrGPGKeyAccessDenied(err) {
|
if asymkey_model.IsErrGPGKeyAccessDenied(err) {
|
||||||
ctx.Error(http.StatusForbidden, "", "You do not have access to this key")
|
ctx.APIError(http.StatusForbidden, "You do not have access to this key")
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "DeleteGPGKey", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -296,16 +296,16 @@ func DeleteGPGKey(ctx *context.APIContext) {
|
||||||
func HandleAddGPGKeyError(ctx *context.APIContext, err error, token string) {
|
func HandleAddGPGKeyError(ctx *context.APIContext, err error, token string) {
|
||||||
switch {
|
switch {
|
||||||
case asymkey_model.IsErrGPGKeyAccessDenied(err):
|
case asymkey_model.IsErrGPGKeyAccessDenied(err):
|
||||||
ctx.Error(http.StatusUnprocessableEntity, "GPGKeyAccessDenied", "You do not have access to this GPG key")
|
ctx.APIError(http.StatusUnprocessableEntity, "You do not have access to this GPG key")
|
||||||
case asymkey_model.IsErrGPGKeyIDAlreadyUsed(err):
|
case asymkey_model.IsErrGPGKeyIDAlreadyUsed(err):
|
||||||
ctx.Error(http.StatusUnprocessableEntity, "GPGKeyIDAlreadyUsed", "A key with the same id already exists")
|
ctx.APIError(http.StatusUnprocessableEntity, "A key with the same id already exists")
|
||||||
case asymkey_model.IsErrGPGKeyParsing(err):
|
case asymkey_model.IsErrGPGKeyParsing(err):
|
||||||
ctx.Error(http.StatusUnprocessableEntity, "GPGKeyParsing", err)
|
ctx.APIError(http.StatusUnprocessableEntity, err)
|
||||||
case asymkey_model.IsErrGPGNoEmailFound(err):
|
case asymkey_model.IsErrGPGNoEmailFound(err):
|
||||||
ctx.Error(http.StatusNotFound, "GPGNoEmailFound", fmt.Sprintf("None of the emails attached to the GPG key could be found. It may still be added if you provide a valid signature for the token: %s", token))
|
ctx.APIError(http.StatusNotFound, fmt.Sprintf("None of the emails attached to the GPG key could be found. It may still be added if you provide a valid signature for the token: %s", token))
|
||||||
case asymkey_model.IsErrGPGInvalidTokenSignature(err):
|
case asymkey_model.IsErrGPGInvalidTokenSignature(err):
|
||||||
ctx.Error(http.StatusUnprocessableEntity, "GPGInvalidSignature", fmt.Sprintf("The provided GPG key, signature and token do not match or token is out of date. Provide a valid signature for the token: %s", token))
|
ctx.APIError(http.StatusUnprocessableEntity, fmt.Sprintf("The provided GPG key, signature and token do not match or token is out of date. Provide a valid signature for the token: %s", token))
|
||||||
default:
|
default:
|
||||||
ctx.Error(http.StatusInternalServerError, "AddGPGKey", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,10 +20,10 @@ func GetUserByPathParam(ctx *context.APIContext, name string) *user_model.User {
|
||||||
if redirectUserID, err2 := user_model.LookupUserRedirect(ctx, username); err2 == nil {
|
if redirectUserID, err2 := user_model.LookupUserRedirect(ctx, username); err2 == nil {
|
||||||
context.RedirectToUser(ctx.Base, username, redirectUserID)
|
context.RedirectToUser(ctx.Base, username, redirectUserID)
|
||||||
} else {
|
} else {
|
||||||
ctx.NotFound("GetUserByName", err)
|
ctx.APIErrorNotFound("GetUserByName", err)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetUserByName", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -63,13 +63,13 @@ func GetHook(ctx *context.APIContext) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if !ctx.Doer.IsAdmin && hook.OwnerID != ctx.Doer.ID {
|
if !ctx.Doer.IsAdmin && hook.OwnerID != ctx.Doer.ID {
|
||||||
ctx.NotFound()
|
ctx.APIErrorNotFound()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
apiHook, err := webhook_service.ToHook(ctx.Doer.HomeLink(), hook)
|
apiHook, err := webhook_service.ToHook(ctx.Doer.HomeLink(), hook)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.InternalServerError(err)
|
ctx.APIErrorInternal(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.JSON(http.StatusOK, apiHook)
|
ctx.JSON(http.StatusOK, apiHook)
|
||||||
|
|
|
@ -81,7 +81,7 @@ func listPublicKeys(ctx *context.APIContext, user *user_model.User) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "ListPublicKeys", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -182,9 +182,9 @@ func GetPublicKey(ctx *context.APIContext) {
|
||||||
key, err := asymkey_model.GetPublicKeyByID(ctx, ctx.PathParamInt64("id"))
|
key, err := asymkey_model.GetPublicKeyByID(ctx, ctx.PathParamInt64("id"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if asymkey_model.IsErrKeyNotExist(err) {
|
if asymkey_model.IsErrKeyNotExist(err) {
|
||||||
ctx.NotFound()
|
ctx.APIErrorNotFound()
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetPublicKeyByID", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -200,7 +200,7 @@ func GetPublicKey(ctx *context.APIContext) {
|
||||||
// CreateUserPublicKey creates new public key to given user by ID.
|
// CreateUserPublicKey creates new public key to given user by ID.
|
||||||
func CreateUserPublicKey(ctx *context.APIContext, form api.CreateKeyOption, uid int64) {
|
func CreateUserPublicKey(ctx *context.APIContext, form api.CreateKeyOption, uid int64) {
|
||||||
if user_model.IsFeatureDisabledWithLoginType(ctx.Doer, setting.UserFeatureManageSSHKeys) {
|
if user_model.IsFeatureDisabledWithLoginType(ctx.Doer, setting.UserFeatureManageSSHKeys) {
|
||||||
ctx.NotFound("Not Found", fmt.Errorf("ssh keys setting is not allowed to be visited"))
|
ctx.APIErrorNotFound("Not Found", fmt.Errorf("ssh keys setting is not allowed to be visited"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -270,7 +270,7 @@ func DeletePublicKey(ctx *context.APIContext) {
|
||||||
// "$ref": "#/responses/notFound"
|
// "$ref": "#/responses/notFound"
|
||||||
|
|
||||||
if user_model.IsFeatureDisabledWithLoginType(ctx.Doer, setting.UserFeatureManageSSHKeys) {
|
if user_model.IsFeatureDisabledWithLoginType(ctx.Doer, setting.UserFeatureManageSSHKeys) {
|
||||||
ctx.NotFound("Not Found", fmt.Errorf("ssh keys setting is not allowed to be visited"))
|
ctx.APIErrorNotFound("Not Found", fmt.Errorf("ssh keys setting is not allowed to be visited"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -278,23 +278,23 @@ func DeletePublicKey(ctx *context.APIContext) {
|
||||||
externallyManaged, err := asymkey_model.PublicKeyIsExternallyManaged(ctx, id)
|
externallyManaged, err := asymkey_model.PublicKeyIsExternallyManaged(ctx, id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if asymkey_model.IsErrKeyNotExist(err) {
|
if asymkey_model.IsErrKeyNotExist(err) {
|
||||||
ctx.NotFound()
|
ctx.APIErrorNotFound()
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "PublicKeyIsExternallyManaged", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if externallyManaged {
|
if externallyManaged {
|
||||||
ctx.Error(http.StatusForbidden, "", "SSH Key is externally managed for this user")
|
ctx.APIError(http.StatusForbidden, "SSH Key is externally managed for this user")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := asymkey_service.DeletePublicKey(ctx, ctx.Doer, id); err != nil {
|
if err := asymkey_service.DeletePublicKey(ctx, ctx.Doer, id); err != nil {
|
||||||
if asymkey_model.IsErrKeyAccessDenied(err) {
|
if asymkey_model.IsErrKeyAccessDenied(err) {
|
||||||
ctx.Error(http.StatusForbidden, "", "You do not have access to this key")
|
ctx.APIError(http.StatusForbidden, "You do not have access to this key")
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "DeletePublicKey", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,12 +26,12 @@ func listUserRepos(ctx *context.APIContext, u *user_model.User, private bool) {
|
||||||
OrderBy: "id ASC",
|
OrderBy: "id ASC",
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetUserRepositories", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := repos.LoadAttributes(ctx); err != nil {
|
if err := repos.LoadAttributes(ctx); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "RepositoryList.LoadAttributes", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,7 +39,7 @@ func listUserRepos(ctx *context.APIContext, u *user_model.User, private bool) {
|
||||||
for i := range repos {
|
for i := range repos {
|
||||||
permission, err := access_model.GetUserRepoPermission(ctx, repos[i], ctx.Doer)
|
permission, err := access_model.GetUserRepoPermission(ctx, repos[i], ctx.Doer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetUserRepoPermission", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if ctx.IsSigned && ctx.Doer.IsAdmin || permission.HasAnyUnitAccess() {
|
if ctx.IsSigned && ctx.Doer.IsAdmin || permission.HasAnyUnitAccess() {
|
||||||
|
@ -113,19 +113,19 @@ func ListMyRepos(ctx *context.APIContext) {
|
||||||
|
|
||||||
repos, count, err := repo_model.SearchRepository(ctx, opts)
|
repos, count, err := repo_model.SearchRepository(ctx, opts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "SearchRepository", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
results := make([]*api.Repository, len(repos))
|
results := make([]*api.Repository, len(repos))
|
||||||
for i, repo := range repos {
|
for i, repo := range repos {
|
||||||
if err = repo.LoadOwner(ctx); err != nil {
|
if err = repo.LoadOwner(ctx); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "LoadOwner", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
permission, err := access_model.GetUserRepoPermission(ctx, repo, ctx.Doer)
|
permission, err := access_model.GetUserRepoPermission(ctx, repo, ctx.Doer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetUserRepoPermission", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
results[i] = convert.ToRepo(ctx, repo, permission)
|
results[i] = convert.ToRepo(ctx, repo, permission)
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,7 +57,7 @@ func UpdateUserSettings(ctx *context.APIContext) {
|
||||||
KeepActivityPrivate: optional.FromPtr(form.HideActivity),
|
KeepActivityPrivate: optional.FromPtr(form.HideActivity),
|
||||||
}
|
}
|
||||||
if err := user_service.UpdateUser(ctx, ctx.Doer, opts); err != nil {
|
if err := user_service.UpdateUser(ctx, ctx.Doer, opts); err != nil {
|
||||||
ctx.InternalServerError(err)
|
ctx.APIErrorInternal(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -72,7 +72,7 @@ func GetStarredRepos(ctx *context.APIContext) {
|
||||||
private := ctx.ContextUser.ID == ctx.Doer.ID
|
private := ctx.ContextUser.ID == ctx.Doer.ID
|
||||||
repos, err := getStarredRepos(ctx, ctx.ContextUser, private)
|
repos, err := getStarredRepos(ctx, ctx.ContextUser, private)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "getStarredRepos", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -104,7 +104,7 @@ func GetMyStarredRepos(ctx *context.APIContext) {
|
||||||
|
|
||||||
repos, err := getStarredRepos(ctx, ctx.Doer, true)
|
repos, err := getStarredRepos(ctx, ctx.Doer, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "getStarredRepos", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.SetTotalCountHeader(int64(ctx.Doer.NumStars))
|
ctx.SetTotalCountHeader(int64(ctx.Doer.NumStars))
|
||||||
|
@ -138,7 +138,7 @@ func IsStarring(ctx *context.APIContext) {
|
||||||
if repo_model.IsStaring(ctx, ctx.Doer.ID, ctx.Repo.Repository.ID) {
|
if repo_model.IsStaring(ctx, ctx.Doer.ID, ctx.Repo.Repository.ID) {
|
||||||
ctx.Status(http.StatusNoContent)
|
ctx.Status(http.StatusNoContent)
|
||||||
} else {
|
} else {
|
||||||
ctx.NotFound()
|
ctx.APIErrorNotFound()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -169,9 +169,9 @@ func Star(ctx *context.APIContext) {
|
||||||
err := repo_model.StarRepo(ctx, ctx.Doer, ctx.Repo.Repository, true)
|
err := repo_model.StarRepo(ctx, ctx.Doer, ctx.Repo.Repository, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if errors.Is(err, user_model.ErrBlockedUser) {
|
if errors.Is(err, user_model.ErrBlockedUser) {
|
||||||
ctx.Error(http.StatusForbidden, "BlockedUser", err)
|
ctx.APIError(http.StatusForbidden, err)
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "StarRepo", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -204,7 +204,7 @@ func Unstar(ctx *context.APIContext) {
|
||||||
|
|
||||||
err := repo_model.StarRepo(ctx, ctx.Doer, ctx.Repo.Repository, false)
|
err := repo_model.StarRepo(ctx, ctx.Doer, ctx.Repo.Repository, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "StarRepo", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.Status(http.StatusNoContent)
|
ctx.Status(http.StatusNoContent)
|
||||||
|
|
|
@ -121,7 +121,7 @@ func GetInfo(ctx *context.APIContext) {
|
||||||
|
|
||||||
if !user_model.IsUserVisibleToViewer(ctx, ctx.ContextUser, ctx.Doer) {
|
if !user_model.IsUserVisibleToViewer(ctx, ctx.ContextUser, ctx.Doer) {
|
||||||
// fake ErrUserNotExist error message to not leak information about existence
|
// fake ErrUserNotExist error message to not leak information about existence
|
||||||
ctx.NotFound("GetUserByName", user_model.ErrUserNotExist{Name: ctx.PathParam("username")})
|
ctx.APIErrorNotFound("GetUserByName", user_model.ErrUserNotExist{Name: ctx.PathParam("username")})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.JSON(http.StatusOK, convert.ToUser(ctx, ctx.ContextUser, ctx.Doer))
|
ctx.JSON(http.StatusOK, convert.ToUser(ctx, ctx.ContextUser, ctx.Doer))
|
||||||
|
@ -162,7 +162,7 @@ func GetUserHeatmapData(ctx *context.APIContext) {
|
||||||
|
|
||||||
heatmap, err := activities_model.GetUserHeatmapDataByUser(ctx, ctx.ContextUser, ctx.Doer)
|
heatmap, err := activities_model.GetUserHeatmapDataByUser(ctx, ctx.ContextUser, ctx.Doer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetUserHeatmapDataByUser", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.JSON(http.StatusOK, heatmap)
|
ctx.JSON(http.StatusOK, heatmap)
|
||||||
|
@ -217,7 +217,7 @@ func ListUserActivityFeeds(ctx *context.APIContext) {
|
||||||
|
|
||||||
feeds, count, err := feed_service.GetFeeds(ctx, opts)
|
feeds, count, err := feed_service.GetFeeds(ctx, opts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetFeeds", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.SetTotalCountHeader(count)
|
ctx.SetTotalCountHeader(count)
|
||||||
|
|
|
@ -68,7 +68,7 @@ func GetWatchedRepos(ctx *context.APIContext) {
|
||||||
private := ctx.ContextUser.ID == ctx.Doer.ID
|
private := ctx.ContextUser.ID == ctx.Doer.ID
|
||||||
repos, total, err := getWatchedRepos(ctx, ctx.ContextUser, private)
|
repos, total, err := getWatchedRepos(ctx, ctx.ContextUser, private)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "getWatchedRepos", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.SetTotalCountHeader(total)
|
ctx.SetTotalCountHeader(total)
|
||||||
|
@ -97,7 +97,7 @@ func GetMyWatchedRepos(ctx *context.APIContext) {
|
||||||
|
|
||||||
repos, total, err := getWatchedRepos(ctx, ctx.Doer, true)
|
repos, total, err := getWatchedRepos(ctx, ctx.Doer, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "getWatchedRepos", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.SetTotalCountHeader(total)
|
ctx.SetTotalCountHeader(total)
|
||||||
|
@ -137,7 +137,7 @@ func IsWatching(ctx *context.APIContext) {
|
||||||
RepositoryURL: ctx.Repo.Repository.APIURL(),
|
RepositoryURL: ctx.Repo.Repository.APIURL(),
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
ctx.NotFound()
|
ctx.APIErrorNotFound()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -168,9 +168,9 @@ func Watch(ctx *context.APIContext) {
|
||||||
err := repo_model.WatchRepo(ctx, ctx.Doer, ctx.Repo.Repository, true)
|
err := repo_model.WatchRepo(ctx, ctx.Doer, ctx.Repo.Repository, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if errors.Is(err, user_model.ErrBlockedUser) {
|
if errors.Is(err, user_model.ErrBlockedUser) {
|
||||||
ctx.Error(http.StatusForbidden, "BlockedUser", err)
|
ctx.APIError(http.StatusForbidden, err)
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "WatchRepo", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -208,7 +208,7 @@ func Unwatch(ctx *context.APIContext) {
|
||||||
|
|
||||||
err := repo_model.WatchRepo(ctx, ctx.Doer, ctx.Repo.Repository, false)
|
err := repo_model.WatchRepo(ctx, ctx.Doer, ctx.Repo.Repository, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "UnwatchRepo", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.Status(http.StatusNoContent)
|
ctx.Status(http.StatusNoContent)
|
||||||
|
|
|
@ -17,7 +17,7 @@ import (
|
||||||
// ResolveRefOrSha resolve ref to sha if exist
|
// ResolveRefOrSha resolve ref to sha if exist
|
||||||
func ResolveRefOrSha(ctx *context.APIContext, ref string) string {
|
func ResolveRefOrSha(ctx *context.APIContext, ref string) string {
|
||||||
if len(ref) == 0 {
|
if len(ref) == 0 {
|
||||||
ctx.Error(http.StatusBadRequest, "ref not given", nil)
|
ctx.APIError(http.StatusBadRequest, nil)
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,7 +26,7 @@ func ResolveRefOrSha(ctx *context.APIContext, ref string) string {
|
||||||
for _, refType := range []string{"heads", "tags"} {
|
for _, refType := range []string{"heads", "tags"} {
|
||||||
refSHA, lastMethodName, err := searchRefCommitByType(ctx, refType, ref)
|
refSHA, lastMethodName, err := searchRefCommitByType(ctx, refType, ref)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, lastMethodName, err)
|
ctx.APIError(http.StatusInternalServerError, fmt.Errorf("%s: %w", lastMethodName, err))
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
if refSHA != "" {
|
if refSHA != "" {
|
||||||
|
|
|
@ -30,7 +30,7 @@ func ListOwnerHooks(ctx *context.APIContext, owner *user_model.User) {
|
||||||
|
|
||||||
hooks, count, err := db.FindAndCount[webhook.Webhook](ctx, opts)
|
hooks, count, err := db.FindAndCount[webhook.Webhook](ctx, opts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.InternalServerError(err)
|
ctx.APIErrorInternal(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,7 +38,7 @@ func ListOwnerHooks(ctx *context.APIContext, owner *user_model.User) {
|
||||||
for i, hook := range hooks {
|
for i, hook := range hooks {
|
||||||
apiHooks[i], err = webhook_service.ToHook(owner.HomeLink(), hook)
|
apiHooks[i], err = webhook_service.ToHook(owner.HomeLink(), hook)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.InternalServerError(err)
|
ctx.APIErrorInternal(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -52,9 +52,9 @@ func GetOwnerHook(ctx *context.APIContext, ownerID, hookID int64) (*webhook.Webh
|
||||||
w, err := webhook.GetWebhookByOwnerID(ctx, ownerID, hookID)
|
w, err := webhook.GetWebhookByOwnerID(ctx, ownerID, hookID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if webhook.IsErrWebhookNotExist(err) {
|
if webhook.IsErrWebhookNotExist(err) {
|
||||||
ctx.NotFound()
|
ctx.APIErrorNotFound()
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetWebhookByOwnerID", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -67,9 +67,9 @@ func GetRepoHook(ctx *context.APIContext, repoID, hookID int64) (*webhook.Webhoo
|
||||||
w, err := webhook.GetWebhookByRepoID(ctx, repoID, hookID)
|
w, err := webhook.GetWebhookByRepoID(ctx, repoID, hookID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if webhook.IsErrWebhookNotExist(err) {
|
if webhook.IsErrWebhookNotExist(err) {
|
||||||
ctx.NotFound()
|
ctx.APIErrorNotFound()
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetWebhookByID", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -80,17 +80,17 @@ func GetRepoHook(ctx *context.APIContext, repoID, hookID int64) (*webhook.Webhoo
|
||||||
// write the appropriate error to `ctx`. Return whether the form is valid
|
// write the appropriate error to `ctx`. Return whether the form is valid
|
||||||
func checkCreateHookOption(ctx *context.APIContext, form *api.CreateHookOption) bool {
|
func checkCreateHookOption(ctx *context.APIContext, form *api.CreateHookOption) bool {
|
||||||
if !webhook_service.IsValidHookTaskType(form.Type) {
|
if !webhook_service.IsValidHookTaskType(form.Type) {
|
||||||
ctx.Error(http.StatusUnprocessableEntity, "", fmt.Sprintf("Invalid hook type: %s", form.Type))
|
ctx.APIError(http.StatusUnprocessableEntity, fmt.Sprintf("Invalid hook type: %s", form.Type))
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
for _, name := range []string{"url", "content_type"} {
|
for _, name := range []string{"url", "content_type"} {
|
||||||
if _, ok := form.Config[name]; !ok {
|
if _, ok := form.Config[name]; !ok {
|
||||||
ctx.Error(http.StatusUnprocessableEntity, "", "Missing config option: "+name)
|
ctx.APIError(http.StatusUnprocessableEntity, "Missing config option: "+name)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if !webhook.IsValidHookContentType(form.Config["content_type"]) {
|
if !webhook.IsValidHookContentType(form.Config["content_type"]) {
|
||||||
ctx.Error(http.StatusUnprocessableEntity, "", "Invalid content type")
|
ctx.APIError(http.StatusUnprocessableEntity, "Invalid content type")
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
|
@ -102,7 +102,7 @@ func AddSystemHook(ctx *context.APIContext, form *api.CreateHookOption) {
|
||||||
if ok {
|
if ok {
|
||||||
h, err := webhook_service.ToHook(setting.AppSubURL+"/-/admin", hook)
|
h, err := webhook_service.ToHook(setting.AppSubURL+"/-/admin", hook)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "convert.ToHook", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.JSON(http.StatusCreated, h)
|
ctx.JSON(http.StatusCreated, h)
|
||||||
|
@ -141,7 +141,7 @@ func AddRepoHook(ctx *context.APIContext, form *api.CreateHookOption) {
|
||||||
func toAPIHook(ctx *context.APIContext, repoLink string, hook *webhook.Webhook) (*api.Hook, bool) {
|
func toAPIHook(ctx *context.APIContext, repoLink string, hook *webhook.Webhook) (*api.Hook, bool) {
|
||||||
apiHook, err := webhook_service.ToHook(repoLink, hook)
|
apiHook, err := webhook_service.ToHook(repoLink, hook)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "ToHook", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return nil, false
|
return nil, false
|
||||||
}
|
}
|
||||||
return apiHook, true
|
return apiHook, true
|
||||||
|
@ -169,7 +169,7 @@ func addHook(ctx *context.APIContext, form *api.CreateHookOption, ownerID, repoI
|
||||||
if form.Config["is_system_webhook"] != "" {
|
if form.Config["is_system_webhook"] != "" {
|
||||||
sw, err := strconv.ParseBool(form.Config["is_system_webhook"])
|
sw, err := strconv.ParseBool(form.Config["is_system_webhook"])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusUnprocessableEntity, "", "Invalid is_system_webhook value")
|
ctx.APIError(http.StatusUnprocessableEntity, "Invalid is_system_webhook value")
|
||||||
return nil, false
|
return nil, false
|
||||||
}
|
}
|
||||||
isSystemWebhook = sw
|
isSystemWebhook = sw
|
||||||
|
@ -215,19 +215,19 @@ func addHook(ctx *context.APIContext, form *api.CreateHookOption, ownerID, repoI
|
||||||
}
|
}
|
||||||
err := w.SetHeaderAuthorization(form.AuthorizationHeader)
|
err := w.SetHeaderAuthorization(form.AuthorizationHeader)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "SetHeaderAuthorization", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return nil, false
|
return nil, false
|
||||||
}
|
}
|
||||||
if w.Type == webhook_module.SLACK {
|
if w.Type == webhook_module.SLACK {
|
||||||
channel, ok := form.Config["channel"]
|
channel, ok := form.Config["channel"]
|
||||||
if !ok {
|
if !ok {
|
||||||
ctx.Error(http.StatusUnprocessableEntity, "", "Missing config option: channel")
|
ctx.APIError(http.StatusUnprocessableEntity, "Missing config option: channel")
|
||||||
return nil, false
|
return nil, false
|
||||||
}
|
}
|
||||||
channel = strings.TrimSpace(channel)
|
channel = strings.TrimSpace(channel)
|
||||||
|
|
||||||
if !webhook_service.IsValidSlackChannel(channel) {
|
if !webhook_service.IsValidSlackChannel(channel) {
|
||||||
ctx.Error(http.StatusBadRequest, "", "Invalid slack channel name")
|
ctx.APIError(http.StatusBadRequest, "Invalid slack channel name")
|
||||||
return nil, false
|
return nil, false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -238,17 +238,17 @@ func addHook(ctx *context.APIContext, form *api.CreateHookOption, ownerID, repoI
|
||||||
Color: form.Config["color"],
|
Color: form.Config["color"],
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "slack: JSON marshal failed", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return nil, false
|
return nil, false
|
||||||
}
|
}
|
||||||
w.Meta = string(meta)
|
w.Meta = string(meta)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := w.UpdateEvent(); err != nil {
|
if err := w.UpdateEvent(); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "UpdateEvent", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return nil, false
|
return nil, false
|
||||||
} else if err := webhook.CreateWebhook(ctx, w); err != nil {
|
} else if err := webhook.CreateWebhook(ctx, w); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "CreateWebhook", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return nil, false
|
return nil, false
|
||||||
}
|
}
|
||||||
return w, true
|
return w, true
|
||||||
|
@ -258,21 +258,21 @@ func addHook(ctx *context.APIContext, form *api.CreateHookOption, ownerID, repoI
|
||||||
func EditSystemHook(ctx *context.APIContext, form *api.EditHookOption, hookID int64) {
|
func EditSystemHook(ctx *context.APIContext, form *api.EditHookOption, hookID int64) {
|
||||||
hook, err := webhook.GetSystemOrDefaultWebhook(ctx, hookID)
|
hook, err := webhook.GetSystemOrDefaultWebhook(ctx, hookID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetSystemOrDefaultWebhook", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if !editHook(ctx, form, hook) {
|
if !editHook(ctx, form, hook) {
|
||||||
ctx.Error(http.StatusInternalServerError, "editHook", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
updated, err := webhook.GetSystemOrDefaultWebhook(ctx, hookID)
|
updated, err := webhook.GetSystemOrDefaultWebhook(ctx, hookID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetSystemOrDefaultWebhook", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
h, err := webhook_service.ToHook(setting.AppURL+"/-/admin", updated)
|
h, err := webhook_service.ToHook(setting.AppURL+"/-/admin", updated)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "convert.ToHook", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.JSON(http.StatusOK, h)
|
ctx.JSON(http.StatusOK, h)
|
||||||
|
@ -328,7 +328,7 @@ func editHook(ctx *context.APIContext, form *api.EditHookOption, w *webhook.Webh
|
||||||
}
|
}
|
||||||
if ct, ok := form.Config["content_type"]; ok {
|
if ct, ok := form.Config["content_type"]; ok {
|
||||||
if !webhook.IsValidHookContentType(ct) {
|
if !webhook.IsValidHookContentType(ct) {
|
||||||
ctx.Error(http.StatusUnprocessableEntity, "", "Invalid content type")
|
ctx.APIError(http.StatusUnprocessableEntity, "Invalid content type")
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
w.ContentType = webhook.ToHookContentType(ct)
|
w.ContentType = webhook.ToHookContentType(ct)
|
||||||
|
@ -343,7 +343,7 @@ func editHook(ctx *context.APIContext, form *api.EditHookOption, w *webhook.Webh
|
||||||
Color: form.Config["color"],
|
Color: form.Config["color"],
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "slack: JSON marshal failed", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
w.Meta = string(meta)
|
w.Meta = string(meta)
|
||||||
|
@ -369,7 +369,7 @@ func editHook(ctx *context.APIContext, form *api.EditHookOption, w *webhook.Webh
|
||||||
|
|
||||||
err := w.SetHeaderAuthorization(form.AuthorizationHeader)
|
err := w.SetHeaderAuthorization(form.AuthorizationHeader)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "SetHeaderAuthorization", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -391,7 +391,7 @@ func editHook(ctx *context.APIContext, form *api.EditHookOption, w *webhook.Webh
|
||||||
w.HookEvents[webhook_module.HookEventPullRequestSync] = pullHook(form.Events, string(webhook_module.HookEventPullRequestSync))
|
w.HookEvents[webhook_module.HookEventPullRequestSync] = pullHook(form.Events, string(webhook_module.HookEventPullRequestSync))
|
||||||
|
|
||||||
if err := w.UpdateEvent(); err != nil {
|
if err := w.UpdateEvent(); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "UpdateEvent", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -400,7 +400,7 @@ func editHook(ctx *context.APIContext, form *api.EditHookOption, w *webhook.Webh
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := webhook.UpdateWebhook(ctx, w); err != nil {
|
if err := webhook.UpdateWebhook(ctx, w); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "UpdateWebhook", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
|
@ -410,9 +410,9 @@ func editHook(ctx *context.APIContext, form *api.EditHookOption, w *webhook.Webh
|
||||||
func DeleteOwnerHook(ctx *context.APIContext, owner *user_model.User, hookID int64) {
|
func DeleteOwnerHook(ctx *context.APIContext, owner *user_model.User, hookID int64) {
|
||||||
if err := webhook.DeleteWebhookByOwnerID(ctx, owner.ID, hookID); err != nil {
|
if err := webhook.DeleteWebhookByOwnerID(ctx, owner.ID, hookID); err != nil {
|
||||||
if webhook.IsErrWebhookNotExist(err) {
|
if webhook.IsErrWebhookNotExist(err) {
|
||||||
ctx.NotFound()
|
ctx.APIErrorNotFound()
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "DeleteWebhookByOwnerID", err)
|
ctx.APIError(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,7 +39,7 @@ func RenderMarkup(ctx *context.Base, ctxRepo *context.Repository, mode, text, ur
|
||||||
rctx := renderhelper.NewRenderContextSimpleDocument(ctx, baseLink).WithUseAbsoluteLink(true).
|
rctx := renderhelper.NewRenderContextSimpleDocument(ctx, baseLink).WithUseAbsoluteLink(true).
|
||||||
WithMarkupType(markdown.MarkupName)
|
WithMarkupType(markdown.MarkupName)
|
||||||
if err := markdown.RenderRaw(rctx, strings.NewReader(text), ctx.Resp); err != nil {
|
if err := markdown.RenderRaw(rctx, strings.NewReader(text), ctx.Resp); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, err.Error())
|
ctx.HTTPError(http.StatusInternalServerError, err.Error())
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -88,15 +88,15 @@ func RenderMarkup(ctx *context.Base, ctxRepo *context.Repository, mode, text, ur
|
||||||
})
|
})
|
||||||
rctx = rctx.WithMarkupType("").WithRelativePath(filePath) // render the repo file content by its extension
|
rctx = rctx.WithMarkupType("").WithRelativePath(filePath) // render the repo file content by its extension
|
||||||
default:
|
default:
|
||||||
ctx.Error(http.StatusUnprocessableEntity, fmt.Sprintf("Unknown mode: %s", mode))
|
ctx.HTTPError(http.StatusUnprocessableEntity, fmt.Sprintf("Unknown mode: %s", mode))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
rctx = rctx.WithUseAbsoluteLink(true)
|
rctx = rctx.WithUseAbsoluteLink(true)
|
||||||
if err := markup.Render(rctx, strings.NewReader(text), ctx.Resp); err != nil {
|
if err := markup.Render(rctx, strings.NewReader(text), ctx.Resp); err != nil {
|
||||||
if errors.Is(err, util.ErrInvalidArgument) {
|
if errors.Is(err, util.ErrInvalidArgument) {
|
||||||
ctx.Error(http.StatusUnprocessableEntity, err.Error())
|
ctx.HTTPError(http.StatusUnprocessableEntity, err.Error())
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, err.Error())
|
ctx.HTTPError(http.StatusInternalServerError, err.Error())
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -291,7 +291,7 @@ func NewAuthSourcePost(ctx *context.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
ctx.Error(http.StatusBadRequest)
|
ctx.HTTPError(http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.Data["HasTLS"] = hasTLS
|
ctx.Data["HasTLS"] = hasTLS
|
||||||
|
@ -413,7 +413,7 @@ func EditAuthSourcePost(ctx *context.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
ctx.Error(http.StatusBadRequest)
|
ctx.HTTPError(http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue