Skip to content

Commit

Permalink
Merge branch 'feature/13' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
andkirby committed Dec 1, 2015
2 parents 505bd35 + c8399ac commit 8b5cb00
Show file tree
Hide file tree
Showing 9 changed files with 724 additions and 78 deletions.
33 changes: 32 additions & 1 deletion LibHooks/config/commit-msg.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,24 @@
<class>\PreCommit\Issue\JiraAdapter</class>
</adapter>
</issue>
<message>
<parser>
<class>\PreCommit\Filter\ShortCommitMsg\Parser\Jira</class>
</parser>
</message>
</jira>

<github>
<not_implemented />
<issue>
<adapter>
<class>\PreCommit\Issue\GitHubAdapter</class>
</adapter>
</issue>
<message>
<parser>
<class>\PreCommit\Filter\ShortCommitMsg\Parser\GitHub</class>
</parser>
</message>
</github>

<redmine>
Expand Down Expand Up @@ -109,6 +123,14 @@
</default>
</allowed>
</jira>
<github>
<allowed>
<!--Commit message type: default-->
<default>
<open>1</open>
</default>
</allowed>
</github>
</status>
</issue>
</IssueStatus>
Expand Down Expand Up @@ -172,6 +194,15 @@
<Bug>bug</Bug>
</default>
</jira>
<github>
<default>
<!--JIRA issue-type map to general issue-type-->
<!-- Tasks -->
<enhancement>task</enhancement>
<!-- Bugs -->
<bug>bug</bug>
</default>
</github>
</tracker>
</type>
</issue>
Expand Down
17 changes: 15 additions & 2 deletions LibHooks/lib/PreCommit/Filter/ShortCommitMsg.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,14 @@ protected function _getFormatterConfig()
/**
* Get parser
*
* @return \PreCommit\Filter\ShortCommitMsg\Parser
* @return \PreCommit\Filter\ShortCommitMsg\Jira\Parser
*/
protected function _getParser()
{
return new ShortCommitMsg\Parser();
$class = $this->_getConfig()->getNode(
'tracker/' . $this->_getTrackerType() . '/message/parser/class'
);
return new $class;
}

/**
Expand Down Expand Up @@ -98,4 +101,14 @@ protected function _getConfig()
{
return Config::getInstance();
}

/**
* Get tracker type
*
* @return string
*/
protected function _getTrackerType()
{
return (string)$this->_getConfig()->getNode('tracker/type');
}
}
29 changes: 29 additions & 0 deletions LibHooks/lib/PreCommit/Filter/ShortCommitMsg/Parser/GitHub.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php
namespace PreCommit\Filter\ShortCommitMsg\Parser;

use PreCommit\Interpreter\InterpreterInterface;
use PreCommit\Filter\ShortCommitMsg;

/**
* Class filter to parse short message
*
* @package PreCommit\Filter\ShortCommitMsg\GitHub
*/
class GitHub
extends ShortCommitMsg\Parser\Jira
implements InterpreterInterface
{
/**
* Convert issue number to issue key
*
* Add project key to issue number when it did not set.
*
* @param string $issueNo
* @return string
* @throws \PreCommit\Exception
*/
protected function _normalizeIssueKey($issueNo)
{
return "#" . ltrim($issueNo, '#');
}
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
<?php
namespace PreCommit\Filter\ShortCommitMsg;
namespace PreCommit\Filter\ShortCommitMsg\Parser;

use PreCommit\Config;
use PreCommit\Exception;
use PreCommit\Interpreter\InterpreterInterface;
use PreCommit\Issue;
use PreCommit\Jira\Api;
use PreCommit\Message;

/**
* Class filter to parse short message
*
* @package PreCommit\Validator
* @package PreCommit\Filter\ShortCommitMsg\Jira
*/
class Parser implements InterpreterInterface
class Jira implements InterpreterInterface
{
/**
* Issue adapter
Expand Down Expand Up @@ -156,11 +155,10 @@ protected function _getVerbs()
*
* @return string
* @throws \PreCommit\Exception
* @todo Refactor this 'cos it belongs to JIRA only
*/
protected function _getActiveIssueKey()
{
return $this->_getConfig()->getNode('tracker/jira/active_task');
return $this->_getConfig()->getNode('tracker/' . $this->_getTrackerType() . '/active_task');
}

/**
Expand All @@ -171,14 +169,13 @@ protected function _getActiveIssueKey()
* @param string $issueNo
* @return string
* @throws \PreCommit\Exception
* @todo Refactor this 'cos it belongs to JIRA only
*/
protected function _normalizeIssueKey($issueNo)
{
if ((string)(int)$issueNo === $issueNo) {
$project = $this->_getConfig()->getNode('tracker/jira/project');
$project = $this->_getConfig()->getNode('tracker/' . $this->_getTrackerType() . '/project');
if (!$project) {
throw new Exception('JIRA project key is not set. Please add it to issue-key or add by XPath "jira/project" in project configuration file "commithook.xml" within current project.');
throw new Exception('JIRA project key is not set. Please add it to issue-key or add by XPath "tracker/jira/project" in project configuration file "commithook.xml" within current project.');
}
$issueNo = "$project-$issueNo";
}
Expand Down Expand Up @@ -358,4 +355,14 @@ protected function _getIssueKeyCompleteRegular()
{
return '[A-Z0-9]+[-][0-9]+';
}

/**
* Get tracker type
*
* @return string
*/
protected function _getTrackerType()
{
return (string)$this->_getConfig()->getNode('tracker/type');
}
}
12 changes: 12 additions & 0 deletions LibHooks/lib/PreCommit/Issue/Exception.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php
namespace PreCommit\Issue;

/**
* Issue adapters exception class
*
* @package PreCommit\Issue
*/
class Exception extends \PreCommit\Exception
{

}
Loading

0 comments on commit 8b5cb00

Please sign in to comment.