Skip to content

Commit

Permalink
Merge branch 'main' into fix-doc
Browse files Browse the repository at this point in the history
  • Loading branch information
KN4CK3R authored May 19, 2024
2 parents 537f90e + 58a03e9 commit 8313cd0
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 26 deletions.
8 changes: 3 additions & 5 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ run:

output:
sort-results: true
sort-order: [file]
show-stats: true

linters-settings:
stylecheck:
Expand All @@ -40,11 +42,7 @@ linters-settings:
- ifElseChain
- singleCaseSwitch # Every time this occurred in the code, there was no other way.
revive:
ignore-generated-header: false
severity: warning
confidence: 0.8
errorCode: 1
warningCode: 1
severity: error
rules:
- name: atomic
- name: bare-return
Expand Down
2 changes: 1 addition & 1 deletion modules/structs/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ type EditRepoOption struct {
Archived *bool `json:"archived,omitempty"`
// set to a string like `8h30m0s` to set the mirror interval time
MirrorInterval *string `json:"mirror_interval,omitempty"`
// enable prune - remove obsolete remote-tracking references
// enable prune - remove obsolete remote-tracking references when mirroring
EnablePrune *bool `json:"enable_prune,omitempty"`
}

Expand Down
2 changes: 2 additions & 0 deletions routers/api/v1/org/avatar.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ func UpdateAvatar(ctx *context.APIContext) {
err = user_service.UploadAvatar(ctx, ctx.Org.Organization.AsUser(), content)
if err != nil {
ctx.Error(http.StatusInternalServerError, "UploadAvatar", err)
return
}

ctx.Status(http.StatusNoContent)
Expand All @@ -72,6 +73,7 @@ func DeleteAvatar(ctx *context.APIContext) {
err := user_service.DeleteAvatar(ctx, ctx.Org.Organization.AsUser())
if err != nil {
ctx.Error(http.StatusInternalServerError, "DeleteAvatar", err)
return
}

ctx.Status(http.StatusNoContent)
Expand Down
12 changes: 3 additions & 9 deletions routers/api/v1/repo/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -1062,16 +1062,10 @@ func updateRepoArchivedState(ctx *context.APIContext, opts api.EditRepoOption) e
func updateMirror(ctx *context.APIContext, opts api.EditRepoOption) error {
repo := ctx.Repo.Repository

// only update mirror if interval or enable prune are provided
if opts.MirrorInterval == nil && opts.EnablePrune == nil {
return nil
}

// these values only make sense if the repo is a mirror
// Skip this update if the repo is not a mirror, do not return error.
// Because reporting errors only makes the logic more complex&fragile, it doesn't really help end users.
if !repo.IsMirror {
err := fmt.Errorf("repo is not a mirror, can not change mirror interval")
ctx.Error(http.StatusUnprocessableEntity, err.Error(), err)
return err
return nil
}

// get the mirror from the repo
Expand Down
2 changes: 2 additions & 0 deletions routers/api/v1/user/avatar.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ func UpdateAvatar(ctx *context.APIContext) {
err = user_service.UploadAvatar(ctx, ctx.Doer, content)
if err != nil {
ctx.Error(http.StatusInternalServerError, "UploadAvatar", err)
return
}

ctx.Status(http.StatusNoContent)
Expand All @@ -57,6 +58,7 @@ func DeleteAvatar(ctx *context.APIContext) {
err := user_service.DeleteAvatar(ctx, ctx.Doer)
if err != nil {
ctx.Error(http.StatusInternalServerError, "DeleteAvatar", err)
return
}

ctx.Status(http.StatusNoContent)
Expand Down
30 changes: 20 additions & 10 deletions services/user/avatar.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ package user

import (
"context"
"errors"
"fmt"
"io"
"os"

"code.gitea.io/gitea/models/db"
user_model "code.gitea.io/gitea/models/user"
Expand Down Expand Up @@ -48,16 +50,24 @@ func UploadAvatar(ctx context.Context, u *user_model.User, data []byte) error {
func DeleteAvatar(ctx context.Context, u *user_model.User) error {
aPath := u.CustomAvatarRelativePath()
log.Trace("DeleteAvatar[%d]: %s", u.ID, aPath)
if len(u.Avatar) > 0 {
if err := storage.Avatars.Delete(aPath); err != nil {
return fmt.Errorf("Failed to remove %s: %w", aPath, err)

return db.WithTx(ctx, func(ctx context.Context) error {
hasAvatar := len(u.Avatar) > 0
u.UseCustomAvatar = false
u.Avatar = ""
if _, err := db.GetEngine(ctx).ID(u.ID).Cols("avatar, use_custom_avatar").Update(u); err != nil {
return fmt.Errorf("DeleteAvatar: %w", err)
}
}

u.UseCustomAvatar = false
u.Avatar = ""
if _, err := db.GetEngine(ctx).ID(u.ID).Cols("avatar, use_custom_avatar").Update(u); err != nil {
return fmt.Errorf("DeleteAvatar: %w", err)
}
return nil
if hasAvatar {
if err := storage.Avatars.Delete(aPath); err != nil {
if !errors.Is(err, os.ErrNotExist) {
return fmt.Errorf("failed to remove %s: %w", aPath, err)
}
log.Warn("Deleting avatar %s but it doesn't exist", aPath)
}
}

return nil
})
}
2 changes: 1 addition & 1 deletion templates/swagger/v1_json.tmpl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 8313cd0

Please sign in to comment.