diff options
author | oliverpool <3864879+oliverpool@users.noreply.github.com> | 2022-08-11 17:48:23 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-08-11 17:48:23 +0200 |
commit | c81b26b0e52f55fcdf94b50a14bca3dfc375e2a9 (patch) | |
tree | acccd4400733b5505a86ca668ceb4167119789fe /routers/api | |
parent | 2b4d43dd4d7388ff73e99c143008ad4663142e61 (diff) | |
download | gitea-c81b26b0e52f55fcdf94b50a14bca3dfc375e2a9.tar.gz gitea-c81b26b0e52f55fcdf94b50a14bca3dfc375e2a9.zip |
refactor webhook *NewPost (#20729)
* refactor webhook *NewPost
* remove empty values
* always show errs.Message
* remove utils.IsValidSlackChannel
* move IsValidSlackChannel to services/webhook package
* binding: handle empty Message case
* make IsValidSlackChannel more strict
Diffstat (limited to 'routers/api')
-rw-r--r-- | routers/api/v1/utils/hook.go | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/routers/api/v1/utils/hook.go b/routers/api/v1/utils/hook.go index f0dc595ad5..ba008f587c 100644 --- a/routers/api/v1/utils/hook.go +++ b/routers/api/v1/utils/hook.go @@ -15,7 +15,6 @@ import ( "code.gitea.io/gitea/modules/json" api "code.gitea.io/gitea/modules/structs" "code.gitea.io/gitea/modules/util" - "code.gitea.io/gitea/routers/utils" webhook_service "code.gitea.io/gitea/services/webhook" ) @@ -141,14 +140,15 @@ func addHook(ctx *context.APIContext, form *api.CreateHookOption, orgID, repoID ctx.Error(http.StatusUnprocessableEntity, "", "Missing config option: channel") return nil, false } + channel = strings.TrimSpace(channel) - if !utils.IsValidSlackChannel(channel) { + if !webhook_service.IsValidSlackChannel(channel) { ctx.Error(http.StatusBadRequest, "", "Invalid slack channel name") return nil, false } meta, err := json.Marshal(&webhook_service.SlackMeta{ - Channel: strings.TrimSpace(channel), + Channel: channel, Username: form.Config["username"], IconURL: form.Config["icon_url"], Color: form.Config["color"], |