Skip to content

Commit

Permalink
[5.x] Track sites.yaml path in git integration config (#10463)
Browse files Browse the repository at this point in the history
  • Loading branch information
jesseleite authored Jul 16, 2024
1 parent a074cb4 commit a5276d1
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 2 deletions.
1 change: 1 addition & 0 deletions config/git.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@
resource_path('forms'),
resource_path('users'),
resource_path('preferences.yaml'),
resource_path('sites.yaml'),
storage_path('forms'),
public_path('assets'),
],
Expand Down
2 changes: 2 additions & 0 deletions src/Events/Concerns/ListensForContentEvents.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ trait ListensForContentEvents
\Statamic\Events\RevisionSaved::class,
\Statamic\Events\RoleDeleted::class,
\Statamic\Events\RoleSaved::class,
\Statamic\Events\SiteDeleted::class,
\Statamic\Events\SiteSaved::class,
\Statamic\Events\SubmissionDeleted::class,
\Statamic\Events\SubmissionSaved::class,
\Statamic\Events\TaxonomyDeleted::class,
Expand Down
8 changes: 7 additions & 1 deletion src/Events/SiteDeleted.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,18 @@

namespace Statamic\Events;

use Statamic\Contracts\Git\ProvidesCommitMessage;
use Statamic\Sites\Site;

class SiteDeleted extends Event
class SiteDeleted extends Event implements ProvidesCommitMessage
{
public function __construct(public Site $site)
{
//
}

public function commitMessage()
{
return __('Site deleted', [], config('statamic.git.locale'));
}
}
8 changes: 7 additions & 1 deletion src/Events/SiteSaved.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,18 @@

namespace Statamic\Events;

use Statamic\Contracts\Git\ProvidesCommitMessage;
use Statamic\Sites\Site;

class SiteSaved extends Event
class SiteSaved extends Event implements ProvidesCommitMessage
{
public function __construct(public Site $site)
{
//
}

public function commitMessage()
{
return __('Site saved', [], config('statamic.git.locale'));
}
}
25 changes: 25 additions & 0 deletions tests/Git/GitEventTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,31 @@ public function it_commits_when_default_user_preferences_are_saved()
Facades\File::delete(resource_path('preferences.yaml'));
}

#[Test]
public function it_commits_when_site_is_saved_and_deleted()
{
// Ensure we have one `en` site to start
Facades\File::put(resource_path('sites.yaml'), Facades\YAML::dump([
'en' => [
'name' => 'English',
'url' => 'http://localhost/',
'locale' => 'en_US',
],
]));

Git::shouldReceive('dispatchCommit')->with('Site saved')->once();
Git::shouldReceive('dispatchCommit')->with('Site deleted')->once();

// Delete the `en` site and save a new `fr` site
Facades\Site::setSites([
'fr' => [
'name' => 'French',
'url' => 'http://localhost/',
'locale' => 'fr_FR',
],
])->save();
}

#[Test]
public function it_commits_when_asset_container_is_saved_and_deleted()
{
Expand Down

0 comments on commit a5276d1

Please sign in to comment.