Skip to content
Snippets Groups Projects
Commit db188a72 authored by Donovan Bourlard's avatar Donovan Bourlard
Browse files

Add Git hook for php-cs-fixer + MR template

parent 63fc80bd
No related branches found
No related tags found
No related merge requests found
## Hooks git
#### 1. Copy .git-hooks directory into project
#### 2. Deplace the hooks to the git's hook repository
Execute this command from your local at the root directory of your project
```bash
cp -R .git-hooks/hooks/ .git/hooks
chmod -R 744 .git/hooks
```
#### 3. Change the git's hook path configuration
Execute this command from your local at the root directory of your project
```bash
git config core.hooksPath .git/hooks
```
This command tell to git where he haves to check for hooks.
By default the hooks path is in .git/hooks, but maybe in future other hooks will be create.
#!/bin/bash
echo Running $BASH_SOURCE
FILES=$(find .git/hooks/pre-commit-scripts -type f|grep "pre-commit-*")
for FILE in $FILES
do
echo "Execution of pre-commit hook: $FILE"
./$FILE
if [ $? -eq 1 ]
then
exit 1
fi
done
#!/bin/bash
# PHP CodeSniffer pre-commit hook for git
#
# @author Soenke Ruempler <soenke@ruempler.eu>
# @author Sebastian Kaspari <s.kaspari@googlemail.com>
# Updated to BiiG usage by Elisabeth Blancon
function checkFile
{
echo "Checking file: $1"
# Set config file depending on file
CONFIG_FILE=""
# Launch csfixer
PATHTOFOLDER=$('PWD')
FILE_WITHOUT_DIR=`echo $1`
# Exec command
echo "Command csfixer: bash $PATHTOFOLDER/docker-service csFixer \"$FILE_WITHOUT_DIR $CONFIG_FILE\""
OUTPUT=$(bash $PATHTOFOLDER/docker-service csFixer "$FILE_WITHOUT_DIR $CONFIG_FILE")
EXEC_SUCCESS=$?
# Add file to git or show error
if [ "$EXEC_SUCCESS" -gt "1" ]
then
echo "An error occured while php-cs-fixer on file: $FILE_WITHOUT_DIR, error msg: $OUTPUT"
exit "$EXEC_SUCCESS"
else
GITADD="git add $1"
$($GITADD)
fi
}
# this is the magic:
# retrieve all files in staging area that are added, modified or renamed
# but no deletions etc
FILES=$(git diff-index --name-only --cached --diff-filter=ACMR HEAD -- | grep -e "\.php$")
if [ "$FILES" == "" ]; then
exit 0
fi
# match files against whitelist
for FILE in $FILES
do
RETVAL=$?
if [ "$RETVAL" -eq "0" ]
then
checkFile "$FILE"
fi
done
exit 0
closes #NumeroDeVotreIssue
Problème
--------
Expliquer le problème si l'issue ne donne pas assez d'informations
Les informations techniques sont intéressantes
Solution proposée
-----------------
Détailler si besoin votre solution technique et ce qu'elle implique potentiellement.
Nouveaux outils et réutilisation
--------------------------------
Vous avez ajouté de nouveaux concepts ? Expliquez ici pourquoi et comment les réutiliser.
N'hésitez pas à ajouter des liens vers des pages de documentation.
Screenshot
----------
Si il y a quelque chose à montrer, vantez vous.
TODO
----
Si applicable, sinon supprimer
- [ ] chose 1
- [ ] chose 2
**Cette MR n'est pas à review tant que les points ne sont pas checkés !**
Vérifiez que c'est complet
--------------------------
- [ ] tests
- [ ] lint
Review de la MR
---------------
- [ ] Vérifier que la MR répond à la problématique
- [ ] Identifier les bugs potentiels
- [ ] Vérifier que des tests ont été ajoutés
- [ ] Vérifier d'éventuels commentaires manquants
- [ ] Vérifier que le code est propre (php csfixer, lint)
Specific:
- [ ] Identifier le non respect des standards solid
- [ ] Tester la MR (dépend de la fonctionnalité)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment