title: Gitlab 12.X - Get project id from storage path in a pre-receive hook
body: <p>With legacy storage, when a pre-receive hook fires, it is easy to guess the URL of the repository involved as the path is "group/project-name.git".</p>
  
  <p>With new hashed storage in Gitlab, the "pwd" command will return a path such as d4735e3a265e16eee03f59718b9b5d03019c07d8b6c51f90da3a666eec13ab35.git  if the project id is 2. </p>
  
  <p>=> How can I get the project id based on the hashed path ?</p>
  
  <p>My aim is to check that all the commits being pushed by someone are authored by people who are actually authorized to write inside that project. I cannot do so if I do not know which project is involved. Although I can launch the "gitlab-rails console"  and used "ProjectRepository.find_by", it is not practical to use that script in the context of a hook.</p>
  
  <p>There are Push Rules that allows to do that. However, Push Rules are not free and are not available in Gitlab CE.</p>
  
  <p>Also, from an admin point of view, it is important to be able to find quickly the project id of a repository based on its repository storage path without necessarily having to launch the "gitlab-rails console". </p>