diff --git a/github/github-accessors.go b/github/github-accessors.go index b16d2847e6b..96dc39de358 100644 --- a/github/github-accessors.go +++ b/github/github-accessors.go @@ -19430,6 +19430,14 @@ func (h *HookDelivery) GetStatusCode() int { return *h.StatusCode } +// GetThrottledAt returns the ThrottledAt field if it's non-nil, zero value otherwise. +func (h *HookDelivery) GetThrottledAt() Timestamp { + if h == nil || h.ThrottledAt == nil { + return Timestamp{} + } + return *h.ThrottledAt +} + // GetHeaders returns the Headers map if it's non-nil, an empty map otherwise. func (h *HookRequest) GetHeaders() map[string]string { if h == nil || h.Headers == nil { diff --git a/github/github-accessors_test.go b/github/github-accessors_test.go index 83103ef47b6..a5fa794120f 100644 --- a/github/github-accessors_test.go +++ b/github/github-accessors_test.go @@ -24414,6 +24414,17 @@ func TestHookDelivery_GetStatusCode(tt *testing.T) { h.GetStatusCode() } +func TestHookDelivery_GetThrottledAt(tt *testing.T) { + tt.Parallel() + var zeroValue Timestamp + h := &HookDelivery{ThrottledAt: &zeroValue} + h.GetThrottledAt() + h = &HookDelivery{} + h.GetThrottledAt() + h = nil + h.GetThrottledAt() +} + func TestHookRequest_GetHeaders(tt *testing.T) { tt.Parallel() zeroValue := map[string]string{} diff --git a/github/github-stringify_test.go b/github/github-stringify_test.go index 60409b9f2a1..2ec670953c9 100644 --- a/github/github-stringify_test.go +++ b/github/github-stringify_test.go @@ -849,10 +849,11 @@ func TestHookDelivery_String(t *testing.T) { Action: new(""), InstallationID: new(int64(0)), RepositoryID: new(int64(0)), + ThrottledAt: &Timestamp{}, Request: &HookRequest{}, Response: &HookResponse{}, } - want := `github.HookDelivery{ID:0, GUID:"", DeliveredAt:github.Timestamp{0001-01-01 00:00:00 +0000 UTC}, Redelivery:false, Duration:0, Status:"", StatusCode:0, Event:"", Action:"", InstallationID:0, RepositoryID:0, Request:github.HookRequest{}, Response:github.HookResponse{}}` + want := `github.HookDelivery{ID:0, GUID:"", DeliveredAt:github.Timestamp{0001-01-01 00:00:00 +0000 UTC}, Redelivery:false, Duration:0, Status:"", StatusCode:0, Event:"", Action:"", InstallationID:0, RepositoryID:0, ThrottledAt:github.Timestamp{0001-01-01 00:00:00 +0000 UTC}, Request:github.HookRequest{}, Response:github.HookResponse{}}` if got := v.String(); got != want { t.Errorf("HookDelivery.String = %v, want %v", got, want) } diff --git a/github/repos_hooks_deliveries.go b/github/repos_hooks_deliveries.go index 85b83e04582..e7b6dabfd9a 100644 --- a/github/repos_hooks_deliveries.go +++ b/github/repos_hooks_deliveries.go @@ -29,6 +29,7 @@ type HookDelivery struct { Action *string `json:"action,omitempty"` InstallationID *int64 `json:"installation_id,omitempty"` RepositoryID *int64 `json:"repository_id,omitempty"` + ThrottledAt *Timestamp `json:"throttled_at,omitempty"` // Request is populated by GetHookDelivery. Request *HookRequest `json:"request,omitempty"` diff --git a/github/repos_hooks_deliveries_test.go b/github/repos_hooks_deliveries_test.go index 4e8853d8808..005f2addc5d 100644 --- a/github/repos_hooks_deliveries_test.go +++ b/github/repos_hooks_deliveries_test.go @@ -22,7 +22,7 @@ func TestRepositoriesService_ListHookDeliveries(t *testing.T) { mux.HandleFunc("/repos/o/r/hooks/1/deliveries", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "GET") testFormValues(t, r, values{"cursor": "v1_12077215967"}) - fmt.Fprint(w, `[{"id":1}, {"id":2}]`) + fmt.Fprint(w, `[{"id":1,"throttled_at":`+referenceTimeStr+`}, {"id":2}]`) }) opt := &ListCursorOptions{Cursor: "v1_12077215967"} @@ -33,7 +33,7 @@ func TestRepositoriesService_ListHookDeliveries(t *testing.T) { t.Errorf("Repositories.ListHookDeliveries returned error: %v", err) } - want := []*HookDelivery{{ID: new(int64(1))}, {ID: new(int64(2))}} + want := []*HookDelivery{{ID: new(int64(1)), ThrottledAt: &referenceTimestamp}, {ID: new(int64(2))}} if d := cmp.Diff(hooks, want); d != "" { t.Errorf("Repositories.ListHooks want (-), got (+):\n%v", d) } @@ -68,7 +68,7 @@ func TestRepositoriesService_GetHookDelivery(t *testing.T) { mux.HandleFunc("/repos/o/r/hooks/1/deliveries/1", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "GET") - fmt.Fprint(w, `{"id":1}`) + fmt.Fprint(w, `{"id":1,"throttled_at":`+referenceTimeStr+`}`) }) ctx := t.Context() @@ -77,7 +77,7 @@ func TestRepositoriesService_GetHookDelivery(t *testing.T) { t.Errorf("Repositories.GetHookDelivery returned error: %v", err) } - want := &HookDelivery{ID: new(int64(1))} + want := &HookDelivery{ID: new(int64(1)), ThrottledAt: &referenceTimestamp} if !cmp.Equal(hook, want) { t.Errorf("Repositories.GetHookDelivery returned %+v, want %+v", hook, want) }