Skip to content
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
5 changes: 5 additions & 0 deletions github/repos_hooks_deliveries.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package github
import (
"context"
"encoding/json"
"errors"
"fmt"
"strings"
)
Expand Down Expand Up @@ -165,6 +166,10 @@ func (s *RepositoriesService) RedeliverHookDelivery(ctx context.Context, owner,
// ParseRequestPayload parses the request payload. For recognized event types,
// a value of the corresponding struct type will be returned.
func (d *HookDelivery) ParseRequestPayload() (any, error) {
if d == nil || d.Request == nil {
return nil, errors.New("hook delivery request is nil")
}

eType, ok := messageToTypeName[d.GetEvent()]
if !ok {
return nil, fmt.Errorf("unsupported event type %q", d.GetEvent())
Expand Down
16 changes: 16 additions & 0 deletions github/repos_hooks_deliveries_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,22 @@ func TestHookDelivery_ParsePayload_invalidPayload(t *testing.T) {
}
}

func TestHookDelivery_ParseRequestPayload_nilRequest(t *testing.T) {
t.Parallel()

var nilDelivery *HookDelivery
if _, err := nilDelivery.ParseRequestPayload(); err == nil {
t.Error("(*HookDelivery)(nil).ParseRequestPayload() returned nil error, want non-nil")
}

d := &HookDelivery{
Event: new("push"),
}
if _, err := d.ParseRequestPayload(); err == nil {
t.Error("HookDelivery.ParseRequestPayload() with nil Request returned nil error, want non-nil")
}
}

func TestHookRequest_GetHeader(t *testing.T) {
t.Parallel()

Expand Down