|
|
@ -368,18 +368,56 @@ func WebHooksNewPost(ctx *middleware.Context, form auth.NewWebhookForm) { |
|
|
|
ctx.Redirect(orCtx.Link + "/settings/hooks") |
|
|
|
ctx.Redirect(orCtx.Link + "/settings/hooks") |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func WebHooksEdit(ctx *middleware.Context) { |
|
|
|
func SlackHooksNewPost(ctx *middleware.Context, form auth.NewSlackHookForm) { |
|
|
|
ctx.Data["Title"] = ctx.Tr("repo.settings.update_webhook") |
|
|
|
ctx.Data["Title"] = ctx.Tr("repo.settings") |
|
|
|
ctx.Data["PageIsSettingsHooks"] = true |
|
|
|
ctx.Data["PageIsSettingsHooks"] = true |
|
|
|
ctx.Data["PageIsSettingsHooksEdit"] = true |
|
|
|
ctx.Data["PageIsSettingsHooksNew"] = true |
|
|
|
|
|
|
|
ctx.Data["Webhook"] = models.Webhook{HookEvent: &models.HookEvent{}} |
|
|
|
|
|
|
|
|
|
|
|
orCtx, err := getOrgRepoCtx(ctx) |
|
|
|
orCtx, err := getOrgRepoCtx(ctx) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
ctx.Handle(500, "getOrgRepoCtx", err) |
|
|
|
ctx.Handle(500, "getOrgRepoCtx", err) |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
ctx.Data["BaseLink"] = orCtx.Link |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ctx.HasError() { |
|
|
|
|
|
|
|
ctx.HTML(200, orCtx.NewTemplate) |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
meta, err := json.Marshal(&models.Slack{ |
|
|
|
|
|
|
|
Channel: form.Channel, |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
ctx.Handle(500, "Marshal", err) |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
w := &models.Webhook{ |
|
|
|
|
|
|
|
RepoID: orCtx.RepoID, |
|
|
|
|
|
|
|
URL: form.PayloadURL, |
|
|
|
|
|
|
|
ContentType: models.JSON, |
|
|
|
|
|
|
|
HookEvent: &models.HookEvent{ |
|
|
|
|
|
|
|
PushOnly: form.PushOnly, |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
IsActive: form.Active, |
|
|
|
|
|
|
|
HookTaskType: models.SLACK, |
|
|
|
|
|
|
|
Meta: string(meta), |
|
|
|
|
|
|
|
OrgID: orCtx.OrgID, |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if err := w.UpdateEvent(); err != nil { |
|
|
|
|
|
|
|
ctx.Handle(500, "UpdateEvent", err) |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} else if err := models.CreateWebhook(w); err != nil { |
|
|
|
|
|
|
|
ctx.Handle(500, "CreateWebhook", err) |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ctx.Flash.Success(ctx.Tr("repo.settings.add_hook_success")) |
|
|
|
|
|
|
|
ctx.Redirect(orCtx.Link + "/settings/hooks") |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func checkWebhook(ctx *middleware.Context) *models.Webhook { |
|
|
|
w, err := models.GetWebhookById(ctx.ParamsInt64(":id")) |
|
|
|
w, err := models.GetWebhookById(ctx.ParamsInt64(":id")) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
if err == models.ErrWebhookNotExist { |
|
|
|
if err == models.ErrWebhookNotExist { |
|
|
@ -387,7 +425,7 @@ func WebHooksEdit(ctx *middleware.Context) { |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
ctx.Handle(500, "GetWebhookById", err) |
|
|
|
ctx.Handle(500, "GetWebhookById", err) |
|
|
|
} |
|
|
|
} |
|
|
|
return |
|
|
|
return nil |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
switch w.HookTaskType { |
|
|
|
switch w.HookTaskType { |
|
|
@ -398,37 +436,19 @@ func WebHooksEdit(ctx *middleware.Context) { |
|
|
|
ctx.Data["HookType"] = "gogs" |
|
|
|
ctx.Data["HookType"] = "gogs" |
|
|
|
} |
|
|
|
} |
|
|
|
w.GetEvent() |
|
|
|
w.GetEvent() |
|
|
|
ctx.Data["Webhook"] = w |
|
|
|
return w |
|
|
|
|
|
|
|
|
|
|
|
ctx.HTML(200, orCtx.NewTemplate) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func WebHooksEditPost(ctx *middleware.Context, form auth.NewWebhookForm) { |
|
|
|
func WebHooksEdit(ctx *middleware.Context) { |
|
|
|
ctx.Data["Title"] = ctx.Tr("repo.settings.update_webhook") |
|
|
|
ctx.Data["Title"] = ctx.Tr("repo.settings.update_webhook") |
|
|
|
ctx.Data["PageIsSettingsHooks"] = true |
|
|
|
ctx.Data["PageIsSettingsHooks"] = true |
|
|
|
ctx.Data["PageIsSettingsHooksEdit"] = true |
|
|
|
ctx.Data["PageIsSettingsHooksEdit"] = true |
|
|
|
|
|
|
|
|
|
|
|
w, err := models.GetWebhookById(ctx.ParamsInt64(":id")) |
|
|
|
ctx.Data["Webhook"] = checkWebhook(ctx) |
|
|
|
if err != nil { |
|
|
|
if ctx.Written() { |
|
|
|
if err == models.ErrWebhookNotExist { |
|
|
|
|
|
|
|
ctx.Handle(404, "GetWebhookById", nil) |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
ctx.Handle(500, "GetWebhookById", err) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// set data per HookTaskType
|
|
|
|
|
|
|
|
switch w.HookTaskType { |
|
|
|
|
|
|
|
case models.SLACK: |
|
|
|
|
|
|
|
ctx.Data["SlackHook"] = w.GetSlackHook() |
|
|
|
|
|
|
|
ctx.Data["HookType"] = "Slack" |
|
|
|
|
|
|
|
default: |
|
|
|
|
|
|
|
ctx.Data["HookType"] = "Gogs" |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
w.GetEvent() |
|
|
|
|
|
|
|
ctx.Data["Webhook"] = w |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
orCtx, err := getOrgRepoCtx(ctx) |
|
|
|
orCtx, err := getOrgRepoCtx(ctx) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
ctx.Handle(500, "getOrgRepoCtx", err) |
|
|
|
ctx.Handle(500, "getOrgRepoCtx", err) |
|
|
@ -436,83 +456,54 @@ func WebHooksEditPost(ctx *middleware.Context, form auth.NewWebhookForm) { |
|
|
|
} |
|
|
|
} |
|
|
|
ctx.Data["BaseLink"] = orCtx.Link |
|
|
|
ctx.Data["BaseLink"] = orCtx.Link |
|
|
|
|
|
|
|
|
|
|
|
if ctx.HasError() { |
|
|
|
|
|
|
|
ctx.HTML(200, orCtx.NewTemplate) |
|
|
|
ctx.HTML(200, orCtx.NewTemplate) |
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
ct := models.JSON |
|
|
|
func WebHooksEditPost(ctx *middleware.Context, form auth.NewWebhookForm) { |
|
|
|
if models.HookContentType(form.ContentType) == models.FORM { |
|
|
|
ctx.Data["Title"] = ctx.Tr("repo.settings.update_webhook") |
|
|
|
ct = models.FORM |
|
|
|
ctx.Data["PageIsSettingsHooks"] = true |
|
|
|
} |
|
|
|
ctx.Data["PageIsSettingsHooksEdit"] = true |
|
|
|
|
|
|
|
|
|
|
|
w.URL = form.PayloadURL |
|
|
|
w := checkWebhook(ctx) |
|
|
|
w.ContentType = ct |
|
|
|
if ctx.Written() { |
|
|
|
w.Secret = form.Secret |
|
|
|
|
|
|
|
w.HookEvent = &models.HookEvent{ |
|
|
|
|
|
|
|
PushOnly: form.PushOnly, |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
w.IsActive = form.Active |
|
|
|
|
|
|
|
if err := w.UpdateEvent(); err != nil { |
|
|
|
|
|
|
|
ctx.Handle(500, "UpdateEvent", err) |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} else if err := models.UpdateWebhook(w); err != nil { |
|
|
|
|
|
|
|
ctx.Handle(500, "WebHooksEditPost", err) |
|
|
|
|
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
ctx.Data["Webhook"] = w |
|
|
|
ctx.Flash.Success(ctx.Tr("repo.settings.update_hook_success")) |
|
|
|
|
|
|
|
ctx.Redirect(orCtx.Link + "/settings/hooks") |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func SlackHooksNewPost(ctx *middleware.Context, form auth.NewSlackHookForm) { |
|
|
|
|
|
|
|
ctx.Data["Title"] = ctx.Tr("repo.settings") |
|
|
|
|
|
|
|
ctx.Data["PageIsSettingsHooks"] = true |
|
|
|
|
|
|
|
ctx.Data["PageIsSettingsHooksNew"] = true |
|
|
|
|
|
|
|
ctx.Data["Webhook"] = models.Webhook{HookEvent: &models.HookEvent{}} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
orCtx, err := getOrgRepoCtx(ctx) |
|
|
|
orCtx, err := getOrgRepoCtx(ctx) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
ctx.Handle(500, "SlackHooksNewPost(getOrgRepoCtx)", err) |
|
|
|
ctx.Handle(500, "getOrgRepoCtx", err) |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
ctx.Data["BaseLink"] = orCtx.Link |
|
|
|
|
|
|
|
|
|
|
|
if ctx.HasError() { |
|
|
|
if ctx.HasError() { |
|
|
|
ctx.HTML(200, orCtx.NewTemplate) |
|
|
|
ctx.HTML(200, orCtx.NewTemplate) |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
meta, err := json.Marshal(&models.Slack{ |
|
|
|
contentType := models.JSON |
|
|
|
Channel: form.Channel, |
|
|
|
if models.HookContentType(form.ContentType) == models.FORM { |
|
|
|
}) |
|
|
|
contentType = models.FORM |
|
|
|
if err != nil { |
|
|
|
|
|
|
|
ctx.Handle(500, "SlackHooksNewPost: JSON marshal failed: ", err) |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
w := &models.Webhook{ |
|
|
|
w.URL = form.PayloadURL |
|
|
|
RepoID: orCtx.RepoID, |
|
|
|
w.ContentType = contentType |
|
|
|
URL: form.PayloadURL, |
|
|
|
w.Secret = form.Secret |
|
|
|
ContentType: models.JSON, |
|
|
|
w.HookEvent = &models.HookEvent{ |
|
|
|
Secret: "", |
|
|
|
|
|
|
|
HookEvent: &models.HookEvent{ |
|
|
|
|
|
|
|
PushOnly: form.PushOnly, |
|
|
|
PushOnly: form.PushOnly, |
|
|
|
}, |
|
|
|
|
|
|
|
IsActive: form.Active, |
|
|
|
|
|
|
|
HookTaskType: models.SLACK, |
|
|
|
|
|
|
|
Meta: string(meta), |
|
|
|
|
|
|
|
OrgID: orCtx.OrgID, |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
w.IsActive = form.Active |
|
|
|
if err := w.UpdateEvent(); err != nil { |
|
|
|
if err := w.UpdateEvent(); err != nil { |
|
|
|
ctx.Handle(500, "UpdateEvent", err) |
|
|
|
ctx.Handle(500, "UpdateEvent", err) |
|
|
|
return |
|
|
|
return |
|
|
|
} else if err := models.CreateWebhook(w); err != nil { |
|
|
|
} else if err := models.UpdateWebhook(w); err != nil { |
|
|
|
ctx.Handle(500, "CreateWebhook", err) |
|
|
|
ctx.Handle(500, "WebHooksEditPost", err) |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
ctx.Flash.Success(ctx.Tr("repo.settings.add_hook_success")) |
|
|
|
ctx.Flash.Success(ctx.Tr("repo.settings.update_hook_success")) |
|
|
|
ctx.Redirect(orCtx.Link + "/settings/hooks") |
|
|
|
ctx.Redirect(fmt.Sprintf("%s/settings/hooks/%d", orCtx.Link, w.ID)) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func SlackHooksEditPost(ctx *middleware.Context, form auth.NewSlackHookForm) { |
|
|
|
func SlackHooksEditPost(ctx *middleware.Context, form auth.NewSlackHookForm) { |
|
|
@ -520,39 +511,29 @@ func SlackHooksEditPost(ctx *middleware.Context, form auth.NewSlackHookForm) { |
|
|
|
ctx.Data["PageIsSettingsHooks"] = true |
|
|
|
ctx.Data["PageIsSettingsHooks"] = true |
|
|
|
ctx.Data["PageIsSettingsHooksEdit"] = true |
|
|
|
ctx.Data["PageIsSettingsHooksEdit"] = true |
|
|
|
|
|
|
|
|
|
|
|
hookId := com.StrTo(ctx.Params(":id")).MustInt64() |
|
|
|
w := checkWebhook(ctx) |
|
|
|
if hookId == 0 { |
|
|
|
if ctx.Written() { |
|
|
|
ctx.Handle(404, "SlackHooksEditPost(hookId)", nil) |
|
|
|
|
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
ctx.Data["Webhook"] = w |
|
|
|
|
|
|
|
|
|
|
|
orCtx, err := getOrgRepoCtx(ctx) |
|
|
|
orCtx, err := getOrgRepoCtx(ctx) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
ctx.Handle(500, "SlackHooksEditPost(getOrgRepoCtx)", err) |
|
|
|
ctx.Handle(500, "getOrgRepoCtx", err) |
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
w, err := models.GetWebhookById(hookId) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
if err == models.ErrWebhookNotExist { |
|
|
|
|
|
|
|
ctx.Handle(404, "GetWebhookById", nil) |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
ctx.Handle(500, "GetWebhookById", err) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
w.GetEvent() |
|
|
|
ctx.Data["BaseLink"] = orCtx.Link |
|
|
|
ctx.Data["Webhook"] = w |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ctx.HasError() { |
|
|
|
if ctx.HasError() { |
|
|
|
ctx.HTML(200, orCtx.NewTemplate) |
|
|
|
ctx.HTML(200, orCtx.NewTemplate) |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
meta, err := json.Marshal(&models.Slack{ |
|
|
|
meta, err := json.Marshal(&models.Slack{ |
|
|
|
Channel: form.Channel, |
|
|
|
Channel: form.Channel, |
|
|
|
}) |
|
|
|
}) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
ctx.Handle(500, "SlackHooksNewPost: JSON marshal failed: ", err) |
|
|
|
ctx.Handle(500, "Marshal", err) |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -566,12 +547,12 @@ func SlackHooksEditPost(ctx *middleware.Context, form auth.NewSlackHookForm) { |
|
|
|
ctx.Handle(500, "UpdateEvent", err) |
|
|
|
ctx.Handle(500, "UpdateEvent", err) |
|
|
|
return |
|
|
|
return |
|
|
|
} else if err := models.UpdateWebhook(w); err != nil { |
|
|
|
} else if err := models.UpdateWebhook(w); err != nil { |
|
|
|
ctx.Handle(500, "SlackHooksEditPost", err) |
|
|
|
ctx.Handle(500, "UpdateWebhook", err) |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
ctx.Flash.Success(ctx.Tr("repo.settings.update_hook_success")) |
|
|
|
ctx.Flash.Success(ctx.Tr("repo.settings.update_hook_success")) |
|
|
|
ctx.Redirect(fmt.Sprintf("%s/settings/hooks/%d", orCtx.Link, hookId)) |
|
|
|
ctx.Redirect(fmt.Sprintf("%s/settings/hooks/%d", orCtx.Link, w.ID)) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func DeleteWebhook(ctx *middleware.Context) { |
|
|
|
func DeleteWebhook(ctx *middleware.Context) { |
|
|
|