summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--docs/content/doc/features/webhooks.en-us.md1
-rw-r--r--docs/content/doc/features/webhooks.zh-cn.md1
-rw-r--r--docs/content/doc/features/webhooks.zh-tw.md1
-rw-r--r--models/webhook/webhook.go1
-rw-r--r--modules/setting/webhook.go2
-rw-r--r--modules/structs/hook.go2
-rw-r--r--options/locale/locale_en-US.ini4
-rw-r--r--public/img/packagist.pngbin0 -> 4573 bytes
-rw-r--r--routers/web/repo/webhook.go99
-rw-r--r--routers/web/web.go4
-rw-r--r--services/forms/repo_form.go14
-rw-r--r--services/webhook/packagist.go112
-rw-r--r--services/webhook/packagist_test.go140
-rw-r--r--services/webhook/webhook.go4
-rw-r--r--templates/admin/hook_new.tmpl3
-rw-r--r--templates/org/settings/hook_new.tmpl3
-rw-r--r--templates/repo/settings/webhook/base_list.tmpl3
-rw-r--r--templates/repo/settings/webhook/new.tmpl3
-rw-r--r--templates/repo/settings/webhook/packagist.tmpl19
-rw-r--r--templates/swagger/v1_json.tmpl3
20 files changed, 416 insertions, 3 deletions
diff --git a/docs/content/doc/features/webhooks.en-us.md b/docs/content/doc/features/webhooks.en-us.md
index 5ded4512c3..2dba7b7f83 100644
--- a/docs/content/doc/features/webhooks.en-us.md
+++ b/docs/content/doc/features/webhooks.en-us.md
@@ -28,6 +28,7 @@ All event pushes are POST requests. The methods currently supported are:
- Microsoft Teams
- Feishu
- Wechatwork
+- Packagist
### Event information
diff --git a/docs/content/doc/features/webhooks.zh-cn.md b/docs/content/doc/features/webhooks.zh-cn.md
index f3a312eee2..76139460c0 100644
--- a/docs/content/doc/features/webhooks.zh-cn.md
+++ b/docs/content/doc/features/webhooks.zh-cn.md
@@ -27,5 +27,6 @@ Gitea 的存储 webhook。这可以有存储库管路设定页 `/:username/:repo
- Microsoft Teams
- Feishu
- Wechatwork
+- Packagist
## TBD
diff --git a/docs/content/doc/features/webhooks.zh-tw.md b/docs/content/doc/features/webhooks.zh-tw.md
index 697b413916..20fec3d62d 100644
--- a/docs/content/doc/features/webhooks.zh-tw.md
+++ b/docs/content/doc/features/webhooks.zh-tw.md
@@ -27,6 +27,7 @@ Gitea 的儲存庫事件支援 web hook。這可以有儲存庫管理員在設
- Microsoft Teams
- Feishu
- Wechatwork
+- Packagist
### 事件資訊
diff --git a/models/webhook/webhook.go b/models/webhook/webhook.go
index 21c01d9289..ffc9b72b64 100644
--- a/models/webhook/webhook.go
+++ b/models/webhook/webhook.go
@@ -161,6 +161,7 @@ const (
FEISHU HookType = "feishu"
MATRIX HookType = "matrix"
WECHATWORK HookType = "wechatwork"
+ PACKAGIST HookType = "packagist"
)
// HookStatus is the status of a web hook
diff --git a/modules/setting/webhook.go b/modules/setting/webhook.go
index b576f9573b..0bfd7dcb4d 100644
--- a/modules/setting/webhook.go
+++ b/modules/setting/webhook.go
@@ -36,7 +36,7 @@ func newWebhookService() {
Webhook.DeliverTimeout = sec.Key("DELIVER_TIMEOUT").MustInt(5)
Webhook.SkipTLSVerify = sec.Key("SKIP_TLS_VERIFY").MustBool()
Webhook.AllowedHostList = sec.Key("ALLOWED_HOST_LIST").MustString("")
- Webhook.Types = []string{"gitea", "gogs", "slack", "discord", "dingtalk", "telegram", "msteams", "feishu", "matrix", "wechatwork"}
+ Webhook.Types = []string{"gitea", "gogs", "slack", "discord", "dingtalk", "telegram", "msteams", "feishu", "matrix", "wechatwork", "packagist"}
Webhook.PagingNum = sec.Key("PAGING_NUM").MustInt(10)
Webhook.ProxyURL = sec.Key("PROXY_URL").MustString("")
if Webhook.ProxyURL != "" {
diff --git a/modules/structs/hook.go b/modules/structs/hook.go
index bb62483cda..e4d7652c72 100644
--- a/modules/structs/hook.go
+++ b/modules/structs/hook.go
@@ -40,7 +40,7 @@ type CreateHookOptionConfig map[string]string
// CreateHookOption options when create a hook
type CreateHookOption struct {
// required: true
- // enum: dingtalk,discord,gitea,gogs,msteams,slack,telegram,feishu,wechatwork
+ // enum: dingtalk,discord,gitea,gogs,msteams,slack,telegram,feishu,wechatwork,packagist
Type string `json:"type" binding:"Required"`
// required: true
Config CreateHookOptionConfig `json:"config" binding:"Required"`
diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini
index 8ee7347c0d..de0d26d647 100644
--- a/options/locale/locale_en-US.ini
+++ b/options/locale/locale_en-US.ini
@@ -1947,6 +1947,10 @@ settings.add_matrix_hook_desc = Integrate <a href="%s">Matrix</a> into your repo
settings.add_msteams_hook_desc = Integrate <a href="%s">Microsoft Teams</a> into your repository.
settings.add_feishu_hook_desc = Integrate <a href="%s">Feishu</a> into your repository.
settings.add_Wechat_hook_desc = Integrate <a href="%s">Wechatwork</a> into your repository.
+settings.add_packagist_hook_desc = Integrate <a href="%s">Packagist</a> into your repository.
+settings.packagist_username = Packagist username
+settings.packagist_api_token = API token
+settings.packagist_package_url = Packagist package URL
settings.deploy_keys = Deploy Keys
settings.add_deploy_key = Add Deploy Key
settings.deploy_key_desc = Deploy keys have read-only pull access to the repository.
diff --git a/public/img/packagist.png b/public/img/packagist.png
new file mode 100644
index 0000000000..76c0e62a20
--- /dev/null
+++ b/public/img/packagist.png
Binary files differ
diff --git a/routers/web/repo/webhook.go b/routers/web/repo/webhook.go
index 2ec2e8911f..fb984de7f5 100644
--- a/routers/web/repo/webhook.go
+++ b/routers/web/repo/webhook.go
@@ -682,6 +682,59 @@ func WechatworkHooksNewPost(ctx *context.Context) {
ctx.Redirect(orCtx.Link)
}
+// PackagistHooksNewPost response for creating packagist hook
+func PackagistHooksNewPost(ctx *context.Context) {
+ 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)
+ if err != nil {
+ ctx.ServerError("getOrgRepoCtx", err)
+ return
+ }
+
+ if ctx.HasError() {
+ ctx.HTML(http.StatusOK, orCtx.NewTemplate)
+ return
+ }
+
+ 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(db.DefaultContext, 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) {
ctx.Data["RequireHighlightJS"] = true
@@ -719,6 +772,8 @@ func checkWebhook(ctx *context.Context) (*orgRepoCtx, *webhook.Webhook) {
ctx.Data["TelegramHook"] = webhook_service.GetTelegramHook(w)
case webhook.MATRIX:
ctx.Data["MatrixHook"] = webhook_service.GetMatrixHook(w)
+ case webhook.PACKAGIST:
+ ctx.Data["PackagistHook"] = webhook_service.GetPackagistHook(w)
}
ctx.Data["History"], err = w.History(1)
@@ -1137,6 +1192,50 @@ func WechatworkHooksEditPost(ctx *context.Context) {
ctx.Redirect(fmt.Sprintf("%s/%d", orCtx.Link, w.ID))
}
+// PackagistHooksEditPost response for editing packagist hook
+func PackagistHooksEditPost(ctx *context.Context) {
+ form := web.GetForm(ctx).(*forms.NewPackagistHookForm)
+ ctx.Data["Title"] = ctx.Tr("repo.settings")
+ ctx.Data["PageIsSettingsHooks"] = true
+ ctx.Data["PageIsSettingsHooksEdit"] = true
+
+ orCtx, w := checkWebhook(ctx)
+ if ctx.Written() {
+ return
+ }
+ ctx.Data["Webhook"] = w
+
+ if ctx.HasError() {
+ ctx.HTML(http.StatusOK, orCtx.NewTemplate)
+ return
+ }
+
+ 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.Meta = string(meta)
+ w.URL = fmt.Sprintf("https://packagist.org/api/update-package?username=%s&apiToken=%s", url.QueryEscape(form.Username), url.QueryEscape(form.APIToken))
+ w.HookEvent = ParseHookEvent(form.WebhookForm)
+ w.IsActive = form.Active
+ if err := w.UpdateEvent(); err != nil {
+ ctx.ServerError("UpdateEvent", err)
+ return
+ } else if err := webhook.UpdateWebhook(w); err != nil {
+ ctx.ServerError("UpdateWebhook", err)
+ return
+ }
+
+ ctx.Flash.Success(ctx.Tr("repo.settings.update_hook_success"))
+ ctx.Redirect(fmt.Sprintf("%s/%d", orCtx.Link, w.ID))
+}
+
// TestWebhook test if web hook is work fine
func TestWebhook(ctx *context.Context) {
hookID := ctx.ParamsInt64(":id")
diff --git a/routers/web/web.go b/routers/web/web.go
index 4c50229906..545194aabd 100644
--- a/routers/web/web.go
+++ b/routers/web/web.go
@@ -448,6 +448,7 @@ func RegisterRoutes(m *web.Route) {
m.Post("/msteams/{id}", bindIgnErr(forms.NewMSTeamsHookForm{}), repo.MSTeamsHooksEditPost)
m.Post("/feishu/{id}", bindIgnErr(forms.NewFeishuHookForm{}), repo.FeishuHooksEditPost)
m.Post("/wechatwork/{id}", bindIgnErr(forms.NewWechatWorkHookForm{}), repo.WechatworkHooksEditPost)
+ m.Post("/packagist/{id}", bindIgnErr(forms.NewPackagistHookForm{}), repo.PackagistHooksEditPost)
}, webhooksEnabled)
m.Group("/{configType:default-hooks|system-hooks}", func() {
@@ -462,6 +463,7 @@ func RegisterRoutes(m *web.Route) {
m.Post("/msteams/new", bindIgnErr(forms.NewMSTeamsHookForm{}), repo.MSTeamsHooksNewPost)
m.Post("/feishu/new", bindIgnErr(forms.NewFeishuHookForm{}), repo.FeishuHooksNewPost)
m.Post("/wechatwork/new", bindIgnErr(forms.NewWechatWorkHookForm{}), repo.WechatworkHooksNewPost)
+ m.Post("/packagist/new", bindIgnErr(forms.NewPackagistHookForm{}), repo.PackagistHooksNewPost)
})
m.Group("/auths", func() {
@@ -657,6 +659,7 @@ func RegisterRoutes(m *web.Route) {
m.Post("/msteams/new", bindIgnErr(forms.NewMSTeamsHookForm{}), repo.MSTeamsHooksNewPost)
m.Post("/feishu/new", bindIgnErr(forms.NewFeishuHookForm{}), repo.FeishuHooksNewPost)
m.Post("/wechatwork/new", bindIgnErr(forms.NewWechatWorkHookForm{}), repo.WechatworkHooksNewPost)
+ m.Post("/packagist/new", bindIgnErr(forms.NewPackagistHookForm{}), repo.PackagistHooksNewPost)
m.Group("/{id}", func() {
m.Get("", repo.WebHooksEdit)
m.Post("/test", repo.TestWebhook)
@@ -672,6 +675,7 @@ func RegisterRoutes(m *web.Route) {
m.Post("/msteams/{id}", bindIgnErr(forms.NewMSTeamsHookForm{}), repo.MSTeamsHooksEditPost)
m.Post("/feishu/{id}", bindIgnErr(forms.NewFeishuHookForm{}), repo.FeishuHooksEditPost)
m.Post("/wechatwork/{id}", bindIgnErr(forms.NewWechatWorkHookForm{}), repo.WechatworkHooksEditPost)
+ m.Post("/packagist/{id}", bindIgnErr(forms.NewPackagistHookForm{}), repo.PackagistHooksEditPost)
}, webhooksEnabled)
m.Group("/keys", func() {
diff --git a/services/forms/repo_form.go b/services/forms/repo_form.go
index 19b5a37664..e6bd088da4 100644
--- a/services/forms/repo_form.go
+++ b/services/forms/repo_form.go
@@ -396,6 +396,20 @@ func (f *NewWechatWorkHookForm) Validate(req *http.Request, errs binding.Errors)
return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
}
+// NewPackagistHookForm form for creating packagist hook
+type NewPackagistHookForm struct {
+ Username string `binding:"Required"`
+ APIToken string `binding:"Required"`
+ PackageURL string `binding:"Required;ValidUrl"`
+ WebhookForm
+}
+
+// Validate validates the fields
+func (f *NewPackagistHookForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
+ ctx := context.GetContext(req)
+ return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
+}
+
// .___
// | | ______ ________ __ ____
// | |/ ___// ___/ | \_/ __ \
diff --git a/services/webhook/packagist.go b/services/webhook/packagist.go
new file mode 100644
index 0000000000..ace93b13ff
--- /dev/null
+++ b/services/webhook/packagist.go
@@ -0,0 +1,112 @@
+// Copyright 2022 The Gitea Authors. All rights reserved.
+// Use of this source code is governed by a MIT-style
+// license that can be found in the LICENSE file.
+
+package webhook
+
+import (
+ "errors"
+
+ webhook_model "code.gitea.io/gitea/models/webhook"
+ "code.gitea.io/gitea/modules/json"
+ "code.gitea.io/gitea/modules/log"
+ api "code.gitea.io/gitea/modules/structs"
+)
+
+type (
+ // PackagistPayload represents
+ PackagistPayload struct {
+ PackagistRepository struct {
+ URL string `json:"url"`
+ } `json:"repository"`
+ }
+
+ // PackagistMeta contains the meta data for the webhook
+ PackagistMeta struct {
+ Username string `json:"username"`
+ APIToken string `json:"api_token"`
+ PackageURL string `json:"package_url"`
+ }
+)
+
+// GetPackagistHook returns packagist metadata
+func GetPackagistHook(w *webhook_model.Webhook) *PackagistMeta {
+ s := &PackagistMeta{}
+ if err := json.Unmarshal([]byte(w.Meta), s); err != nil {
+ log.Error("webhook.GetPackagistHook(%d): %v", w.ID, err)
+ }
+ return s
+}
+
+// JSONPayload Marshals the PackagistPayload to json
+func (f *PackagistPayload) JSONPayload() ([]byte, error) {
+ data, err := json.MarshalIndent(f, "", " ")
+ if err != nil {
+ return []byte{}, err
+ }
+ return data, nil
+}
+
+var _ PayloadConvertor = &PackagistPayload{}
+
+// Create implements PayloadConvertor Create method
+func (f *PackagistPayload) Create(p *api.CreatePayload) (api.Payloader, error) {
+ return nil, nil
+}
+
+// Delete implements PayloadConvertor Delete method
+func (f *PackagistPayload) Delete(p *api.DeletePayload) (api.Payloader, error) {
+ return nil, nil
+}
+
+// Fork implements PayloadConvertor Fork method
+func (f *PackagistPayload) Fork(p *api.ForkPayload) (api.Payloader, error) {
+ return nil, nil
+}
+
+// Push implements PayloadConvertor Push method
+func (f *PackagistPayload) Push(p *api.PushPayload) (api.Payloader, error) {
+ return f, nil
+}
+
+// Issue implements PayloadConvertor Issue method
+func (f *PackagistPayload) Issue(p *api.IssuePayload) (api.Payloader, error) {
+ return nil, nil
+}
+
+// IssueComment implements PayloadConvertor IssueComment method
+func (f *PackagistPayload) IssueComment(p *api.IssueCommentPayload) (api.Payloader, error) {
+ return nil, nil
+}
+
+// PullRequest implements PayloadConvertor PullRequest method
+func (f *PackagistPayload) PullRequest(p *api.PullRequestPayload) (api.Payloader, error) {
+ return nil, nil
+}
+
+// Review implements PayloadConvertor Review method
+func (f *PackagistPayload) Review(p *api.PullRequestPayload, event webhook_model.HookEventType) (api.Payloader, error) {
+ return nil, nil
+}
+
+// Repository implements PayloadConvertor Repository method
+func (f *PackagistPayload) Repository(p *api.RepositoryPayload) (api.Payloader, error) {
+ return nil, nil
+}
+
+// Release implements PayloadConvertor Release method
+func (f *PackagistPayload) Release(p *api.ReleasePayload) (api.Payloader, error) {
+ return nil, nil
+}
+
+// GetPackagistPayload converts a packagist webhook into a PackagistPayload
+func GetPackagistPayload(p api.Payloader, event webhook_model.HookEventType, meta string) (api.Payloader, error) {
+ s := new(PackagistPayload)
+
+ packagist := &PackagistMeta{}
+ if err := json.Unmarshal([]byte(meta), &packagist); err != nil {
+ return s, errors.New("GetPackagistPayload meta json:" + err.Error())
+ }
+ s.PackagistRepository.URL = packagist.PackageURL
+ return convertPayloader(s, p, event)
+}
diff --git a/services/webhook/packagist_test.go b/services/webhook/packagist_test.go
new file mode 100644
index 0000000000..08912924d2
--- /dev/null
+++ b/services/webhook/packagist_test.go
@@ -0,0 +1,140 @@
+// Copyright 2022 The Gitea Authors. All rights reserved.
+// Use of this source code is governed by a MIT-style
+// license that can be found in the LICENSE file.
+
+package webhook
+
+import (
+ "testing"
+
+ webhook_model "code.gitea.io/gitea/models/webhook"
+ api "code.gitea.io/gitea/modules/structs"
+
+ "github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
+)
+
+func TestPackagistPayload(t *testing.T) {
+ t.Run("Create", func(t *testing.T) {
+ p := createTestPayload()
+
+ d := new(PackagistPayload)
+ pl, err := d.Create(p)
+ require.NoError(t, err)
+ require.Nil(t, pl)
+ })
+
+ t.Run("Delete", func(t *testing.T) {
+ p := deleteTestPayload()
+
+ d := new(PackagistPayload)
+ pl, err := d.Delete(p)
+ require.NoError(t, err)
+ require.Nil(t, pl)
+ })
+
+ t.Run("Fork", func(t *testing.T) {
+ p := forkTestPayload()
+
+ d := new(PackagistPayload)
+ pl, err := d.Fork(p)
+ require.NoError(t, err)
+ require.Nil(t, pl)
+ })
+
+ t.Run("Push", func(t *testing.T) {
+ p := pushTestPayload()
+
+ d := new(PackagistPayload)
+ d.PackagistRepository.URL = "https://packagist.org/api/update-package?username=THEUSERNAME&apiToken=TOPSECRETAPITOKEN"
+ pl, err := d.Push(p)
+ require.NoError(t, err)
+ require.NotNil(t, pl)
+ require.IsType(t, &PackagistPayload{}, pl)
+
+ assert.Equal(t, "https://packagist.org/api/update-package?username=THEUSERNAME&apiToken=TOPSECRETAPITOKEN", pl.(*PackagistPayload).PackagistRepository.URL)
+ })
+
+ t.Run("Issue", func(t *testing.T) {
+ p := issueTestPayload()
+
+ d := new(PackagistPayload)
+ p.Action = api.HookIssueOpened
+ pl, err := d.Issue(p)
+ require.NoError(t, err)
+ require.Nil(t, pl)
+
+ p.Action = api.HookIssueClosed
+ pl, err = d.Issue(p)
+ require.NoError(t, err)
+ require.Nil(t, pl)
+ })
+
+ t.Run("IssueComment", func(t *testing.T) {
+ p := issueCommentTestPayload()
+
+ d := new(PackagistPayload)
+ pl, err := d.IssueComment(p)
+ require.NoError(t, err)
+ require.Nil(t, pl)
+ })
+
+ t.Run("PullRequest", func(t *testing.T) {
+ p := pullRequestTestPayload()
+
+ d := new(PackagistPayload)
+ pl, err := d.PullRequest(p)
+ require.NoError(t, err)
+ require.Nil(t, pl)
+ })
+
+ t.Run("PullRequestComment", func(t *testing.T) {
+ p := pullRequestCommentTestPayload()
+
+ d := new(PackagistPayload)
+ pl, err := d.IssueComment(p)
+ require.NoError(t, err)
+ require.Nil(t, pl)
+ })
+
+ t.Run("Review", func(t *testing.T) {
+ p := pullRequestTestPayload()
+ p.Action = api.HookIssueReviewed
+
+ d := new(PackagistPayload)
+ pl, err := d.Review(p, webhook_model.HookEventPullRequestReviewApproved)
+ require.NoError(t, err)
+ require.Nil(t, pl)
+ })
+
+ t.Run("Repository", func(t *testing.T) {
+ p := repositoryTestPayload()
+
+ d := new(PackagistPayload)
+ pl, err := d.Repository(p)
+ require.NoError(t, err)
+ require.Nil(t, pl)
+ })
+
+ t.Run("Release", func(t *testing.T) {
+ p := pullReleaseTestPayload()
+
+ d := new(PackagistPayload)
+ pl, err := d.Release(p)
+ require.NoError(t, err)
+ require.Nil(t, pl)
+ })
+}
+
+func TestPackagistJSONPayload(t *testing.T) {
+ p := pushTestPayload()
+
+ pl, err := new(PackagistPayload).Push(p)
+ require.NoError(t, err)
+ require.NotNil(t, pl)
+ require.IsType(t, &PackagistPayload{}, pl)
+
+ json, err := pl.JSONPayload()
+ require.NoError(t, err)
+ assert.NotEmpty(t, json)
+}
diff --git a/services/webhook/webhook.go b/services/webhook/webhook.go
index bb7a9692d1..607fac9634 100644
--- a/services/webhook/webhook.go
+++ b/services/webhook/webhook.go
@@ -58,6 +58,10 @@ var webhooks = map[webhook_model.HookType]*webhook{
name: webhook_model.WECHATWORK,
payloadCreator: GetWechatworkPayload,
},
+ webhook_model.PACKAGIST: {
+ name: webhook_model.PACKAGIST,
+ payloadCreator: GetPackagistPayload,
+ },
}
// RegisterWebhook registers a webhook
diff --git a/templates/admin/hook_new.tmpl b/templates/admin/hook_new.tmpl
index 2cd3fc826c..049e54ef83 100644
--- a/templates/admin/hook_new.tmpl
+++ b/templates/admin/hook_new.tmpl
@@ -34,6 +34,8 @@
<img width="26" height="26" src="{{AssetUrlPrefix}}/img/matrix.svg">
{{else if eq .HookType "wechatwork"}}
<img width="26" height="26" src="{{AssetUrlPrefix}}/img/wechatwork.png">
+ {{else if eq .HookType "packagist"}}
+ <img width="26" height="26" src="{{AssetUrlPrefix}}/img/packagist.png">
{{end}}
</div>
</h4>
@@ -48,6 +50,7 @@
{{template "repo/settings/webhook/feishu" .}}
{{template "repo/settings/webhook/matrix" .}}
{{template "repo/settings/webhook/wechatwork" .}}
+ {{template "repo/settings/webhook/packagist" .}}
</div>
{{template "repo/settings/webhook/history" .}}
diff --git a/templates/org/settings/hook_new.tmpl b/templates/org/settings/hook_new.tmpl
index 43351d0ceb..5e8ebb51e9 100644
--- a/templates/org/settings/hook_new.tmpl
+++ b/templates/org/settings/hook_new.tmpl
@@ -29,6 +29,8 @@
<img width="26" height="26" src="{{AssetUrlPrefix}}/img/matrix.svg">
{{else if eq .HookType "wechatwork"}}
<img width="26" height="26" src="{{AssetUrlPrefix}}/img/wechatwork.png">
+ {{else if eq .HookType "packagist"}}
+ <img width="26" height="26" src="{{AssetUrlPrefix}}/img/packagist.png">
{{end}}
</div>
</h4>
@@ -43,6 +45,7 @@
{{template "repo/settings/webhook/feishu" .}}
{{template "repo/settings/webhook/matrix" .}}
{{template "repo/settings/webhook/wechatwork" .}}
+ {{template "repo/settings/webhook/packagist" .}}
</div>
{{template "repo/settings/webhook/history" .}}
diff --git a/templates/repo/settings/webhook/base_list.tmpl b/templates/repo/settings/webhook/base_list.tmpl
index e96d086039..f16c43bad6 100644
--- a/templates/repo/settings/webhook/base_list.tmpl
+++ b/templates/repo/settings/webhook/base_list.tmpl
@@ -34,6 +34,9 @@
<a class="item" href="{{.BaseLinkNew}}/wechatwork/new">
<img width="20" height="20" src="{{AssetUrlPrefix}}/img/wechatwork.png">Wechatwork
</a>
+ <a class="item" href="{{.BaseLinkNew}}/packagist/new">
+ <img width="20" height="20" src="{{AssetUrlPrefix}}/img/packagist.png">Packagist
+ </a>
</div>
</div>
</div>
diff --git a/templates/repo/settings/webhook/new.tmpl b/templates/repo/settings/webhook/new.tmpl
index 6df128f40a..a438a4c71a 100644
--- a/templates/repo/settings/webhook/new.tmpl
+++ b/templates/repo/settings/webhook/new.tmpl
@@ -27,6 +27,8 @@
<img width="26" height="26" src="{{AssetUrlPrefix}}/img/matrix.svg">
{{else if eq .HookType "wechatwork"}}
<img width="26" height="26" src="{{AssetUrlPrefix}}/img/wechatwork.png">
+ {{else if eq .HookType "packagist"}}
+ <img width="26" height="26" src="{{AssetUrlPrefix}}/img/packagist.png">
{{end}}
</div>
</h4>
@@ -41,6 +43,7 @@
{{template "repo/settings/webhook/feishu" .}}
{{template "repo/settings/webhook/matrix" .}}
{{template "repo/settings/webhook/wechatwork" .}}
+ {{template "repo/settings/webhook/packagist" .}}
</div>
{{template "repo/settings/webhook/history" .}}
diff --git a/templates/repo/settings/webhook/packagist.tmpl b/templates/repo/settings/webhook/packagist.tmpl
new file mode 100644
index 0000000000..04161dc40f
--- /dev/null
+++ b/templates/repo/settings/webhook/packagist.tmpl
@@ -0,0 +1,19 @@
+{{if eq .HookType "packagist"}}
+ <p>{{.i18n.Tr "repo.settings.add_packagist_hook_desc" "https://packagist.org" | Str2html}}</p>
+ <form class="ui form" action="{{.BaseLink}}/packagist/{{or .Webhook.ID "new"}}" method="post">
+ {{.CsrfTokenHtml}}
+ <div class="required field {{if .Err_Username}}error{{end}}">
+ <label for="username">{{.i18n.Tr "repo.settings.packagist_username"}}</label>
+ <input id="username" name="username" value="{{.PackagistHook.Username}}" placeholder="e.g. Gitea" autofocus required>
+ </div>
+ <div class="required field {{if .Err_APIToken}}error{{end}}">
+ <label for="api_token">{{.i18n.Tr "repo.settings.packagist_api_token"}}</label>
+ <input id="api_token" name="api_token" value="{{.PackagistHook.APIToken}}" placeholder="e.g. X5F_tZ-Wj3c1vqaU2Rky" required>
+ </div>
+ <div class="required field {{if .Err_PackageURL}}error{{end}}">
+ <label for="package_url">{{.i18n.Tr "repo.settings.packagist_package_url"}}</label>
+ <input id="package_url" name="package_url" value="{{.PackagistHook.PackageURL}}" placeholder="e.g. https://packagist.org/packages/laravel/framework" required>
+ </div>
+ {{template "repo/settings/webhook/settings" .}}
+ </form>
+{{end}}
diff --git a/templates/swagger/v1_json.tmpl b/templates/swagger/v1_json.tmpl
index bba728363a..768c4c69ee 100644
--- a/templates/swagger/v1_json.tmpl
+++ b/templates/swagger/v1_json.tmpl
@@ -13517,7 +13517,8 @@
"slack",
"telegram",
"feishu",
- "wechatwork"
+ "wechatwork",
+ "packagist"
],
"x-go-name": "Type"
}