Skip to content

Commit

Permalink
Merge pull request #111 from MH4GF/fix-depracated-api
Browse files Browse the repository at this point in the history
maintenance: Use event.ParsePayload() instead of deprecated event.Payload()
  • Loading branch information
masutaka authored Oct 19, 2023
2 parents 6712b39 + 3b9f8a3 commit 7b116d2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
20 changes: 13 additions & 7 deletions lib/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()))
}

Expand Down Expand Up @@ -101,25 +101,31 @@ 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
result = append(result, 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":
Expand All @@ -134,5 +140,5 @@ func htmlURL(event *github.Event) string {
result = *payload.(*github.PullRequestReviewEvent).PullRequest.HTMLURL
}

return result
return result, nil
}
5 changes: 4 additions & 1 deletion lib/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 7b116d2

Please sign in to comment.