Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clean up RepositoryIntrospector #11

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 29 additions & 13 deletions src/Scrutinizer/Ocular/Util/RepositoryIntrospector.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,30 +19,26 @@ public function __construct($repositoryDir)

public function getCurrentRevision()
{
$proc = new Process('git rev-parse HEAD', $this->dir);
if (0 !== $proc->run()) {
throw new ProcessFailedException($proc);
}
$proc = $this->exec('git rev-parse HEAD');

return trim($proc->getOutput());
}

public function getCurrentParents()
{
$proc = new Process('git log --pretty="%P" -n1 HEAD', $this->dir);
if (0 !== $proc->run()) {
throw new ProcessFailedException($proc);
}
$proc = $this->exec('git log --pretty="%P" -n1 HEAD');

return explode(' ', trim($proc->getOutput()));
}

/**
*
* @throws \RuntimeException
* @return string
*/
public function getQualifiedName()
{
$proc = new Process('git remote -v', $this->dir);
if (0 !== $proc->run()) {
throw new ProcessFailedException($proc);
}
$proc = $this->exec('git remote -v');

$output = $proc->getOutput();

Expand All @@ -62,6 +58,12 @@ public function getQualifiedName()
throw new \RuntimeException(sprintf("Could not extract repository name from:\n%s", $output));
}

/**
*
* @param string $host
* @throws \LogicException
* @return string
*/
private function getRepositoryType($host)
{
switch ($host) {
Expand All @@ -75,4 +77,18 @@ private function getRepositoryType($host)
throw new \LogicException(sprintf('Unknown host "%s".', $host));
}
}
}

/**
*
* @param string $command
* @param string $dir
* @throws ProcessFailedException
*/
protected function exec($command, $dir = null)
{
$proc = new Process($command, $dir ?: $this->dir);
if (0 !== $proc->run()) {
throw new ProcessFailedException($proc);
}
}
}