summaryrefslogtreecommitdiffstats
path: root/services/webhook/general.go
diff options
context:
space:
mode:
Diffstat (limited to 'services/webhook/general.go')
-rw-r--r--services/webhook/general.go35
1 files changed, 35 insertions, 0 deletions
diff --git a/services/webhook/general.go b/services/webhook/general.go
index bec752cffe..1f7d204d1f 100644
--- a/services/webhook/general.go
+++ b/services/webhook/general.go
@@ -9,9 +9,11 @@ import (
"net/url"
"strings"
+ webhook_model "code.gitea.io/gitea/models/webhook"
"code.gitea.io/gitea/modules/setting"
api "code.gitea.io/gitea/modules/structs"
"code.gitea.io/gitea/modules/util"
+ webhook_module "code.gitea.io/gitea/modules/webhook"
)
type linkFormatter = func(string, string) string
@@ -223,3 +225,36 @@ func getIssueCommentPayloadInfo(p *api.IssueCommentPayload, linkFormatter linkFo
return text, issueTitle, color
}
+
+// ToHook convert models.Webhook to api.Hook
+// This function is not part of the convert package to prevent an import cycle
+func ToHook(repoLink string, w *webhook_model.Webhook) (*api.Hook, error) {
+ config := map[string]string{
+ "url": w.URL,
+ "content_type": w.ContentType.Name(),
+ }
+ if w.Type == webhook_module.SLACK {
+ s := GetSlackHook(w)
+ config["channel"] = s.Channel
+ config["username"] = s.Username
+ config["icon_url"] = s.IconURL
+ config["color"] = s.Color
+ }
+
+ authorizationHeader, err := w.HeaderAuthorization()
+ if err != nil {
+ return nil, err
+ }
+
+ return &api.Hook{
+ ID: w.ID,
+ Type: w.Type,
+ URL: fmt.Sprintf("%s/settings/hooks/%d", repoLink, w.ID),
+ Active: w.IsActive,
+ Config: config,
+ Events: w.EventsArray(),
+ AuthorizationHeader: authorizationHeader,
+ Updated: w.UpdatedUnix.AsTime(),
+ Created: w.CreatedUnix.AsTime(),
+ }, nil
+}