diff --git a/eventum-cvs-hook.php b/eventum-cvs-hook.php index 6dccada..fa4f8f9 100755 --- a/eventum-cvs-hook.php +++ b/eventum-cvs-hook.php @@ -46,7 +46,7 @@ function main($context) $commit_msg = cvs_commit_msg($context['stdin']); // parse the commit message and get all issue numbers we can find - $issues = match_issues($commit_msg); + $issues = match_issues($commit_msg, $context['eventum_url']); if (!$issues) { return; } diff --git a/eventum-git-hook.php b/eventum-git-hook.php index 43e13e5..402c171 100755 --- a/eventum-git-hook.php +++ b/eventum-git-hook.php @@ -213,17 +213,6 @@ function git_format($rev, $format) return execl("git log --format=$format -n1 $rev"); } -/** - * Get short Git shorter unique SHA1 reference - * - * @param string $rev - * @return string - */ -function git_short_rev($rev) -{ - return execl("git rev-parse --short $rev"); -} - /** * get git branch name for the refname * diff --git a/eventum-svn-hook.php b/eventum-svn-hook.php index 3b41d97..0b56167 100755 --- a/eventum-svn-hook.php +++ b/eventum-svn-hook.php @@ -35,12 +35,11 @@ function main($scm_name, $argv) { - if (count($argv) != 2) { + if (count($argv) !== 2) { throw new InvalidArgumentException('Invalid arguments'); } - $repos = $argv[0]; - $rev = $argv[1]; + list($repos, $rev) = $argv; global $svnlook; if (!isset($svnlook)) { diff --git a/helpers.php b/helpers.php index 50a0d45..f65ec5f 100644 --- a/helpers.php +++ b/helpers.php @@ -91,14 +91,27 @@ function fileparts($abspath) * parse the commit message and get all issue numbers we can find * * @param string $commit_msg + * @param string|null $eventum_url * @return array */ -function match_issues($commit_msg) +function match_issues($commit_msg, $eventum_url = null) { - preg_match_all('/(?:issue|bug) ?:? ?#?(\d+)/i', $commit_msg, $matches); - - if (count($matches[1]) > 0) { - return $matches[1]; + $url_quoted = rtrim($eventum_url ? preg_quote($eventum_url, '/') : '', '/'); + + preg_match_all("/ + (?: + # match issue xxx and bug xxx + (?i:issue|bug)\s*:?\s*#? + | + # match url + {$url_quoted}/view\.php\?id= + ) + + (?P\d+) + /x", $commit_msg, $matches); + + if (count($matches['issue_id']) > 0) { + return $matches['issue_id']; } return null;