[REFACTOR] webhook packagist endpoint
This commit is contained in:
parent
36a1d37532
commit
dce754cde1
4 changed files with 22 additions and 43 deletions
|
@ -388,32 +388,6 @@ func gogsHookParams(ctx *context.Context) webhookParams {
|
|||
}
|
||||
}
|
||||
|
||||
// PackagistHooksNewPost response for creating Packagist webhook
|
||||
func PackagistHooksNewPost(ctx *context.Context) {
|
||||
createWebhook(ctx, packagistHookParams(ctx))
|
||||
}
|
||||
|
||||
// PackagistHooksEditPost response for editing Packagist webhook
|
||||
func PackagistHooksEditPost(ctx *context.Context) {
|
||||
editWebhook(ctx, packagistHookParams(ctx))
|
||||
}
|
||||
|
||||
func packagistHookParams(ctx *context.Context) webhookParams {
|
||||
form := web.GetForm(ctx).(*forms.NewPackagistHookForm)
|
||||
|
||||
return webhookParams{
|
||||
Type: webhook_module.PACKAGIST,
|
||||
URL: fmt.Sprintf("https://packagist.org/api/update-package?username=%s&apiToken=%s", url.QueryEscape(form.Username), url.QueryEscape(form.APIToken)),
|
||||
ContentType: webhook.ContentTypeJSON,
|
||||
WebhookForm: form.WebhookForm,
|
||||
Meta: &webhook_service.PackagistMeta{
|
||||
Username: form.Username,
|
||||
APIToken: form.APIToken,
|
||||
PackageURL: form.PackageURL,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func checkWebhook(ctx *context.Context) (*ownerRepoCtx, *webhook.Webhook) {
|
||||
orCtx, err := getOwnerRepoCtx(ctx)
|
||||
if err != nil {
|
||||
|
|
|
@ -403,13 +403,11 @@ func registerRoutes(m *web.Route) {
|
|||
addWebhookAddRoutes := func() {
|
||||
m.Get("/{type}/new", repo_setting.WebhooksNew)
|
||||
m.Post("/gogs/new", web.Bind(forms.NewGogshookForm{}), repo_setting.GogsHooksNewPost)
|
||||
m.Post("/packagist/new", web.Bind(forms.NewPackagistHookForm{}), repo_setting.PackagistHooksNewPost)
|
||||
m.Post("/{type}/new", repo_setting.WebhookCreate)
|
||||
}
|
||||
|
||||
addWebhookEditRoutes := func() {
|
||||
m.Post("/gogs/{id}", web.Bind(forms.NewGogshookForm{}), repo_setting.GogsHooksEditPost)
|
||||
m.Post("/packagist/{id}", web.Bind(forms.NewPackagistHookForm{}), repo_setting.PackagistHooksEditPost)
|
||||
m.Post("/{type}/{id:[0-9]+}", repo_setting.WebhookUpdate)
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue