Skip to content
This repository was archived by the owner on Sep 18, 2024. It is now read-only.

Commit 1183f3c

Browse files
committed
Fix: system hooks bug
1 parent 4eb2a29 commit 1183f3c

File tree

2 files changed

+18
-10
lines changed

2 files changed

+18
-10
lines changed

cmd/serv.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,12 @@ func fail(ctx context.Context, userMessage, logMsgFmt string, args ...any) error
103103
// There appears to be a chance to cause a zombie process and failure to read the Exit status
104104
// if nothing is outputted on stdout.
105105
_, _ = fmt.Fprintln(os.Stdout, "")
106-
_, _ = fmt.Fprintln(os.Stderr, "Gitea:", userMessage)
106+
_, _ = fmt.Fprintln(os.Stderr, userMessage)
107107

108108
if logMsgFmt != "" {
109109
logMsg := fmt.Sprintf(logMsgFmt, args...)
110110
if !setting.IsProd {
111-
_, _ = fmt.Fprintln(os.Stderr, "Gitea:", logMsg)
111+
_, _ = fmt.Fprintln(os.Stderr, logMsg)
112112
}
113113
if userMessage != "" {
114114
if unicode.IsPunct(rune(userMessage[len(userMessage)-1])) {
@@ -143,7 +143,7 @@ func runServ(c *cli.Context) error {
143143
setup(ctx, c.Bool("debug"))
144144

145145
if setting.SSH.Disabled {
146-
println("Gitea: SSH has been disabled")
146+
println("SSH has been disabled")
147147
return nil
148148
}
149149

routers/api/v1/utils/hook.go

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package utils
66
import (
77
"fmt"
88
"net/http"
9+
"strconv"
910
"strings"
1011

1112
"code.gitea.io/gitea/models/db"
@@ -164,13 +165,20 @@ func addHook(ctx *context.APIContext, form *api.CreateHookOption, ownerID, repoI
164165
if len(form.Events) == 0 {
165166
form.Events = []string{"push"}
166167
}
168+
169+
isSystemWebhook, err := strconv.ParseBool(form.Config["is_system_webhook"])
170+
if err != nil {
171+
ctx.Error(http.StatusUnprocessableEntity, "", "Invalid is_system_webhook value")
172+
return nil, false
173+
}
167174
w := &webhook.Webhook{
168-
OwnerID: ownerID,
169-
RepoID: repoID,
170-
URL: form.Config["url"],
171-
ContentType: webhook.ToHookContentType(form.Config["content_type"]),
172-
Secret: form.Config["secret"],
173-
HTTPMethod: "POST",
175+
OwnerID: ownerID,
176+
RepoID: repoID,
177+
URL: form.Config["url"],
178+
ContentType: webhook.ToHookContentType(form.Config["content_type"]),
179+
Secret: form.Config["secret"],
180+
HTTPMethod: "POST",
181+
IsSystemWebhook: isSystemWebhook,
174182
HookEvent: &webhook_module.HookEvent{
175183
ChooseEvents: true,
176184
HookEvents: webhook_module.HookEvents{
@@ -200,7 +208,7 @@ func addHook(ctx *context.APIContext, form *api.CreateHookOption, ownerID, repoI
200208
IsActive: form.Active,
201209
Type: form.Type,
202210
}
203-
err := w.SetHeaderAuthorization(form.AuthorizationHeader)
211+
err = w.SetHeaderAuthorization(form.AuthorizationHeader)
204212
if err != nil {
205213
ctx.Error(http.StatusInternalServerError, "SetHeaderAuthorization", err)
206214
return nil, false

0 commit comments

Comments
 (0)