mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2025-01-29 18:04:15 +02:00
Added hook parser and opaque in request
This commit is contained in:
parent
d9f9d6f762
commit
044e2ea07a
@ -74,6 +74,10 @@ func (c *Client) Do(method, url, opaque string, body []byte) ([]byte, error) {
|
|||||||
|
|
||||||
req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", c.Token))
|
req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", c.Token))
|
||||||
|
|
||||||
|
if len(opaque) > 0 {
|
||||||
|
req.URL.Opaque = opaque
|
||||||
|
}
|
||||||
|
|
||||||
resp, err := c.Client.Do(req)
|
resp, err := c.Client.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("Client.Do error: %q", err)
|
return nil, fmt.Errorf("Client.Do error: %q", err)
|
||||||
|
@ -1,5 +1,41 @@
|
|||||||
package client
|
package client
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
)
|
||||||
|
|
||||||
|
// ParseHook parses hook payload from GitLab
|
||||||
func ParseHook(payload []byte) (*HookPayload, error) {
|
func ParseHook(payload []byte) (*HookPayload, error) {
|
||||||
return nil, nil
|
hp := HookPayload{}
|
||||||
|
if err := json.Unmarshal(payload, &hp); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Basic sanity check
|
||||||
|
switch {
|
||||||
|
case len(hp.ObjectKind) == 0:
|
||||||
|
// Assume this is a post-receive within repository
|
||||||
|
if len(hp.After) == 0 {
|
||||||
|
return nil, fmt.Errorf("Invalid hook received, commit hash not found.")
|
||||||
|
}
|
||||||
|
case hp.ObjectKind == "push":
|
||||||
|
if hp.Repository == nil {
|
||||||
|
return nil, fmt.Errorf("Invalid push hook received, attributes not found")
|
||||||
|
}
|
||||||
|
case hp.ObjectKind == "tag_push":
|
||||||
|
if hp.Repository == nil {
|
||||||
|
return nil, fmt.Errorf("Invalid tag push hook received, attributes not found")
|
||||||
|
}
|
||||||
|
case hp.ObjectKind == "issue":
|
||||||
|
fallthrough
|
||||||
|
case hp.ObjectKind == "merge_request":
|
||||||
|
if hp.ObjectAttributes == nil {
|
||||||
|
return nil, fmt.Errorf("Invalid hook received, attributes not found.")
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
return nil, fmt.Errorf("Invalid hook received, payload format not recognized.")
|
||||||
|
}
|
||||||
|
|
||||||
|
return &hp, nil
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user