Added ticket 259, automatic linking of issues/commits to support TortoiseSVN preferred issue/commit naming.

This commit is contained in:
Mehdi Kabab 2009-11-06 16:00:47 +01:00 committed by Loic d'Anterroches
parent 3c46b7734f
commit 73dba2fa1a

View File

@ -43,7 +43,7 @@ class IDF_Template_IssueComment extends Pluf_Template_Tag
'<a href="\1">\1</a>', $text); '<a href="\1">\1</a>', $text);
} }
if ($request->rights['hasIssuesAccess']) { if ($request->rights['hasIssuesAccess']) {
$text = preg_replace_callback('#(issues?|bugs?|tickets?)\s+(\d+)(\#ic\d*){0,1}((\s+and|\s+or|,)\s+(\d+)(\#ic\d*){0,1}){0,}#im', $text = preg_replace_callback('#((?:issue|bug|ticket)(s)?\s+|\s+\#)(\d+)(\#ic\d+)?(?(2)((?:[, \w]+(?:\s+\#)?)?\d+(?:\#ic\d+)?){0,})#im',
array($this, 'callbackIssues'), $text); array($this, 'callbackIssues'), $text);
} }
if ($request->rights['hasReviewAccess']) { if ($request->rights['hasReviewAccess']) {
@ -70,23 +70,30 @@ class IDF_Template_IssueComment extends Pluf_Template_Tag
*/ */
function callbackIssues($m) function callbackIssues($m)
{ {
if (count($m) == 3 || count($m) == 4) { $c = count($m);
$issue = new IDF_Issue($m[2]); if (4 === $c || 5 === $c) {
if ($issue->id > 0 and $issue->project == $this->project->id) { $issue = new IDF_Issue($m[3]);
if (count($m) == 3) { if (0 < $issue->id and $issue->project == $this->project->id) {
return $this->linkIssue($issue, $m[1].' '.$m[2]); $m[1] = trim($m[1]);
$prefix = '';
if ('#' === $m[1]) {
$title = $m[1].$m[3];
$prefix = mb_substr($m[0], 0, strpos($m[0], $m[1])); // fixes \n matches
} else { } else {
return $this->linkIssue($issue, $m[1].' '.$m[2], $m[3]); $title = $m[1].' '.$m[3];
} }
if (4 === $c) {
return $prefix.$this->linkIssue($issue, $title);
} else { } else {
return $prefix.$this->linkIssue($issue, $title, $m[4]);
}
}
return $m[0]; // not existing issue. return $m[0]; // not existing issue.
} }
} else { return preg_replace_callback('#(\#)?(\d+)(\#ic\d+)?#',
return preg_replace_callback('/(\d+)/',
array($this, 'callbackIssue'), array($this, 'callbackIssue'),
$m[0]); $m[0]);
} }
}
/** /**
* Call back for the case of multiple issues like 'issues 1, 2 and 3'. * Call back for the case of multiple issues like 'issues 1, 2 and 3'.
@ -96,12 +103,14 @@ class IDF_Template_IssueComment extends Pluf_Template_Tag
*/ */
function callbackIssue($m) function callbackIssue($m)
{ {
$issue = new IDF_Issue($m[1]); $issue = new IDF_Issue($m[2]);
if ($issue->id > 0 and $issue->project == $this->project->id) { if (0 < $issue->id and $issue->project == $this->project->id) {
return $this->linkIssue($issue, $m[1]); if (4 === count($m)) {
} else { return $this->linkIssue($issue, $m[1].$m[2], $m[3]);
return $m[0]; // not existing issue.
} }
return $this->linkIssue($issue, $m[1].$m[2]);
}
return $m[0]; // not existing issue.
} }
/** /**