I have configured GitLab with LDAP,using LDAP credentials users able to push code successfully.My use case is I need to retrieve the user’s user name who pushed the code recently.To be more specific lets assume user ‘A’ pushed the code using his LDAP credentials (username:firstname.lastname@example.org and password: ******),I have configured Jenkins in such a way that whenever code is pushed it triggers a build,now I want to retrieve the user name of a guy who pushed the code,here I need to get something like email@example.com.Is there any API that gives this result?or any other process that will help me?Thanks in advance
This is one way to find out the name of the person who has pushed code.
When some one pushes code the gitlab-shell log loos like this
I, [2016-08-16T12:23:30.570521 #4548] INFO -- : POST http://127.0.0.1:8080/api/v3/internal/allowed 4.12064 I, [2016-08-16T12:23:30.571094 #4548] INFO -- : gitlab-shell: executing git command <git-receive-pack /var/opt/gitlab/git-data/repositories/root/hello1.git> for user with key key-1. I, [2016-08-16T12:23:31.235396 #4560] INFO -- : POST http://127.0.0.1:8080/api/v3/internal/allowed 0.23182 I, [2016-08-16T12:23:31.639468 #4567] INFO -- : GET http://127.0.0.1:8080/api/v3/internal/broadcast_message 0.05272
From the above log Key-1 is the person who has pushed the code.
Now you can find the email id of the Key-1 from authorized_keys file.
[ershad@GitlabServer .ssh]# grep key-1 authorized_keys command="/opt/gitlab/embedded/service/gitlab-shell/bin/gitlab-shell key-1",no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDP/CnK1KaHK+OHAQVGtKR3/TxOMp1fKEV+fowzIi7U1O6DMTW5np9i3c3sx2+tuBuvHCw7+pG/Hc/VCfFwa00sTdztTneycoo6G2Y18xtsCbLCOenvXl/46wZ58sXPIaLPTNUcW4eyjN3GWurt2/C28yc863xceVQiI1X6AUOs46NzK/4D/a/okM6OlVVBPSAub8iDkpflDl/9n1nvRGz+OSXXq7gvTmeiP4p2gX+TellaGM1MwOiungqAtCJZc7fQNq4cmRAZmquwgLiMTNcii/hLsl Ershad@gitlab.com
here Ershad@gitlab.com is the email id associated with Key-1. Authorised keys files is the file which stores all the ssh keys of all the users present in the gitlab server.
you might need to write a script to achieve this. There could some other ways also, this the way i know.