How to implement branch commit check before merge

Hello. For my project I want to force all merge request authors to conform some rules of branch structure:

  1. The main branch is the only branch that can be merged into MR’s branch
  2. Merge request branch must have linear commit history
  3. The number of changes should not exceed N percent of the entire codebase
  4. Commit messages must confirm a defined regexp
  5. Commits must have the same committer user and author user
  6. Commits must have the same committer date and author date

But I don’t clearly understand what tool to use to implement these rules and how to integrate it to my repos. I firstly planned to achieve it using bash scripts called from GitLab CI but maybe is there a better way? Has anyone tried to do this before?

I’m using self-managed gitlab

Thank you in advance :love_you_gesture:

Hi @RareScrap

Since you are planning to do some heavy git history stuff, a custom solution is the only option I can see.