Skip to content

Commit

Permalink
add not found check
Browse files Browse the repository at this point in the history
  • Loading branch information
huhudev-git committed Mar 9, 2022
1 parent 20d888c commit 9101d63
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions gitea/gitea.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ var (
ErrInvalidHTTPMethod = errors.New("invalid HTTP Method")
ErrMissingGiteaEventHeader = errors.New("missing X-Gitea-Event Header")
ErrMissingGiteaSignatureHeader = errors.New("missing X-Gitea-Signature Header")
ErrEventNotFound = errors.New("event not defined to be parsed")
ErrParsingPayload = errors.New("error parsing payload")
ErrHMACVerificationFailed = errors.New("HMAC verification failed")
)
Expand Down Expand Up @@ -102,6 +103,18 @@ func (hook Webhook) Parse(r *http.Request, events ...Event) (interface{}, error)

giteaEvent := Event(event)

var found bool
for _, evt := range events {
if evt == giteaEvent {
found = true
break
}
}
// event not defined to be parsed
if !found {
return nil, ErrEventNotFound
}

payload, err := ioutil.ReadAll(r.Body)
if err != nil || len(payload) == 0 {
return nil, ErrParsingPayload
Expand Down

0 comments on commit 9101d63

Please sign in to comment.