mirror of
https://github.com/go-gitea/gitea.git
synced 2024-11-25 17:56:48 +08:00
Implement Default Webhooks (#4299)
Partially implement #770. Add "Default Webhooks" page in site admin UI. Persist to the existing webhooks table, but store with RepoID=0 and OrgID=0. Upon repo creation, copy the set of default webhooks into the new repo.
This commit is contained in:
parent
cac9e6e760
commit
b34996a629
|
@ -1366,6 +1366,10 @@ func createRepository(e *xorm.Session, doer, u *User, repo *Repository) (err err
|
|||
return fmt.Errorf("newRepoAction: %v", err)
|
||||
}
|
||||
|
||||
if err = copyDefaultWebhooksToRepo(e, repo.ID); err != nil {
|
||||
return fmt.Errorf("copyDefaultWebhooksToRepo: %v", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
@ -241,7 +241,11 @@ func (w *Webhook) EventsArray() []string {
|
|||
|
||||
// CreateWebhook creates a new web hook.
|
||||
func CreateWebhook(w *Webhook) error {
|
||||
_, err := x.Insert(w)
|
||||
return createWebhook(x, w)
|
||||
}
|
||||
|
||||
func createWebhook(e Engine, w *Webhook) error {
|
||||
_, err := e.Insert(w)
|
||||
return err
|
||||
}
|
||||
|
||||
|
@ -316,6 +320,32 @@ func GetWebhooksByOrgID(orgID int64) (ws []*Webhook, err error) {
|
|||
return ws, err
|
||||
}
|
||||
|
||||
// GetDefaultWebhook returns admin-default webhook by given ID.
|
||||
func GetDefaultWebhook(id int64) (*Webhook, error) {
|
||||
webhook := &Webhook{ID: id}
|
||||
has, err := x.
|
||||
Where("repo_id=? AND org_id=?", 0, 0).
|
||||
Get(webhook)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else if !has {
|
||||
return nil, ErrWebhookNotExist{id}
|
||||
}
|
||||
return webhook, nil
|
||||
}
|
||||
|
||||
// GetDefaultWebhooks returns all admin-default webhooks.
|
||||
func GetDefaultWebhooks() ([]*Webhook, error) {
|
||||
return getDefaultWebhooks(x)
|
||||
}
|
||||
|
||||
func getDefaultWebhooks(e Engine) ([]*Webhook, error) {
|
||||
webhooks := make([]*Webhook, 0, 5)
|
||||
return webhooks, e.
|
||||
Where("repo_id=? AND org_id=?", 0, 0).
|
||||
Find(&webhooks)
|
||||
}
|
||||
|
||||
// UpdateWebhook updates information of webhook.
|
||||
func UpdateWebhook(w *Webhook) error {
|
||||
_, err := x.ID(w.ID).AllCols().Update(w)
|
||||
|
@ -364,6 +394,47 @@ func DeleteWebhookByOrgID(orgID, id int64) error {
|
|||
})
|
||||
}
|
||||
|
||||
// DeleteDefaultWebhook deletes an admin-default webhook by given ID.
|
||||
func DeleteDefaultWebhook(id int64) error {
|
||||
sess := x.NewSession()
|
||||
defer sess.Close()
|
||||
if err := sess.Begin(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
count, err := sess.
|
||||
Where("repo_id=? AND org_id=?", 0, 0).
|
||||
Delete(&Webhook{ID: id})
|
||||
if err != nil {
|
||||
return err
|
||||
} else if count == 0 {
|
||||
return ErrWebhookNotExist{ID: id}
|
||||
}
|
||||
|
||||
if _, err := sess.Delete(&HookTask{HookID: id}); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return sess.Commit()
|
||||
}
|
||||
|
||||
// copyDefaultWebhooksToRepo creates copies of the default webhooks in a new repo
|
||||
func copyDefaultWebhooksToRepo(e Engine, repoID int64) error {
|
||||
ws, err := getDefaultWebhooks(e)
|
||||
if err != nil {
|
||||
return fmt.Errorf("GetDefaultWebhooks: %v", err)
|
||||
}
|
||||
|
||||
for _, w := range ws {
|
||||
w.ID = 0
|
||||
w.RepoID = repoID
|
||||
if err := createWebhook(e, w); err != nil {
|
||||
return fmt.Errorf("CreateWebhook: %v", err)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// ___ ___ __ ___________ __
|
||||
// / | \ ____ ____ | | _\__ ___/____ _____| | __
|
||||
// / ~ \/ _ \ / _ \| |/ / | | \__ \ / ___/ |/ /
|
||||
|
|
|
@ -1433,6 +1433,7 @@ dashboard = Dashboard
|
|||
users = User Accounts
|
||||
organizations = Organizations
|
||||
repositories = Repositories
|
||||
hooks = Default Webhooks
|
||||
authentication = Authentication Sources
|
||||
config = Configuration
|
||||
notices = System Notices
|
||||
|
@ -1546,6 +1547,10 @@ repos.forks = Forks
|
|||
repos.issues = Issues
|
||||
repos.size = Size
|
||||
|
||||
hooks.desc = Webhooks automatically make HTTP POST requests to a server when certain Gitea events trigger. Webhooks defined here are defaults and will be copied into all new repositories. Read more in the <a target="_blank" rel="noopener" href="https://docs.gitea.io/en-us/webhooks/">webhooks guide</a>.
|
||||
hooks.add_webhook = Add Default Webhook
|
||||
hooks.update_webhook = Update Default Webhook
|
||||
|
||||
auths.auth_manage_panel = Authentication Source Management
|
||||
auths.new = Add Authentication Source
|
||||
auths.name = Name
|
||||
|
|
47
routers/admin/hooks.go
Normal file
47
routers/admin/hooks.go
Normal file
|
@ -0,0 +1,47 @@
|
|||
// Copyright 2018 The Gitea Authors. All rights reserved.
|
||||
// Use of this source code is governed by a MIT-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package admin
|
||||
|
||||
import (
|
||||
"code.gitea.io/gitea/models"
|
||||
"code.gitea.io/gitea/modules/base"
|
||||
"code.gitea.io/gitea/modules/context"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
)
|
||||
|
||||
const (
|
||||
// tplAdminHooks template path for render hook settings
|
||||
tplAdminHooks base.TplName = "admin/hooks"
|
||||
)
|
||||
|
||||
// DefaultWebhooks render admin-default webhook list page
|
||||
func DefaultWebhooks(ctx *context.Context) {
|
||||
ctx.Data["Title"] = ctx.Tr("admin.hooks")
|
||||
ctx.Data["PageIsAdminHooks"] = true
|
||||
ctx.Data["BaseLink"] = setting.AppSubURL + "/admin/hooks"
|
||||
ctx.Data["Description"] = ctx.Tr("admin.hooks.desc")
|
||||
|
||||
ws, err := models.GetDefaultWebhooks()
|
||||
if err != nil {
|
||||
ctx.ServerError("GetWebhooksDefaults", err)
|
||||
return
|
||||
}
|
||||
|
||||
ctx.Data["Webhooks"] = ws
|
||||
ctx.HTML(200, tplAdminHooks)
|
||||
}
|
||||
|
||||
// DeleteDefaultWebhook response for delete admin-default webhook
|
||||
func DeleteDefaultWebhook(ctx *context.Context) {
|
||||
if err := models.DeleteDefaultWebhook(ctx.QueryInt64("id")); err != nil {
|
||||
ctx.Flash.Error("DeleteDefaultWebhook: " + err.Error())
|
||||
} else {
|
||||
ctx.Flash.Success(ctx.Tr("repo.settings.webhook_deletion_success"))
|
||||
}
|
||||
|
||||
ctx.JSON(200, map[string]interface{}{
|
||||
"redirect": setting.AppSubURL + "/admin/hooks",
|
||||
})
|
||||
}
|
|
@ -150,7 +150,7 @@ func SettingsDelete(ctx *context.Context) {
|
|||
func Webhooks(ctx *context.Context) {
|
||||
ctx.Data["Title"] = ctx.Tr("org.settings")
|
||||
ctx.Data["PageIsSettingsHooks"] = true
|
||||
ctx.Data["BaseLink"] = ctx.Org.OrgLink
|
||||
ctx.Data["BaseLink"] = ctx.Org.OrgLink + "/settings/hooks"
|
||||
ctx.Data["Description"] = ctx.Tr("org.settings.hooks_desc")
|
||||
|
||||
ws, err := models.GetWebhooksByOrgID(ctx.Org.Organization.ID)
|
||||
|
|
|
@ -9,6 +9,7 @@ import (
|
|||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"path"
|
||||
"strings"
|
||||
|
||||
"code.gitea.io/git"
|
||||
|
@ -26,13 +27,14 @@ const (
|
|||
tplHooks base.TplName = "repo/settings/webhook/base"
|
||||
tplHookNew base.TplName = "repo/settings/webhook/new"
|
||||
tplOrgHookNew base.TplName = "org/settings/hook_new"
|
||||
tplAdminHookNew base.TplName = "admin/hook_new"
|
||||
)
|
||||
|
||||
// Webhooks render web hooks list page
|
||||
func Webhooks(ctx *context.Context) {
|
||||
ctx.Data["Title"] = ctx.Tr("repo.settings.hooks")
|
||||
ctx.Data["PageIsSettingsHooks"] = true
|
||||
ctx.Data["BaseLink"] = ctx.Repo.RepoLink
|
||||
ctx.Data["BaseLink"] = ctx.Repo.RepoLink + "/settings/hooks"
|
||||
ctx.Data["Description"] = ctx.Tr("repo.settings.hooks_desc", "https://docs.gitea.io/en-us/webhooks/")
|
||||
|
||||
ws, err := models.GetWebhooksByRepoID(ctx.Repo.Repository.ID)
|
||||
|
@ -48,16 +50,17 @@ func Webhooks(ctx *context.Context) {
|
|||
type orgRepoCtx struct {
|
||||
OrgID int64
|
||||
RepoID int64
|
||||
IsAdmin bool
|
||||
Link string
|
||||
NewTemplate base.TplName
|
||||
}
|
||||
|
||||
// getOrgRepoCtx determines whether this is a repo context or organization context.
|
||||
// getOrgRepoCtx determines whether this is a repo, organization, or admin context.
|
||||
func getOrgRepoCtx(ctx *context.Context) (*orgRepoCtx, error) {
|
||||
if len(ctx.Repo.RepoLink) > 0 {
|
||||
return &orgRepoCtx{
|
||||
RepoID: ctx.Repo.Repository.ID,
|
||||
Link: ctx.Repo.RepoLink,
|
||||
Link: path.Join(ctx.Repo.RepoLink, "settings/hooks"),
|
||||
NewTemplate: tplHookNew,
|
||||
}, nil
|
||||
}
|
||||
|
@ -65,11 +68,19 @@ func getOrgRepoCtx(ctx *context.Context) (*orgRepoCtx, error) {
|
|||
if len(ctx.Org.OrgLink) > 0 {
|
||||
return &orgRepoCtx{
|
||||
OrgID: ctx.Org.Organization.ID,
|
||||
Link: ctx.Org.OrgLink,
|
||||
Link: path.Join(ctx.Org.OrgLink, "settings/hooks"),
|
||||
NewTemplate: tplOrgHookNew,
|
||||
}, nil
|
||||
}
|
||||
|
||||
if ctx.User.IsAdmin {
|
||||
return &orgRepoCtx{
|
||||
IsAdmin: true,
|
||||
Link: path.Join(setting.AppSubURL, "/admin/hooks"),
|
||||
NewTemplate: tplAdminHookNew,
|
||||
}, nil
|
||||
}
|
||||
|
||||
return nil, errors.New("Unable to set OrgRepo context")
|
||||
}
|
||||
|
||||
|
@ -85,8 +96,6 @@ func checkHookType(ctx *context.Context) string {
|
|||
// WebhooksNew render creating webhook page
|
||||
func WebhooksNew(ctx *context.Context) {
|
||||
ctx.Data["Title"] = ctx.Tr("repo.settings.add_webhook")
|
||||
ctx.Data["PageIsSettingsHooks"] = true
|
||||
ctx.Data["PageIsSettingsHooksNew"] = true
|
||||
ctx.Data["Webhook"] = models.Webhook{HookEvent: &models.HookEvent{}}
|
||||
|
||||
orCtx, err := getOrgRepoCtx(ctx)
|
||||
|
@ -95,6 +104,14 @@ func WebhooksNew(ctx *context.Context) {
|
|||
return
|
||||
}
|
||||
|
||||
if orCtx.IsAdmin {
|
||||
ctx.Data["PageIsAdminHooks"] = true
|
||||
ctx.Data["PageIsAdminHooksNew"] = true
|
||||
} else {
|
||||
ctx.Data["PageIsSettingsHooks"] = true
|
||||
ctx.Data["PageIsSettingsHooksNew"] = true
|
||||
}
|
||||
|
||||
hookType := checkHookType(ctx)
|
||||
ctx.Data["HookType"] = hookType
|
||||
if ctx.Written() {
|
||||
|
@ -175,7 +192,7 @@ func WebHooksNewPost(ctx *context.Context, form auth.NewWebhookForm) {
|
|||
}
|
||||
|
||||
ctx.Flash.Success(ctx.Tr("repo.settings.add_hook_success"))
|
||||
ctx.Redirect(orCtx.Link + "/settings/hooks")
|
||||
ctx.Redirect(orCtx.Link)
|
||||
}
|
||||
|
||||
// GogsHooksNewPost response for creating webhook
|
||||
|
@ -222,7 +239,7 @@ func GogsHooksNewPost(ctx *context.Context, form auth.NewGogshookForm) {
|
|||
}
|
||||
|
||||
ctx.Flash.Success(ctx.Tr("repo.settings.add_hook_success"))
|
||||
ctx.Redirect(orCtx.Link + "/settings/hooks")
|
||||
ctx.Redirect(orCtx.Link)
|
||||
}
|
||||
|
||||
// DiscordHooksNewPost response for creating discord hook
|
||||
|
@ -271,7 +288,7 @@ func DiscordHooksNewPost(ctx *context.Context, form auth.NewDiscordHookForm) {
|
|||
}
|
||||
|
||||
ctx.Flash.Success(ctx.Tr("repo.settings.add_hook_success"))
|
||||
ctx.Redirect(orCtx.Link + "/settings/hooks")
|
||||
ctx.Redirect(orCtx.Link)
|
||||
}
|
||||
|
||||
// DingtalkHooksNewPost response for creating dingtalk hook
|
||||
|
@ -311,7 +328,7 @@ func DingtalkHooksNewPost(ctx *context.Context, form auth.NewDingtalkHookForm) {
|
|||
}
|
||||
|
||||
ctx.Flash.Success(ctx.Tr("repo.settings.add_hook_success"))
|
||||
ctx.Redirect(orCtx.Link + "/settings/hooks")
|
||||
ctx.Redirect(orCtx.Link)
|
||||
}
|
||||
|
||||
// SlackHooksNewPost response for creating slack hook
|
||||
|
@ -368,7 +385,7 @@ func SlackHooksNewPost(ctx *context.Context, form auth.NewSlackHookForm) {
|
|||
}
|
||||
|
||||
ctx.Flash.Success(ctx.Tr("repo.settings.add_hook_success"))
|
||||
ctx.Redirect(orCtx.Link + "/settings/hooks")
|
||||
ctx.Redirect(orCtx.Link)
|
||||
}
|
||||
|
||||
func checkWebhook(ctx *context.Context) (*orgRepoCtx, *models.Webhook) {
|
||||
|
@ -384,8 +401,10 @@ func checkWebhook(ctx *context.Context) (*orgRepoCtx, *models.Webhook) {
|
|||
var w *models.Webhook
|
||||
if orCtx.RepoID > 0 {
|
||||
w, err = models.GetWebhookByRepoID(ctx.Repo.Repository.ID, ctx.ParamsInt64(":id"))
|
||||
} else {
|
||||
} else if orCtx.OrgID > 0 {
|
||||
w, err = models.GetWebhookByOrgID(ctx.Org.Organization.ID, ctx.ParamsInt64(":id"))
|
||||
} else {
|
||||
w, err = models.GetDefaultWebhook(ctx.ParamsInt64(":id"))
|
||||
}
|
||||
if err != nil {
|
||||
if models.IsErrWebhookNotExist(err) {
|
||||
|
@ -462,7 +481,7 @@ func WebHooksEditPost(ctx *context.Context, form auth.NewWebhookForm) {
|
|||
}
|
||||
|
||||
ctx.Flash.Success(ctx.Tr("repo.settings.update_hook_success"))
|
||||
ctx.Redirect(fmt.Sprintf("%s/settings/hooks/%d", orCtx.Link, w.ID))
|
||||
ctx.Redirect(fmt.Sprintf("%s/%d", orCtx.Link, w.ID))
|
||||
}
|
||||
|
||||
// GogsHooksEditPost response for editing gogs hook
|
||||
|
@ -501,7 +520,7 @@ func GogsHooksEditPost(ctx *context.Context, form auth.NewGogshookForm) {
|
|||
}
|
||||
|
||||
ctx.Flash.Success(ctx.Tr("repo.settings.update_hook_success"))
|
||||
ctx.Redirect(fmt.Sprintf("%s/settings/hooks/%d", orCtx.Link, w.ID))
|
||||
ctx.Redirect(fmt.Sprintf("%s/%d", orCtx.Link, w.ID))
|
||||
}
|
||||
|
||||
// SlackHooksEditPost response for editing slack hook
|
||||
|
@ -551,7 +570,7 @@ func SlackHooksEditPost(ctx *context.Context, form auth.NewSlackHookForm) {
|
|||
}
|
||||
|
||||
ctx.Flash.Success(ctx.Tr("repo.settings.update_hook_success"))
|
||||
ctx.Redirect(fmt.Sprintf("%s/settings/hooks/%d", orCtx.Link, w.ID))
|
||||
ctx.Redirect(fmt.Sprintf("%s/%d", orCtx.Link, w.ID))
|
||||
}
|
||||
|
||||
// DiscordHooksEditPost response for editing discord hook
|
||||
|
@ -593,7 +612,7 @@ func DiscordHooksEditPost(ctx *context.Context, form auth.NewDiscordHookForm) {
|
|||
}
|
||||
|
||||
ctx.Flash.Success(ctx.Tr("repo.settings.update_hook_success"))
|
||||
ctx.Redirect(fmt.Sprintf("%s/settings/hooks/%d", orCtx.Link, w.ID))
|
||||
ctx.Redirect(fmt.Sprintf("%s/%d", orCtx.Link, w.ID))
|
||||
}
|
||||
|
||||
// DingtalkHooksEditPost response for editing discord hook
|
||||
|
@ -625,7 +644,7 @@ func DingtalkHooksEditPost(ctx *context.Context, form auth.NewDingtalkHookForm)
|
|||
}
|
||||
|
||||
ctx.Flash.Success(ctx.Tr("repo.settings.update_hook_success"))
|
||||
ctx.Redirect(fmt.Sprintf("%s/settings/hooks/%d", orCtx.Link, w.ID))
|
||||
ctx.Redirect(fmt.Sprintf("%s/%d", orCtx.Link, w.ID))
|
||||
}
|
||||
|
||||
// TestWebhook test if web hook is work fine
|
||||
|
|
|
@ -373,6 +373,23 @@ func RegisterRoutes(m *macaron.Macaron) {
|
|||
m.Post("/delete", admin.DeleteRepo)
|
||||
})
|
||||
|
||||
m.Group("/hooks", func() {
|
||||
m.Get("", admin.DefaultWebhooks)
|
||||
m.Post("/delete", admin.DeleteDefaultWebhook)
|
||||
m.Get("/:type/new", repo.WebhooksNew)
|
||||
m.Post("/gitea/new", bindIgnErr(auth.NewWebhookForm{}), repo.WebHooksNewPost)
|
||||
m.Post("/gogs/new", bindIgnErr(auth.NewGogshookForm{}), repo.GogsHooksNewPost)
|
||||
m.Post("/slack/new", bindIgnErr(auth.NewSlackHookForm{}), repo.SlackHooksNewPost)
|
||||
m.Post("/discord/new", bindIgnErr(auth.NewDiscordHookForm{}), repo.DiscordHooksNewPost)
|
||||
m.Post("/dingtalk/new", bindIgnErr(auth.NewDingtalkHookForm{}), repo.DingtalkHooksNewPost)
|
||||
m.Get("/:id", repo.WebHooksEdit)
|
||||
m.Post("/gitea/:id", bindIgnErr(auth.NewWebhookForm{}), repo.WebHooksEditPost)
|
||||
m.Post("/gogs/:id", bindIgnErr(auth.NewGogshookForm{}), repo.GogsHooksEditPost)
|
||||
m.Post("/slack/:id", bindIgnErr(auth.NewSlackHookForm{}), repo.SlackHooksEditPost)
|
||||
m.Post("/discord/:id", bindIgnErr(auth.NewDiscordHookForm{}), repo.DiscordHooksEditPost)
|
||||
m.Post("/dingtalk/:id", bindIgnErr(auth.NewDingtalkHookForm{}), repo.DingtalkHooksEditPost)
|
||||
})
|
||||
|
||||
m.Group("/auths", func() {
|
||||
m.Get("", admin.Authentications)
|
||||
m.Combo("/new").Get(admin.NewAuthSource).Post(bindIgnErr(auth.AuthenticationForm{}), admin.NewAuthSourcePost)
|
||||
|
|
37
templates/admin/hook_new.tmpl
Normal file
37
templates/admin/hook_new.tmpl
Normal file
|
@ -0,0 +1,37 @@
|
|||
{{template "base/head" .}}
|
||||
<div class="admin new webhook">
|
||||
{{template "admin/navbar" .}}
|
||||
<div class="ui container">
|
||||
{{template "base/alert" .}}
|
||||
<h4 class="ui top attached header">
|
||||
{{if .PageIsAdminHooksNew}}
|
||||
{{.i18n.Tr "admin.hooks.add_webhook"}}
|
||||
{{else}}
|
||||
{{.i18n.Tr "admin.hooks.update_webhook"}}
|
||||
{{end}}
|
||||
<div class="ui right">
|
||||
{{if eq .HookType "gitea"}}
|
||||
<img class="img-13" src="{{AppSubUrl}}/img/gitea-sm.png">
|
||||
{{else if eq .HookType "gogs"}}
|
||||
<img class="img-13" src="{{AppSubUrl}}/img/gogs.ico">
|
||||
{{else if eq .HookType "slack"}}
|
||||
<img class="img-13" src="{{AppSubUrl}}/img/slack.png">
|
||||
{{else if eq .HookType "discord"}}
|
||||
<img class="img-13" src="{{AppSubUrl}}/img/discord.png">
|
||||
{{else if eq .HookType "dingtalk"}}
|
||||
<img class="img-13" src="{{AppSubUrl}}/img/dingtalk.ico">
|
||||
{{end}}
|
||||
</div>
|
||||
</h4>
|
||||
<div class="ui attached segment">
|
||||
{{template "repo/settings/webhook/gitea" .}}
|
||||
{{template "repo/settings/webhook/gogs" .}}
|
||||
{{template "repo/settings/webhook/slack" .}}
|
||||
{{template "repo/settings/webhook/discord" .}}
|
||||
{{template "repo/settings/webhook/dingtalk" .}}
|
||||
</div>
|
||||
|
||||
{{template "repo/settings/webhook/history" .}}
|
||||
</div>
|
||||
</div>
|
||||
{{template "base/footer" .}}
|
8
templates/admin/hooks.tmpl
Normal file
8
templates/admin/hooks.tmpl
Normal file
|
@ -0,0 +1,8 @@
|
|||
{{template "base/head" .}}
|
||||
<div class="admin hooks">
|
||||
{{template "admin/navbar" .}}
|
||||
<div class="ui container">
|
||||
{{template "repo/settings/webhook/list" .}}
|
||||
</div>
|
||||
</div>
|
||||
{{template "base/footer" .}}
|
|
@ -6,6 +6,7 @@
|
|||
<li {{if .PageIsAdminUsers}}class="current"{{end}}><a href="{{AppSubUrl}}/admin/users">{{.i18n.Tr "admin.users"}}</a></li>
|
||||
<li {{if .PageIsAdminOrganizations}}class="current"{{end}}><a href="{{AppSubUrl}}/admin/orgs">{{.i18n.Tr "admin.organizations"}}</a></li>
|
||||
<li {{if .PageIsAdminRepositories}}class="current"{{end}}><a href="{{AppSubUrl}}/admin/repos">{{.i18n.Tr "admin.repositories"}}</a></li>
|
||||
<li {{if .PageIsAdminHooks}}class="current"{{end}}><a href="{{AppSubUrl}}/admin/hooks">{{.i18n.Tr "admin.hooks"}}</a></li>
|
||||
<li {{if .PageIsAdminAuthentications}}class="current"{{end}}><a href="{{AppSubUrl}}/admin/auths">{{.i18n.Tr "admin.authentication"}}</a></li>
|
||||
<li {{if .PageIsAdminConfig}}class="current"{{end}}><a href="{{AppSubUrl}}/admin/config">{{.i18n.Tr "admin.config"}}</a></li>
|
||||
<li {{if .PageIsAdminNotices}}class="current"{{end}}><a href="{{AppSubUrl}}/admin/notices">{{.i18n.Tr "admin.notices"}}</a></li>
|
||||
|
|
|
@ -11,6 +11,9 @@
|
|||
<a class="{{if .PageIsAdminRepositories}}active{{end}} item" href="{{AppSubUrl}}/admin/repos">
|
||||
{{.i18n.Tr "admin.repositories"}}
|
||||
</a>
|
||||
<a class="{{if .PageIsAdminHooks}}active{{end}} item" href="{{AppSubUrl}}/admin/hooks">
|
||||
{{.i18n.Tr "admin.hooks"}}
|
||||
</a>
|
||||
<a class="{{if .PageIsAdminAuthentications}}active{{end}} item" href="{{AppSubUrl}}/admin/auths">
|
||||
{{.i18n.Tr "admin.authentication"}}
|
||||
</a>
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{{if eq .HookType "dingtalk"}}
|
||||
<p>{{.i18n.Tr "repo.settings.add_dingtalk_hook_desc" "https://dingtalk.com" | Str2html}}</p>
|
||||
<form class="ui form" action="{{.BaseLink}}/settings/hooks/dingtalk/{{if .PageIsSettingsHooksNew}}new{{else}}{{.Webhook.ID}}{{end}}" method="post">
|
||||
<form class="ui form" action="{{.BaseLink}}/dingtalk/{{or .Webhook.ID "new"}}" method="post">
|
||||
{{.CsrfTokenHtml}}
|
||||
<div class="required field {{if .Err_PayloadURL}}error{{end}}">
|
||||
<label for="payload_url">{{.i18n.Tr "repo.settings.payload_url"}}</label>
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{{if eq .HookType "discord"}}
|
||||
<p>{{.i18n.Tr "repo.settings.add_discord_hook_desc" "https://discordapp.com" | Str2html}}</p>
|
||||
<form class="ui form" action="{{.BaseLink}}/settings/hooks/discord/{{if .PageIsSettingsHooksNew}}new{{else}}{{.Webhook.ID}}{{end}}" method="post">
|
||||
<form class="ui form" action="{{.BaseLink}}/discord/{{or .Webhook.ID "new"}}" method="post">
|
||||
{{.CsrfTokenHtml}}
|
||||
<div class="required field {{if .Err_PayloadURL}}error{{end}}">
|
||||
<label for="payload_url">{{.i18n.Tr "repo.settings.payload_url"}}</label>
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{{if eq .HookType "gitea"}}
|
||||
<p>{{.i18n.Tr "repo.settings.add_webhook_desc" "https://docs.gitea.io/en-us/webhooks/" | Str2html}}</p>
|
||||
<form class="ui form" action="{{.BaseLink}}/settings/hooks/gitea/{{if .PageIsSettingsHooksNew}}new{{else}}{{.Webhook.ID}}{{end}}" method="post">
|
||||
<form class="ui form" action="{{.BaseLink}}/gitea/{{or .Webhook.ID "new"}}" method="post">
|
||||
{{.CsrfTokenHtml}}
|
||||
<div class="required field {{if .Err_PayloadURL}}error{{end}}">
|
||||
<label for="payload_url">{{.i18n.Tr "repo.settings.payload_url"}}</label>
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{{if eq .HookType "gogs"}}
|
||||
<p>{{.i18n.Tr "repo.settings.add_webhook_desc" "https://docs.gitea.io/en-us/webhooks/" | Str2html}}</p>
|
||||
<form class="ui form" action="{{.BaseLink}}/settings/hooks/gogs/{{if .PageIsSettingsHooksNew}}new{{else}}{{.Webhook.ID}}{{end}}" method="post">
|
||||
<form class="ui form" action="{{.BaseLink}}/gogs/{{or .Webhook.ID "new"}}" method="post">
|
||||
{{.CsrfTokenHtml}}
|
||||
<div class="required field {{if .Err_PayloadURL}}error{{end}}">
|
||||
<label for="payload_url">{{.i18n.Tr "repo.settings.payload_url"}}</label>
|
||||
|
|
|
@ -5,19 +5,19 @@
|
|||
<div class="ui floating1 jump dropdown">
|
||||
<div class="ui blue tiny button">{{.i18n.Tr "repo.settings.add_webhook"}}</div>
|
||||
<div class="menu">
|
||||
<a class="item" href="{{.BaseLink}}/settings/hooks/gitea/new">
|
||||
<a class="item" href="{{.BaseLink}}/gitea/new">
|
||||
<img class="img-10" src="{{AppSubUrl}}/img/gitea-sm.png">Gitea
|
||||
</a>
|
||||
<a class="item" href="{{.BaseLink}}/settings/hooks/gogs/new">
|
||||
<a class="item" href="{{.BaseLink}}/gogs/new">
|
||||
<img class="img-10" src="{{AppSubUrl}}/img/gogs.ico">Gogs
|
||||
</a>
|
||||
<a class="item" href="{{.BaseLink}}/settings/hooks/slack/new">
|
||||
<a class="item" href="{{.BaseLink}}/slack/new">
|
||||
<img class="img-10" src="{{AppSubUrl}}/img/slack.png">Slack
|
||||
</a>
|
||||
<a class="item" href="{{.BaseLink}}/settings/hooks/discord/new">
|
||||
<a class="item" href="{{.BaseLink}}/discord/new">
|
||||
<img class="img-10" src="{{AppSubUrl}}/img/discord.png">Discord
|
||||
</a>
|
||||
<a class="item" href="{{.BaseLink}}/settings/hooks/dingtalk/new">
|
||||
<a class="item" href="{{.BaseLink}}/dingtalk/new">
|
||||
<img class="img-10" src="{{AppSubUrl}}/img/dingtalk.ico">Dingtalk
|
||||
</a>
|
||||
</div>
|
||||
|
@ -38,9 +38,9 @@
|
|||
{{else}}
|
||||
<span class="text grey"><i class="octicon octicon-primitive-dot"></i></span>
|
||||
{{end}}
|
||||
<a class="dont-break-out" href="{{$.BaseLink}}/settings/hooks/{{.ID}}">{{.URL}}</a>
|
||||
<a class="dont-break-out" href="{{$.BaseLink}}/{{.ID}}">{{.URL}}</a>
|
||||
<div class="ui right">
|
||||
<span class="text blue"><a href="{{$.BaseLink}}/settings/hooks/{{.ID}}"><i class="fa fa-pencil"></i></a></span>
|
||||
<span class="text blue"><a href="{{$.BaseLink}}/{{.ID}}"><i class="fa fa-pencil"></i></a></span>
|
||||
<span class="text red"><a class="delete-button" data-url="{{$.Link}}/delete" data-id="{{.ID}}"><i class="fa fa-times"></i></a></span>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
{{$isNew:=or .PageIsSettingsHooksNew .PageIsAdminHooksNew}}
|
||||
<div class="field">
|
||||
<h4>{{.i18n.Tr "repo.settings.event_desc"}}</h4>
|
||||
<div class="grouped event type fields">
|
||||
<div class="field">
|
||||
<div class="ui radio non-events checkbox">
|
||||
<input class="hidden" name="events" type="radio" value="push_only" {{if or .PageIsSettingsHooksNew .Webhook.PushOnly}}checked{{end}}>
|
||||
<input class="hidden" name="events" type="radio" value="push_only" {{if or $isNew .Webhook.PushOnly}}checked{{end}}>
|
||||
<label>{{.i18n.Tr "repo.settings.event_push_only" | Str2html}}</label>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -119,17 +120,17 @@
|
|||
|
||||
<div class="inline field">
|
||||
<div class="ui checkbox">
|
||||
<input class="hidden" name="active" type="checkbox" tabindex="0" {{if or .PageIsSettingsHooksNew .Webhook.IsActive}}checked{{end}}>
|
||||
<input class="hidden" name="active" type="checkbox" tabindex="0" {{if or $isNew .Webhook.IsActive}}checked{{end}}>
|
||||
<label>{{.i18n.Tr "repo.settings.active"}}</label>
|
||||
<span class="help">{{.i18n.Tr "repo.settings.active_helper"}}</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="field">
|
||||
{{if .PageIsSettingsHooksNew}}
|
||||
{{if $isNew}}
|
||||
<button class="ui green button">{{.i18n.Tr "repo.settings.add_webhook"}}</button>
|
||||
{{else}}
|
||||
<button class="ui green button">{{.i18n.Tr "repo.settings.update_webhook"}}</button>
|
||||
<a class="ui red delete-button button" data-url="{{.BaseLink}}/settings/hooks/delete" data-id="{{.Webhook.ID}}">{{.i18n.Tr "repo.settings.delete_webhook"}}</a>
|
||||
<a class="ui red delete-button button" data-url="{{.BaseLink}}/delete" data-id="{{.Webhook.ID}}">{{.i18n.Tr "repo.settings.delete_webhook"}}</a>
|
||||
{{end}}
|
||||
</div>
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{{if eq .HookType "slack"}}
|
||||
<p>{{.i18n.Tr "repo.settings.add_slack_hook_desc" "http://slack.com" | Str2html}}</p>
|
||||
<form class="ui form" action="{{.BaseLink}}/settings/hooks/slack/{{if .PageIsSettingsHooksNew}}new{{else}}{{.Webhook.ID}}{{end}}" method="post">
|
||||
<form class="ui form" action="{{.BaseLink}}/slack/{{or .Webhook.ID "new"}}" method="post">
|
||||
{{.CsrfTokenHtml}}
|
||||
<div class="required field {{if .Err_PayloadURL}}error{{end}}">
|
||||
<label for="payload_url">{{.i18n.Tr "repo.settings.payload_url"}}</label>
|
||||
|
|
Loading…
Reference in New Issue
Block a user