Skip to content

Match also eventum url in commit messages #10

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion eventum-cvs-hook.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
11 changes: 0 additions & 11 deletions eventum-git-hook.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
5 changes: 2 additions & 3 deletions eventum-svn-hook.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
23 changes: 18 additions & 5 deletions helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<issue_id>\d+)
/x", $commit_msg, $matches);

if (count($matches['issue_id']) > 0) {
return $matches['issue_id'];
}

return null;
Expand Down