How to configure pre_receive_hooks, so that the hooks validates all the branches and its commits when Developer commits

Hello folks,
I am trying to setup a pipeline in gitlab which validates the below, whenever developers pushes commit to gitlab.

  1. The commit message shall start with ‘#’, followed by 7 digits, A Space, & 3-400 characters.
    eg: #1234567 Implementation
  2. #1234567 is the Ticket ID from Code beamer.
    git commit operation should be valid, only is this Ticket ID is in OPEN status in code beamer.

How do i achieve this? only with pipelines

Trials:

  1. script on ./git/hooks isnot feasible as the changes is in local and wont reflect if any new user clones the repo.
  2. Push rules: this isnot feasible as well, as we need to add branches in Protected State

./git/hooks couldnot be an ideal solution as it limited only to local