Skip to content

Commit

Permalink
Add git hooks for branch name validation
Browse files Browse the repository at this point in the history
  • Loading branch information
SudoBrendan committed Mar 22, 2024
1 parent 14e3c5a commit d4c27b9
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 1 deletion.
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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) .

Expand Down Expand Up @@ -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
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions docs/prepare-your-dev-environment.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 changes: 23 additions & 0 deletions hack/git/hooks/pre-commit
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit d4c27b9

Please sign in to comment.