Skip to content

Commit 7712d78

Browse files
committed
Add error prefix in git remote
Return user facing errors in agit for block and collaborator
1 parent e94f37f commit 7712d78

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

cmd/serv.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,9 @@ func fail(ctx context.Context, userMessage, logMsgFmt string, args ...any) error
104104
// There appears to be a chance to cause a zombie process and failure to read the Exit status
105105
// if nothing is outputted on stdout.
106106
_, _ = fmt.Fprintln(os.Stdout, "")
107-
_, _ = fmt.Fprintln(os.Stderr, "Gitea:", userMessage)
107+
_, _ = fmt.Fprintln(os.Stderr, "error:")
108+
_, _ = fmt.Fprintln(os.Stderr, "error:", userMessage)
109+
_, _ = fmt.Fprintln(os.Stderr, "error:")
108110

109111
if logMsgFmt != "" {
110112
logMsg := fmt.Sprintf(logMsgFmt, args...)

routers/private/hook_proc_receive.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,12 @@
44
package private
55

66
import (
7+
"errors"
78
"net/http"
89

10+
issues_model "code.gitea.io/gitea/models/issues"
911
repo_model "code.gitea.io/gitea/models/repo"
12+
user_model "code.gitea.io/gitea/models/user"
1013
"code.gitea.io/gitea/modules/git"
1114
"code.gitea.io/gitea/modules/log"
1215
"code.gitea.io/gitea/modules/private"
@@ -27,6 +30,14 @@ func HookProcReceive(ctx *gitea_context.PrivateContext) {
2730
if err != nil {
2831
if repo_model.IsErrUserDoesNotHaveAccessToRepo(err) {
2932
ctx.Error(http.StatusBadRequest, "UserDoesNotHaveAccessToRepo", err.Error())
33+
} else if errors.Is(err, issues_model.ErrMustCollaborator) {
34+
ctx.JSON(http.StatusUnauthorized, private.Response{
35+
Err: err.Error(), UserMsg: string(ctx.Tr("repo.pulls.new.must_collaborator")),
36+
})
37+
} else if errors.Is(err, user_model.ErrBlockedUser) {
38+
ctx.JSON(http.StatusUnauthorized, private.Response{
39+
Err: err.Error(), UserMsg: string(ctx.Tr("repo.pulls.new.blocked_user")),
40+
})
3041
} else {
3142
log.Error(err.Error())
3243
ctx.JSON(http.StatusInternalServerError, private.Response{

0 commit comments

Comments
 (0)