Add git hooks for branch name validation (#3479)

This commit is contained in:
Brendan Bergen 2024-03-25 13:48:08 -06:00 коммит произвёл GitHub
Родитель 1495c32317
Коммит 2d6b88cb10
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
4 изменённых файлов: 40 добавлений и 1 удалений

Просмотреть файл

@ -113,6 +113,9 @@ generate-kiota:
go run ./hack/validate-imports pkg/util/graph/graphsdk
go run ./hack/licenses -dirs ./pkg/util/graph/graphsdk
init-contrib:
cp -R hack/git/hooks/* .git/hooks/
image-aro-multistage:
docker build --platform=linux/amd64 --network=host --no-cache -f Dockerfile.aro-multistage -t $(ARO_IMAGE) --build-arg REGISTRY=$(REGISTRY) .
@ -270,4 +273,4 @@ vendor:
install-go-tools:
go install ${GOTESTSUM}
.PHONY: admin.kubeconfig aks.kubeconfig aro az ci-portal clean client deploy dev-config.yaml discoverycache generate image-aro-multistage image-fluentbit image-proxy lint-go runlocal-rp proxy publish-image-aro-multistage publish-image-fluentbit publish-image-proxy secrets secrets-update e2e.test tunnel test-e2e test-go test-python vendor build-all validate-go unit-test-go coverage-go validate-fips install-go-tools
.PHONY: admin.kubeconfig aks.kubeconfig aro az ci-portal clean client deploy dev-config.yaml discoverycache generate image-aro-multistage image-fluentbit image-proxy init-contrib lint-go runlocal-rp proxy publish-image-aro-multistage publish-image-fluentbit publish-image-proxy secrets secrets-update e2e.test tunnel test-e2e test-go test-python vendor build-all validate-go unit-test-go coverage-go validate-fips install-go-tools

Просмотреть файл

@ -29,6 +29,13 @@ you to agree to a Contributor License Agreement (CLA) declaring that you have
the right to, and actually do, grant us the rights to use your contribution. For
details, visit https://cla.microsoft.com.
Before you start development, please set up your local git hooks to conform to our
development standards:
```bash
make init-contrib
```
When you submit a pull request, a CLA-bot will automatically determine whether
you need to provide a CLA and decorate the PR appropriately (e.g., label,
comment). Simply follow the instructions provided by the bot. You will only need

Просмотреть файл

@ -138,3 +138,9 @@ Make sure that `PKG_CONFIG_PATH` contains the pkgconfig files of the above packa
```bash
cd ${GOPATH:-$HOME/go}/src/github.com/Azure/ARO-RP
```
1. Add standard git hooks
```bash
make init-contrib
```

23
hack/git/hooks/pre-commit Normal file
Просмотреть файл

@ -0,0 +1,23 @@
#!/usr/bin/env bash
set -e
LC_ALL=C
git_username_lower="$(git config github.user | tr '[:upper:]' '[:lower:]')"
if [[ -z "${git_username_lower}" ]]
then
echo "Please set github.user (git config github.user) locally or globally before issuing commits to this repo."
exit 1
fi
# e.g. "USERNAME/ARO-1234", "USERNAME/hotfix-v20240321.00", or "USERNAME/gh-issue-123"
valid_branch_regex="^${git_username_lower}\/(ARO-[0-9]{4}[a-z0-9._-]*|hotfix-[a-z0-9._-]+|gh-issue-[0-9]+[a-z0-9._-]*)$"
local_branch="$(git rev-parse --abbrev-ref HEAD)"
if [[ ! $local_branch =~ $valid_branch_regex ]]
then
echo "There is something wrong with your branch name. Branch names in this project must adhere to this contract: $valid_branch_regex. Your commit will be rejected. Please rename your branch (git branch --move) to a valid name and try again."
exit 1
fi
exit 0