Skip to content

Commit

Permalink
Modify branch validator
Browse files Browse the repository at this point in the history
Added `branch.name.validation.yml

Added pre-commit hook with wpcs-check
  • Loading branch information
girafffee committed Nov 22, 2023
1 parent 6b5b8ff commit 8c0e795
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
* text=auto

.wordpress-org export-ignore
.husky export-ignore
codeception.yml export-ignore
codeception.dist.yml export-ignore
.env.example export-ignore
composer.json export-ignore
package.json export-ignore
phpcs.xml export-ignore
README.md export-ignore
wp-cli.local.yml export-ignore
Expand Down
20 changes: 20 additions & 0 deletions .github/workflows/branch.name.validation.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Branch Name Validation

on:
create:
branches:
- '*'

jobs:
branch_name_validation:
runs-on: ubuntu-latest

steps:
- name: Check Branch Name
id: check_branch
run: |
branch_name="${GITHUB_REF#refs/heads/}"
if ! [[ "$branch_name" =~ ^(main|(release/[0-9]+\.[0-9]+\.[0-9]+)|(issue/[0-9]+)|(suggestion/[0-9]+)|(feature/[a-z0-9\-]+)|(dev/[a-z0-9\-]+))$ ]]; then
echo "Invalid branch name: $branch_name"
exit 1
fi
9 changes: 9 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

# Check if there are modified or newly created .php files
if git status --porcelain | grep -e '^M' -e '^A' | grep '\.php$' &> /dev/null; then
composer cs
else
exit 0
fi
14 changes: 14 additions & 0 deletions .husky/pre-push
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

while read local_ref local_sha remote_ref remote_sha; do
# Extracting the branch name
branch_name=$(echo "$local_ref" | cut -d '/' -f 3-)

# Check if the branch name matches any of the specified patterns
# shellcheck disable=SC2039
if ! [[ "$branch_name" =~ ^(main|(release/[0-9]+\.[0-9]+\.[0-9]+)|(issue/[0-9]+)|(suggestion/[0-9]+)|(feature/[a-z0-9\-]+)|(dev/[a-z0-9\-]+))$ ]]; then
echo "Error: Branch name \"$branch_name\" is not allowed."
exit 1
fi
done
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
"./vendor/bin/phpcbf -p -n --colors --standard=./phpcs.xml ."
],
"cs": "./vendor/bin/phpcs -p -s -n --colors --standard=./phpcs.xml .",
"test:wpunit": "./vendor/bin/codecept run wpunit"
"test:wpunit": "./vendor/bin/codecept run wpunit",
"post-install-cmd": "npm install"
},
"minimum-stability": "stable",
"require-dev": {
Expand Down
30 changes: 30 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"name": "jetformbuilder",
"version": "3.2.0",
"description": "wordpress-plugin",
"directories": {
"test": "tests"
},
"repository": {
"type": "git",
"url": "git+https://github.com/Crocoblock/jetformbuilder.git"
},
"keywords": [
"plugin",
"wordpress",
"form",
"builder"
],
"author": "Oleksandr Ivanenko <[email protected]>",
"license": "MIT",
"bugs": {
"url": "https://github.com/Crocoblock/jetformbuilder/issues"
},
"homepage": "https://github.com/Crocoblock/jetformbuilder#readme",
"devDependencies": {
"husky": "^8.0.3"
},
"scripts": {
"postinstall": "npx husky install"
}
}

0 comments on commit 8c0e795

Please sign in to comment.