Final Class Yiisoft\Yii\Debug\Api\Inspector\Controller\GitController
| Inheritance | Yiisoft\Yii\Debug\Api\Inspector\Controller\GitController |
|---|
Public Methods
Method Details
| public mixed __construct ( \Yiisoft\DataResponse\DataResponseFactoryInterface $responseFactory, \Yiisoft\Aliases\Aliases $aliases ) | ||
| $responseFactory | \Yiisoft\DataResponse\DataResponseFactoryInterface | |
| $aliases | \Yiisoft\Aliases\Aliases | |
public function __construct(
private DataResponseFactoryInterface $responseFactory,
private Aliases $aliases,
) {
}
| public \Psr\Http\Message\ResponseInterface checkout ( \Psr\Http\Message\ServerRequestInterface $request ) | ||
| $request | \Psr\Http\Message\ServerRequestInterface | |
public function checkout(ServerRequestInterface $request): ResponseInterface
{
$git = $this->getGit();
$parsedBody = \json_decode($request->getBody()->getContents(), true, 512, JSON_THROW_ON_ERROR);
$branch = $parsedBody['branch'] ?? null;
if ($branch === null) {
throw new InvalidArgumentException('Branch should not be empty.');
}
$git->getWorkingCopy()->checkout($branch);
return $this->responseFactory->createResponse([]);
}
| public \Psr\Http\Message\ResponseInterface command ( \Psr\Http\Message\ServerRequestInterface $request ) | ||
| $request | \Psr\Http\Message\ServerRequestInterface | |
public function command(ServerRequestInterface $request): ResponseInterface
{
$git = $this->getGit();
$availableCommands = ['pull', 'fetch'];
$command = $request->getQueryParams()['command'] ?? null;
if ($command === null) {
throw new InvalidArgumentException('Command should not be empty.');
}
if (!in_array($command, $availableCommands, true)) {
throw new InvalidArgumentException(
sprintf(
'Unknown command "%s". Available commands: "%s".',
$command,
implode('", "', $availableCommands),
)
);
}
if ($command === 'pull') {
$git->run('pull', ['--rebase=false']);
} elseif ($command === 'fetch') {
$git->run('fetch', ['--tags']);
}
return $this->responseFactory->createResponse([]);
}
| public \Psr\Http\Message\ResponseInterface log ( ) |
public function log(): ResponseInterface
{
$git = $this->getGit();
$references = $git->getReferences(false);
$name = trim($git->run('branch', ['--show-current']));
$branch = $references->getBranch($name);
$result = [
'currentBranch' => $branch->getName(),
'sha' => $branch->getCommitHash(),
'commits' => array_map($this->serializeCommit(...), $git->getLog(limit: 20)->getCommits()),
];
$response = VarDumper::create($result)->asPrimitives(255);
return $this->responseFactory->createResponse($response);
}
| public \Psr\Http\Message\ResponseInterface summary ( ) |
public function summary(): ResponseInterface
{
$git = $this->getGit();
$references = $git->getReferences();
$name = trim($git->run('branch', ['--show-current']));
$branch = $references->getBranch($name);
$branches = $references->getBranches();
$remoteNames = explode("\n", trim($git->run('remote')));
$result = [
'currentBranch' => $branch->getName(),
'sha' => $branch->getCommitHash(),
'remotes' => array_map(fn (string $name) => [
'name' => $name,
'url' => trim($git->run('remote', ['get-url', $name])),
], $remoteNames),
'branches' => array_map(fn (Branch $branch) => $branch->getName(), $branches),
'lastCommit' => $this->serializeCommit($branch->getCommit()),
'status' => explode("\n", $git->run('status')),
];
$response = VarDumper::create($result)->asPrimitives(255);
return $this->responseFactory->createResponse($response);
}
Signup or Login in order to comment.