aboutsummaryrefslogtreecommitdiff
path: root/routers/repo/webhook.go
diff options
context:
space:
mode:
Diffstat (limited to 'routers/repo/webhook.go')
-rw-r--r--routers/repo/webhook.go338
1 files changed, 169 insertions, 169 deletions
diff --git a/routers/repo/webhook.go b/routers/repo/webhook.go
index a0888877..c572d446 100644
--- a/routers/repo/webhook.go
+++ b/routers/repo/webhook.go
@@ -27,21 +27,21 @@ const (
ORG_WEBHOOK_NEW = "org/settings/webhook_new"
)
-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["Description"] = ctx.Tr("repo.settings.hooks_desc", "https://github.com/gogits/go-gogs-client/wiki/Repositories-Webhooks")
- ctx.Data["Types"] = setting.Webhook.Types
-
- ws, err := models.GetWebhooksByRepoID(ctx.Repo.Repository.ID)
+func Webhooks(c *context.Context) {
+ c.Data["Title"] = c.Tr("repo.settings.hooks")
+ c.Data["PageIsSettingsHooks"] = true
+ c.Data["BaseLink"] = c.Repo.RepoLink
+ c.Data["Description"] = c.Tr("repo.settings.hooks_desc", "https://github.com/gogits/go-gogs-client/wiki/Repositories-Webhooks")
+ c.Data["Types"] = setting.Webhook.Types
+
+ ws, err := models.GetWebhooksByRepoID(c.Repo.Repository.ID)
if err != nil {
- ctx.Handle(500, "GetWebhooksByRepoID", err)
+ c.Handle(500, "GetWebhooksByRepoID", err)
return
}
- ctx.Data["Webhooks"] = ws
+ c.Data["Webhooks"] = ws
- ctx.HTML(200, WEBHOOKS)
+ c.HTML(200, WEBHOOKS)
}
type OrgRepoCtx struct {
@@ -52,21 +52,21 @@ type OrgRepoCtx struct {
}
// getOrgRepoCtx determines whether this is a repo context or organization context.
-func getOrgRepoCtx(ctx *context.Context) (*OrgRepoCtx, error) {
- if len(ctx.Repo.RepoLink) > 0 {
- ctx.Data["PageIsRepositoryContext"] = true
+func getOrgRepoCtx(c *context.Context) (*OrgRepoCtx, error) {
+ if len(c.Repo.RepoLink) > 0 {
+ c.Data["PageIsRepositoryContext"] = true
return &OrgRepoCtx{
- RepoID: ctx.Repo.Repository.ID,
- Link: ctx.Repo.RepoLink,
+ RepoID: c.Repo.Repository.ID,
+ Link: c.Repo.RepoLink,
NewTemplate: WEBHOOK_NEW,
}, nil
}
- if len(ctx.Org.OrgLink) > 0 {
- ctx.Data["PageIsOrganizationContext"] = true
+ if len(c.Org.OrgLink) > 0 {
+ c.Data["PageIsOrganizationContext"] = true
return &OrgRepoCtx{
- OrgID: ctx.Org.Organization.ID,
- Link: ctx.Org.OrgLink,
+ OrgID: c.Org.Organization.ID,
+ Link: c.Org.OrgLink,
NewTemplate: ORG_WEBHOOK_NEW,
}, nil
}
@@ -74,34 +74,34 @@ func getOrgRepoCtx(ctx *context.Context) (*OrgRepoCtx, error) {
return nil, errors.New("Unable to set OrgRepo context")
}
-func checkHookType(ctx *context.Context) string {
- hookType := strings.ToLower(ctx.Params(":type"))
+func checkHookType(c *context.Context) string {
+ hookType := strings.ToLower(c.Params(":type"))
if !com.IsSliceContainsStr(setting.Webhook.Types, hookType) {
- ctx.Handle(404, "checkHookType", nil)
+ c.Handle(404, "checkHookType", nil)
return ""
}
return hookType
}
-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{}}
+func WebhooksNew(c *context.Context) {
+ c.Data["Title"] = c.Tr("repo.settings.add_webhook")
+ c.Data["PageIsSettingsHooks"] = true
+ c.Data["PageIsSettingsHooksNew"] = true
+ c.Data["Webhook"] = models.Webhook{HookEvent: &models.HookEvent{}}
- orCtx, err := getOrgRepoCtx(ctx)
+ orCtx, err := getOrgRepoCtx(c)
if err != nil {
- ctx.Handle(500, "getOrgRepoCtx", err)
+ c.Handle(500, "getOrgRepoCtx", err)
return
}
- ctx.Data["HookType"] = checkHookType(ctx)
- if ctx.Written() {
+ c.Data["HookType"] = checkHookType(c)
+ if c.Written() {
return
}
- ctx.Data["BaseLink"] = orCtx.Link
+ c.Data["BaseLink"] = orCtx.Link
- ctx.HTML(200, orCtx.NewTemplate)
+ c.HTML(200, orCtx.NewTemplate)
}
func ParseHookEvent(f form.Webhook) *models.HookEvent {
@@ -122,22 +122,22 @@ func ParseHookEvent(f form.Webhook) *models.HookEvent {
}
}
-func WebHooksNewPost(ctx *context.Context, f form.NewWebhook) {
- 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{}}
- ctx.Data["HookType"] = "gogs"
+func WebHooksNewPost(c *context.Context, f form.NewWebhook) {
+ c.Data["Title"] = c.Tr("repo.settings.add_webhook")
+ c.Data["PageIsSettingsHooks"] = true
+ c.Data["PageIsSettingsHooksNew"] = true
+ c.Data["Webhook"] = models.Webhook{HookEvent: &models.HookEvent{}}
+ c.Data["HookType"] = "gogs"
- orCtx, err := getOrgRepoCtx(ctx)
+ orCtx, err := getOrgRepoCtx(c)
if err != nil {
- ctx.Handle(500, "getOrgRepoCtx", err)
+ c.Handle(500, "getOrgRepoCtx", err)
return
}
- ctx.Data["BaseLink"] = orCtx.Link
+ c.Data["BaseLink"] = orCtx.Link
- if ctx.HasError() {
- ctx.HTML(200, orCtx.NewTemplate)
+ if c.HasError() {
+ c.HTML(200, orCtx.NewTemplate)
return
}
@@ -157,31 +157,31 @@ func WebHooksNewPost(ctx *context.Context, f form.NewWebhook) {
OrgID: orCtx.OrgID,
}
if err := w.UpdateEvent(); err != nil {
- ctx.Handle(500, "UpdateEvent", err)
+ c.Handle(500, "UpdateEvent", err)
return
} else if err := models.CreateWebhook(w); err != nil {
- ctx.Handle(500, "CreateWebhook", err)
+ c.Handle(500, "CreateWebhook", err)
return
}
- ctx.Flash.Success(ctx.Tr("repo.settings.add_hook_success"))
- ctx.Redirect(orCtx.Link + "/settings/hooks")
+ c.Flash.Success(c.Tr("repo.settings.add_hook_success"))
+ c.Redirect(orCtx.Link + "/settings/hooks")
}
-func SlackHooksNewPost(ctx *context.Context, f form.NewSlackHook) {
- ctx.Data["Title"] = ctx.Tr("repo.settings")
- ctx.Data["PageIsSettingsHooks"] = true
- ctx.Data["PageIsSettingsHooksNew"] = true
- ctx.Data["Webhook"] = models.Webhook{HookEvent: &models.HookEvent{}}
+func SlackHooksNewPost(c *context.Context, f form.NewSlackHook) {
+ c.Data["Title"] = c.Tr("repo.settings")
+ c.Data["PageIsSettingsHooks"] = true
+ c.Data["PageIsSettingsHooksNew"] = true
+ c.Data["Webhook"] = models.Webhook{HookEvent: &models.HookEvent{}}
- orCtx, err := getOrgRepoCtx(ctx)
+ orCtx, err := getOrgRepoCtx(c)
if err != nil {
- ctx.Handle(500, "getOrgRepoCtx", err)
+ c.Handle(500, "getOrgRepoCtx", err)
return
}
- if ctx.HasError() {
- ctx.HTML(200, orCtx.NewTemplate)
+ if c.HasError() {
+ c.HTML(200, orCtx.NewTemplate)
return
}
@@ -192,7 +192,7 @@ func SlackHooksNewPost(ctx *context.Context, f form.NewSlackHook) {
Color: f.Color,
})
if err != nil {
- ctx.Handle(500, "Marshal", err)
+ c.Handle(500, "Marshal", err)
return
}
@@ -207,32 +207,32 @@ func SlackHooksNewPost(ctx *context.Context, f form.NewSlackHook) {
OrgID: orCtx.OrgID,
}
if err := w.UpdateEvent(); err != nil {
- ctx.Handle(500, "UpdateEvent", err)
+ c.Handle(500, "UpdateEvent", err)
return
} else if err := models.CreateWebhook(w); err != nil {
- ctx.Handle(500, "CreateWebhook", err)
+ c.Handle(500, "CreateWebhook", err)
return
}
- ctx.Flash.Success(ctx.Tr("repo.settings.add_hook_success"))
- ctx.Redirect(orCtx.Link + "/settings/hooks")
+ c.Flash.Success(c.Tr("repo.settings.add_hook_success"))
+ c.Redirect(orCtx.Link + "/settings/hooks")
}
// FIXME: merge logic to Slack
-func DiscordHooksNewPost(ctx *context.Context, f form.NewDiscordHook) {
- ctx.Data["Title"] = ctx.Tr("repo.settings")
- ctx.Data["PageIsSettingsHooks"] = true
- ctx.Data["PageIsSettingsHooksNew"] = true
- ctx.Data["Webhook"] = models.Webhook{HookEvent: &models.HookEvent{}}
+func DiscordHooksNewPost(c *context.Context, f form.NewDiscordHook) {
+ c.Data["Title"] = c.Tr("repo.settings")
+ c.Data["PageIsSettingsHooks"] = true
+ c.Data["PageIsSettingsHooksNew"] = true
+ c.Data["Webhook"] = models.Webhook{HookEvent: &models.HookEvent{}}
- orCtx, err := getOrgRepoCtx(ctx)
+ orCtx, err := getOrgRepoCtx(c)
if err != nil {
- ctx.Handle(500, "getOrgRepoCtx", err)
+ c.Handle(500, "getOrgRepoCtx", err)
return
}
- if ctx.HasError() {
- ctx.HTML(200, orCtx.NewTemplate)
+ if c.HasError() {
+ c.HTML(200, orCtx.NewTemplate)
return
}
@@ -242,7 +242,7 @@ func DiscordHooksNewPost(ctx *context.Context, f form.NewDiscordHook) {
Color: f.Color,
})
if err != nil {
- ctx.Handle(500, "Marshal", err)
+ c.Handle(500, "Marshal", err)
return
}
@@ -257,83 +257,83 @@ func DiscordHooksNewPost(ctx *context.Context, f form.NewDiscordHook) {
OrgID: orCtx.OrgID,
}
if err := w.UpdateEvent(); err != nil {
- ctx.Handle(500, "UpdateEvent", err)
+ c.Handle(500, "UpdateEvent", err)
return
} else if err := models.CreateWebhook(w); err != nil {
- ctx.Handle(500, "CreateWebhook", err)
+ c.Handle(500, "CreateWebhook", err)
return
}
- ctx.Flash.Success(ctx.Tr("repo.settings.add_hook_success"))
- ctx.Redirect(orCtx.Link + "/settings/hooks")
+ c.Flash.Success(c.Tr("repo.settings.add_hook_success"))
+ c.Redirect(orCtx.Link + "/settings/hooks")
}
-func checkWebhook(ctx *context.Context) (*OrgRepoCtx, *models.Webhook) {
- ctx.Data["RequireHighlightJS"] = true
+func checkWebhook(c *context.Context) (*OrgRepoCtx, *models.Webhook) {
+ c.Data["RequireHighlightJS"] = true
- orCtx, err := getOrgRepoCtx(ctx)
+ orCtx, err := getOrgRepoCtx(c)
if err != nil {
- ctx.Handle(500, "getOrgRepoCtx", err)
+ c.Handle(500, "getOrgRepoCtx", err)
return nil, nil
}
- ctx.Data["BaseLink"] = orCtx.Link
+ c.Data["BaseLink"] = orCtx.Link
var w *models.Webhook
if orCtx.RepoID > 0 {
- w, err = models.GetWebhookOfRepoByID(ctx.Repo.Repository.ID, ctx.ParamsInt64(":id"))
+ w, err = models.GetWebhookOfRepoByID(c.Repo.Repository.ID, c.ParamsInt64(":id"))
} else {
- w, err = models.GetWebhookByOrgID(ctx.Org.Organization.ID, ctx.ParamsInt64(":id"))
+ w, err = models.GetWebhookByOrgID(c.Org.Organization.ID, c.ParamsInt64(":id"))
}
if err != nil {
- ctx.NotFoundOrServerError("GetWebhookOfRepoByID/GetWebhookByOrgID", errors.IsWebhookNotExist, err)
+ c.NotFoundOrServerError("GetWebhookOfRepoByID/GetWebhookByOrgID", errors.IsWebhookNotExist, err)
return nil, nil
}
switch w.HookTaskType {
case models.SLACK:
- ctx.Data["SlackHook"] = w.GetSlackHook()
- ctx.Data["HookType"] = "slack"
+ c.Data["SlackHook"] = w.GetSlackHook()
+ c.Data["HookType"] = "slack"
case models.DISCORD:
- ctx.Data["SlackHook"] = w.GetSlackHook()
- ctx.Data["HookType"] = "discord"
+ c.Data["SlackHook"] = w.GetSlackHook()
+ c.Data["HookType"] = "discord"
default:
- ctx.Data["HookType"] = "gogs"
+ c.Data["HookType"] = "gogs"
}
- ctx.Data["History"], err = w.History(1)
+ c.Data["History"], err = w.History(1)
if err != nil {
- ctx.Handle(500, "History", err)
+ c.Handle(500, "History", err)
}
return orCtx, w
}
-func WebHooksEdit(ctx *context.Context) {
- ctx.Data["Title"] = ctx.Tr("repo.settings.update_webhook")
- ctx.Data["PageIsSettingsHooks"] = true
- ctx.Data["PageIsSettingsHooksEdit"] = true
+func WebHooksEdit(c *context.Context) {
+ c.Data["Title"] = c.Tr("repo.settings.update_webhook")
+ c.Data["PageIsSettingsHooks"] = true
+ c.Data["PageIsSettingsHooksEdit"] = true
- orCtx, w := checkWebhook(ctx)
- if ctx.Written() {
+ orCtx, w := checkWebhook(c)
+ if c.Written() {
return
}
- ctx.Data["Webhook"] = w
+ c.Data["Webhook"] = w
- ctx.HTML(200, orCtx.NewTemplate)
+ c.HTML(200, orCtx.NewTemplate)
}
-func WebHooksEditPost(ctx *context.Context, f form.NewWebhook) {
- ctx.Data["Title"] = ctx.Tr("repo.settings.update_webhook")
- ctx.Data["PageIsSettingsHooks"] = true
- ctx.Data["PageIsSettingsHooksEdit"] = true
+func WebHooksEditPost(c *context.Context, f form.NewWebhook) {
+ c.Data["Title"] = c.Tr("repo.settings.update_webhook")
+ c.Data["PageIsSettingsHooks"] = true
+ c.Data["PageIsSettingsHooksEdit"] = true
- orCtx, w := checkWebhook(ctx)
- if ctx.Written() {
+ orCtx, w := checkWebhook(c)
+ if c.Written() {
return
}
- ctx.Data["Webhook"] = w
+ c.Data["Webhook"] = w
- if ctx.HasError() {
- ctx.HTML(200, orCtx.NewTemplate)
+ if c.HasError() {
+ c.HTML(200, orCtx.NewTemplate)
return
}
@@ -348,30 +348,30 @@ func WebHooksEditPost(ctx *context.Context, f form.NewWebhook) {
w.HookEvent = ParseHookEvent(f.Webhook)
w.IsActive = f.Active
if err := w.UpdateEvent(); err != nil {
- ctx.Handle(500, "UpdateEvent", err)
+ c.Handle(500, "UpdateEvent", err)
return
} else if err := models.UpdateWebhook(w); err != nil {
- ctx.Handle(500, "WebHooksEditPost", err)
+ c.Handle(500, "WebHooksEditPost", err)
return
}
- ctx.Flash.Success(ctx.Tr("repo.settings.update_hook_success"))
- ctx.Redirect(fmt.Sprintf("%s/settings/hooks/%d", orCtx.Link, w.ID))
+ c.Flash.Success(c.Tr("repo.settings.update_hook_success"))
+ c.Redirect(fmt.Sprintf("%s/settings/hooks/%d", orCtx.Link, w.ID))
}
-func SlackHooksEditPost(ctx *context.Context, f form.NewSlackHook) {
- ctx.Data["Title"] = ctx.Tr("repo.settings")
- ctx.Data["PageIsSettingsHooks"] = true
- ctx.Data["PageIsSettingsHooksEdit"] = true
+func SlackHooksEditPost(c *context.Context, f form.NewSlackHook) {
+ c.Data["Title"] = c.Tr("repo.settings")
+ c.Data["PageIsSettingsHooks"] = true
+ c.Data["PageIsSettingsHooksEdit"] = true
- orCtx, w := checkWebhook(ctx)
- if ctx.Written() {
+ orCtx, w := checkWebhook(c)
+ if c.Written() {
return
}
- ctx.Data["Webhook"] = w
+ c.Data["Webhook"] = w
- if ctx.HasError() {
- ctx.HTML(200, orCtx.NewTemplate)
+ if c.HasError() {
+ c.HTML(200, orCtx.NewTemplate)
return
}
@@ -382,7 +382,7 @@ func SlackHooksEditPost(ctx *context.Context, f form.NewSlackHook) {
Color: f.Color,
})
if err != nil {
- ctx.Handle(500, "Marshal", err)
+ c.Handle(500, "Marshal", err)
return
}
@@ -391,31 +391,31 @@ func SlackHooksEditPost(ctx *context.Context, f form.NewSlackHook) {
w.HookEvent = ParseHookEvent(f.Webhook)
w.IsActive = f.Active
if err := w.UpdateEvent(); err != nil {
- ctx.Handle(500, "UpdateEvent", err)
+ c.Handle(500, "UpdateEvent", err)
return
} else if err := models.UpdateWebhook(w); err != nil {
- ctx.Handle(500, "UpdateWebhook", err)
+ c.Handle(500, "UpdateWebhook", err)
return
}
- ctx.Flash.Success(ctx.Tr("repo.settings.update_hook_success"))
- ctx.Redirect(fmt.Sprintf("%s/settings/hooks/%d", orCtx.Link, w.ID))
+ c.Flash.Success(c.Tr("repo.settings.update_hook_success"))
+ c.Redirect(fmt.Sprintf("%s/settings/hooks/%d", orCtx.Link, w.ID))
}
// FIXME: merge logic to Slack
-func DiscordHooksEditPost(ctx *context.Context, f form.NewDiscordHook) {
- ctx.Data["Title"] = ctx.Tr("repo.settings")
- ctx.Data["PageIsSettingsHooks"] = true
- ctx.Data["PageIsSettingsHooksEdit"] = true
+func DiscordHooksEditPost(c *context.Context, f form.NewDiscordHook) {
+ c.Data["Title"] = c.Tr("repo.settings")
+ c.Data["PageIsSettingsHooks"] = true
+ c.Data["PageIsSettingsHooksEdit"] = true
- orCtx, w := checkWebhook(ctx)
- if ctx.Written() {
+ orCtx, w := checkWebhook(c)
+ if c.Written() {
return
}
- ctx.Data["Webhook"] = w
+ c.Data["Webhook"] = w
- if ctx.HasError() {
- ctx.HTML(200, orCtx.NewTemplate)
+ if c.HasError() {
+ c.HTML(200, orCtx.NewTemplate)
return
}
@@ -425,7 +425,7 @@ func DiscordHooksEditPost(ctx *context.Context, f form.NewDiscordHook) {
Color: f.Color,
})
if err != nil {
- ctx.Handle(500, "Marshal", err)
+ c.Handle(500, "Marshal", err)
return
}
@@ -434,22 +434,22 @@ func DiscordHooksEditPost(ctx *context.Context, f form.NewDiscordHook) {
w.HookEvent = ParseHookEvent(f.Webhook)
w.IsActive = f.Active
if err := w.UpdateEvent(); err != nil {
- ctx.Handle(500, "UpdateEvent", err)
+ c.Handle(500, "UpdateEvent", err)
return
} else if err := models.UpdateWebhook(w); err != nil {
- ctx.Handle(500, "UpdateWebhook", err)
+ c.Handle(500, "UpdateWebhook", err)
return
}
- ctx.Flash.Success(ctx.Tr("repo.settings.update_hook_success"))
- ctx.Redirect(fmt.Sprintf("%s/settings/hooks/%d", orCtx.Link, w.ID))
+ c.Flash.Success(c.Tr("repo.settings.update_hook_success"))
+ c.Redirect(fmt.Sprintf("%s/settings/hooks/%d", orCtx.Link, w.ID))
}
-func TestWebhook(ctx *context.Context) {
+func TestWebhook(c *context.Context) {
var authorUsername, committerUsername string
// Grab latest commit or fake one if it's empty repository.
- commit := ctx.Repo.Commit
+ commit := c.Repo.Commit
if commit == nil {
ghost := models.NewGhostUser()
commit = &git.Commit{
@@ -466,7 +466,7 @@ func TestWebhook(ctx *context.Context) {
if err == nil {
authorUsername = author.Name
} else if !errors.IsUserNotExist(err) {
- ctx.Handle(500, "GetUserByEmail.(author)", err)
+ c.Handle(500, "GetUserByEmail.(author)", err)
return
}
@@ -474,27 +474,27 @@ func TestWebhook(ctx *context.Context) {
if err == nil {
committerUsername = committer.Name
} else if !errors.IsUserNotExist(err) {
- ctx.Handle(500, "GetUserByEmail.(committer)", err)
+ c.Handle(500, "GetUserByEmail.(committer)", err)
return
}
}
fileStatus, err := commit.FileStatus()
if err != nil {
- ctx.Handle(500, "FileStatus", err)
+ c.Handle(500, "FileStatus", err)
return
}
- apiUser := ctx.User.APIFormat()
+ apiUser := c.User.APIFormat()
p := &api.PushPayload{
- Ref: git.BRANCH_PREFIX + ctx.Repo.Repository.DefaultBranch,
+ Ref: git.BRANCH_PREFIX + c.Repo.Repository.DefaultBranch,
Before: commit.ID.String(),
After: commit.ID.String(),
Commits: []*api.PayloadCommit{
{
ID: commit.ID.String(),
Message: commit.Message(),
- URL: ctx.Repo.Repository.HTMLURL() + "/commit/" + commit.ID.String(),
+ URL: c.Repo.Repository.HTMLURL() + "/commit/" + commit.ID.String(),
Author: &api.PayloadUser{
Name: commit.Author.Name,
Email: commit.Author.Email,
@@ -510,49 +510,49 @@ func TestWebhook(ctx *context.Context) {
Modified: fileStatus.Modified,
},
},
- Repo: ctx.Repo.Repository.APIFormat(nil),
+ Repo: c.Repo.Repository.APIFormat(nil),
Pusher: apiUser,
Sender: apiUser,
}
- if err := models.TestWebhook(ctx.Repo.Repository, models.HOOK_EVENT_PUSH, p, ctx.ParamsInt64("id")); err != nil {
- ctx.Handle(500, "TestWebhook", err)
+ if err := models.TestWebhook(c.Repo.Repository, models.HOOK_EVENT_PUSH, p, c.ParamsInt64("id")); err != nil {
+ c.Handle(500, "TestWebhook", err)
} else {
- ctx.Flash.Info(ctx.Tr("repo.settings.webhook.test_delivery_success"))
- ctx.Status(200)
+ c.Flash.Info(c.Tr("repo.settings.webhook.test_delivery_success"))
+ c.Status(200)
}
}
-func RedeliveryWebhook(ctx *context.Context) {
- webhook, err := models.GetWebhookOfRepoByID(ctx.Repo.Repository.ID, ctx.ParamsInt64(":id"))
+func RedeliveryWebhook(c *context.Context) {
+ webhook, err := models.GetWebhookOfRepoByID(c.Repo.Repository.ID, c.ParamsInt64(":id"))
if err != nil {
- ctx.NotFoundOrServerError("GetWebhookOfRepoByID/GetWebhookByOrgID", errors.IsWebhookNotExist, err)
+ c.NotFoundOrServerError("GetWebhookOfRepoByID/GetWebhookByOrgID", errors.IsWebhookNotExist, err)
return
}
- hookTask, err := models.GetHookTaskOfWebhookByUUID(webhook.ID, ctx.Query("uuid"))
+ hookTask, err := models.GetHookTaskOfWebhookByUUID(webhook.ID, c.Query("uuid"))
if err != nil {
- ctx.NotFoundOrServerError("GetHookTaskOfWebhookByUUID/GetWebhookByOrgID", errors.IsHookTaskNotExist, err)
+ c.NotFoundOrServerError("GetHookTaskOfWebhookByUUID/GetWebhookByOrgID", errors.IsHookTaskNotExist, err)
return
}
hookTask.IsDelivered = false
if err = models.UpdateHookTask(hookTask); err != nil {
- ctx.Handle(500, "UpdateHookTask", err)
+ c.Handle(500, "UpdateHookTask", err)
} else {
- go models.HookQueue.Add(ctx.Repo.Repository.ID)
- ctx.Flash.Info(ctx.Tr("repo.settings.webhook.redelivery_success", hookTask.UUID))
- ctx.Status(200)
+ go models.HookQueue.Add(c.Repo.Repository.ID)
+ c.Flash.Info(c.Tr("repo.settings.webhook.redelivery_success", hookTask.UUID))
+ c.Status(200)
}
}
-func DeleteWebhook(ctx *context.Context) {
- if err := models.DeleteWebhookOfRepoByID(ctx.Repo.Repository.ID, ctx.QueryInt64("id")); err != nil {
- ctx.Flash.Error("DeleteWebhookByRepoID: " + err.Error())
+func DeleteWebhook(c *context.Context) {
+ if err := models.DeleteWebhookOfRepoByID(c.Repo.Repository.ID, c.QueryInt64("id")); err != nil {
+ c.Flash.Error("DeleteWebhookByRepoID: " + err.Error())
} else {
- ctx.Flash.Success(ctx.Tr("repo.settings.webhook_deletion_success"))
+ c.Flash.Success(c.Tr("repo.settings.webhook_deletion_success"))
}
- ctx.JSON(200, map[string]interface{}{
- "redirect": ctx.Repo.RepoLink + "/settings/hooks",
+ c.JSON(200, map[string]interface{}{
+ "redirect": c.Repo.RepoLink + "/settings/hooks",
})
}