Refactor webhook (#31587)

A more complete fix for #31588

1. Make "generic" code more readable
2. Clarify HTML or Markdown for the payload content
This commit is contained in:
wxiaoguang 2024-07-10 19:37:16 +08:00 committed by GitHub
parent 4ea2a6de81
commit 72b6bc8caf
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
18 changed files with 173 additions and 182 deletions

View file

@ -40,6 +40,10 @@ func GetPackagistHook(w *webhook_model.Webhook) *PackagistMeta {
return s
}
type packagistConvertor struct {
PackageURL string
}
// Create implements PayloadConvertor Create method
func (pc packagistConvertor) Create(_ *api.CreatePayload) (PackagistPayload, error) {
return PackagistPayload{}, nil
@ -106,18 +110,12 @@ func (pc packagistConvertor) Package(_ *api.PackagePayload) (PackagistPayload, e
return PackagistPayload{}, nil
}
type packagistConvertor struct {
PackageURL string
}
var _ payloadConvertor[PackagistPayload] = packagistConvertor{}
func newPackagistRequest(_ context.Context, w *webhook_model.Webhook, t *webhook_model.HookTask) (*http.Request, []byte, error) {
meta := &PackagistMeta{}
if err := json.Unmarshal([]byte(w.Meta), meta); err != nil {
return nil, nil, fmt.Errorf("newpackagistRequest meta json: %w", err)
}
pc := packagistConvertor{
var pc payloadConvertor[PackagistPayload] = packagistConvertor{
PackageURL: meta.PackageURL,
}
return newJSONRequest(pc, w, t, true)