From 3e25b22abd4285b0ad9c893e4380783952abe63b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elan=20Ruusam=C3=A4e?= Date: Sat, 24 Oct 2020 11:51:18 +0300 Subject: [PATCH 1/3] Code style improvements --- eventum-svn-hook.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) 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)) { From 1884242241d050271f29281033baf3112d467faa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elan=20Ruusam=C3=A4e?= Date: Sat, 24 Oct 2020 11:51:28 +0300 Subject: [PATCH 2/3] Drop unused git_short_rev --- eventum-git-hook.php | 11 ----------- 1 file changed, 11 deletions(-) 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 * From 0aceaaa7b62d14143eb9d4edd31bd1170acf08c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elan=20Ruusam=C3=A4e?= Date: Sat, 24 Oct 2020 11:44:23 +0300 Subject: [PATCH 3/3] Match also eventum issue urls in commit messages --- eventum-cvs-hook.php | 2 +- helpers.php | 23 ++++++++++++++++++----- 2 files changed, 19 insertions(+), 6 deletions(-) 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/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;