From 16dee4f1b251eec933a6c32520dc0e285a3d6f42 Mon Sep 17 00:00:00 2001
From: Yarden Shoham <git@yardenshoham.com>
Date: Mon, 21 Aug 2023 14:43:52 +0300
Subject: [PATCH] Add `branch_filter` to hooks API endpoints (#26599)

We now include the branch filler in the response.

- Closes #26591

# Before

![image](https://github.com/go-gitea/gitea/assets/20454870/73933940-c1a7-4573-abae-f340b63028b2)

# After

![image](https://github.com/go-gitea/gitea/assets/20454870/3b3c4a85-0f7c-48c7-8617-def7a66c671d)

---------

Signed-off-by: Yarden Shoham <git@yardenshoham.com>
Co-authored-by: Giteabot <teabot@gitea.io>
---
 modules/structs/hook.go        | 1 +
 services/webhook/general.go    | 1 +
 templates/swagger/v1_json.tmpl | 4 ++++
 3 files changed, 6 insertions(+)

diff --git a/modules/structs/hook.go b/modules/structs/hook.go
index cd91d4bc46..0babe84410 100644
--- a/modules/structs/hook.go
+++ b/modules/structs/hook.go
@@ -19,6 +19,7 @@ var ErrInvalidReceiveHook = errors.New("Invalid JSON payload received over webho
 type Hook struct {
 	ID                  int64             `json:"id"`
 	Type                string            `json:"type"`
+	BranchFilter        string            `json:"branch_filter"`
 	URL                 string            `json:"-"`
 	Config              map[string]string `json:"config"`
 	Events              []string          `json:"events"`
diff --git a/services/webhook/general.go b/services/webhook/general.go
index f53ea31ffa..b9cc3dc845 100644
--- a/services/webhook/general.go
+++ b/services/webhook/general.go
@@ -260,5 +260,6 @@ func ToHook(repoLink string, w *webhook_model.Webhook) (*api.Hook, error) {
 		AuthorizationHeader: authorizationHeader,
 		Updated:             w.UpdatedUnix.AsTime(),
 		Created:             w.CreatedUnix.AsTime(),
+		BranchFilter:        w.BranchFilter,
 	}, nil
 }
diff --git a/templates/swagger/v1_json.tmpl b/templates/swagger/v1_json.tmpl
index da43c530af..734a73bc0c 100644
--- a/templates/swagger/v1_json.tmpl
+++ b/templates/swagger/v1_json.tmpl
@@ -19137,6 +19137,10 @@
           "type": "string",
           "x-go-name": "AuthorizationHeader"
         },
+        "branch_filter": {
+          "type": "string",
+          "x-go-name": "BranchFilter"
+        },
         "config": {
           "type": "object",
           "additionalProperties": {