phpro / grumphp

A PHP code-quality tool
MIT License
4.15k stars 431 forks source link

mono -> many repo structure feasibility #531

Closed redthor closed 6 years ago

redthor commented 6 years ago
Q A
Version 0.14.1
Bug? yes
New feature? yes
Question? yes
Documentation? no
Related tickets

Thanks for GrumPHP!

I'm setting up for the first time and I just wanted to get some feedback on GrumPHP and applicability with the mono -> many repo structure enabled by https://github.com/splitsh/lite and https://github.com/jderusse/docker-gitsplit

It simply might not be suitable, but you might have some feedback or ideas for me, hence this ticket.

Given this structure:

/mono
  /.git
  /projectA (commits in the folder are sent to git@business.com:business/projectA.git by a CI job)
    /src
    /tests
    /composer.json
    /grumphp.yml
  /projectB
  /..

I added "phpro/grumphp" into projectA/composer.json and GrumPHP created projectA/.git and added the hooks in there instead of adding it to mono/.git/. The fix might be to look recursively up the folder tree for .git/ and and use that one instead. However I then realised there were other problems with my setup.

You can set GrumPHP config to look at the right .git/ folder:

# projectA/grumphp.yml
parameters:
    # assuming we are working from the mono repo
    git_dir: ../.git

Then run GrumPHP from the projectA folder:

cd mono\projectA
./vendor/bin/grumphp run

The issue is that it appears to prefix CWD to the files it finds with ls-files. Also, ls-files is returning all files from all project folders. It then passes to the Task, e.g. phpmd, which then complains the files cannot be found:

# projectA files:
Path /mono/projectA/projectA/src/Business/ProjectA/MyClass.php does not exist

# projectB files:
Path /mono/projectA/projectB/src/Business/ProjectB/MyClass.php does not exist

I could look into a solution for this, but I did wonder, what should I expect my commit includes changes in projectB? I wasn't sure of the answer given it might have it's own projectB/grumphp.yml... One could have a warning "only checking files descending from grumphp.yml"

So to summarise:

  1. Possible ascend up and look for .git folder on initialisation;
  2. Prevent CWD prefix issue;
  3. Possible feature (config setting?) to whitelist files that descend from grumphp.yml;
redthor commented 6 years ago

Part of my issues appears to be due to git_dir parameter being the folder where the .git folder is found as opposed to the actual .git folder. Removing .git helped a bit.

In the future it'd be good if git_dir meant the "git directory" :)