From dd00a74c9b19bcf2076145238ec1f86fcf726f68 Mon Sep 17 00:00:00 2001 From: Jesse Leite Date: Wed, 3 Jun 2020 13:12:39 -0400 Subject: [PATCH 01/73] Git integration config. --- config/git.php | 81 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 config/git.php diff --git a/config/git.php b/config/git.php new file mode 100644 index 0000000000..6e9ce6edec --- /dev/null +++ b/config/git.php @@ -0,0 +1,81 @@ + env('STATAMIC_GIT_ENABLED', false), + + /* + |-------------------------------------------------------------------------- + | Git User + |-------------------------------------------------------------------------- + | + | The git user that will be used when committing changes to your repo. + | By default, the currently authenticated user name and email will + | be used. However, this can be overridden to something global. + | + */ + + 'user' => [ + 'name' => env('STATAMIC_GIT_USER_NAME', '{current_user_name}'), + 'email' => env('STATAMIC_GIT_USER_EMAIL', '{current_user_email}'), + ], + + /* + |-------------------------------------------------------------------------- + | Commands + |-------------------------------------------------------------------------- + | + | Define the commands to be run when `DataSaved` events are fired. By + | default this will `git add` your changes, and `git commit` them + | to the git repository relative to your working directory. + | + */ + + 'commands' => [ + 'cd {cwd}', + 'git add {path}', + 'git commit -m "{message}" -c "user.name={name}" -c "user.email={email}"', + ], + + /* + |-------------------------------------------------------------------------- + | Push + |-------------------------------------------------------------------------- + | + | Determine whether `git push` should be run after the commands above + | have finished. This is disabled by default, but can be enabled + | globally, or per environment using the provided variable. + | + */ + + 'push' => env('STATAMIC_GIT_PUSH', false), + + /* + |-------------------------------------------------------------------------- + | Ignored Events + |-------------------------------------------------------------------------- + | + | Statamic will listen on all `DataSaved` compatible events, as well as + | any `DataSaved` events registered by installed addons. If you wish + | to ignore any specific events, you may reference them here. + | + */ + + 'ignored_events' => [ + // \Statamic\Events\UserSaved::class, + ], + +]; From 8fd26b0f3780e6fff84e71be927d924ba7fdd6dc Mon Sep 17 00:00:00 2001 From: Jesse Leite Date: Wed, 3 Jun 2020 13:17:18 -0400 Subject: [PATCH 02/73] Make dynamic vars antlers parsable. --- config/git.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/config/git.php b/config/git.php index 6e9ce6edec..7865d8c0c0 100644 --- a/config/git.php +++ b/config/git.php @@ -29,8 +29,8 @@ */ 'user' => [ - 'name' => env('STATAMIC_GIT_USER_NAME', '{current_user_name}'), - 'email' => env('STATAMIC_GIT_USER_EMAIL', '{current_user_email}'), + 'name' => env('STATAMIC_GIT_USER_NAME', '{{ current_user_name }}'), + 'email' => env('STATAMIC_GIT_USER_EMAIL', '{{ current_user_email }}'), ], /* @@ -45,9 +45,9 @@ */ 'commands' => [ - 'cd {cwd}', - 'git add {path}', - 'git commit -m "{message}" -c "user.name={name}" -c "user.email={email}"', + 'cd {{ cwd }}', + 'git add {{ path }}', + 'git commit -m "{{ message }}" -c "user.name={{ name }}" -c "user.email={{ email }}"', ], /* From 23418c5b5eef8c0166c090d4ec87575f5c4f09ab Mon Sep 17 00:00:00 2001 From: Jesse Leite Date: Wed, 3 Jun 2020 15:13:54 -0400 Subject: [PATCH 03/73] Allow for manual control of git commits. --- config/git.php | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/config/git.php b/config/git.php index 7865d8c0c0..c08e176c5b 100644 --- a/config/git.php +++ b/config/git.php @@ -4,10 +4,10 @@ /* |-------------------------------------------------------------------------- - | Automatic Git Integration + | Git Integration |-------------------------------------------------------------------------- | - | Whether automatic git integration should be enabled. This feature + | Whether Statamic's git integration should be enabled. This feature | assumes that git is already installed and accessible by your | PHP process' server user. For more info, see the docs at: | @@ -17,6 +17,20 @@ 'enabled' => env('STATAMIC_GIT_ENABLED', false), + /* + |-------------------------------------------------------------------------- + | Automatically Run + |-------------------------------------------------------------------------- + | + | By default, git commands will be run automatically after `DataSaved` + | events are fired. If you prefer users to manually trigger the git + | commands, set this to `false` and your users will be presented + | with the relevant GUI to commit the changes as they see fit. + | + */ + + 'automatic' => env('STATAMIC_GIT_AUTOMATIC', true), + /* |-------------------------------------------------------------------------- | Git User From f490ca0cc69bbe22c29718692f6d1c86ca1016ad Mon Sep 17 00:00:00 2001 From: Jesse Leite Date: Wed, 3 Jun 2020 16:11:33 -0400 Subject: [PATCH 04/73] Add plural `{{ paths }}` (to be compiled from stache config). --- config/git.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/git.php b/config/git.php index c08e176c5b..f4bafa613a 100644 --- a/config/git.php +++ b/config/git.php @@ -60,7 +60,7 @@ 'commands' => [ 'cd {{ cwd }}', - 'git add {{ path }}', + 'git add {{ paths }}', 'git commit -m "{{ message }}" -c "user.name={{ name }}" -c "user.email={{ email }}"', ], From 5d49c86c047f6eb1ab37361d83b3f5402d36e2c6 Mon Sep 17 00:00:00 2001 From: Jesse Leite Date: Wed, 3 Jun 2020 22:04:18 -0400 Subject: [PATCH 05/73] Add content path/directory tracking. --- config/git.php | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/config/git.php b/config/git.php index f4bafa613a..50876009f0 100644 --- a/config/git.php +++ b/config/git.php @@ -47,19 +47,38 @@ 'email' => env('STATAMIC_GIT_USER_EMAIL', '{{ current_user_email }}'), ], + /* + |-------------------------------------------------------------------------- + | Tracked Paths + |-------------------------------------------------------------------------- + | + | Define the tracked paths to be considered when staging changes. Default + | stache and file locations are already set up for you, but feel free + | to modify these paths to suit your storage config. Absolute paths + | are valid when referencing content stored in external repos. + | + */ + + 'paths' => [ + 'content', + 'users', + 'resources/users', + 'public/assets', + ], + /* |-------------------------------------------------------------------------- | Commands |-------------------------------------------------------------------------- | - | Define the commands to be run when `DataSaved` events are fired. By - | default this will `git add` your changes, and `git commit` them - | to the git repository relative to your working directory. + | Define a list commands to be run when Statamic is ready to `git add` + | and `git commit` your changes. These commands will be run once + | per repo, attempting to consolidate commits where possible. | */ 'commands' => [ - 'cd {{ cwd }}', + 'cd {{ git_root }}', 'git add {{ paths }}', 'git commit -m "{{ message }}" -c "user.name={{ name }}" -c "user.email={{ email }}"', ], From baeb0b0166841e370a2ea8bbdc7a4dcd9678f56f Mon Sep 17 00:00:00 2001 From: Jesse Leite Date: Thu, 4 Jun 2020 18:20:57 -0400 Subject: [PATCH 06/73] Propare large commit. --- src/Console/Processes/Composer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Console/Processes/Composer.php b/src/Console/Processes/Composer.php index 99180fc545..72ba18fbd5 100644 --- a/src/Console/Processes/Composer.php +++ b/src/Console/Processes/Composer.php @@ -176,7 +176,7 @@ private function queueComposerCommand($command, $package, ...$extraParams) } /** - * Propare process arguments. + * Prepare process arguments. * * @param array $parts * @return array From 70c8a80b6d83db75d12d1f338fee4be347c6244a Mon Sep 17 00:00:00 2001 From: Jesse Leite Date: Mon, 8 Jun 2020 22:12:46 -0400 Subject: [PATCH 07/73] Add git utility. --- src/CP/Utilities/CoreUtilities.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/CP/Utilities/CoreUtilities.php b/src/CP/Utilities/CoreUtilities.php index 6eb0415355..fcde722009 100644 --- a/src/CP/Utilities/CoreUtilities.php +++ b/src/CP/Utilities/CoreUtilities.php @@ -54,5 +54,18 @@ public static function boot() $router->post('/', [EmailController::class, 'send']); }) ->register(); + + if (config('statamic.git.enabled')) { + Utility::make('git') + ->view('statamic::utilities.git') + ->title(__('Git')) + ->icon('email-utility') // TODO: Find better icon + ->description(__('Manage git tracked content.')) // TODO: Move into language files + ->docsUrl(Statamic::docsUrl('utilities/git')) + ->routes(function ($router) { + // $router->post('/', [EmailController::class, 'send']); + }) + ->register(); + } } } From 734cd437dfeb52bf3cfdb8d9e6e80cffc88153ed Mon Sep 17 00:00:00 2001 From: Jesse Leite Date: Thu, 11 Jun 2020 23:48:01 -0400 Subject: [PATCH 08/73] Add git process. --- src/Console/Processes/Git.php | 63 +++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 src/Console/Processes/Git.php diff --git a/src/Console/Processes/Git.php b/src/Console/Processes/Git.php new file mode 100644 index 0000000000..5ba16140a2 --- /dev/null +++ b/src/Console/Processes/Git.php @@ -0,0 +1,63 @@ +runGitCommand('status', '-s', $path); + } + + /** + * Get git root at current path. + * + * @return string + */ + public function root() + { + return $this->runGitCommand('rev-parse', '--show-toplevel'); + } + + /** + * Run git command. + * + * @param mixed $parts + * @return mixed + */ + private function runGitCommand(...$parts) + { + return $this->run($this->prepareProcessArguments($parts)); + } + + /** + * Queue git command. + * + * @param string $command + * @param string $package + * @param mixed $extraParams + */ + // private function queueGitCommand($command, $package, ...$extraParams) + // { + // $parts = array_merge([$command, $package], $extraParams); + + // dispatch(new RunComposer($this->prepareProcessArguments($parts), $this->getCacheKey($package))); + // } + + /** + * Prepare process arguments. + * + * @param array $parts + * @return array + */ + private function prepareProcessArguments($parts) + { + return array_merge(['git'], $parts); + } +} From 961dc42113c6aa3366fea95319179d2cd55e304a Mon Sep 17 00:00:00 2001 From: Jason Varga Date: Tue, 5 May 2020 17:34:29 -0400 Subject: [PATCH 09/73] Fix php 7.4 error --- src/Console/Processes/Process.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Console/Processes/Process.php b/src/Console/Processes/Process.php index 1959e006b2..105e4f9ccb 100644 --- a/src/Console/Processes/Process.php +++ b/src/Console/Processes/Process.php @@ -3,6 +3,7 @@ namespace Statamic\Console\Processes; use Illuminate\Support\Facades\Cache; +use Statamic\Support\Arr; use Symfony\Component\Process\Exception\ProcessFailedException; use Symfony\Component\Process\PhpExecutableFinder; use Symfony\Component\Process\Process as SymfonyProcess; @@ -158,7 +159,9 @@ public function cachedOutput(string $cacheKey) */ public function lastCompletedCachedOutput(string $cacheKey) { - return Cache::get($cacheKey)['completed'] ? Cache::get($cacheKey) : ['output' => false]; + $cache = $this->cachedOutput($cacheKey); + + return Arr::get($cache, 'completed') ? $cache : ['output' => false]; } /** From 52f6c2e30a4d46b287a8300e01977504927bc539 Mon Sep 17 00:00:00 2001 From: Jason Varga Date: Mon, 8 Jun 2020 13:15:00 -0400 Subject: [PATCH 10/73] Composer output is colored (opt-in) --- package-lock.json | 15 ++++++++ package.json | 1 + resources/js/components/ComposerOutput.vue | 28 +++++++++++++-- src/Console/Processes/Composer.php | 1 + src/Console/Processes/Process.php | 34 ++++++++++++++----- .../CP/ComposerOutputController.php | 2 +- 6 files changed, 70 insertions(+), 11 deletions(-) diff --git a/package-lock.json b/package-lock.json index 2088560cc4..07ddc53f97 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1659,6 +1659,21 @@ "color-convert": "^1.9.0" } }, + "ansi-to-html": { + "version": "0.6.14", + "resolved": "https://registry.npmjs.org/ansi-to-html/-/ansi-to-html-0.6.14.tgz", + "integrity": "sha512-7ZslfB1+EnFSDO5Ju+ue5Y6It19DRnZXWv8jrGHgIlPna5Mh4jz7BV5jCbQneXNFurQcKoolaaAjHtgSBfOIuA==", + "requires": { + "entities": "^1.1.2" + }, + "dependencies": { + "entities": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/entities/-/entities-1.1.2.tgz", + "integrity": "sha512-f2LZMYl1Fzu7YSBKg+RoROelpOaNrcGmE9AZubeDfrCEia483oW4MI4VyFd5VNHIgQ/7qm1I0wUHK1eJnn2y2w==" + } + } + }, "anymatch": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/anymatch/-/anymatch-2.0.0.tgz", diff --git a/package.json b/package.json index a583731a58..38f186696e 100644 --- a/package.json +++ b/package.json @@ -16,6 +16,7 @@ "@popperjs/core": "^2.1.0", "@shopify/draggable": "^1.0.0-beta.8", "@simonwep/pickr": "^1.5.1", + "ansi-to-html": "^0.6.14", "autosize": "~3.0.12", "axios": "^0.19.2", "body-scroll-lock": "^2.6.4", diff --git a/resources/js/components/ComposerOutput.vue b/resources/js/components/ComposerOutput.vue index 6bd4b21953..3bb1838be1 100644 --- a/resources/js/components/ComposerOutput.vue +++ b/resources/js/components/ComposerOutput.vue @@ -1,14 +1,20 @@