diff --git a/models/migrations/migrations.go b/models/migrations/migrations.go index bb8dad5ec6..cad4156dee 100644 --- a/models/migrations/migrations.go +++ b/models/migrations/migrations.go @@ -404,6 +404,7 @@ func prepareMigrationTasks() []*migration { newMigration(327, "Add disabled state to action runners", v1_26.AddDisabledToActionRunner), newMigration(328, "Add TokenPermissions column to ActionRunJob", v1_26.AddTokenPermissionsToActionRunJob), newMigration(329, "Add unique constraint for user badge", v1_26.AddUniqueIndexForUserBadge), + newMigration(330, "Add name column to webhook", v1_26.AddNameToWebhook), } return preparedMigrations } diff --git a/models/migrations/v1_26/v330.go b/models/migrations/v1_26/v330.go new file mode 100644 index 0000000000..9f77331090 --- /dev/null +++ b/models/migrations/v1_26/v330.go @@ -0,0 +1,16 @@ +// Copyright 2026 The Gitea Authors. All rights reserved. +// SPDX-License-Identifier: MIT + +package v1_26 + +import ( + "xorm.io/xorm" +) + +func AddNameToWebhook(x *xorm.Engine) error { + type Webhook struct { + Name string `xorm:"VARCHAR(255) NOT NULL DEFAULT ''"` + } + _, err := x.SyncWithOptions(xorm.SyncOptions{IgnoreDropIndices: true}, new(Webhook)) + return err +} diff --git a/models/webhook/webhook.go b/models/webhook/webhook.go index 7d4b2e2237..5144c0eca6 100644 --- a/models/webhook/webhook.go +++ b/models/webhook/webhook.go @@ -126,6 +126,7 @@ type Webhook struct { OwnerID int64 `xorm:"INDEX"` IsSystemWebhook bool URL string `xorm:"url TEXT"` + Name string `xorm:"VARCHAR(255) NOT NULL DEFAULT ''"` HTTPMethod string `xorm:"http_method"` ContentType HookContentType Secret string `xorm:"TEXT"` diff --git a/modules/structs/hook.go b/modules/structs/hook.go index 931589696a..99c1535155 100644 --- a/modules/structs/hook.go +++ b/modules/structs/hook.go @@ -19,6 +19,8 @@ var ErrInvalidReceiveHook = errors.New("Invalid JSON payload received over webho type Hook struct { // The unique identifier of the webhook ID int64 `json:"id"` + // Optional human-readable name for the webhook + Name string `json:"name"` // The type of the webhook (e.g., gitea, slack, discord) Type string `json:"type"` // Branch filter pattern to determine which branches trigger the webhook @@ -66,6 +68,8 @@ type CreateHookOption struct { // default: false // Whether the webhook should be active upon creation Active bool `json:"active"` + // Optional human-readable name for the webhook + Name string `json:"name" binding:"MaxSize(255)"` } // EditHookOption options when modify one hook @@ -80,6 +84,8 @@ type EditHookOption struct { AuthorizationHeader string `json:"authorization_header"` // Whether the webhook is active and will be triggered Active *bool `json:"active"` + // Optional human-readable name + Name *string `json:"name,omitzero" binding:"MaxSize(255)"` } // Payloader payload is some part of one hook diff --git a/options/locale/locale_en-US.json b/options/locale/locale_en-US.json index ce9f1027aa..acf45d989a 100644 --- a/options/locale/locale_en-US.json +++ b/options/locale/locale_en-US.json @@ -2258,6 +2258,9 @@ "repo.settings.payload_url": "Target URL", "repo.settings.http_method": "HTTP Method", "repo.settings.content_type": "POST Content Type", + "repo.settings.webhook.name": "Webhook name", + "repo.settings.webhook.name_helper": "Optionally give this webhook a friendly name", + "repo.settings.webhook.name_empty": "Unnamed Webhook", "repo.settings.secret": "Secret", "repo.settings.webhook_secret_desc": "If the webhook server supports using secret, you can follow the webhook's manual and fill in a secret here.", "repo.settings.slack_username": "Username", diff --git a/routers/api/v1/utils/hook.go b/routers/api/v1/utils/hook.go index c4f21eac8b..bbada746b7 100644 --- a/routers/api/v1/utils/hook.go +++ b/routers/api/v1/utils/hook.go @@ -215,6 +215,7 @@ func addHook(ctx *context.APIContext, form *api.CreateHookOption, ownerID, repoI w := &webhook.Webhook{ OwnerID: ownerID, RepoID: repoID, + Name: strings.TrimSpace(form.Name), URL: form.Config["url"], ContentType: webhook.ToHookContentType(form.Config["content_type"]), Secret: form.Config["secret"], @@ -392,6 +393,10 @@ func editHook(ctx *context.APIContext, form *api.EditHookOption, w *webhook.Webh w.IsActive = *form.Active } + if form.Name != nil { + w.Name = strings.TrimSpace(*form.Name) + } + if err := webhook.UpdateWebhook(ctx, w); err != nil { ctx.APIErrorInternal(err) return false diff --git a/routers/web/repo/setting/webhook.go b/routers/web/repo/setting/webhook.go index f107449749..b0f3a5cfee 100644 --- a/routers/web/repo/setting/webhook.go +++ b/routers/web/repo/setting/webhook.go @@ -234,6 +234,7 @@ func createWebhook(ctx *context.Context, params webhookParams) { w := &webhook.Webhook{ RepoID: orCtx.RepoID, URL: params.URL, + Name: strings.TrimSpace(params.WebhookForm.Name), HTTPMethod: params.HTTPMethod, ContentType: params.ContentType, Secret: params.WebhookForm.Secret, @@ -288,6 +289,7 @@ func editWebhook(ctx *context.Context, params webhookParams) { } w.URL = params.URL + w.Name = strings.TrimSpace(params.WebhookForm.Name) w.ContentType = params.ContentType w.Secret = params.WebhookForm.Secret w.HookEvent = ParseHookEvent(params.WebhookForm) diff --git a/services/forms/repo_form.go b/services/forms/repo_form.go index 7ccf0aa622..3792190a76 100644 --- a/services/forms/repo_form.go +++ b/services/forms/repo_form.go @@ -206,6 +206,7 @@ type ProtectBranchPriorityForm struct { // WebhookForm form for changing web hook type WebhookForm struct { + Name string `binding:"MaxSize(255)"` Events string Create bool Delete bool diff --git a/services/webhook/general.go b/services/webhook/general.go index 3186f53d74..9572c926df 100644 --- a/services/webhook/general.go +++ b/services/webhook/general.go @@ -411,6 +411,7 @@ func ToHook(repoLink string, w *webhook_model.Webhook) (*api.Hook, error) { return &api.Hook{ ID: w.ID, + Name: w.Name, Type: w.Type, URL: fmt.Sprintf("%s/settings/hooks/%d", repoLink, w.ID), Active: w.IsActive, diff --git a/templates/repo/settings/webhook/base_list.tmpl b/templates/repo/settings/webhook/base_list.tmpl index 67b8ba32a7..8c4096ddc5 100644 --- a/templates/repo/settings/webhook/base_list.tmpl +++ b/templates/repo/settings/webhook/base_list.tmpl @@ -14,7 +14,8 @@
{{ctx.Locale.Tr "repo.settings.webhook.name_helper"}}
+