pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://github.com/drone/go-scm/pull/35/files

428.css" /> fix for gitea push webhook by jstrachan · Pull Request #35 · drone/go-scm · GitHub
Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions scm/driver/gitea/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,13 @@ func (s *webhookService) Parse(req *http.Request, fn scm.SecretFunc) (scm.Webhoo
return nil, err
}

secret := ""
var hook scm.Webhook
switch req.Header.Get("X-Gitea-Event") {
case "push":
hook, err = s.parsePushHook(data)
var push *pushHook
hook, push, err = s.parsePushHook(data)
secret = push.Secret
case "create":
hook, err = s.parseCreateHook(data)
case "delete":
Expand All @@ -49,6 +52,10 @@ func (s *webhookService) Parse(req *http.Request, fn scm.SecretFunc) (scm.Webhoo
return nil, err
}

if secret == "" {
secret = req.FormValue("secret")
}

// get the gitea signature key to verify the payload
// signature. If no key is provided, no validation
// is performed.
Expand All @@ -59,14 +66,13 @@ func (s *webhookService) Parse(req *http.Request, fn scm.SecretFunc) (scm.Webhoo
return hook, nil
}

secret := req.FormValue("secret")
signature := req.Header.Get("X-Gitea-Signature")

// fail if no signature passed
if signature == "" && secret == "" {
return hook, scm.ErrSignatureInvalid
}

// test signature if header not set and secret is in payload
if signature == "" && secret != "" && secret != key {
return hook, scm.ErrSignatureInvalid
Expand All @@ -80,10 +86,10 @@ func (s *webhookService) Parse(req *http.Request, fn scm.SecretFunc) (scm.Webhoo
return hook, nil
}

func (s *webhookService) parsePushHook(data []byte) (scm.Webhook, error) {
func (s *webhookService) parsePushHook(data []byte) (scm.Webhook, *pushHook, error) {
dst := new(pushHook)
err := json.Unmarshal(data, dst)
return convertPushHook(dst), err
return convertPushHook(dst), dst, err
}

func (s *webhookService) parseCreateHook(data []byte) (scm.Webhook, error) {
Expand Down Expand Up @@ -140,6 +146,7 @@ func (s *webhookService) parsePullRequestHook(data []byte) (scm.Webhook, error)
type (
// gitea push webhook payload
pushHook struct {
Secret string `json:"secret"`
Ref string `json:"ref"`
Before string `json:"before"`
After string `json:"after"`
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy