diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..dd9a2b5 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,15 @@ +root = true + +[*] +charset = utf-8 +end_of_line = lf +indent_size = 4 +indent_style = space +insert_final_newline = true +trim_trailing_whitespace = true + +[*.md] +trim_trailing_whitespace = false + +[*.{yml,yaml}] +indent_size = 2 diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..9e9519b --- /dev/null +++ b/.gitattributes @@ -0,0 +1,19 @@ +# Path-based git attributes +# https://www.kernel.org/pub/software/scm/git/docs/gitattributes.html + +# Ignore all test and documentation with "export-ignore". +/.github export-ignore +/.gitattributes export-ignore +/.gitignore export-ignore +/phpunit.xml.dist export-ignore +/art export-ignore +/docs export-ignore +/tests export-ignore +/.editorconfig export-ignore +/.php_cs.dist.php export-ignore +/psalm.xml export-ignore +/psalm.xml.dist export-ignore +/testbench.yaml export-ignore +/UPGRADING.md export-ignore +/phpstan.neon.dist export-ignore +/phpstan-baseline.neon export-ignore diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml new file mode 100644 index 0000000..25bbf87 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/config.yml @@ -0,0 +1,14 @@ +blank_issues_enabled: false +contact_links: + - name: Ask a question + url: https://github.com/alphaolomi/laravel-sarufi/discussions/new?category=q-a + about: Ask the community for help + - name: Request a feature + url: https://github.com/alphaolomi/laravel-sarufi/discussions/new?category=ideas + about: Share ideas for new features + - name: Report a security issue + url: https://github.com/alphaolomi/laravel-sarufi/security/policy + about: Learn how to notify us for sensitive bugs + - name: Report a bug + url: https://github.com/alphaolomi/laravel-sarufi/issues/new + about: Report a reproducible bug diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..30c8a49 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,12 @@ +# Please see the documentation for all configuration options: +# https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates + +version: 2 +updates: + + - package-ecosystem: "github-actions" + directory: "/" + schedule: + interval: "weekly" + labels: + - "dependencies" \ No newline at end of file diff --git a/.github/workflows/dependabot-auto-merge.yml b/.github/workflows/dependabot-auto-merge.yml new file mode 100644 index 0000000..41099d3 --- /dev/null +++ b/.github/workflows/dependabot-auto-merge.yml @@ -0,0 +1,32 @@ +name: dependabot-auto-merge +on: pull_request_target + +permissions: + pull-requests: write + contents: write + +jobs: + dependabot: + runs-on: ubuntu-latest + if: ${{ github.actor == 'dependabot[bot]' }} + steps: + + - name: Dependabot metadata + id: metadata + uses: dependabot/fetch-metadata@v1.3.4 + with: + github-token: "${{ secrets.GITHUB_TOKEN }}" + + - name: Auto-merge Dependabot PRs for semver-minor updates + if: ${{steps.metadata.outputs.update-type == 'version-update:semver-minor'}} + run: gh pr merge --auto --merge "$PR_URL" + env: + PR_URL: ${{github.event.pull_request.html_url}} + GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} + + - name: Auto-merge Dependabot PRs for semver-patch updates + if: ${{steps.metadata.outputs.update-type == 'version-update:semver-patch'}} + run: gh pr merge --auto --merge "$PR_URL" + env: + PR_URL: ${{github.event.pull_request.html_url}} + GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} diff --git a/.github/workflows/fix-php-code-style-issues.yml b/.github/workflows/fix-php-code-style-issues.yml new file mode 100644 index 0000000..150750c --- /dev/null +++ b/.github/workflows/fix-php-code-style-issues.yml @@ -0,0 +1,24 @@ +name: Fix PHP code style issues + +on: + push: + paths: + - '**.php' + +jobs: + php-code-styling: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v3 + with: + ref: ${{ github.head_ref }} + + - name: Fix PHP code style issues + uses: aglipanci/laravel-pint-action@1.0.0 + + - name: Commit changes + uses: stefanzweifel/git-auto-commit-action@v4 + with: + commit_message: Fix styling diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml new file mode 100644 index 0000000..eeb3eae --- /dev/null +++ b/.github/workflows/run-tests.yml @@ -0,0 +1,50 @@ +name: run-tests + +on: + push: + branches: [main] + pull_request: + branches: [main] + +jobs: + test: + runs-on: ${{ matrix.os }} + strategy: + fail-fast: true + matrix: + os: [ubuntu-latest, windows-latest] + php: [8.2, 8.1] + laravel: [9.*] + stability: [prefer-lowest, prefer-stable] + include: + - laravel: 9.* + testbench: 7.* + + name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - ${{ matrix.os }} + + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick, fileinfo + coverage: none + + - name: Setup problem matchers + run: | + echo "::add-matcher::${{ runner.tool_cache }}/php.json" + echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json" + + - name: Install dependencies + run: | + composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update + composer update --${{ matrix.stability }} --prefer-dist --no-interaction + + - name: List Installed Dependencies + run: composer show -D + + - name: Execute tests + run: vendor/bin/pest diff --git a/.github/workflows/update-changelog.yml b/.github/workflows/update-changelog.yml new file mode 100644 index 0000000..b20f3b6 --- /dev/null +++ b/.github/workflows/update-changelog.yml @@ -0,0 +1,28 @@ +name: "Update Changelog" + +on: + release: + types: [released] + +jobs: + update: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v3 + with: + ref: main + + - name: Update Changelog + uses: stefanzweifel/changelog-updater-action@v1 + with: + latest-version: ${{ github.event.release.name }} + release-notes: ${{ github.event.release.body }} + + - name: Commit updated CHANGELOG + uses: stefanzweifel/git-auto-commit-action@v4 + with: + branch: main + commit_message: Update CHANGELOG + file_pattern: CHANGELOG.md diff --git a/.gitignore b/.gitignore index c1bdfc9..83c9b9f 100644 --- a/.gitignore +++ b/.gitignore @@ -8,4 +8,4 @@ phpunit.xml phpstan.neon testbench.yaml vendor -node_modules \ No newline at end of file +node_modules diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..72f0263 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,3 @@ +# Changelog + +All notable changes to `laravel-sarufi` will be documented in this file. diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 0000000..ad4050f --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) Alpha Olomi + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/README.md b/README.md index abc4c13..c160002 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ composer require alphaolomi/laravel-sarufi ```bash -php artisan vendor:publish --tag="laravel-sarufi-config" +php artisan vendor:publish --tag="sarufi-config" ``` ## Configuration @@ -30,15 +30,31 @@ SARUFI_PASSWORD="your_nice_password" ## Usage ```php -use Alphaolomi\Laravel\Facades\Sarufi; -$bot = Sarufi::createBot([ - "name" => "YOUR AWESOME BOT NAME", - "description" => "PUT DESCRIPTION HERE", - "industry" => "YOUR BOT INDUSTRY", - "intents" => [], - "flows" => [], -]); +use Alphaolomi\Laravel\Sarufi\Facades\Sarufi; +$bot = Sarufi::createBot( + name: "Danny bot", + description: "PUT DESCRIPTION HERE", + industry: "YOUR BOT INDUSTRY", + intents: [], + flows: [] +); + print_r($bot1); +// Output +// => [ +// "intents" => [], +// "user_id" => 54, +// "description" => "PUT DESCRIPTION HERE", +// "industry" => "YOUR BOT INDUSTRY", +// "created_at" => "2022-10-20T14:24:32.862859", +// "name" => "Danny bot", +// "flows" => [], +// "id" => 81, +// "model_name" => "models/24bea90e2ad6f9d279d4fa86795c8ea0.pkl", +// "visible_on_community" => false, +// "updated_at" => "2022-10-20T14:24:32.862872", +// ] + // OR // From files with intent and metadata/ diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..0a74b7b --- /dev/null +++ b/composer.json @@ -0,0 +1,67 @@ +{ + "name": "alphaolomi/laravel-sarufi", + "description": "Sarufi for Laravel", + "keywords": [ + "sarufi", + "laravel-sarufi" + ], + "homepage": "https://github.com/alphaolomi/laravel-sarufi", + "license": "MIT", + "authors": [ + { + "name": "Alpha Olomi", + "email": "alphaolomi@gmail.com", + "role": "Developer" + } + ], + "require": { + "php": "^8.1", + "alphaolomi/sarufi-php": "^0.0.1", + "illuminate/contracts": "^9.0", + "spatie/laravel-package-tools": "^1.13.0" + }, + "require-dev": { + "laravel/pint": "^1.0", + "nunomaduro/collision": "^6.0", + "orchestra/testbench": "^7.0", + "pestphp/pest": "^1.21", + "pestphp/pest-plugin-laravel": "^1.1", + "phpunit/phpunit": "^9.5" + }, + "autoload": { + "psr-4": { + "Alphaolomi\\Laravel\\Sarufi\\": "src" + } + }, + "autoload-dev": { + "psr-4": { + "Alphaolomi\\Laravel\\Sarufi\\Tests\\": "tests" + } + }, + "scripts": { + "post-autoload-dump": "@php ./vendor/bin/testbench package:discover --ansi", + "analyse": "vendor/bin/phpstan analyse", + "test": "vendor/bin/pest", + "test-coverage": "vendor/bin/pest --coverage", + "format": "vendor/bin/pint" + }, + "config": { + "sort-packages": true, + "allow-plugins": { + "pestphp/pest-plugin": true, + "phpstan/extension-installer": true + } + }, + "extra": { + "laravel": { + "providers": [ + "Alphaolomi\\Laravel\\Sarufi\\SarufiServiceProvider" + ], + "aliases": { + "Sarufi": "Alphaolomi\\Laravel\\Sarufi\\Facades\\Sarufi" + } + } + }, + "minimum-stability": "dev", + "prefer-stable": true +} diff --git a/config/sarufi.php b/config/sarufi.php new file mode 100644 index 0000000..3de0bd3 --- /dev/null +++ b/config/sarufi.php @@ -0,0 +1,15 @@ + env('SARUFI_USERNAME'), + + /* + * Sarudi Password + */ + 'password' => env('SARUFI_PASSWORD'), + +]; diff --git a/phpunit.xml.dist b/phpunit.xml.dist new file mode 100644 index 0000000..a3fd386 --- /dev/null +++ b/phpunit.xml.dist @@ -0,0 +1,39 @@ + + + + + tests + + + + + ./src + + + + + + + + + + + diff --git a/src/Facades/Sarufi.php b/src/Facades/Sarufi.php new file mode 100644 index 0000000..66ee2d1 --- /dev/null +++ b/src/Facades/Sarufi.php @@ -0,0 +1,24 @@ +name('laravel-sarufi') + ->hasConfigFile(); + } + + // public function registeringPackage() + // { + // } + + public function packageRegistered() + { + $this->app->singleton('sarufi', function () { + $username = config('sarufi.username', ''); + $password = config('sarufi.password', ''); + if (empty($username)) { + throw new \RuntimeException('Username is missing: add SARUFI_USERNAME to you .env file'); + } + if (empty($password)) { + throw new \RuntimeException('Password is missing: add SARUFI_PASSWORD to you .env file'); + } + + return new Sarufi( + username: $username, + password: $password + ); + }); + } +} diff --git a/tests/Pest.php b/tests/Pest.php new file mode 100644 index 0000000..db464db --- /dev/null +++ b/tests/Pest.php @@ -0,0 +1,5 @@ +in(__DIR__); diff --git a/tests/SarufiTest.php b/tests/SarufiTest.php new file mode 100644 index 0000000..8b555eb --- /dev/null +++ b/tests/SarufiTest.php @@ -0,0 +1,6 @@ + +toBeTrue(); +}); diff --git a/tests/TestCase.php b/tests/TestCase.php new file mode 100644 index 0000000..447850a --- /dev/null +++ b/tests/TestCase.php @@ -0,0 +1,14 @@ +