forked from forgejo/forgejo
parent
226fa396df
commit
a47a1e0777
3 changed files with 59 additions and 268 deletions
|
@ -11,12 +11,11 @@ import (
|
|||
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"
|
||||
webhook_module "code.gitea.io/gitea/modules/webhook"
|
||||
)
|
||||
|
||||
type (
|
||||
// PackagistPayload represents
|
||||
// PackagistPayload represents a packagist payload
|
||||
// as expected by https://packagist.org/about
|
||||
PackagistPayload struct {
|
||||
PackagistRepository struct {
|
||||
URL string `json:"url"`
|
||||
|
@ -40,85 +39,19 @@ func GetPackagistHook(w *webhook_model.Webhook) *PackagistMeta {
|
|||
return s
|
||||
}
|
||||
|
||||
// Create implements PayloadConvertor Create method
|
||||
func (pc packagistConvertor) Create(_ *api.CreatePayload) (PackagistPayload, error) {
|
||||
return PackagistPayload{}, nil
|
||||
}
|
||||
|
||||
// Delete implements PayloadConvertor Delete method
|
||||
func (pc packagistConvertor) Delete(_ *api.DeletePayload) (PackagistPayload, error) {
|
||||
return PackagistPayload{}, nil
|
||||
}
|
||||
|
||||
// Fork implements PayloadConvertor Fork method
|
||||
func (pc packagistConvertor) Fork(_ *api.ForkPayload) (PackagistPayload, error) {
|
||||
return PackagistPayload{}, nil
|
||||
}
|
||||
|
||||
// Push implements PayloadConvertor Push method
|
||||
// https://packagist.org/about
|
||||
func (pc packagistConvertor) Push(_ *api.PushPayload) (PackagistPayload, error) {
|
||||
return PackagistPayload{
|
||||
PackagistRepository: struct {
|
||||
URL string `json:"url"`
|
||||
}{
|
||||
URL: pc.PackageURL,
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
|
||||
// Issue implements PayloadConvertor Issue method
|
||||
func (pc packagistConvertor) Issue(_ *api.IssuePayload) (PackagistPayload, error) {
|
||||
return PackagistPayload{}, nil
|
||||
}
|
||||
|
||||
// IssueComment implements PayloadConvertor IssueComment method
|
||||
func (pc packagistConvertor) IssueComment(_ *api.IssueCommentPayload) (PackagistPayload, error) {
|
||||
return PackagistPayload{}, nil
|
||||
}
|
||||
|
||||
// PullRequest implements PayloadConvertor PullRequest method
|
||||
func (pc packagistConvertor) PullRequest(_ *api.PullRequestPayload) (PackagistPayload, error) {
|
||||
return PackagistPayload{}, nil
|
||||
}
|
||||
|
||||
// Review implements PayloadConvertor Review method
|
||||
func (pc packagistConvertor) Review(_ *api.PullRequestPayload, _ webhook_module.HookEventType) (PackagistPayload, error) {
|
||||
return PackagistPayload{}, nil
|
||||
}
|
||||
|
||||
// Repository implements PayloadConvertor Repository method
|
||||
func (pc packagistConvertor) Repository(_ *api.RepositoryPayload) (PackagistPayload, error) {
|
||||
return PackagistPayload{}, nil
|
||||
}
|
||||
|
||||
// Wiki implements PayloadConvertor Wiki method
|
||||
func (pc packagistConvertor) Wiki(_ *api.WikiPayload) (PackagistPayload, error) {
|
||||
return PackagistPayload{}, nil
|
||||
}
|
||||
|
||||
// Release implements PayloadConvertor Release method
|
||||
func (pc packagistConvertor) Release(_ *api.ReleasePayload) (PackagistPayload, error) {
|
||||
return PackagistPayload{}, nil
|
||||
}
|
||||
|
||||
func (pc packagistConvertor) Package(_ *api.PackagePayload) (PackagistPayload, error) {
|
||||
return PackagistPayload{}, nil
|
||||
}
|
||||
|
||||
type packagistConvertor struct {
|
||||
PackageURL string
|
||||
}
|
||||
|
||||
var _ payloadConvertor[PackagistPayload] = packagistConvertor{}
|
||||
|
||||
// newPackagistRequest creates a request with the [PackagistPayload] for packagist (same payload for all events).
|
||||
func newPackagistRequest(ctx 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{
|
||||
PackageURL: meta.PackageURL,
|
||||
|
||||
payload := PackagistPayload{
|
||||
PackagistRepository: struct {
|
||||
URL string `json:"url"`
|
||||
}{
|
||||
URL: meta.PackageURL,
|
||||
},
|
||||
}
|
||||
return newJSONRequest(pc, w, t, true)
|
||||
return newJSONRequestWithPayload(payload, w, t, false)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue