Skip to content
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

maintenance: Use event.ParsePayload() instead of deprecated event.Payload() #111

Merged
merged 1 commit into from
Oct 19, 2023
Merged
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: 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