Skip to content

Commit

Permalink
feature: basic Git integration
Browse files Browse the repository at this point in the history
  • Loading branch information
ryangjchandler committed Mar 21, 2021
1 parent 9e7ac2c commit 0ea529f
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 0 deletions.
2 changes: 2 additions & 0 deletions config/orbit.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
'enabled' => env('ORBIT_GIT_ENABLED', false),
'name' => env('ORBIT_GIT_NAME'),
'email' => env('ORBIT_GIT_EMAIL'),
'root' => env('ORBIT_GIT_ROOT', base_path()),
'binary' => env('ORBIT_GIT_BINARY', '/usr/bin/git'),
],

];
1 change: 1 addition & 0 deletions src/Facades/Orbit.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* @method static string getDatabasePath()
* @method static string getGitName()
* @method static string getGitEmail()
* @method static string getGitRoot()
*
* @see \Orbit\OrbitManager
*/
Expand Down
31 changes: 31 additions & 0 deletions src/Listeners/ProcessGitTransaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,49 @@

namespace Orbit\Listeners;

use Exception;
use Orbit\Events\OrbitalCreated;
use Orbit\Events\OrbitalUpdated;
use Orbit\Facades\Orbit;
use Symplify\GitWrapper\Exception\GitException;
use Symplify\GitWrapper\GitWrapper;

class ProcessGitTransaction
{
public function created(OrbitalCreated $event)
{
$message = 'orbit: created ' . class_basename($event->model) . ' ' . $event->model->getKey();

$this->commit($message);
}

public function updated(OrbitalUpdated $event)
{
$message = 'orbit: updated ' . class_basename($event->model) . ' ' . $event->model->getKey();

$this->commit($message);
}

protected function commit(string $message)
{
$wrapper = new GitWrapper(
Orbit::getGitBinary()
);

$git = $wrapper->workingCopy(
Orbit::getGitRoot()
);

if (! $git->hasChanges()) {
return;
}

$git->add(
config('orbit.paths.content')
);

$git->commit($message);

$git->push();
}
}
10 changes: 10 additions & 0 deletions src/OrbitManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,14 @@ public function getGitEmail()

return config('orbit.git.email');
}

public function getGitRoot()
{
return config('orbit.git.root');
}

public function getGitBinary()
{
return config('orbit.git.binary');
}
}

0 comments on commit 0ea529f

Please sign in to comment.