Skip to content

Use hp.ObjectKind as expression in payload switch #48

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
20 changes: 9 additions & 11 deletions hook_payload.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,20 +86,18 @@ func ParseHook(payload []byte) (*HookPayload, error) {
}

// 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 == "pipeline":
fallthrough
case hp.ObjectKind == "issue":
fallthrough
case hp.ObjectKind == "merge_request":
switch hp.ObjectKind {
case "push":
break
case "pipeline":
break
case "issue":
break
case "merge_request":
if hp.ObjectAttributes == nil {
return nil, fmt.Errorf("Invalid hook received, attributes not found.")
}
break
default:
return nil, fmt.Errorf("Invalid hook received, payload format not recognized.")
}
Expand Down
1 change: 1 addition & 0 deletions stubs/hooks/push.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"object_kind": "push",
"before": "95790bf891e76fee5e1747ab589903a6a1f80f22",
"after": "da1560886d4f094c3e6c9ef40349f7d38b5d27d7",
"ref": "refs/heads/master",
Expand Down