From 3b9f8a3c825cb46a00a95910500f223db79e8094 Mon Sep 17 00:00:00 2001 From: MH4GF Date: Thu, 19 Oct 2023 10:01:18 +0900 Subject: [PATCH] maintenance: Use event.ParsePayload() instead of deprecated event.Payload() --- lib/events.go | 20 +++++++++++++------- lib/list.go | 5 ++++- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/lib/events.go b/lib/events.go index 51c746b..0ffc325 100644 --- a/lib/events.go +++ b/lib/events.go @@ -26,7 +26,7 @@ func NewEvents(ctx context.Context, client *github.Client, user string, sinceTim } // Collect retrieve GitHub `e.user` events from `e.sinceTime` to `e.untilTime` -func (e *Events) Collect() []*github.Event { +func (e *Events) Collect() ([]*github.Event, error) { return e.uniq(e.filter(e.retrieve())) } @@ -101,12 +101,15 @@ func (e *Events) filter(events []*github.Event) []*github.Event { return result } -func (e *Events) uniq(events []*github.Event) []*github.Event { +func (e *Events) uniq(events []*github.Event) ([]*github.Event, error) { m := make(map[string]bool) var result []*github.Event for _, event := range events { - htmlURL := htmlURL(event) + htmlURL, err := htmlURL(event) + if err != nil { + return nil, err + } if !m[htmlURL] { m[htmlURL] = true @@ -114,12 +117,15 @@ func (e *Events) uniq(events []*github.Event) []*github.Event { } } - return result + return result, nil } -func htmlURL(event *github.Event) string { +func htmlURL(event *github.Event) (string, error) { var result string - payload := event.Payload() + payload, err := event.ParsePayload() + if err != nil { + return "", err + } switch *event.Type { case "IssuesEvent": @@ -134,5 +140,5 @@ func htmlURL(event *github.Event) string { result = *payload.(*github.PullRequestReviewEvent).PullRequest.HTMLURL } - return result + return result, nil } diff --git a/lib/list.go b/lib/list.go index 2dcc1c5..7043553 100644 --- a/lib/list.go +++ b/lib/list.go @@ -35,7 +35,10 @@ func List(sinceDate, untilDate string, debug bool) error { ctx := context.Background() client := getClient(ctx, accessToken) - events := NewEvents(ctx, client, user, sinceTime, untilTime, debug).Collect() + events, err := NewEvents(ctx, client, user, sinceTime, untilTime, debug).Collect() + if err != nil { + return err + } format := NewFormat(ctx, client, debug) parallelNum, err := getParallelNum()