Final Class Yiisoft\Yii\Debug\Api\Inspector\Controller\GitController
| Inheritance | Yiisoft\ |
|---|
Public Methods
Method Details
| public mixed __construct ( \ | ||
| $responseFactory | \ |
|
| $aliases | \ |
|
public function __construct(
private DataResponseFactoryInterface $responseFactory,
private Aliases $aliases,
) {}
| public \ | ||
| $request | \ |
|
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 \ | ||
| $request | \ |
|
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 \ |
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 \ |
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);
}
User Contributed Notes
Leave a comment
Join the conversation to share a note.