From ea8c829c820f70eda7e4a0a3fac6f323d321691f Mon Sep 17 00:00:00 2001 From: Andrew Roslik Date: Mon, 3 Aug 2015 21:22:17 +0300 Subject: [PATCH 01/17] #13 Implement integration with GitHub - Added comment about local config. --- commithook.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/commithook.xml b/commithook.xml index 956a1fe..8f1ceba 100644 --- a/commithook.xml +++ b/commithook.xml @@ -1,4 +1,5 @@ + From d4ffbaa61f34d5796273b9ba08a89d1aa73e1fe5 Mon Sep 17 00:00:00 2001 From: Andrew Roslik Date: Mon, 3 Aug 2015 21:31:37 +0300 Subject: [PATCH 02/17] - Refactored tracker type config node. --- LibHooks/config/commithook.xml | 6 +++--- LibHooks/lib/PreCommit/Issue.php | 6 +++--- LibHooks/lib/PreCommit/Issue/AdapterAbstract.php | 8 ++++---- LibHooks/lib/PreCommit/Validator/IssueStatus.php | 8 ++++---- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/LibHooks/config/commithook.xml b/LibHooks/config/commithook.xml index 0c26f8f..51df46a 100644 --- a/LibHooks/config/commithook.xml +++ b/LibHooks/config/commithook.xml @@ -1,9 +1,9 @@ - - jira - + + jira + diff --git a/LibHooks/lib/PreCommit/Issue.php b/LibHooks/lib/PreCommit/Issue.php index 48bd930..fa80eb9 100644 --- a/LibHooks/lib/PreCommit/Issue.php +++ b/LibHooks/lib/PreCommit/Issue.php @@ -27,7 +27,7 @@ class Issue static public function factory($key) { if (!isset(self::$_adapters[$key])) { - $tracker = self::_getTrackerName(); + $tracker = self::_getTrackerType(); if (!$tracker) { return null; } @@ -47,9 +47,9 @@ static public function factory($key) * * @return string */ - static protected function _getTrackerName() + static protected function _getTrackerType() { - return (string)self::_getConfig()->getNode('tracker_name'); + return (string)self::_getConfig()->getNode('tracker/type'); } /** diff --git a/LibHooks/lib/PreCommit/Issue/AdapterAbstract.php b/LibHooks/lib/PreCommit/Issue/AdapterAbstract.php index 41eb9f3..8de76a9 100644 --- a/LibHooks/lib/PreCommit/Issue/AdapterAbstract.php +++ b/LibHooks/lib/PreCommit/Issue/AdapterAbstract.php @@ -52,9 +52,9 @@ public function getType() { $issueType = $this->_normalizeName($this->getOriginalType()); return $this->_getConfig()->getNode('hooks/commit-msg/message/issue/type/tracker/' - . $this->_getTrackerName() . '/' . $this->_type . '/' . $issueType) + . $this->_getTrackerType() . '/' . $this->_type . '/' . $issueType) ?: $this->_getConfig()->getNode('hooks/commit-msg/message/issue/type/tracker/' - . $this->_getTrackerName() . '/default/' . $issueType); + . $this->_getTrackerType() . '/default/' . $issueType); } /** @@ -73,8 +73,8 @@ protected function _normalizeName($name) * * @return string */ - protected function _getTrackerName() + protected function _getTrackerType() { - return (string)$this->_getConfig()->getNode('tracker_name'); + return (string)$this->_getConfig()->getNode('tracker/type'); } } diff --git a/LibHooks/lib/PreCommit/Validator/IssueStatus.php b/LibHooks/lib/PreCommit/Validator/IssueStatus.php index 16cb430..2270162 100644 --- a/LibHooks/lib/PreCommit/Validator/IssueStatus.php +++ b/LibHooks/lib/PreCommit/Validator/IssueStatus.php @@ -68,8 +68,8 @@ public function validate($message, $file) protected function _getStatuses() { return (array)$this->_getConfig()->getNodeArray( - 'validators/IssueStatus/issue/status/' . $this->_getTrackerName() . '/allowed/' . $this->_type) - ?: (array)$this->_getConfig()->getNodeArray('validators/IssueStatus/issue/status/' . $this->_getTrackerName() . '/allowed/' . $this->_type); + 'validators/IssueStatus/issue/status/' . $this->_getTrackerType() . '/allowed/' . $this->_type) + ?: (array)$this->_getConfig()->getNodeArray('validators/IssueStatus/issue/status/' . $this->_getTrackerType() . '/allowed/' . $this->_type); } /** @@ -77,9 +77,9 @@ protected function _getStatuses() * * @return string */ - protected function _getTrackerName() + protected function _getTrackerType() { - return (string)$this->_getConfig()->getNode('tracker_name'); + return (string)$this->_getConfig()->getNode('tracker/type'); } /** From 94bcc13c56993de235fbd7ceeab25e43520df358 Mon Sep 17 00:00:00 2001 From: Andrew Roslik Date: Mon, 3 Aug 2015 21:34:21 +0300 Subject: [PATCH 03/17] - Refactored tracker info into commit-msg.xml file. --- LibHooks/config/commit-msg.xml | 13 +++++++++++++ LibHooks/config/commithook.xml | 13 +------------ 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/LibHooks/config/commit-msg.xml b/LibHooks/config/commit-msg.xml index 3cd5913..99b3424 100644 --- a/LibHooks/config/commit-msg.xml +++ b/LibHooks/config/commit-msg.xml @@ -1,5 +1,18 @@ + + + jira + + + + + \PreCommit\Issue\JiraAdapter + + + + + diff --git a/LibHooks/config/commithook.xml b/LibHooks/config/commithook.xml index 51df46a..9753c9a 100644 --- a/LibHooks/config/commithook.xml +++ b/LibHooks/config/commithook.xml @@ -1,15 +1,4 @@ - - - jira - - - - - \PreCommit\Issue\JiraAdapter - - - - + From 1ef6d640288a7722e1847d5d5204517d999c7e16 Mon Sep 17 00:00:00 2001 From: Andrew Roslik Date: Mon, 3 Aug 2015 21:39:31 +0300 Subject: [PATCH 04/17] #13 Implement integration with GitHub - Added local configuration. --- commithook.xml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/commithook.xml b/commithook.xml index 8f1ceba..7c6ac66 100644 --- a/commithook.xml +++ b/commithook.xml @@ -13,4 +13,12 @@ + + + github + + andkirby + commithook + + From d1e4f35c44edca82878c0743f4b0f9c05dfc2d68 Mon Sep 17 00:00:00 2001 From: Andrew Roslik Date: Tue, 1 Dec 2015 19:45:56 +0200 Subject: [PATCH 05/17] #13 Implement integration with GitHub - Added exception. --- LibHooks/lib/PreCommit/Issue/Exception.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 LibHooks/lib/PreCommit/Issue/Exception.php diff --git a/LibHooks/lib/PreCommit/Issue/Exception.php b/LibHooks/lib/PreCommit/Issue/Exception.php new file mode 100644 index 0000000..2793dda --- /dev/null +++ b/LibHooks/lib/PreCommit/Issue/Exception.php @@ -0,0 +1,12 @@ + Date: Tue, 1 Dec 2015 19:46:41 +0200 Subject: [PATCH 06/17] #13 Implement integration with GitHub - Added GitHub API library. --- composer.json | 3 +- composer.lock | 368 +++++++++++++++++++++++++++++++++++++++++--------- 2 files changed, 305 insertions(+), 66 deletions(-) diff --git a/composer.json b/composer.json index 760ed24..8edd161 100644 --- a/composer.json +++ b/composer.json @@ -14,7 +14,8 @@ "php": ">=5.3.2", "symfony/console": "~2.5@stable", "chobie/jira-api-restclient": "2.0.x-dev", - "zendframework/zend-cache": "~2.5@stable" + "zendframework/zend-cache": "~2.5@stable", + "knplabs/github-api": "~1.4" }, "require-dev": { "phpunit/phpunit": "~4.0@stable" diff --git a/composer.lock b/composer.lock index 4743e56..a1a0fe6 100644 --- a/composer.lock +++ b/composer.lock @@ -4,8 +4,8 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "b75ff0d9c0e3ee10c2b819f5b1bd1c5e", - "content-hash": "0b4e45c349aa45a39fa7fd0e28f8f011", + "hash": "8d3bd92604c97f1f1b457a422f4a0d22", + "content-hash": "cf39bf9089ff15a2ad62895da8bb361c", "packages": [ { "name": "chobie/jira-api-restclient", @@ -57,28 +57,184 @@ ], "time": "2014-07-27 11:55:20" }, + { + "name": "guzzle/guzzle", + "version": "v3.9.3", + "source": { + "type": "git", + "url": "https://github.com/guzzle/guzzle3.git", + "reference": "0645b70d953bc1c067bbc8d5bc53194706b628d9" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/guzzle/guzzle3/zipball/0645b70d953bc1c067bbc8d5bc53194706b628d9", + "reference": "0645b70d953bc1c067bbc8d5bc53194706b628d9", + "shasum": "" + }, + "require": { + "ext-curl": "*", + "php": ">=5.3.3", + "symfony/event-dispatcher": "~2.1" + }, + "replace": { + "guzzle/batch": "self.version", + "guzzle/cache": "self.version", + "guzzle/common": "self.version", + "guzzle/http": "self.version", + "guzzle/inflection": "self.version", + "guzzle/iterator": "self.version", + "guzzle/log": "self.version", + "guzzle/parser": "self.version", + "guzzle/plugin": "self.version", + "guzzle/plugin-async": "self.version", + "guzzle/plugin-backoff": "self.version", + "guzzle/plugin-cache": "self.version", + "guzzle/plugin-cookie": "self.version", + "guzzle/plugin-curlauth": "self.version", + "guzzle/plugin-error-response": "self.version", + "guzzle/plugin-history": "self.version", + "guzzle/plugin-log": "self.version", + "guzzle/plugin-md5": "self.version", + "guzzle/plugin-mock": "self.version", + "guzzle/plugin-oauth": "self.version", + "guzzle/service": "self.version", + "guzzle/stream": "self.version" + }, + "require-dev": { + "doctrine/cache": "~1.3", + "monolog/monolog": "~1.0", + "phpunit/phpunit": "3.7.*", + "psr/log": "~1.0", + "symfony/class-loader": "~2.1", + "zendframework/zend-cache": "2.*,<2.3", + "zendframework/zend-log": "2.*,<2.3" + }, + "suggest": { + "guzzlehttp/guzzle": "Guzzle 5 has moved to a new package name. The package you have installed, Guzzle 3, is deprecated." + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.9-dev" + } + }, + "autoload": { + "psr-0": { + "Guzzle": "src/", + "Guzzle\\Tests": "tests/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Michael Dowling", + "email": "mtdowling@gmail.com", + "homepage": "https://github.com/mtdowling" + }, + { + "name": "Guzzle Community", + "homepage": "https://github.com/guzzle/guzzle/contributors" + } + ], + "description": "PHP HTTP client. This library is deprecated in favor of https://packagist.org/packages/guzzlehttp/guzzle", + "homepage": "http://guzzlephp.org/", + "keywords": [ + "client", + "curl", + "framework", + "http", + "http client", + "rest", + "web service" + ], + "time": "2015-03-18 18:23:50" + }, + { + "name": "knplabs/github-api", + "version": "1.5.1", + "source": { + "type": "git", + "url": "https://github.com/KnpLabs/php-github-api.git", + "reference": "832b7be695ed2733741cd5c79166b4a88fb50786" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/KnpLabs/php-github-api/zipball/832b7be695ed2733741cd5c79166b4a88fb50786", + "reference": "832b7be695ed2733741cd5c79166b4a88fb50786", + "shasum": "" + }, + "require": { + "ext-curl": "*", + "guzzle/guzzle": "~3.7", + "php": ">=5.3.2" + }, + "require-dev": { + "phpunit/phpunit": "~4.0" + }, + "suggest": { + "knplabs/gaufrette": "Needed for optional Gaufrette cache" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.4.x-dev" + } + }, + "autoload": { + "psr-4": { + "Github\\": "lib/Github/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Thibault Duplessis", + "email": "thibault.duplessis@gmail.com", + "homepage": "http://ornicar.github.com" + }, + { + "name": "KnpLabs Team", + "homepage": "http://knplabs.com" + } + ], + "description": "GitHub API v3 client", + "homepage": "https://github.com/KnpLabs/php-github-api", + "keywords": [ + "api", + "gh", + "gist", + "github" + ], + "time": "2015-10-11 02:38:28" + }, { "name": "symfony/console", - "version": "v2.7.5", + "version": "v2.8.0", "source": { "type": "git", "url": "https://github.com/symfony/console.git", - "reference": "06cb17c013a82f94a3d840682b49425cd00a2161" + "reference": "d232bfc100dfd32b18ccbcab4bcc8f28697b7e41" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/console/zipball/06cb17c013a82f94a3d840682b49425cd00a2161", - "reference": "06cb17c013a82f94a3d840682b49425cd00a2161", + "url": "https://api.github.com/repos/symfony/console/zipball/d232bfc100dfd32b18ccbcab4bcc8f28697b7e41", + "reference": "d232bfc100dfd32b18ccbcab4bcc8f28697b7e41", "shasum": "" }, "require": { - "php": ">=5.3.9" + "php": ">=5.3.9", + "symfony/polyfill-mbstring": "~1.0" }, "require-dev": { "psr/log": "~1.0", - "symfony/event-dispatcher": "~2.1", - "symfony/phpunit-bridge": "~2.7", - "symfony/process": "~2.1" + "symfony/event-dispatcher": "~2.1|~3.0.0", + "symfony/process": "~2.1|~3.0.0" }, "suggest": { "psr/log": "For using the console logger", @@ -88,13 +244,16 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "2.7-dev" + "dev-master": "2.8-dev" } }, "autoload": { "psr-4": { "Symfony\\Component\\Console\\": "" - } + }, + "exclude-from-classmap": [ + "/Tests/" + ] }, "notification-url": "https://packagist.org/downloads/", "license": [ @@ -112,7 +271,123 @@ ], "description": "Symfony Console Component", "homepage": "https://symfony.com", - "time": "2015-09-25 08:32:23" + "time": "2015-11-30 12:35:10" + }, + { + "name": "symfony/event-dispatcher", + "version": "v2.8.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/event-dispatcher.git", + "reference": "a5eb815363c0388e83247e7e9853e5dbc14999cc" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/event-dispatcher/zipball/a5eb815363c0388e83247e7e9853e5dbc14999cc", + "reference": "a5eb815363c0388e83247e7e9853e5dbc14999cc", + "shasum": "" + }, + "require": { + "php": ">=5.3.9" + }, + "require-dev": { + "psr/log": "~1.0", + "symfony/config": "~2.0,>=2.0.5|~3.0.0", + "symfony/dependency-injection": "~2.6|~3.0.0", + "symfony/expression-language": "~2.6|~3.0.0", + "symfony/stopwatch": "~2.3|~3.0.0" + }, + "suggest": { + "symfony/dependency-injection": "", + "symfony/http-kernel": "" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.8-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Component\\EventDispatcher\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony EventDispatcher Component", + "homepage": "https://symfony.com", + "time": "2015-10-30 20:15:42" + }, + { + "name": "symfony/polyfill-mbstring", + "version": "v1.0.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-mbstring.git", + "reference": "0b6a8940385311a24e060ec1fe35680e17c74497" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/0b6a8940385311a24e060ec1fe35680e17c74497", + "reference": "0b6a8940385311a24e060ec1fe35680e17c74497", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Polyfill\\Mbstring\\": "" + }, + "files": [ + "bootstrap.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony polyfill for the Mbstring extension", + "homepage": "https://symfony.com", + "keywords": [ + "compatibility", + "mbstring", + "polyfill", + "portable", + "shim" + ], + "time": "2015-11-04 20:28:58" }, { "name": "zendframework/zend-cache", @@ -890,16 +1165,16 @@ }, { "name": "phpunit/phpunit", - "version": "4.8.12", + "version": "4.8.19", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "00194eb95989190a73198390ceca081ad3441a7f" + "reference": "b2caaf8947aba5e002d42126723e9d69795f32b4" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/00194eb95989190a73198390ceca081ad3441a7f", - "reference": "00194eb95989190a73198390ceca081ad3441a7f", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/b2caaf8947aba5e002d42126723e9d69795f32b4", + "reference": "b2caaf8947aba5e002d42126723e9d69795f32b4", "shasum": "" }, "require": { @@ -958,7 +1233,7 @@ "testing", "xunit" ], - "time": "2015-10-12 03:36:47" + "time": "2015-11-30 08:18:59" }, { "name": "phpunit/phpunit-mock-objects", @@ -1389,34 +1664,34 @@ }, { "name": "symfony/yaml", - "version": "v2.7.5", + "version": "v2.8.0", "source": { "type": "git", "url": "https://github.com/symfony/yaml.git", - "reference": "31cb2ad0155c95b88ee55fe12bc7ff92232c1770" + "reference": "f79824187de95064a2f5038904c4d7f0227fedb5" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/yaml/zipball/31cb2ad0155c95b88ee55fe12bc7ff92232c1770", - "reference": "31cb2ad0155c95b88ee55fe12bc7ff92232c1770", + "url": "https://api.github.com/repos/symfony/yaml/zipball/f79824187de95064a2f5038904c4d7f0227fedb5", + "reference": "f79824187de95064a2f5038904c4d7f0227fedb5", "shasum": "" }, "require": { "php": ">=5.3.9" }, - "require-dev": { - "symfony/phpunit-bridge": "~2.7" - }, "type": "library", "extra": { "branch-alias": { - "dev-master": "2.7-dev" + "dev-master": "2.8-dev" } }, "autoload": { "psr-4": { "Symfony\\Component\\Yaml\\": "" - } + }, + "exclude-from-classmap": [ + "/Tests/" + ] }, "notification-url": "https://packagist.org/downloads/", "license": [ @@ -1434,44 +1709,7 @@ ], "description": "Symfony Yaml Component", "homepage": "https://symfony.com", - "time": "2015-09-14 14:14:09" - }, - { - "name": "zf1/zend-exception", - "version": "1.12.11", - "source": { - "type": "git", - "url": "https://github.com/zf1/zend-exception.git", - "reference": "ca30959d3e2f522f481a3d1459386acf1aa4ca74" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/zf1/zend-exception/zipball/ca30959d3e2f522f481a3d1459386acf1aa4ca74", - "reference": "ca30959d3e2f522f481a3d1459386acf1aa4ca74", - "shasum": "" - }, - "require": { - "php": ">=5.2.11" - }, - "type": "library", - "autoload": { - "psr-0": { - "Zend_Exception": "library/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "description": "Zend Framework 1 Exception package", - "homepage": "http://framework.zend.com/", - "keywords": [ - "ZF1", - "exception", - "framework", - "zend" - ], - "time": "2015-04-30 11:10:20" + "time": "2015-11-30 12:35:10" } ], "aliases": [], From b902fa6232ff4af5f75dff71797243aaad4d59ce Mon Sep 17 00:00:00 2001 From: Andrew Roslik Date: Tue, 1 Dec 2015 19:51:25 +0200 Subject: [PATCH 07/17] #13 Implement integration with GitHub - Refactored parser path. --- LibHooks/lib/PreCommit/Filter/ShortCommitMsg.php | 4 ++-- .../lib/PreCommit/Filter/ShortCommitMsg/{ => Jira}/Parser.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) rename LibHooks/lib/PreCommit/Filter/ShortCommitMsg/{ => Jira}/Parser.php (99%) diff --git a/LibHooks/lib/PreCommit/Filter/ShortCommitMsg.php b/LibHooks/lib/PreCommit/Filter/ShortCommitMsg.php index 15a552e..d7d33b2 100644 --- a/LibHooks/lib/PreCommit/Filter/ShortCommitMsg.php +++ b/LibHooks/lib/PreCommit/Filter/ShortCommitMsg.php @@ -60,11 +60,11 @@ protected function _getFormatterConfig() /** * Get parser * - * @return \PreCommit\Filter\ShortCommitMsg\Parser + * @return \PreCommit\Filter\ShortCommitMsg\Jira\Parser */ protected function _getParser() { - return new ShortCommitMsg\Parser(); + return new ShortCommitMsg\Jira\Parser(); } /** diff --git a/LibHooks/lib/PreCommit/Filter/ShortCommitMsg/Parser.php b/LibHooks/lib/PreCommit/Filter/ShortCommitMsg/Jira/Parser.php similarity index 99% rename from LibHooks/lib/PreCommit/Filter/ShortCommitMsg/Parser.php rename to LibHooks/lib/PreCommit/Filter/ShortCommitMsg/Jira/Parser.php index 5d76625..053a537 100644 --- a/LibHooks/lib/PreCommit/Filter/ShortCommitMsg/Parser.php +++ b/LibHooks/lib/PreCommit/Filter/ShortCommitMsg/Jira/Parser.php @@ -1,5 +1,5 @@ Date: Tue, 1 Dec 2015 19:54:11 +0200 Subject: [PATCH 08/17] #13 Implement integration with GitHub - Updated configuration for trackers. --- LibHooks/config/commit-msg.xml | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/LibHooks/config/commit-msg.xml b/LibHooks/config/commit-msg.xml index 7f3550c..6e62efc 100644 --- a/LibHooks/config/commit-msg.xml +++ b/LibHooks/config/commit-msg.xml @@ -17,10 +17,24 @@ \PreCommit\Issue\JiraAdapter + + + \PreCommit\Filter\ShortCommitMsg\Jira\Parser + + - + + + \PreCommit\Issue\GitHubAdapter + + + + + \PreCommit\Filter\ShortCommitMsg\GitHub\Parser + + From 01fb5a50c435c8ae5631e95cd84a287fcdf68e65 Mon Sep 17 00:00:00 2001 From: Andrew Roslik Date: Tue, 1 Dec 2015 20:00:44 +0200 Subject: [PATCH 09/17] #13 Implement integration with GitHub - Added getting class name of parser of short message.. --- LibHooks/lib/PreCommit/Filter/ShortCommitMsg.php | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/LibHooks/lib/PreCommit/Filter/ShortCommitMsg.php b/LibHooks/lib/PreCommit/Filter/ShortCommitMsg.php index d7d33b2..0626029 100644 --- a/LibHooks/lib/PreCommit/Filter/ShortCommitMsg.php +++ b/LibHooks/lib/PreCommit/Filter/ShortCommitMsg.php @@ -64,7 +64,10 @@ protected function _getFormatterConfig() */ protected function _getParser() { - return new ShortCommitMsg\Jira\Parser(); + $class = $this->_getConfig()->getNode( + 'tracker/' . $this->_getTrackerType() . '/message/parser/class' + ); + return new $class; } /** @@ -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'); + } } From a7897433e6e2e19ac6eb58ab285571ca306921de Mon Sep 17 00:00:00 2001 From: Andrew Roslik Date: Tue, 1 Dec 2015 20:08:24 +0200 Subject: [PATCH 10/17] #13 Implement integration with GitHub - Refactored "jira" in xpaths. --- .../Filter/ShortCommitMsg/Jira/Parser.php | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/LibHooks/lib/PreCommit/Filter/ShortCommitMsg/Jira/Parser.php b/LibHooks/lib/PreCommit/Filter/ShortCommitMsg/Jira/Parser.php index 053a537..53eb802 100644 --- a/LibHooks/lib/PreCommit/Filter/ShortCommitMsg/Jira/Parser.php +++ b/LibHooks/lib/PreCommit/Filter/ShortCommitMsg/Jira/Parser.php @@ -11,7 +11,7 @@ /** * Class filter to parse short message * - * @package PreCommit\Validator + * @package PreCommit\Filter\ShortCommitMsg\Jira */ class Parser implements InterpreterInterface { @@ -156,11 +156,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'); } /** @@ -176,9 +175,9 @@ protected function _getActiveIssueKey() 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"; } @@ -358,4 +357,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'); + } } From 8291a9f5ea20c9ee6be43870e63ea9897c2b1aeb Mon Sep 17 00:00:00 2001 From: Andrew Roslik Date: Tue, 1 Dec 2015 20:10:29 +0200 Subject: [PATCH 11/17] #13 Implement integration with GitHub - Added GitHub parser class.. --- .../Filter/ShortCommitMsg/GitHub/Parser.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 LibHooks/lib/PreCommit/Filter/ShortCommitMsg/GitHub/Parser.php diff --git a/LibHooks/lib/PreCommit/Filter/ShortCommitMsg/GitHub/Parser.php b/LibHooks/lib/PreCommit/Filter/ShortCommitMsg/GitHub/Parser.php new file mode 100644 index 0000000..c2f193f --- /dev/null +++ b/LibHooks/lib/PreCommit/Filter/ShortCommitMsg/GitHub/Parser.php @@ -0,0 +1,16 @@ + Date: Tue, 1 Dec 2015 20:11:23 +0200 Subject: [PATCH 12/17] #13 Implement integration with GitHub - Removed redundant "use". --- LibHooks/lib/PreCommit/Filter/ShortCommitMsg/Jira/Parser.php | 1 - 1 file changed, 1 deletion(-) diff --git a/LibHooks/lib/PreCommit/Filter/ShortCommitMsg/Jira/Parser.php b/LibHooks/lib/PreCommit/Filter/ShortCommitMsg/Jira/Parser.php index 53eb802..3539473 100644 --- a/LibHooks/lib/PreCommit/Filter/ShortCommitMsg/Jira/Parser.php +++ b/LibHooks/lib/PreCommit/Filter/ShortCommitMsg/Jira/Parser.php @@ -5,7 +5,6 @@ use PreCommit\Exception; use PreCommit\Interpreter\InterpreterInterface; use PreCommit\Issue; -use PreCommit\Jira\Api; use PreCommit\Message; /** From ec249e6c038ac050db3001c72bc6a5159ef757a5 Mon Sep 17 00:00:00 2001 From: Andrew Roslik Date: Tue, 1 Dec 2015 20:17:47 +0200 Subject: [PATCH 13/17] #13 Implement integration with GitHub - Removed redundant comment. --- LibHooks/lib/PreCommit/Filter/ShortCommitMsg/Jira/Parser.php | 1 - 1 file changed, 1 deletion(-) diff --git a/LibHooks/lib/PreCommit/Filter/ShortCommitMsg/Jira/Parser.php b/LibHooks/lib/PreCommit/Filter/ShortCommitMsg/Jira/Parser.php index 3539473..162cdf3 100644 --- a/LibHooks/lib/PreCommit/Filter/ShortCommitMsg/Jira/Parser.php +++ b/LibHooks/lib/PreCommit/Filter/ShortCommitMsg/Jira/Parser.php @@ -169,7 +169,6 @@ protected function _getActiveIssueKey() * @param string $issueNo * @return string * @throws \PreCommit\Exception - * @todo Refactor this 'cos it belongs to JIRA only */ protected function _normalizeIssueKey($issueNo) { From dee2232a8dd8325b69a877a32d9a4345326423d8 Mon Sep 17 00:00:00 2001 From: Andrew Roslik Date: Tue, 1 Dec 2015 20:18:23 +0200 Subject: [PATCH 14/17] #13 Implement integration with GitHub - Added method for normalizing issue key. --- .../Filter/ShortCommitMsg/GitHub/Parser.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/LibHooks/lib/PreCommit/Filter/ShortCommitMsg/GitHub/Parser.php b/LibHooks/lib/PreCommit/Filter/ShortCommitMsg/GitHub/Parser.php index c2f193f..f135296 100644 --- a/LibHooks/lib/PreCommit/Filter/ShortCommitMsg/GitHub/Parser.php +++ b/LibHooks/lib/PreCommit/Filter/ShortCommitMsg/GitHub/Parser.php @@ -13,4 +13,17 @@ class Parser extends ShortCommitMsg\Jira\Parser 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, '#'); + } } From 04f87a0896deb5a7bbc2649f53087a25cdc2192c Mon Sep 17 00:00:00 2001 From: Andrew Roslik Date: Tue, 1 Dec 2015 20:19:43 +0200 Subject: [PATCH 15/17] #13 Implement integration with GitHub - Added base class of github issue adapter. --- .../lib/PreCommit/Issue/GitHubAdapter.php | 231 ++++++++++++++++++ 1 file changed, 231 insertions(+) create mode 100644 LibHooks/lib/PreCommit/Issue/GitHubAdapter.php diff --git a/LibHooks/lib/PreCommit/Issue/GitHubAdapter.php b/LibHooks/lib/PreCommit/Issue/GitHubAdapter.php new file mode 100644 index 0000000..7448346 --- /dev/null +++ b/LibHooks/lib/PreCommit/Issue/GitHubAdapter.php @@ -0,0 +1,231 @@ +_issueKey = (string)$issueKey; + } + + /** + * Get issue + * + * @return array + * @throws \PreCommit\Issue\Exception + */ + protected function _getIssue() + { + if (null === $this->_issue) { + $this->_issue = $this->_getCachedResult($this->_issueKey); + if (!$this->_issue) { + $this->_issue = $this->_loadIssueData(); + if (!$this->_issue) { + throw new Exception( + "Issue not {$this->_issueKey} found.", self::EXCEPTION_CODE_ISSUE_NOT_FOUND + ); + } + $this->_cacheResult($this->_issueKey, $this->_issue); + } + } + return $this->_issue; + } + + /** + * Get issue number + * + * @return int + */ + protected function _getIssueNumber() + { + return (int)ltrim($this->_issueKey, '#'); + } + + //region Caching methods + /** + * Write summary to cache file + * + * @param string $key + * @param array $result + * @return $this + */ + protected function _cacheResult($key, $result) + { + if ($result) { + $this->_getCache()->setItem($key, serialize($result)); + } else { + $this->_getCache()->removeItem($key); + } + return $this; + } + + /** + * Get cache summary string + * + * @param string $key + * @return string|bool + */ + protected function _getCachedResult($key) + { + $data = $this->_getCache()->getItem($key); + return $data ? unserialize($data) : null; + } + + /** + * Get cache directory + * + * @return string + */ + protected function _getCacheDir() + { + return $this->_getConfig()->getCacheDir(COMMIT_HOOKS_ROOT); + } + + /** + * Get cache adapter + * + * @return \Zend\Cache\Storage\Adapter\Filesystem + */ + protected function _getCache() + { + return new CacheAdapter( + array( + 'cache_dir' => $this->_getCacheDir(), + 'ttl' => 7200, + 'namespace' => 'issue-github-' . self::CACHE_SCHEMA_VERSION + ) + ); + } + //endregion + + //region Interface methods + /** + * Get issue summary + * + * @return string + */ + public function getSummary() + { + return $this->_getIssue()->getSummary(); + } + + /** + * Get issue key + * + * @return string + */ + public function getKey() + { + return $this->_getIssue()->getKey(); + } + + /** + * Get issue type + * + * @return string + */ + public function getOriginalType() + { + return $this->_getIssue()->getIssueType(); + } + + /** + * Get status name + * + * @return string + */ + public function getStatus() + { + return $this->_normalizeName($this->_getIssue()->getStatus()); + } + + /** + * Cache issue + * + * @return $this + */ + public function ignoreIssue() + { + $this->_cacheResult($this->_issueKey, array()); + return $this; + } + //endregion + + //region API methods + /** + * Load issue by API + * + * @return array + * @throws Exception + */ + protected function _loadIssueData() + { + if (!$this->_canRequest()) { + throw new Exception('Connection params not fully set.'); + } + return $this->_getApi()->issue()->show( + $this->_getConfig()->getNode('github/name'), + $this->_getConfig()->getNode('github/repository'), + $this->_getIssueNumber() + ); + } + + /** + * Get GitHub API + * + * @return Api + */ + protected function _getApi() + { + return new Api(); + } + + /** + * Check if can make a request + * + * @return bool + */ + protected function _canRequest() + { + return $this->_getConfig()->getNode('tracker/github/name') + && $this->_getConfig()->getNode('tracker/github/repository'); + } + //endregion +} From c6ff6140814c4f8982738362981845862fb8d991 Mon Sep 17 00:00:00 2001 From: Andrew Roslik Date: Tue, 1 Dec 2015 21:10:28 +0200 Subject: [PATCH 16/17] Implemented #13: Implement integration with GitHub - Updated code of getting an issue data. --- LibHooks/config/commit-msg.xml | 17 +++ .../lib/PreCommit/Issue/GitHubAdapter.php | 105 +++++++++++++++--- 2 files changed, 107 insertions(+), 15 deletions(-) diff --git a/LibHooks/config/commit-msg.xml b/LibHooks/config/commit-msg.xml index 6e62efc..5051eb9 100644 --- a/LibHooks/config/commit-msg.xml +++ b/LibHooks/config/commit-msg.xml @@ -123,6 +123,14 @@ + + + + + 1 + + + @@ -186,6 +194,15 @@ bug + + + + + task + + bug + + diff --git a/LibHooks/lib/PreCommit/Issue/GitHubAdapter.php b/LibHooks/lib/PreCommit/Issue/GitHubAdapter.php index 7448346..e801189 100644 --- a/LibHooks/lib/PreCommit/Issue/GitHubAdapter.php +++ b/LibHooks/lib/PreCommit/Issue/GitHubAdapter.php @@ -1,7 +1,7 @@ _issueKey = (string)$issueKey; } @@ -54,15 +78,20 @@ public function __construct($issueKey) protected function _getIssue() { if (null === $this->_issue) { - $this->_issue = $this->_getCachedResult($this->_issueKey); + $this->_issue = $this->_getCachedResult( + $this->_getCacheKey() + ); if (!$this->_issue) { $this->_issue = $this->_loadIssueData(); if (!$this->_issue) { throw new Exception( - "Issue not {$this->_issueKey} found.", self::EXCEPTION_CODE_ISSUE_NOT_FOUND + "Issue not {$this->_issueKey} found.", + self::EXCEPTION_CODE_ISSUE_NOT_FOUND ); } - $this->_cacheResult($this->_issueKey, $this->_issue); + $this->_cacheResult( + $this->_getCacheKey(), $this->_issue + ); } } return $this->_issue; @@ -79,11 +108,22 @@ protected function _getIssueNumber() } //region Caching methods + /** + * Get cache key + * + * @return string + */ + protected function _getCacheKey() + { + return $this->_getVendorName() . '-' . $this->_getRepositoryName() + . '-' . $this->_getIssueNumber(); + } + /** * Write summary to cache file * * @param string $key - * @param array $result + * @param array $result * @return $this */ protected function _cacheResult($key, $result) @@ -143,7 +183,8 @@ protected function _getCache() */ public function getSummary() { - return $this->_getIssue()->getSummary(); + $issue = $this->_getIssue(); + return $issue['title']; } /** @@ -153,7 +194,8 @@ public function getSummary() */ public function getKey() { - return $this->_getIssue()->getKey(); + $issue = $this->_getIssue(); + return $issue['number']; } /** @@ -163,7 +205,15 @@ public function getKey() */ public function getOriginalType() { - return $this->_getIssue()->getIssueType(); + $issue = $this->_getIssue(); + if (!empty($issue['labels'])) { + foreach ($issue['labels'] as $label) { + if (in_array($label['name'], $this->_labelTypes)) { + return $label['name']; + } + } + } + return $this->_defaultLabelType; } /** @@ -173,7 +223,8 @@ public function getOriginalType() */ public function getStatus() { - return $this->_normalizeName($this->_getIssue()->getStatus()); + $issue = $this->_getIssue(); + return $this->_normalizeName($issue['state']); } /** @@ -183,7 +234,7 @@ public function getStatus() */ public function ignoreIssue() { - $this->_cacheResult($this->_issueKey, array()); + $this->_cacheResult($this->_getCacheKey(), array()); return $this; } //endregion @@ -201,8 +252,8 @@ protected function _loadIssueData() throw new Exception('Connection params not fully set.'); } return $this->_getApi()->issue()->show( - $this->_getConfig()->getNode('github/name'), - $this->_getConfig()->getNode('github/repository'), + $this->_getVendorName(), + $this->_getRepositoryName(), $this->_getIssueNumber() ); } @@ -214,7 +265,11 @@ protected function _loadIssueData() */ protected function _getApi() { - return new Api(); + if ($this->_api === null) { + $this->_api = new Api(); + $this->_api->authenticate('andkirby', 'gigaleon33'); + } + return $this->_api; } /** @@ -224,8 +279,28 @@ protected function _getApi() */ protected function _canRequest() { - return $this->_getConfig()->getNode('tracker/github/name') - && $this->_getConfig()->getNode('tracker/github/repository'); + return $this->_getVendorName() + && $this->_getRepositoryName(); } //endregion + + /** + * Get vendor name + * + * @return string + */ + protected function _getVendorName() + { + return $this->_getConfig()->getNode('tracker/github/name'); + } + + /** + * Get repository name + * + * @return string + */ + protected function _getRepositoryName() + { + return $this->_getConfig()->getNode('tracker/github/repository'); + } } From c8399ac542a71f52138105ef3f84bb55a707f95d Mon Sep 17 00:00:00 2001 From: Andrew Roslik Date: Tue, 1 Dec 2015 21:14:09 +0200 Subject: [PATCH 17/17] Refactored #13: Implement integration with GitHub - Updated class path. --- LibHooks/config/commit-msg.xml | 4 ++-- .../ShortCommitMsg/{GitHub/Parser.php => Parser/GitHub.php} | 6 +++--- .../ShortCommitMsg/{Jira/Parser.php => Parser/Jira.php} | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) rename LibHooks/lib/PreCommit/Filter/ShortCommitMsg/{GitHub/Parser.php => Parser/GitHub.php} (84%) rename LibHooks/lib/PreCommit/Filter/ShortCommitMsg/{Jira/Parser.php => Parser/Jira.php} (99%) diff --git a/LibHooks/config/commit-msg.xml b/LibHooks/config/commit-msg.xml index 5051eb9..04e1e3c 100644 --- a/LibHooks/config/commit-msg.xml +++ b/LibHooks/config/commit-msg.xml @@ -19,7 +19,7 @@ - \PreCommit\Filter\ShortCommitMsg\Jira\Parser + \PreCommit\Filter\ShortCommitMsg\Parser\Jira @@ -32,7 +32,7 @@ - \PreCommit\Filter\ShortCommitMsg\GitHub\Parser + \PreCommit\Filter\ShortCommitMsg\Parser\GitHub diff --git a/LibHooks/lib/PreCommit/Filter/ShortCommitMsg/GitHub/Parser.php b/LibHooks/lib/PreCommit/Filter/ShortCommitMsg/Parser/GitHub.php similarity index 84% rename from LibHooks/lib/PreCommit/Filter/ShortCommitMsg/GitHub/Parser.php rename to LibHooks/lib/PreCommit/Filter/ShortCommitMsg/Parser/GitHub.php index f135296..40eb14a 100644 --- a/LibHooks/lib/PreCommit/Filter/ShortCommitMsg/GitHub/Parser.php +++ b/LibHooks/lib/PreCommit/Filter/ShortCommitMsg/Parser/GitHub.php @@ -1,5 +1,5 @@