Backport https://github.com/go-gitea/gitea/pull/29740 (based on #29671 ...) (cherry picked from commit 0cbbcf20e3f83413a88fe3d436451d707639fe55)