|
|
@ -185,14 +185,22 @@ func ParseHookEvent(form forms.WebhookForm) *webhook.HookEvent { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// GiteaHooksNewPost response for creating Gitea webhook
|
|
|
|
type webhookCreationParams struct { |
|
|
|
func GiteaHooksNewPost(ctx *context.Context) { |
|
|
|
URL string |
|
|
|
form := web.GetForm(ctx).(*forms.NewWebhookForm) |
|
|
|
ContentType webhook.HookContentType |
|
|
|
|
|
|
|
Secret string |
|
|
|
|
|
|
|
HTTPMethod string |
|
|
|
|
|
|
|
WebhookForm forms.WebhookForm |
|
|
|
|
|
|
|
Type string |
|
|
|
|
|
|
|
Meta interface{} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func createWebhook(ctx *context.Context, params webhookCreationParams) { |
|
|
|
ctx.Data["Title"] = ctx.Tr("repo.settings.add_webhook") |
|
|
|
ctx.Data["Title"] = ctx.Tr("repo.settings.add_webhook") |
|
|
|
ctx.Data["PageIsSettingsHooks"] = true |
|
|
|
ctx.Data["PageIsSettingsHooks"] = true |
|
|
|
ctx.Data["PageIsSettingsHooksNew"] = true |
|
|
|
ctx.Data["PageIsSettingsHooksNew"] = true |
|
|
|
ctx.Data["Webhook"] = webhook.Webhook{HookEvent: &webhook.HookEvent{}} |
|
|
|
ctx.Data["Webhook"] = webhook.Webhook{HookEvent: &webhook.HookEvent{}} |
|
|
|
ctx.Data["HookType"] = webhook.GITEA |
|
|
|
ctx.Data["HookType"] = params.Type |
|
|
|
|
|
|
|
|
|
|
|
orCtx, err := getOrgRepoCtx(ctx) |
|
|
|
orCtx, err := getOrgRepoCtx(ctx) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
@ -206,20 +214,25 @@ func GiteaHooksNewPost(ctx *context.Context) { |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
contentType := webhook.ContentTypeJSON |
|
|
|
var meta []byte |
|
|
|
if webhook.HookContentType(form.ContentType) == webhook.ContentTypeForm { |
|
|
|
if params.Meta != nil { |
|
|
|
contentType = webhook.ContentTypeForm |
|
|
|
meta, err = json.Marshal(params.Meta) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
ctx.ServerError("Marshal", err) |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
w := &webhook.Webhook{ |
|
|
|
w := &webhook.Webhook{ |
|
|
|
RepoID: orCtx.RepoID, |
|
|
|
RepoID: orCtx.RepoID, |
|
|
|
URL: form.PayloadURL, |
|
|
|
URL: params.URL, |
|
|
|
HTTPMethod: form.HTTPMethod, |
|
|
|
HTTPMethod: params.HTTPMethod, |
|
|
|
ContentType: contentType, |
|
|
|
ContentType: params.ContentType, |
|
|
|
Secret: form.Secret, |
|
|
|
Secret: params.Secret, |
|
|
|
HookEvent: ParseHookEvent(form.WebhookForm), |
|
|
|
HookEvent: ParseHookEvent(params.WebhookForm), |
|
|
|
IsActive: form.Active, |
|
|
|
IsActive: params.WebhookForm.Active, |
|
|
|
Type: webhook.GITEA, |
|
|
|
Type: params.Type, |
|
|
|
|
|
|
|
Meta: string(meta), |
|
|
|
OrgID: orCtx.OrgID, |
|
|
|
OrgID: orCtx.OrgID, |
|
|
|
IsSystemWebhook: orCtx.IsSystemWebhook, |
|
|
|
IsSystemWebhook: orCtx.IsSystemWebhook, |
|
|
|
} |
|
|
|
} |
|
|
@ -235,503 +248,175 @@ func GiteaHooksNewPost(ctx *context.Context) { |
|
|
|
ctx.Redirect(orCtx.Link) |
|
|
|
ctx.Redirect(orCtx.Link) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// GogsHooksNewPost response for creating webhook
|
|
|
|
// GiteaHooksNewPost response for creating Gitea webhook
|
|
|
|
func GogsHooksNewPost(ctx *context.Context) { |
|
|
|
func GiteaHooksNewPost(ctx *context.Context) { |
|
|
|
form := web.GetForm(ctx).(*forms.NewGogshookForm) |
|
|
|
form := web.GetForm(ctx).(*forms.NewWebhookForm) |
|
|
|
newGogsWebhookPost(ctx, *form, webhook.GOGS) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// newGogsWebhookPost response for creating gogs hook
|
|
|
|
|
|
|
|
func newGogsWebhookPost(ctx *context.Context, form forms.NewGogshookForm, kind webhook.HookType) { |
|
|
|
|
|
|
|
ctx.Data["Title"] = ctx.Tr("repo.settings.add_webhook") |
|
|
|
|
|
|
|
ctx.Data["PageIsSettingsHooks"] = true |
|
|
|
|
|
|
|
ctx.Data["PageIsSettingsHooksNew"] = true |
|
|
|
|
|
|
|
ctx.Data["Webhook"] = webhook.Webhook{HookEvent: &webhook.HookEvent{}} |
|
|
|
|
|
|
|
ctx.Data["HookType"] = webhook.GOGS |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
orCtx, err := getOrgRepoCtx(ctx) |
|
|
|
contentType := webhook.ContentTypeJSON |
|
|
|
if err != nil { |
|
|
|
if webhook.HookContentType(form.ContentType) == webhook.ContentTypeForm { |
|
|
|
ctx.ServerError("getOrgRepoCtx", err) |
|
|
|
contentType = webhook.ContentTypeForm |
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
ctx.Data["BaseLink"] = orCtx.LinkNew |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ctx.HasError() { |
|
|
|
createWebhook(ctx, webhookCreationParams{ |
|
|
|
ctx.HTML(http.StatusOK, orCtx.NewTemplate) |
|
|
|
URL: form.PayloadURL, |
|
|
|
return |
|
|
|
ContentType: contentType, |
|
|
|
} |
|
|
|
Secret: form.Secret, |
|
|
|
|
|
|
|
HTTPMethod: form.HTTPMethod, |
|
|
|
|
|
|
|
WebhookForm: form.WebhookForm, |
|
|
|
|
|
|
|
Type: webhook.GITEA, |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// GogsHooksNewPost response for creating webhook
|
|
|
|
|
|
|
|
func GogsHooksNewPost(ctx *context.Context) { |
|
|
|
|
|
|
|
form := web.GetForm(ctx).(*forms.NewGogshookForm) |
|
|
|
|
|
|
|
|
|
|
|
contentType := webhook.ContentTypeJSON |
|
|
|
contentType := webhook.ContentTypeJSON |
|
|
|
if webhook.HookContentType(form.ContentType) == webhook.ContentTypeForm { |
|
|
|
if webhook.HookContentType(form.ContentType) == webhook.ContentTypeForm { |
|
|
|
contentType = webhook.ContentTypeForm |
|
|
|
contentType = webhook.ContentTypeForm |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
w := &webhook.Webhook{ |
|
|
|
createWebhook(ctx, webhookCreationParams{ |
|
|
|
RepoID: orCtx.RepoID, |
|
|
|
URL: form.PayloadURL, |
|
|
|
URL: form.PayloadURL, |
|
|
|
ContentType: contentType, |
|
|
|
ContentType: contentType, |
|
|
|
Secret: form.Secret, |
|
|
|
Secret: form.Secret, |
|
|
|
WebhookForm: form.WebhookForm, |
|
|
|
HookEvent: ParseHookEvent(form.WebhookForm), |
|
|
|
Type: webhook.GOGS, |
|
|
|
IsActive: form.Active, |
|
|
|
}) |
|
|
|
Type: kind, |
|
|
|
|
|
|
|
OrgID: orCtx.OrgID, |
|
|
|
|
|
|
|
IsSystemWebhook: orCtx.IsSystemWebhook, |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if err := w.UpdateEvent(); err != nil { |
|
|
|
|
|
|
|
ctx.ServerError("UpdateEvent", err) |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} else if err := webhook.CreateWebhook(ctx, w); err != nil { |
|
|
|
|
|
|
|
ctx.ServerError("CreateWebhook", err) |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ctx.Flash.Success(ctx.Tr("repo.settings.add_hook_success")) |
|
|
|
|
|
|
|
ctx.Redirect(orCtx.Link) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// DiscordHooksNewPost response for creating discord hook
|
|
|
|
// DiscordHooksNewPost response for creating discord hook
|
|
|
|
func DiscordHooksNewPost(ctx *context.Context) { |
|
|
|
func DiscordHooksNewPost(ctx *context.Context) { |
|
|
|
form := web.GetForm(ctx).(*forms.NewDiscordHookForm) |
|
|
|
form := web.GetForm(ctx).(*forms.NewDiscordHookForm) |
|
|
|
ctx.Data["Title"] = ctx.Tr("repo.settings") |
|
|
|
|
|
|
|
ctx.Data["PageIsSettingsHooks"] = true |
|
|
|
|
|
|
|
ctx.Data["PageIsSettingsHooksNew"] = true |
|
|
|
|
|
|
|
ctx.Data["Webhook"] = webhook.Webhook{HookEvent: &webhook.HookEvent{}} |
|
|
|
|
|
|
|
ctx.Data["HookType"] = webhook.DISCORD |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
orCtx, err := getOrgRepoCtx(ctx) |
|
|
|
createWebhook(ctx, webhookCreationParams{ |
|
|
|
if err != nil { |
|
|
|
URL: form.PayloadURL, |
|
|
|
ctx.ServerError("getOrgRepoCtx", err) |
|
|
|
ContentType: webhook.ContentTypeJSON, |
|
|
|
return |
|
|
|
WebhookForm: form.WebhookForm, |
|
|
|
} |
|
|
|
Type: webhook.DISCORD, |
|
|
|
|
|
|
|
Meta: &webhook_service.DiscordMeta{ |
|
|
|
if ctx.HasError() { |
|
|
|
Username: form.Username, |
|
|
|
ctx.HTML(http.StatusOK, orCtx.NewTemplate) |
|
|
|
IconURL: form.IconURL, |
|
|
|
return |
|
|
|
}, |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
meta, err := json.Marshal(&webhook_service.DiscordMeta{ |
|
|
|
|
|
|
|
Username: form.Username, |
|
|
|
|
|
|
|
IconURL: form.IconURL, |
|
|
|
|
|
|
|
}) |
|
|
|
}) |
|
|
|
if err != nil { |
|
|
|
|
|
|
|
ctx.ServerError("Marshal", err) |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
w := &webhook.Webhook{ |
|
|
|
|
|
|
|
RepoID: orCtx.RepoID, |
|
|
|
|
|
|
|
URL: form.PayloadURL, |
|
|
|
|
|
|
|
ContentType: webhook.ContentTypeJSON, |
|
|
|
|
|
|
|
HookEvent: ParseHookEvent(form.WebhookForm), |
|
|
|
|
|
|
|
IsActive: form.Active, |
|
|
|
|
|
|
|
Type: webhook.DISCORD, |
|
|
|
|
|
|
|
Meta: string(meta), |
|
|
|
|
|
|
|
OrgID: orCtx.OrgID, |
|
|
|
|
|
|
|
IsSystemWebhook: orCtx.IsSystemWebhook, |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if err := w.UpdateEvent(); err != nil { |
|
|
|
|
|
|
|
ctx.ServerError("UpdateEvent", err) |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} else if err := webhook.CreateWebhook(ctx, w); err != nil { |
|
|
|
|
|
|
|
ctx.ServerError("CreateWebhook", err) |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ctx.Flash.Success(ctx.Tr("repo.settings.add_hook_success")) |
|
|
|
|
|
|
|
ctx.Redirect(orCtx.Link) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// DingtalkHooksNewPost response for creating dingtalk hook
|
|
|
|
// DingtalkHooksNewPost response for creating dingtalk hook
|
|
|
|
func DingtalkHooksNewPost(ctx *context.Context) { |
|
|
|
func DingtalkHooksNewPost(ctx *context.Context) { |
|
|
|
form := web.GetForm(ctx).(*forms.NewDingtalkHookForm) |
|
|
|
form := web.GetForm(ctx).(*forms.NewDingtalkHookForm) |
|
|
|
ctx.Data["Title"] = ctx.Tr("repo.settings") |
|
|
|
|
|
|
|
ctx.Data["PageIsSettingsHooks"] = true |
|
|
|
|
|
|
|
ctx.Data["PageIsSettingsHooksNew"] = true |
|
|
|
|
|
|
|
ctx.Data["Webhook"] = webhook.Webhook{HookEvent: &webhook.HookEvent{}} |
|
|
|
|
|
|
|
ctx.Data["HookType"] = webhook.DINGTALK |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
orCtx, err := getOrgRepoCtx(ctx) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
ctx.ServerError("getOrgRepoCtx", err) |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ctx.HasError() { |
|
|
|
|
|
|
|
ctx.HTML(http.StatusOK, orCtx.NewTemplate) |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
w := &webhook.Webhook{ |
|
|
|
createWebhook(ctx, webhookCreationParams{ |
|
|
|
RepoID: orCtx.RepoID, |
|
|
|
URL: form.PayloadURL, |
|
|
|
URL: form.PayloadURL, |
|
|
|
ContentType: webhook.ContentTypeJSON, |
|
|
|
ContentType: webhook.ContentTypeJSON, |
|
|
|
WebhookForm: form.WebhookForm, |
|
|
|
HookEvent: ParseHookEvent(form.WebhookForm), |
|
|
|
Type: webhook.DINGTALK, |
|
|
|
IsActive: form.Active, |
|
|
|
}) |
|
|
|
Type: webhook.DINGTALK, |
|
|
|
|
|
|
|
Meta: "", |
|
|
|
|
|
|
|
OrgID: orCtx.OrgID, |
|
|
|
|
|
|
|
IsSystemWebhook: orCtx.IsSystemWebhook, |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if err := w.UpdateEvent(); err != nil { |
|
|
|
|
|
|
|
ctx.ServerError("UpdateEvent", err) |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} else if err := webhook.CreateWebhook(ctx, w); err != nil { |
|
|
|
|
|
|
|
ctx.ServerError("CreateWebhook", err) |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ctx.Flash.Success(ctx.Tr("repo.settings.add_hook_success")) |
|
|
|
|
|
|
|
ctx.Redirect(orCtx.Link) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// TelegramHooksNewPost response for creating telegram hook
|
|
|
|
// TelegramHooksNewPost response for creating telegram hook
|
|
|
|
func TelegramHooksNewPost(ctx *context.Context) { |
|
|
|
func TelegramHooksNewPost(ctx *context.Context) { |
|
|
|
form := web.GetForm(ctx).(*forms.NewTelegramHookForm) |
|
|
|
form := web.GetForm(ctx).(*forms.NewTelegramHookForm) |
|
|
|
ctx.Data["Title"] = ctx.Tr("repo.settings") |
|
|
|
|
|
|
|
ctx.Data["PageIsSettingsHooks"] = true |
|
|
|
|
|
|
|
ctx.Data["PageIsSettingsHooksNew"] = true |
|
|
|
|
|
|
|
ctx.Data["Webhook"] = webhook.Webhook{HookEvent: &webhook.HookEvent{}} |
|
|
|
|
|
|
|
ctx.Data["HookType"] = webhook.TELEGRAM |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
orCtx, err := getOrgRepoCtx(ctx) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
ctx.ServerError("getOrgRepoCtx", err) |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ctx.HasError() { |
|
|
|
|
|
|
|
ctx.HTML(http.StatusOK, orCtx.NewTemplate) |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
meta, err := json.Marshal(&webhook_service.TelegramMeta{ |
|
|
|
createWebhook(ctx, webhookCreationParams{ |
|
|
|
BotToken: form.BotToken, |
|
|
|
URL: fmt.Sprintf("https://api.telegram.org/bot%s/sendMessage?chat_id=%s", url.PathEscape(form.BotToken), url.QueryEscape(form.ChatID)), |
|
|
|
ChatID: form.ChatID, |
|
|
|
ContentType: webhook.ContentTypeJSON, |
|
|
|
|
|
|
|
WebhookForm: form.WebhookForm, |
|
|
|
|
|
|
|
Type: webhook.TELEGRAM, |
|
|
|
|
|
|
|
Meta: &webhook_service.TelegramMeta{ |
|
|
|
|
|
|
|
BotToken: form.BotToken, |
|
|
|
|
|
|
|
ChatID: form.ChatID, |
|
|
|
|
|
|
|
}, |
|
|
|
}) |
|
|
|
}) |
|
|
|
if err != nil { |
|
|
|
|
|
|
|
ctx.ServerError("Marshal", err) |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
w := &webhook.Webhook{ |
|
|
|
|
|
|
|
RepoID: orCtx.RepoID, |
|
|
|
|
|
|
|
URL: fmt.Sprintf("https://api.telegram.org/bot%s/sendMessage?chat_id=%s", url.PathEscape(form.BotToken), url.QueryEscape(form.ChatID)), |
|
|
|
|
|
|
|
ContentType: webhook.ContentTypeJSON, |
|
|
|
|
|
|
|
HookEvent: ParseHookEvent(form.WebhookForm), |
|
|
|
|
|
|
|
IsActive: form.Active, |
|
|
|
|
|
|
|
Type: webhook.TELEGRAM, |
|
|
|
|
|
|
|
Meta: string(meta), |
|
|
|
|
|
|
|
OrgID: orCtx.OrgID, |
|
|
|
|
|
|
|
IsSystemWebhook: orCtx.IsSystemWebhook, |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if err := w.UpdateEvent(); err != nil { |
|
|
|
|
|
|
|
ctx.ServerError("UpdateEvent", err) |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} else if err := webhook.CreateWebhook(ctx, w); err != nil { |
|
|
|
|
|
|
|
ctx.ServerError("CreateWebhook", err) |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ctx.Flash.Success(ctx.Tr("repo.settings.add_hook_success")) |
|
|
|
|
|
|
|
ctx.Redirect(orCtx.Link) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// MatrixHooksNewPost response for creating a Matrix hook
|
|
|
|
// MatrixHooksNewPost response for creating a Matrix hook
|
|
|
|
func MatrixHooksNewPost(ctx *context.Context) { |
|
|
|
func MatrixHooksNewPost(ctx *context.Context) { |
|
|
|
form := web.GetForm(ctx).(*forms.NewMatrixHookForm) |
|
|
|
form := web.GetForm(ctx).(*forms.NewMatrixHookForm) |
|
|
|
ctx.Data["Title"] = ctx.Tr("repo.settings") |
|
|
|
|
|
|
|
ctx.Data["PageIsSettingsHooks"] = true |
|
|
|
|
|
|
|
ctx.Data["PageIsSettingsHooksNew"] = true |
|
|
|
|
|
|
|
ctx.Data["Webhook"] = webhook.Webhook{HookEvent: &webhook.HookEvent{}} |
|
|
|
|
|
|
|
ctx.Data["HookType"] = webhook.MATRIX |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
orCtx, err := getOrgRepoCtx(ctx) |
|
|
|
createWebhook(ctx, webhookCreationParams{ |
|
|
|
if err != nil { |
|
|
|
URL: fmt.Sprintf("%s/_matrix/client/r0/rooms/%s/send/m.room.message", form.HomeserverURL, url.PathEscape(form.RoomID)), |
|
|
|
ctx.ServerError("getOrgRepoCtx", err) |
|
|
|
ContentType: webhook.ContentTypeJSON, |
|
|
|
return |
|
|
|
HTTPMethod: http.MethodPut, |
|
|
|
} |
|
|
|
WebhookForm: form.WebhookForm, |
|
|
|
|
|
|
|
Type: webhook.MATRIX, |
|
|
|
if ctx.HasError() { |
|
|
|
Meta: &webhook_service.MatrixMeta{ |
|
|
|
ctx.HTML(http.StatusOK, orCtx.NewTemplate) |
|
|
|
HomeserverURL: form.HomeserverURL, |
|
|
|
return |
|
|
|
Room: form.RoomID, |
|
|
|
} |
|
|
|
AccessToken: form.AccessToken, |
|
|
|
|
|
|
|
MessageType: form.MessageType, |
|
|
|
meta, err := json.Marshal(&webhook_service.MatrixMeta{ |
|
|
|
}, |
|
|
|
HomeserverURL: form.HomeserverURL, |
|
|
|
|
|
|
|
Room: form.RoomID, |
|
|
|
|
|
|
|
AccessToken: form.AccessToken, |
|
|
|
|
|
|
|
MessageType: form.MessageType, |
|
|
|
|
|
|
|
}) |
|
|
|
}) |
|
|
|
if err != nil { |
|
|
|
|
|
|
|
ctx.ServerError("Marshal", err) |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
w := &webhook.Webhook{ |
|
|
|
|
|
|
|
RepoID: orCtx.RepoID, |
|
|
|
|
|
|
|
URL: fmt.Sprintf("%s/_matrix/client/r0/rooms/%s/send/m.room.message", form.HomeserverURL, url.PathEscape(form.RoomID)), |
|
|
|
|
|
|
|
ContentType: webhook.ContentTypeJSON, |
|
|
|
|
|
|
|
HTTPMethod: "PUT", |
|
|
|
|
|
|
|
HookEvent: ParseHookEvent(form.WebhookForm), |
|
|
|
|
|
|
|
IsActive: form.Active, |
|
|
|
|
|
|
|
Type: webhook.MATRIX, |
|
|
|
|
|
|
|
Meta: string(meta), |
|
|
|
|
|
|
|
OrgID: orCtx.OrgID, |
|
|
|
|
|
|
|
IsSystemWebhook: orCtx.IsSystemWebhook, |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if err := w.UpdateEvent(); err != nil { |
|
|
|
|
|
|
|
ctx.ServerError("UpdateEvent", err) |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} else if err := webhook.CreateWebhook(ctx, w); err != nil { |
|
|
|
|
|
|
|
ctx.ServerError("CreateWebhook", err) |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ctx.Flash.Success(ctx.Tr("repo.settings.add_hook_success")) |
|
|
|
|
|
|
|
ctx.Redirect(orCtx.Link) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// MSTeamsHooksNewPost response for creating MS Teams hook
|
|
|
|
// MSTeamsHooksNewPost response for creating MS Teams hook
|
|
|
|
func MSTeamsHooksNewPost(ctx *context.Context) { |
|
|
|
func MSTeamsHooksNewPost(ctx *context.Context) { |
|
|
|
form := web.GetForm(ctx).(*forms.NewMSTeamsHookForm) |
|
|
|
form := web.GetForm(ctx).(*forms.NewMSTeamsHookForm) |
|
|
|
ctx.Data["Title"] = ctx.Tr("repo.settings") |
|
|
|
|
|
|
|
ctx.Data["PageIsSettingsHooks"] = true |
|
|
|
|
|
|
|
ctx.Data["PageIsSettingsHooksNew"] = true |
|
|
|
|
|
|
|
ctx.Data["Webhook"] = webhook.Webhook{HookEvent: &webhook.HookEvent{}} |
|
|
|
|
|
|
|
ctx.Data["HookType"] = webhook.MSTEAMS |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
orCtx, err := getOrgRepoCtx(ctx) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
ctx.ServerError("getOrgRepoCtx", err) |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ctx.HasError() { |
|
|
|
createWebhook(ctx, webhookCreationParams{ |
|
|
|
ctx.HTML(http.StatusOK, orCtx.NewTemplate) |
|
|
|
URL: form.PayloadURL, |
|
|
|
return |
|
|
|
ContentType: webhook.ContentTypeJSON, |
|
|
|
} |
|
|
|
WebhookForm: form.WebhookForm, |
|
|
|
|
|
|
|
Type: webhook.MSTEAMS, |
|
|
|
w := &webhook.Webhook{ |
|
|
|
}) |
|
|
|
RepoID: orCtx.RepoID, |
|
|
|
|
|
|
|
URL: form.PayloadURL, |
|
|
|
|
|
|
|
ContentType: webhook.ContentTypeJSON, |
|
|
|
|
|
|
|
HookEvent: ParseHookEvent(form.WebhookForm), |
|
|
|
|
|
|
|
IsActive: form.Active, |
|
|
|
|
|
|
|
Type: webhook.MSTEAMS, |
|
|
|
|
|
|
|
Meta: "", |
|
|
|
|
|
|
|
OrgID: orCtx.OrgID, |
|
|
|
|
|
|
|
IsSystemWebhook: orCtx.IsSystemWebhook, |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if err := w.UpdateEvent(); err != nil { |
|
|
|
|
|
|
|
ctx.ServerError("UpdateEvent", err) |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} else if err := webhook.CreateWebhook(ctx, w); err != nil { |
|
|
|
|
|
|
|
ctx.ServerError("CreateWebhook", err) |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ctx.Flash.Success(ctx.Tr("repo.settings.add_hook_success")) |
|
|
|
|
|
|
|
ctx.Redirect(orCtx.Link) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// SlackHooksNewPost response for creating slack hook
|
|
|
|
// SlackHooksNewPost response for creating slack hook
|
|
|
|
func SlackHooksNewPost(ctx *context.Context) { |
|
|
|
func SlackHooksNewPost(ctx *context.Context) { |
|
|
|
form := web.GetForm(ctx).(*forms.NewSlackHookForm) |
|
|
|
form := web.GetForm(ctx).(*forms.NewSlackHookForm) |
|
|
|
ctx.Data["Title"] = ctx.Tr("repo.settings") |
|
|
|
|
|
|
|
ctx.Data["PageIsSettingsHooks"] = true |
|
|
|
|
|
|
|
ctx.Data["PageIsSettingsHooksNew"] = true |
|
|
|
|
|
|
|
ctx.Data["Webhook"] = webhook.Webhook{HookEvent: &webhook.HookEvent{}} |
|
|
|
|
|
|
|
ctx.Data["HookType"] = webhook.SLACK |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
orCtx, err := getOrgRepoCtx(ctx) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
ctx.ServerError("getOrgRepoCtx", err) |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ctx.HasError() { |
|
|
|
|
|
|
|
ctx.HTML(http.StatusOK, orCtx.NewTemplate) |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if form.HasInvalidChannel() { |
|
|
|
|
|
|
|
ctx.Flash.Error(ctx.Tr("repo.settings.add_webhook.invalid_channel_name")) |
|
|
|
|
|
|
|
ctx.Redirect(orCtx.LinkNew + "/slack/new") |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
meta, err := json.Marshal(&webhook_service.SlackMeta{ |
|
|
|
createWebhook(ctx, webhookCreationParams{ |
|
|
|
Channel: strings.TrimSpace(form.Channel), |
|
|
|
URL: form.PayloadURL, |
|
|
|
Username: form.Username, |
|
|
|
ContentType: webhook.ContentTypeJSON, |
|
|
|
IconURL: form.IconURL, |
|
|
|
WebhookForm: form.WebhookForm, |
|
|
|
Color: form.Color, |
|
|
|
Type: webhook.SLACK, |
|
|
|
|
|
|
|
Meta: &webhook_service.SlackMeta{ |
|
|
|
|
|
|
|
Channel: strings.TrimSpace(form.Channel), |
|
|
|
|
|
|
|
Username: form.Username, |
|
|
|
|
|
|
|
IconURL: form.IconURL, |
|
|
|
|
|
|
|
Color: form.Color, |
|
|
|
|
|
|
|
}, |
|
|
|
}) |
|
|
|
}) |
|
|
|
if err != nil { |
|
|
|
|
|
|
|
ctx.ServerError("Marshal", err) |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
w := &webhook.Webhook{ |
|
|
|
|
|
|
|
RepoID: orCtx.RepoID, |
|
|
|
|
|
|
|
URL: form.PayloadURL, |
|
|
|
|
|
|
|
ContentType: webhook.ContentTypeJSON, |
|
|
|
|
|
|
|
HookEvent: ParseHookEvent(form.WebhookForm), |
|
|
|
|
|
|
|
IsActive: form.Active, |
|
|
|
|
|
|
|
Type: webhook.SLACK, |
|
|
|
|
|
|
|
Meta: string(meta), |
|
|
|
|
|
|
|
OrgID: orCtx.OrgID, |
|
|
|
|
|
|
|
IsSystemWebhook: orCtx.IsSystemWebhook, |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if err := w.UpdateEvent(); err != nil { |
|
|
|
|
|
|
|
ctx.ServerError("UpdateEvent", err) |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} else if err := webhook.CreateWebhook(ctx, w); err != nil { |
|
|
|
|
|
|
|
ctx.ServerError("CreateWebhook", err) |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ctx.Flash.Success(ctx.Tr("repo.settings.add_hook_success")) |
|
|
|
|
|
|
|
ctx.Redirect(orCtx.Link) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// FeishuHooksNewPost response for creating feishu hook
|
|
|
|
// FeishuHooksNewPost response for creating feishu hook
|
|
|
|
func FeishuHooksNewPost(ctx *context.Context) { |
|
|
|
func FeishuHooksNewPost(ctx *context.Context) { |
|
|
|
form := web.GetForm(ctx).(*forms.NewFeishuHookForm) |
|
|
|
form := web.GetForm(ctx).(*forms.NewFeishuHookForm) |
|
|
|
ctx.Data["Title"] = ctx.Tr("repo.settings") |
|
|
|
|
|
|
|
ctx.Data["PageIsSettingsHooks"] = true |
|
|
|
|
|
|
|
ctx.Data["PageIsSettingsHooksNew"] = true |
|
|
|
|
|
|
|
ctx.Data["Webhook"] = webhook.Webhook{HookEvent: &webhook.HookEvent{}} |
|
|
|
|
|
|
|
ctx.Data["HookType"] = webhook.FEISHU |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
orCtx, err := getOrgRepoCtx(ctx) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
ctx.ServerError("getOrgRepoCtx", err) |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ctx.HasError() { |
|
|
|
createWebhook(ctx, webhookCreationParams{ |
|
|
|
ctx.HTML(http.StatusOK, orCtx.NewTemplate) |
|
|
|
URL: form.PayloadURL, |
|
|
|
return |
|
|
|
ContentType: webhook.ContentTypeJSON, |
|
|
|
} |
|
|
|
WebhookForm: form.WebhookForm, |
|
|
|
|
|
|
|
Type: webhook.FEISHU, |
|
|
|
w := &webhook.Webhook{ |
|
|
|
}) |
|
|
|
RepoID: orCtx.RepoID, |
|
|
|
|
|
|
|
URL: form.PayloadURL, |
|
|
|
|
|
|
|
ContentType: webhook.ContentTypeJSON, |
|
|
|
|
|
|
|
HookEvent: ParseHookEvent(form.WebhookForm), |
|
|
|
|
|
|
|
IsActive: form.Active, |
|
|
|
|
|
|
|
Type: webhook.FEISHU, |
|
|
|
|
|
|
|
Meta: "", |
|
|
|
|
|
|
|
OrgID: orCtx.OrgID, |
|
|
|
|
|
|
|
IsSystemWebhook: orCtx.IsSystemWebhook, |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if err := w.UpdateEvent(); err != nil { |
|
|
|
|
|
|
|
ctx.ServerError("UpdateEvent", err) |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} else if err := webhook.CreateWebhook(ctx, w); err != nil { |
|
|
|
|
|
|
|
ctx.ServerError("CreateWebhook", err) |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ctx.Flash.Success(ctx.Tr("repo.settings.add_hook_success")) |
|
|
|
|
|
|
|
ctx.Redirect(orCtx.Link) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// WechatworkHooksNewPost response for creating wechatwork hook
|
|
|
|
// WechatworkHooksNewPost response for creating wechatwork hook
|
|
|
|
func WechatworkHooksNewPost(ctx *context.Context) { |
|
|
|
func WechatworkHooksNewPost(ctx *context.Context) { |
|
|
|
form := web.GetForm(ctx).(*forms.NewWechatWorkHookForm) |
|
|
|
form := web.GetForm(ctx).(*forms.NewWechatWorkHookForm) |
|
|
|
|
|
|
|
|
|
|
|
ctx.Data["Title"] = ctx.Tr("repo.settings") |
|
|
|
createWebhook(ctx, webhookCreationParams{ |
|
|
|
ctx.Data["PageIsSettingsHooks"] = true |
|
|
|
URL: form.PayloadURL, |
|
|
|
ctx.Data["PageIsSettingsHooksNew"] = true |
|
|
|
ContentType: webhook.ContentTypeJSON, |
|
|
|
ctx.Data["Webhook"] = webhook.Webhook{HookEvent: &webhook.HookEvent{}} |
|
|
|
WebhookForm: form.WebhookForm, |
|
|
|
ctx.Data["HookType"] = webhook.WECHATWORK |
|
|
|
Type: webhook.WECHATWORK, |
|
|
|
|
|
|
|
}) |
|
|
|
orCtx, err := getOrgRepoCtx(ctx) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
ctx.ServerError("getOrgRepoCtx", err) |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ctx.HasError() { |
|
|
|
|
|
|
|
ctx.HTML(http.StatusOK, orCtx.NewTemplate) |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
w := &webhook.Webhook{ |
|
|
|
|
|
|
|
RepoID: orCtx.RepoID, |
|
|
|
|
|
|
|
URL: form.PayloadURL, |
|
|
|
|
|
|
|
ContentType: webhook.ContentTypeJSON, |
|
|
|
|
|
|
|
HookEvent: ParseHookEvent(form.WebhookForm), |
|
|
|
|
|
|
|
IsActive: form.Active, |
|
|
|
|
|
|
|
Type: webhook.WECHATWORK, |
|
|
|
|
|
|
|
Meta: "", |
|
|
|
|
|
|
|
OrgID: orCtx.OrgID, |
|
|
|
|
|
|
|
IsSystemWebhook: orCtx.IsSystemWebhook, |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if err := w.UpdateEvent(); err != nil { |
|
|
|
|
|
|
|
ctx.ServerError("UpdateEvent", err) |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} else if err := webhook.CreateWebhook(ctx, w); err != nil { |
|
|
|
|
|
|
|
ctx.ServerError("CreateWebhook", err) |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ctx.Flash.Success(ctx.Tr("repo.settings.add_hook_success")) |
|
|
|
|
|
|
|
ctx.Redirect(orCtx.Link) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// PackagistHooksNewPost response for creating packagist hook
|
|
|
|
// PackagistHooksNewPost response for creating packagist hook
|
|
|
|
func PackagistHooksNewPost(ctx *context.Context) { |
|
|
|
func PackagistHooksNewPost(ctx *context.Context) { |
|
|
|
form := web.GetForm(ctx).(*forms.NewPackagistHookForm) |
|
|
|
form := web.GetForm(ctx).(*forms.NewPackagistHookForm) |
|
|
|
ctx.Data["Title"] = ctx.Tr("repo.settings") |
|
|
|
|
|
|
|
ctx.Data["PageIsSettingsHooks"] = true |
|
|
|
|
|
|
|
ctx.Data["PageIsSettingsHooksNew"] = true |
|
|
|
|
|
|
|
ctx.Data["Webhook"] = webhook.Webhook{HookEvent: &webhook.HookEvent{}} |
|
|
|
|
|
|
|
ctx.Data["HookType"] = webhook.PACKAGIST |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
orCtx, err := getOrgRepoCtx(ctx) |
|
|
|
createWebhook(ctx, webhookCreationParams{ |
|
|
|
if err != nil { |
|
|
|
URL: fmt.Sprintf("https://packagist.org/api/update-package?username=%s&apiToken=%s", url.QueryEscape(form.Username), url.QueryEscape(form.APIToken)), |
|
|
|
ctx.ServerError("getOrgRepoCtx", err) |
|
|
|
ContentType: webhook.ContentTypeJSON, |
|
|
|
return |
|
|
|
WebhookForm: form.WebhookForm, |
|
|
|
} |
|
|
|
Type: webhook.PACKAGIST, |
|
|
|
|
|
|
|
Meta: &webhook_service.PackagistMeta{ |
|
|
|
if ctx.HasError() { |
|
|
|
Username: form.Username, |
|
|
|
ctx.HTML(http.StatusOK, orCtx.NewTemplate) |
|
|
|
APIToken: form.APIToken, |
|
|
|
return |
|
|
|
PackageURL: form.PackageURL, |
|
|
|
} |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
meta, err := json.Marshal(&webhook_service.PackagistMeta{ |
|
|
|
|
|
|
|
Username: form.Username, |
|
|
|
|
|
|
|
APIToken: form.APIToken, |
|
|
|
|
|
|
|
PackageURL: form.PackageURL, |
|
|
|
|
|
|
|
}) |
|
|
|
}) |
|
|
|
if err != nil { |
|
|
|
|
|
|
|
ctx.ServerError("Marshal", err) |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
w := &webhook.Webhook{ |
|
|
|
|
|
|
|
RepoID: orCtx.RepoID, |
|
|
|
|
|
|
|
URL: fmt.Sprintf("https://packagist.org/api/update-package?username=%s&apiToken=%s", url.QueryEscape(form.Username), url.QueryEscape(form.APIToken)), |
|
|
|
|
|
|
|
ContentType: webhook.ContentTypeJSON, |
|
|
|
|
|
|
|
HookEvent: ParseHookEvent(form.WebhookForm), |
|
|
|
|
|
|
|
IsActive: form.Active, |
|
|
|
|
|
|
|
Type: webhook.PACKAGIST, |
|
|
|
|
|
|
|
Meta: string(meta), |
|
|
|
|
|
|
|
OrgID: orCtx.OrgID, |
|
|
|
|
|
|
|
IsSystemWebhook: orCtx.IsSystemWebhook, |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if err := w.UpdateEvent(); err != nil { |
|
|
|
|
|
|
|
ctx.ServerError("UpdateEvent", err) |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} else if err := webhook.CreateWebhook(ctx, w); err != nil { |
|
|
|
|
|
|
|
ctx.ServerError("CreateWebhook", err) |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ctx.Flash.Success(ctx.Tr("repo.settings.add_hook_success")) |
|
|
|
|
|
|
|
ctx.Redirect(orCtx.Link) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func checkWebhook(ctx *context.Context) (*orgRepoCtx, *webhook.Webhook) { |
|
|
|
func checkWebhook(ctx *context.Context) (*orgRepoCtx, *webhook.Webhook) { |
|
|
@ -894,12 +579,6 @@ func SlackHooksEditPost(ctx *context.Context) { |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if form.HasInvalidChannel() { |
|
|
|
|
|
|
|
ctx.Flash.Error(ctx.Tr("repo.settings.add_webhook.invalid_channel_name")) |
|
|
|
|
|
|
|
ctx.Redirect(fmt.Sprintf("%s/%d", orCtx.Link, w.ID)) |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
meta, err := json.Marshal(&webhook_service.SlackMeta{ |
|
|
|
meta, err := json.Marshal(&webhook_service.SlackMeta{ |
|
|
|
Channel: strings.TrimSpace(form.Channel), |
|
|
|
Channel: strings.TrimSpace(form.Channel), |
|
|
|
Username: form.Username, |
|
|
|
Username: form.Username, |
|
|
|