Skip to content

Commit

Permalink
fix: improve GetPushEventPayload
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfogre committed Mar 1, 2023
1 parent 7a5af25 commit b99f9f8
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions models/actions/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,29 @@ func (run *ActionRun) Duration() time.Duration {

func (run *ActionRun) GetPushEventPayload() (*api.PushPayload, error) {
if run.Event == webhook_module.HookEventPush {
var payload api.PushPayload
if err := json.Unmarshal([]byte(run.EventPayload), &payload); err != nil {
return nil, err
}
return &payload, nil
return nil, fmt.Errorf("event %s is not a push event", run.Event)
}

payload := &api.PushPayload{}
if err := json.Unmarshal([]byte(run.EventPayload), payload); err != nil {
return nil, err
}

// Since it comes from json unmarshal, we should check if it's broken
if payload.HeadCommit == nil {
return nil, fmt.Errorf("nil HeadCommit")
}
if payload.Repo == nil {
return nil, fmt.Errorf("nil Repo")
}
if payload.Pusher == nil {
return nil, fmt.Errorf("nil Pusher")
}
return nil, fmt.Errorf("event %s is not a push event", run.Event)
if payload.Sender == nil {
return nil, fmt.Errorf("nil Sender")
}

return payload, nil
}

func updateRepoRunsNumbers(ctx context.Context, repo *repo_model.Repository) error {
Expand Down

0 comments on commit b99f9f8

Please sign in to comment.