magallanes/src/Task/BuiltIn/Git/UpdateTask.php

65 lines
1.4 KiB
PHP
Raw Normal View History

2016-12-31 07:52:25 +01:00
<?php
2022-04-10 06:20:03 +02:00
2016-12-31 07:52:25 +01:00
/*
* This file is part of the Magallanes package.
*
* (c) Andrés Montañez <andres@andresmontanez.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Mage\Task\BuiltIn\Git;
use Symfony\Component\Process\Process;
use Mage\Task\AbstractTask;
use Mage\Task\Exception\SkipException;
2016-12-31 07:52:25 +01:00
/**
* Git Task - Pull
*
* @author Andrés Montañez <andresmontanez@gmail.com>
*/
class UpdateTask extends AbstractTask
{
2022-04-10 06:20:03 +02:00
public function getName(): string
2016-12-31 07:52:25 +01:00
{
return 'git/update';
}
2022-04-10 06:20:03 +02:00
public function getDescription(): string
2016-12-31 07:52:25 +01:00
{
return '[Git] Update';
}
2022-04-10 06:20:03 +02:00
public function execute(): bool
2016-12-31 07:52:25 +01:00
{
$options = $this->getOptions();
if ($options['tag']) {
throw new SkipException();
}
2016-12-31 07:52:25 +01:00
$command = $options['path'] . ' pull';
$process = $this->runtime->runLocalCommand($command);
return $process->isSuccessful();
}
2022-04-10 06:20:03 +02:00
/**
* @return array<string, string>
*/
protected function getOptions(): array
2016-12-31 07:52:25 +01:00
{
2017-01-12 02:22:21 +01:00
$branch = $this->runtime->getEnvOption('branch', 'master');
$tag = $this->runtime->getEnvOption('tag', false);
2016-12-31 07:52:25 +01:00
$options = array_merge(
['path' => 'git', 'branch' => $branch, 'tag' => $tag],
2016-12-31 07:52:25 +01:00
$this->options
);
return $options;
}
}