From 9c61b2e3d905072318f7d0d85c843dd5e9001a9b Mon Sep 17 00:00:00 2001 From: Er Amit Gupta <72160684+eramitgupta@users.noreply.github.com> Date: Wed, 25 Dec 2024 16:54:21 +0530 Subject: [PATCH 01/10] Create lint.yml --- .github/workflows/lint.yml | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 .github/workflows/lint.yml diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 0000000..6063ed8 --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,34 @@ +name: Lint Check + +on: + push: + branches: + - main + pull_request: + branches: + - main + +jobs: + lint: + runs-on: ubuntu-latest + + steps: + # Checkout the code + - name: Checkout code + uses: actions/checkout@v3 + + # Set up PHP + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: '8.0' # Adjust to match your PHP version + extensions: mbstring, bcmath + tools: composer + + # Install dependencies + - name: Install dependencies + run: composer install --no-scripts --no-interaction --prefer-dist + + # Run Pint linting + - name: Run Pint Lint + run: composer lint From d00466e99b7c28da2de63d5fdf6e4fd4e534c8cd Mon Sep 17 00:00:00 2001 From: eramitgupta Date: Wed, 25 Dec 2024 16:57:10 +0530 Subject: [PATCH 02/10] feat: add pint --- composer.json | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/composer.json b/composer.json index 4256cc2..0d32ff3 100644 --- a/composer.json +++ b/composer.json @@ -24,6 +24,7 @@ "homepage": "https://github.com/eramitgupta/laravel-role-permission", "require": { "php": "^8.0", + "laravel/pint": "^1.13", "illuminate/auth": "^8.12|^9.0|^10.0|^11.0", "illuminate/container": "^8.12|^9.0|^10.0|^11.0", "illuminate/contracts": "^8.12|^9.0|^10.0|^11.0", @@ -38,11 +39,19 @@ } }, "prefer-stable": true, + "minimum-stability": "stable", "extra": { "laravel": { "providers": [ "EragPermission\\PermissionServiceProvider" ] } + }, + "scripts": { + "lint": "pint", + "lint:dirty": "pint --dirty", + "post-install-cmd": [ + "@lint" + ] } } From 3e3b12071a2377bc6112e8f036ca2e778827c294 Mon Sep 17 00:00:00 2001 From: eramitgupta Date: Wed, 25 Dec 2024 17:00:20 +0530 Subject: [PATCH 03/10] feat: fix --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 0d32ff3..b2e6298 100644 --- a/composer.json +++ b/composer.json @@ -23,8 +23,8 @@ ], "homepage": "https://github.com/eramitgupta/laravel-role-permission", "require": { - "php": "^8.0", - "laravel/pint": "^1.13", + "php": "^8.0|^8.1", + "laravel/pint": "^1.18", "illuminate/auth": "^8.12|^9.0|^10.0|^11.0", "illuminate/container": "^8.12|^9.0|^10.0|^11.0", "illuminate/contracts": "^8.12|^9.0|^10.0|^11.0", From 747960fff7163b518b42c2b7e047d48a76581582 Mon Sep 17 00:00:00 2001 From: eramitgupta Date: Wed, 25 Dec 2024 17:02:40 +0530 Subject: [PATCH 04/10] feat: fix --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index b2e6298..ff21c21 100644 --- a/composer.json +++ b/composer.json @@ -24,7 +24,7 @@ "homepage": "https://github.com/eramitgupta/laravel-role-permission", "require": { "php": "^8.0|^8.1", - "laravel/pint": "^1.18", + "laravel/pint": "^1.13", "illuminate/auth": "^8.12|^9.0|^10.0|^11.0", "illuminate/container": "^8.12|^9.0|^10.0|^11.0", "illuminate/contracts": "^8.12|^9.0|^10.0|^11.0", From 7df8f7aacf90e9c0b912ecc91f3518b24eb34d10 Mon Sep 17 00:00:00 2001 From: Er Amit Gupta <72160684+eramitgupta@users.noreply.github.com> Date: Wed, 25 Dec 2024 17:04:26 +0530 Subject: [PATCH 05/10] Update lint.yml --- .github/workflows/lint.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 6063ed8..cf6df3e 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -21,7 +21,7 @@ jobs: - name: Setup PHP uses: shivammathur/setup-php@v2 with: - php-version: '8.0' # Adjust to match your PHP version + php-version: '8.0' extensions: mbstring, bcmath tools: composer From b8d19292a5b9bad91831b51e12c5a0faef69dc4d Mon Sep 17 00:00:00 2001 From: eramitgupta Date: Wed, 25 Dec 2024 17:08:16 +0530 Subject: [PATCH 06/10] feat: fix --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index ff21c21..0d32ff3 100644 --- a/composer.json +++ b/composer.json @@ -23,7 +23,7 @@ ], "homepage": "https://github.com/eramitgupta/laravel-role-permission", "require": { - "php": "^8.0|^8.1", + "php": "^8.0", "laravel/pint": "^1.13", "illuminate/auth": "^8.12|^9.0|^10.0|^11.0", "illuminate/container": "^8.12|^9.0|^10.0|^11.0", From 5f6ec813816596dcb5c711a959bd6d7d75c4dc7f Mon Sep 17 00:00:00 2001 From: Er Amit Gupta <72160684+eramitgupta@users.noreply.github.com> Date: Wed, 25 Dec 2024 17:09:17 +0530 Subject: [PATCH 07/10] Update lint.yml --- .github/workflows/lint.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index cf6df3e..76e00e8 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -21,7 +21,7 @@ jobs: - name: Setup PHP uses: shivammathur/setup-php@v2 with: - php-version: '8.0' + php-version: '8.1' extensions: mbstring, bcmath tools: composer From f465cd1a3549f213fad035445552b7ee517ebbd9 Mon Sep 17 00:00:00 2001 From: eramitgupta Date: Wed, 25 Dec 2024 17:10:33 +0530 Subject: [PATCH 08/10] feat: test --- src/Middleware/PermissionsMiddleware.php | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/Middleware/PermissionsMiddleware.php b/src/Middleware/PermissionsMiddleware.php index 8d5bd8a..af7870f 100644 --- a/src/Middleware/PermissionsMiddleware.php +++ b/src/Middleware/PermissionsMiddleware.php @@ -13,16 +13,16 @@ class PermissionsMiddleware * * @param Closure(Request): (Response) $next */ - public function handle(Request $request, Closure $next, ...$permissions): Response - { - if (! $request->user()) { - abort(403, 'Unauthorized action.'); - } + public function handle(Request $request, Closure $next, ...$permissions): Response + { + if (! $request->user()) { + abort(403, 'Unauthorized action.'); + } - if (! $request->user()->hasPermissions($permissions)) { - abort(403, 'You do not have the required permission.'); - } + if (! $request->user()->hasPermissions($permissions)) { + abort( 403, 'You do not have the required permission.'); + } - return $next($request); - } + return $next($request); + } } From b1c7029dfb01624affaf56c7f9e7c321a5a3e5a3 Mon Sep 17 00:00:00 2001 From: Er Amit Gupta <72160684+eramitgupta@users.noreply.github.com> Date: Wed, 25 Dec 2024 17:18:31 +0530 Subject: [PATCH 09/10] Update lint.yml --- .github/workflows/lint.yml | 49 ++++++++++++++++++++++++++++++-------- 1 file changed, 39 insertions(+), 10 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 76e00e8..b14c72f 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -9,26 +9,55 @@ on: - main jobs: - lint: + style: runs-on: ubuntu-latest + permissions: + contents: read + pull-requests: write steps: - # Checkout the code - name: Checkout code uses: actions/checkout@v3 - # Set up PHP - name: Setup PHP uses: shivammathur/setup-php@v2 with: - php-version: '8.1' + php-version: '8.1' extensions: mbstring, bcmath - tools: composer + tools: composer:v2 - # Install dependencies - - name: Install dependencies + - name: Install Dependencies run: composer install --no-scripts --no-interaction --prefer-dist - # Run Pint linting - - name: Run Pint Lint - run: composer lint + - name: Check code style with Pint + run: | + vendor/bin/pint --test + if [ $? -eq 0 ]; then + echo "✅ Code style is clean" + else + echo "❌ Code style issues found" + vendor/bin/pint --verbose + exit 1 + fi + + - name: Add Lint Results as PR Comment + if: github.event_name == 'pull_request' && failure() + uses: actions/github-script@v6 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + script: | + const output = ` + ## ⚠️ PHP Code Style Check Failed + + Please fix the code style issues found by Laravel Pint. + Run \`composer lint\` locally to see and fix the issues. + + For more information about Laravel Pint, visit: https://laravel.com/docs/pint + `; + + github.rest.issues.createComment({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + body: output + }) From a0e04173006306c6b6f0ad7df85505c534df1fae Mon Sep 17 00:00:00 2001 From: eramitgupta Date: Wed, 25 Dec 2024 17:19:56 +0530 Subject: [PATCH 10/10] feat: fix --- src/Middleware/PermissionsMiddleware.php | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/Middleware/PermissionsMiddleware.php b/src/Middleware/PermissionsMiddleware.php index af7870f..8d5bd8a 100644 --- a/src/Middleware/PermissionsMiddleware.php +++ b/src/Middleware/PermissionsMiddleware.php @@ -13,16 +13,16 @@ class PermissionsMiddleware * * @param Closure(Request): (Response) $next */ - public function handle(Request $request, Closure $next, ...$permissions): Response - { - if (! $request->user()) { - abort(403, 'Unauthorized action.'); - } - - if (! $request->user()->hasPermissions($permissions)) { - abort( 403, 'You do not have the required permission.'); - } + public function handle(Request $request, Closure $next, ...$permissions): Response + { + if (! $request->user()) { + abort(403, 'Unauthorized action.'); + } - return $next($request); + if (! $request->user()->hasPermissions($permissions)) { + abort(403, 'You do not have the required permission.'); } + + return $next($request); + } }