77use Filament \Actions ;
88use Filament \Actions \Action ;
99use Filament \Forms \Components \DatePicker ;
10+ use Filament \Forms \Components \Placeholder ;
11+ use Filament \Forms \Components \TextInput ;
1012use Filament \Notifications \Notification ;
1113use Filament \Resources \Pages \ViewRecord ;
14+ use FreedomtechHosting \PolydockApp \Enums \PolydockAppInstanceStatus ;
15+ use Illuminate \Support \Facades \Process ;
1216
1317class ViewPolydockAppInstance extends ViewRecord
1418{
@@ -19,6 +23,63 @@ protected function getHeaderActions(): array
1923 {
2024 return [
2125 Actions \EditAction::make (),
26+ Action::make ('trigger_deploy ' )
27+ ->label ('Trigger Deploy ' )
28+ ->icon ('heroicon-o-rocket-launch ' )
29+ ->color ('warning ' )
30+ ->requiresConfirmation ()
31+ ->form ([
32+ TextInput::make ('branch ' )
33+ ->label ('Branch / Environment ' )
34+ ->required ()
35+ ->disabled ()
36+ ->default (fn ($ record ) => $ record ->getKeyValue ('lagoon-deploy-branch ' )),
37+ Placeholder::make ('last_deployment_date ' )
38+ ->label ('Last Deployment Date ' )
39+ ->content (function ($ record ) {
40+ $ lastDeployLog = $ record ->logs ()
41+ ->whereJsonContains ('data->new_status ' , PolydockAppInstanceStatus::DEPLOY_COMPLETED ->value )
42+ ->latest ()
43+ ->first ();
44+
45+ return $ lastDeployLog ? $ lastDeployLog ->created_at ->toDateTimeString () : 'Never ' ;
46+ }),
47+ ])
48+ ->action (function (array $ data , $ record ): void {
49+ $ projectName = $ record ->getKeyValue ('lagoon-project-name ' );
50+ $ branch = $ data ['branch ' ];
51+
52+ if (empty ($ projectName ) || empty ($ branch )) {
53+ Notification::make ()
54+ ->title ('Deployment Failed ' )
55+ ->danger ()
56+ ->body ('Missing project name or branch configuration. ' )
57+ ->send ();
58+
59+ return ;
60+ }
61+
62+ $ fullCommand = sprintf ('lagoon deploy -p %s -e %s ' ,
63+ escapeshellarg ($ projectName ),
64+ escapeshellarg ($ branch )
65+ );
66+
67+ $ result = Process::run ($ fullCommand );
68+
69+ if ($ result ->successful ()) {
70+ Notification::make ()
71+ ->title ('Deployment Triggered ' )
72+ ->success ()
73+ ->body ('Output: ' .trim ($ result ->output ()))
74+ ->send ();
75+ } else {
76+ Notification::make ()
77+ ->title ('Deployment Failed ' )
78+ ->danger ()
79+ ->body ('Error: ' .trim ($ result ->errorOutput ()))
80+ ->send ();
81+ }
82+ }),
2283 Action::make ('extend_trial ' )
2384 ->label ('Extend Trial ' )
2485 ->icon ('heroicon-o-calendar ' )
0 commit comments