jubeki/orbit-git

Provide git features for the flat-file eloquent driver orbit

0.1.0 2022-03-21 16:25 UTC

This package is auto-updated.

Last update: 2024-12-21 22:59:36 UTC


README

Packagist License Latest Stable Version

Installation

Require this package with composer.

composer require jubeki/orbit-git

The service provider will be automatically registered using package discovery.

If you don't use auto-discovery you should add the service provider to the providers array in config/app.php.

// existing providers...
Jubeki\OrbitGit\OrbitGitServiceProvider::class,

Customisation

Customising the author name and email

By default, Orbit will use the system's name and email address when making commits to your repository. If you wish to change the name, use the ORBIT_GIT_NAME and ORBIT_GIT_EMAIL environment variables.

If you would like to use a more dynamic name and email address, you can use the OrbitGit::resolveNameUsing and Orbit::resolveEmailUsing methods instead:

use Jubeki\OrbitGit\Facades\OrbitGit;

public function boot()
{
    OrbitGit::resolveNameUsing(function () {
        return Auth::user()->name;
    });

    OrbitGit::resolveEmailUsing(function () {
        return Auth::user()->email;
    });
}

Customizing the commit message

The default is [AUTO] {event} {model} {primary_key}. You can also change the commit message with the OrbitGit::resolveMessageUsing method.

use Jubeki\OrbitGit\Facades\OrbitGit;

public function boot()
{
    OrbitGit::resolveMessageUsing(function ($event) {
        return (string) Str::of(config('orbit-git.message_template'))
                ->replace('{event}', $this->getTypeOfEvent($event))
                ->replace('{model}', class_basename($event->model))
                ->replace('{primary_key}', $event->model->getKey());
    });
}

You can also overwrite messages for specific events which has a higher priority than the default OrbitGit::resolveMessageUsing method:

use Jubeki\OrbitGit\Facades\OrbitGit;

public function boot()
{
    OrbitGit::resolveCreatedMessageUsing(function ($event) {
        return '...',
    });

    OrbitGit::resolveDeletedMessageUsing(function ($event) {
        return '...',
    });

    OrbitGit::resolveForceDeletedMessageUsing(function ($event) {
        return '...',
    });

    OrbitGit::resolveUpdatedMessageUsing(function ($event) {
        return '...',
    });
}

Deploy with Laravel Forge

You can add the following to the top of your deployment script to skip the deployment from commits made using Orbit on the production system.

if [[ $FORGE_DEPLOY_MESSAGE =~ ^\[AUTO\](.*)$ ]]; then
    echo "AUTOMATED COMMIT FROM THE SERVER DO NOT DEPLOY!!!"
    exit 0
fi

Change log

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

TODO

  • Commit only changed file by event instead of complete path
  • Only push if wanted
  • Allow queuing of Git commits (possible risk of timing issued if multiple people update the same model at the same time)

Credits

License

The MIT License (MIT). Please see License File for more information.