Skip to content

Commit

Permalink
Add Dump-Issue function and Help
Browse files Browse the repository at this point in the history
  • Loading branch information
amenk committed Feb 11, 2019
1 parent d1c9ec3 commit 9727f8c
Showing 1 changed file with 44 additions and 4 deletions.
48 changes: 44 additions & 4 deletions shifter.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,40 @@ public function __construct()
public function execute($action)
{
switch ($action) {
case "push":
$this->authenticate();
$this->ensureTemporaryRepositoryExists();
$this->push();
$this->sayHowToShift();
break;
case "show":
$this->authenticate();
$this->exportPullRequest();
break;
case "clean":
$this->authenticate();
$this->removeTemporaryRepository();
break;
default:
$this->authenticate();
$this->ensureTemporaryRepositoryExists();
$this->push();
$this->sayHowToShift();
$this->showHelp();
break;
}
}

protected function showHelp()
{
echo 'You can use the following parameters (in the order of the lifecycle)' . PHP_EOL;

echo PHP_EOL;

echo 'shifter push (Step 1)' . PHP_EOL;
echo '(do your shift now)' . PHP_EOL;
echo '(merge back)' . PHP_EOL;
echo 'shifter show > my-shift.md (show the latest merge request, dump to file)' . PHP_EOL;
echo 'shifter clean (remove the repo from github)' . PHP_EOL;

}

protected function authenticate()
{
$tokenFile = __DIR__ . '/.github_token';
Expand Down Expand Up @@ -137,6 +158,25 @@ protected function removeTemporaryRepository()
} catch (\Cz\Git\GitException $e) {
echo "Not necessary to remove remote" . PHP_EOL;
}
}

protected function exportPullRequest()
{
$issues = $this->gitHub->api('issues')->all($this->userName, $this->temporaryRepoName);
$lastIssue = array_pop($issues);

$result = sprintf('== Pull Request %d == ', $lastIssue['number']) . PHP_EOL . PHP_EOL;

$result .= $lastIssue['body'] . PHP_EOL . PHP_EOL;;

$comments = $this->gitHub->api('issue')->comments()->all($this->userName, $this->temporaryRepoName, $lastIssue['number']);

foreach($comments as $sequence => $comment) {
$result .= sprintf('=== Comment %d === ', $sequence + 1) . PHP_EOL . PHP_EOL;
$result .= $comment['body'] . PHP_EOL . PHP_EOL;
}

echo $result;
}
}

0 comments on commit 9727f8c

Please sign in to comment.