mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-12-01 13:44:06 +01:00
Merge pull request #581 from compressed/slack_upd
update slack hook to use new format
This commit is contained in:
commit
baae94b9cf
4 changed files with 5 additions and 24 deletions
|
@ -16,8 +16,6 @@ const (
|
||||||
)
|
)
|
||||||
|
|
||||||
type Slack struct {
|
type Slack struct {
|
||||||
Domain string `json:"domain"`
|
|
||||||
Token string `json:"token"`
|
|
||||||
Channel string `json:"channel"`
|
Channel string `json:"channel"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,14 +34,6 @@ type SlackAttachment struct {
|
||||||
Text string `json:"text"`
|
Text string `json:"text"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetSlackURL(domain string, token string) string {
|
|
||||||
return fmt.Sprintf(
|
|
||||||
"https://%s.slack.com/services/hooks/incoming-webhook?token=%s",
|
|
||||||
domain,
|
|
||||||
token,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p SlackPayload) GetJSONPayload() ([]byte, error) {
|
func (p SlackPayload) GetJSONPayload() ([]byte, error) {
|
||||||
data, err := json.Marshal(p)
|
data, err := json.Marshal(p)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -81,8 +81,7 @@ func (f *NewWebhookForm) Validate(ctx *macaron.Context, errs binding.Errors) bin
|
||||||
|
|
||||||
type NewSlackHookForm struct {
|
type NewSlackHookForm struct {
|
||||||
HookTaskType string `form:"hook_type" binding:"Required"`
|
HookTaskType string `form:"hook_type" binding:"Required"`
|
||||||
Domain string `form:"domain" binding:"Required`
|
PayloadUrl string `form:"payload_url" binding:"Required`
|
||||||
Token string `form:"token" binding:"Required"`
|
|
||||||
Channel string `form:"channel" binding:"Required"`
|
Channel string `form:"channel" binding:"Required"`
|
||||||
PushOnly bool `form:"push_only"`
|
PushOnly bool `form:"push_only"`
|
||||||
Active bool `form:"active"`
|
Active bool `form:"active"`
|
||||||
|
|
|
@ -483,9 +483,7 @@ func SlackHooksNewPost(ctx *middleware.Context, form auth.NewSlackHookForm) {
|
||||||
}
|
}
|
||||||
|
|
||||||
meta, err := json.Marshal(&models.Slack{
|
meta, err := json.Marshal(&models.Slack{
|
||||||
Domain: form.Domain,
|
|
||||||
Channel: form.Channel,
|
Channel: form.Channel,
|
||||||
Token: form.Token,
|
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Handle(500, "SlackHooksNewPost: JSON marshal failed: ", err)
|
ctx.Handle(500, "SlackHooksNewPost: JSON marshal failed: ", err)
|
||||||
|
@ -494,7 +492,7 @@ func SlackHooksNewPost(ctx *middleware.Context, form auth.NewSlackHookForm) {
|
||||||
|
|
||||||
w := &models.Webhook{
|
w := &models.Webhook{
|
||||||
RepoId: orCtx.RepoId,
|
RepoId: orCtx.RepoId,
|
||||||
Url: models.GetSlackURL(form.Domain, form.Token),
|
Url: form.PayloadUrl,
|
||||||
ContentType: models.JSON,
|
ContentType: models.JSON,
|
||||||
Secret: "",
|
Secret: "",
|
||||||
HookEvent: &models.HookEvent{
|
HookEvent: &models.HookEvent{
|
||||||
|
@ -551,16 +549,14 @@ func SlackHooksEditPost(ctx *middleware.Context, form auth.NewSlackHookForm) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
meta, err := json.Marshal(&models.Slack{
|
meta, err := json.Marshal(&models.Slack{
|
||||||
Domain: form.Domain,
|
|
||||||
Channel: form.Channel,
|
Channel: form.Channel,
|
||||||
Token: form.Token,
|
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Handle(500, "SlackHooksNewPost: JSON marshal failed: ", err)
|
ctx.Handle(500, "SlackHooksNewPost: JSON marshal failed: ", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
w.Url = models.GetSlackURL(form.Domain, form.Token)
|
w.Url = form.PayloadUrl
|
||||||
w.Meta = string(meta)
|
w.Meta = string(meta)
|
||||||
w.HookEvent = &models.HookEvent{
|
w.HookEvent = &models.HookEvent{
|
||||||
PushOnly: form.PushOnly,
|
PushOnly: form.PushOnly,
|
||||||
|
|
|
@ -4,12 +4,8 @@
|
||||||
<input type="hidden" name="hook_type" value="slack">
|
<input type="hidden" name="hook_type" value="slack">
|
||||||
<div class="text-center panel-desc">{{.i18n.Tr "repo.settings.add_slack_hook_desc" | Str2html}}</div>
|
<div class="text-center panel-desc">{{.i18n.Tr "repo.settings.add_slack_hook_desc" | Str2html}}</div>
|
||||||
<div class="field">
|
<div class="field">
|
||||||
<label class="req" for="domain">{{.i18n.Tr "repo.settings.slack_domain"}}</label>
|
<label class="req" for="payload-url">{{.i18n.Tr "repo.settings.payload_url"}}</label>
|
||||||
<input class="ipt ipt-large ipt-radius {{if .Err_UserName}}ipt-error{{end}}" id="domain" name="domain" type="text" value="{{.SlackHook.Domain}}" placeholde="myslack" required />
|
<input class="ipt ipt-large ipt-radius {{if .Err_UserName}}ipt-error{{end}}" id="payload-url" name="payload_url" type="url" value="{{.Webhook.Url}}" required />
|
||||||
</div>
|
|
||||||
<div class="field">
|
|
||||||
<label class="req" for="token">{{.i18n.Tr "repo.settings.slack_token"}}</label>
|
|
||||||
<input class="ipt ipt-large ipt-radius {{if .Err_UserName}}ipt-error{{end}}" id="token" name="token" type="text" value="{{.SlackHook.Token}}" autocomplete="off" required />
|
|
||||||
</div>
|
</div>
|
||||||
<div class="field">
|
<div class="field">
|
||||||
<label class="req" for="channel">{{.i18n.Tr "repo.settings.slack_channel"}}</label>
|
<label class="req" for="channel">{{.i18n.Tr "repo.settings.slack_channel"}}</label>
|
||||||
|
|
Loading…
Reference in a new issue