-
Notifications
You must be signed in to change notification settings - Fork 438
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #43 from veewee/feature/commit-msg
Commit message task
- Loading branch information
Showing
14 changed files
with
467 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#!/bin/sh | ||
|
||
# | ||
# Run the hook command. | ||
# Note: this will be replaced by the real command during copy. | ||
# | ||
|
||
GIT_USER=$(git config user.name) | ||
GIT_EMAIL=$(git config user.email) | ||
COMMIT_MSG_FILE=$1 | ||
|
||
(cd "${HOOK_EXEC_PATH}" && exec $(HOOK_COMMAND) "--git-user=$GIT_USER" "--git-email=$GIT_EMAIL" "$COMMIT_MSG_FILE") | ||
|
||
# Validate exit code of above command | ||
RC=$? | ||
if [ "$RC" != 0 ]; then | ||
exit $RC; | ||
fi | ||
|
||
# Clean exit: | ||
exit 0; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
|
||
namespace spec\GrumPHP\Task\Context; | ||
|
||
use GrumPHP\Collection\FilesCollection; | ||
use PhpSpec\ObjectBehavior; | ||
use Prophecy\Argument; | ||
|
||
class GitCommitMsgContextSpec extends ObjectBehavior | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
protected $tempFile; | ||
|
||
function let(FilesCollection $files, \SplFileInfo $fileInfo) | ||
{ | ||
$this->beConstructedWith($files, $fileInfo, 'user', '[email protected]'); | ||
} | ||
|
||
function it_is_initializable() | ||
{ | ||
$this->shouldHaveType('GrumPHP\Task\Context\GitCommitMsgContext'); | ||
} | ||
|
||
function it_should_be_a_task_context() | ||
{ | ||
$this->shouldImplement('GrumPHP\Task\Context\ContextInterface'); | ||
} | ||
|
||
function it_should_have_files(FilesCollection $files) | ||
{ | ||
$this->getFiles()->shouldBe($files); | ||
} | ||
|
||
function it_should_know_the_git_user() | ||
{ | ||
$this->getUserName()->shouldBe('user'); | ||
} | ||
|
||
function it_should_know_the_git_email() | ||
{ | ||
$this->getUserEmail()->shouldBe('[email protected]'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
|
||
namespace spec\GrumPHP\Task\Git; | ||
|
||
use GrumPHP\Configuration\GrumPHP; | ||
use GrumPHP\Task\Context\GitCommitMsgContext; | ||
use PhpSpec\ObjectBehavior; | ||
use Prophecy\Argument; | ||
|
||
class CommitMessageSpec extends ObjectBehavior | ||
{ | ||
function let(GrumPHP $grumPHP) | ||
{ | ||
$this->beConstructedWith($grumPHP, array( | ||
'matchers' => array('test', '*es*', 'te[s][t]', '/^te(.*)/', '/(.*)st$/', '/t(e|a)st/', 'TEST') | ||
)); | ||
} | ||
|
||
function it_is_initializable() | ||
{ | ||
$this->shouldHaveType('GrumPHP\Task\Git\CommitMessage'); | ||
} | ||
|
||
function it_is_a_grumphp_task() | ||
{ | ||
$this->shouldImplement('GrumPHP\Task\TaskInterface'); | ||
} | ||
|
||
function it_should_run_in_git_commit_msg_context(GitCommitMsgContext $context) | ||
{ | ||
$this->canRunInContext($context)->shouldReturn(true); | ||
} | ||
|
||
function it_runs_the_suite(GitCommitMsgContext $context) | ||
{ | ||
$context->getCommitMessage()->willReturn('test'); | ||
|
||
$this->run($context); | ||
} | ||
|
||
function it_throws_exception_if_the_process_fails(GitCommitMsgContext $context) { | ||
$context->getCommitMessage()->willReturn('invalid'); | ||
$this->shouldThrow('GrumPHP\Exception\RuntimeException')->duringRun($context); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
<?php | ||
|
||
namespace GrumPHP\Console\Command\Git; | ||
|
||
use GrumPHP\Collection\FilesCollection; | ||
use GrumPHP\Configuration\GrumPHP; | ||
use GrumPHP\Console\Helper\PathsHelper; | ||
use GrumPHP\Console\Helper\TaskRunnerHelper; | ||
use GrumPHP\Locator\LocatorInterface; | ||
use GrumPHP\Task\Context\GitCommitMsgContext; | ||
use SplFileInfo; | ||
use Symfony\Component\Console\Command\Command; | ||
use Symfony\Component\Console\Input\InputArgument; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Input\InputOption; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
/** | ||
* This command runs the git commit-msg hook. | ||
*/ | ||
class CommitMsgCommand extends Command | ||
{ | ||
const COMMAND_NAME = 'git:commit-msg'; | ||
|
||
/** | ||
* @var GrumPHP | ||
*/ | ||
protected $grumPHP; | ||
|
||
/** | ||
* @var LocatorInterface | ||
*/ | ||
protected $changedFilesLocator; | ||
|
||
/** | ||
* @param GrumPHP $grumPHP | ||
* @param LocatorInterface $changedFilesLocator | ||
*/ | ||
public function __construct(GrumPHP $grumPHP, LocatorInterface $changedFilesLocator) | ||
{ | ||
parent::__construct(); | ||
|
||
$this->grumPHP = $grumPHP; | ||
$this->changedFilesLocator = $changedFilesLocator; | ||
} | ||
|
||
/** | ||
* Configure command | ||
*/ | ||
protected function configure() | ||
{ | ||
$this->setName(self::COMMAND_NAME); | ||
$this->addOption('git-user', null, InputOption::VALUE_REQUIRED, 'The configured git user name.', ''); | ||
$this->addOption('git-email', null, InputOption::VALUE_REQUIRED, 'The configured git email.', ''); | ||
$this->addArgument('commit-msg-file', InputArgument::REQUIRED, 'The configured commit message file.'); | ||
} | ||
|
||
/** | ||
* @param InputInterface $input | ||
* @param OutputInterface $output | ||
* | ||
* @return int|void | ||
*/ | ||
public function execute(InputInterface $input, OutputInterface $output) | ||
{ | ||
$files = $this->getCommittedFiles(); | ||
$gitUser = $input->getOption('git-user'); | ||
$gitEmail = $input->getOption('git-email'); | ||
$commitMsgPath = $input->getArgument('commit-msg-file'); | ||
$commitMsgFile = new SplFileInfo($commitMsgPath); | ||
|
||
$context = new GitCommitMsgContext($files, $commitMsgFile, $gitUser, $gitEmail); | ||
return $this->taskRunner()->run($output, $context); | ||
} | ||
|
||
/** | ||
* @return FilesCollection | ||
*/ | ||
protected function getCommittedFiles() | ||
{ | ||
return $this->changedFilesLocator->locate(); | ||
} | ||
|
||
/** | ||
* @return TaskRunnerHelper | ||
*/ | ||
protected function taskRunner() | ||
{ | ||
return $this->getHelper(TaskRunnerHelper::HELPER_NAME); | ||
} | ||
|
||
/** | ||
* @return PathsHelper | ||
*/ | ||
protected function paths() | ||
{ | ||
return $this->getHelper(PathsHelper::HELPER_NAME); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.