-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: adding freeze and unfreeze commands
- Loading branch information
Showing
4 changed files
with
249 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
<?php | ||
|
||
namespace App\Console\Commands; | ||
|
||
use App\Models\Repository; | ||
use Illuminate\Console\Command; | ||
use Illuminate\Contracts\Console\PromptsForMissingInput; | ||
use Illuminate\Database\Eloquent\ModelNotFoundException; | ||
|
||
use function Laravel\Prompts\select; | ||
|
||
class FreezeRepository extends Command implements PromptsForMissingInput | ||
{ | ||
/** | ||
* The name and signature of the console command. | ||
* | ||
* @var string | ||
*/ | ||
protected $signature = 'repository:freeze {repository} {directory?}'; | ||
|
||
/** | ||
* The console command description. | ||
* | ||
* @var string | ||
*/ | ||
protected $description = 'Freeze specified repository'; | ||
|
||
/** | ||
* Execute the console command. | ||
*/ | ||
public function handle(): int | ||
{ | ||
$repoName = $this->argument('repository'); | ||
try { | ||
$repository = Repository::where('name', $repoName)->firstOrFail(); | ||
} catch (ModelNotFoundException) { | ||
$this->error("Repository '$repoName' not found."); | ||
return self::FAILURE; | ||
} | ||
if ($repository->freeze != null) { | ||
$this->error("Repository '$repository->name' is already frozen."); | ||
return self::FAILURE; | ||
} | ||
if (is_null($this->argument('directory'))) { | ||
$directory = basename($repository->getStablePath()); | ||
} else { | ||
$directory = $this->argument('directory'); | ||
} | ||
$this->info("Freezing repository '$repository->name' to '$directory'..."); | ||
$repository->freeze = $directory; | ||
$repository->save(); | ||
return self::SUCCESS; | ||
} | ||
|
||
/** | ||
* Prompt for missing input arguments using the returned questions. | ||
* | ||
* @return array<string, string> | ||
*/ | ||
protected function promptForMissingArgumentsUsing(): array | ||
{ | ||
return [ | ||
'repository' => fn () => select( | ||
label: 'Choose repository to freeze', | ||
options: Repository::pluck('name'), | ||
required: true, | ||
), | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<?php | ||
|
||
namespace App\Console\Commands; | ||
|
||
use App\Models\Repository; | ||
use Illuminate\Console\Command; | ||
use Illuminate\Contracts\Console\PromptsForMissingInput; | ||
use Illuminate\Database\Eloquent\ModelNotFoundException; | ||
use function Laravel\Prompts\select; | ||
|
||
class UnFreezeRepository extends Command implements PromptsForMissingInput | ||
{ | ||
/** | ||
* The name and signature of the console command. | ||
* | ||
* @var string | ||
*/ | ||
protected $signature = 'repository:unfreeze {repository}'; | ||
|
||
/** | ||
* The console command description. | ||
* | ||
* @var string | ||
*/ | ||
protected $description = 'Unfreeze a frozen repository.'; | ||
|
||
/** | ||
* Execute the console command. | ||
*/ | ||
public function handle(): int | ||
{ | ||
$repoName = $this->argument('repository'); | ||
try { | ||
$repository = Repository::where('name', $repoName)->firstOrFail(); | ||
} catch (ModelNotFoundException) { | ||
$this->error("Repository '$repoName' not found."); | ||
return self::FAILURE; | ||
} | ||
if ($repository->freeze == null) { | ||
$this->error("Repository '$repository->name' is not frozen."); | ||
return self::FAILURE; | ||
} | ||
$this->info("Unfreezing repository '$repository->name'..."); | ||
$repository->freeze = null; | ||
$repository->save(); | ||
return self::SUCCESS; | ||
} | ||
|
||
/** | ||
* Prompt for missing input arguments using the returned questions. | ||
* | ||
* @return array<string, string> | ||
*/ | ||
protected function promptForMissingArgumentsUsing(): array | ||
{ | ||
return [ | ||
'repository' => fn () => select( | ||
label: 'Choose repository to unfreeze', | ||
options: Repository::pluck('name'), | ||
required: true, | ||
), | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters