webhook firing on the oldest commit instead of the latest

Summary

When a webhook is fired on a git push event consisted of multiple commits, the hook's data contains the oldest commit instead of the very latest commit

Steps to reproduce

  1. create an empty repo on gitlab.com and add a webhook on push event
  2. clone an existing repo with multiple commits, and push the repo over to gitlab.com

Example Project

https://gitlab.com/yuanchenlu/repo50641/hooks/1245050/hook_logs/194854073

What is the current bug behavior?

hook's request data has commits[0] as the latest commit

What is the expected correct behavior?

hook's request data has commits[0] as the oldest commit per https://docs.gitlab.com/ee/user/project/integrations/webhooks.html#push-events

Relevant logs and/or screenshots

screenshot here

Output of checks

(If you are reporting a bug on GitLab.com, write: This bug happens on GitLab.com)

Results of GitLab environment info

Expand for output related to GitLab environment info

(For installations with omnibus-gitlab package run and paste the output of: sudo gitlab-rake gitlab:env:info)

(For installations from source run and paste the output of: sudo -u git -H bundle exec rake gitlab:env:info RAILS_ENV=production)

Results of GitLab application Check

Expand for output related to the GitLab application check

(For installations with omnibus-gitlab package run and paste the output of: sudo gitlab-rake gitlab:check SANITIZE=true)

(For installations from source run and paste the output of: sudo -u git -H bundle exec rake gitlab:check RAILS_ENV=production SANITIZE=true)

(we will only investigate if the tests are passing)

Possible fixes

in app/services/git/base_hooks_service.rb: event_push_data commits.last returns the last element of the commits array, which happens to be the oldest commit; A comparison between the timestamps of two commits (commits[len-1] and commits[0]) should be checked before passing the newer one to push_data

Assignee Loading
Time tracking Loading