Skip to content

Commit 96a0c37

Browse files
authored
Merge pull request #161 from aik099/deleted-project-bug-traq-regexp-fix
Fixed detection of bug tracking expression for deleted projects
2 parents 06984a3 + f348164 commit 96a0c37

File tree

3 files changed

+31
-8
lines changed

3 files changed

+31
-8
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
2828
- Queue SVN-Buddy new repository commit discovery, after a new commit in SVN-Buddy was made.
2929
- The `log` and `merge` commands no longer fails with large (>999) revision lists on SQLite <= 3.32.0.
3030
- The deletion of project wasn't deleting its refs (branches/tags) resulting them to reported as existing.
31+
- The attempt to detect a "bugtraq:logregex" of a deleted project failed.
3132

3233
## [0.7.0] - 2024-04-12
3334
### Added

src/SVNBuddy/Repository/RevisionLog/Plugin/DatabaseCollectorPlugin/BugsPlugin.php

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ protected function populateMissingBugRegExp($cache_overwrite = false)
178178
*/
179179
protected function detectProjectBugTraqRegEx($project_path, $revision, $project_deleted, $cache_overwrite = false)
180180
{
181-
$ref_paths = $this->getLastChangedRefPaths($project_path);
181+
$ref_paths = $this->getLastChangedRefPaths($project_path, $revision, $project_deleted);
182182

183183
if ( !$ref_paths ) {
184184
return '';
@@ -204,20 +204,30 @@ protected function detectProjectBugTraqRegEx($project_path, $revision, $project_
204204
/**
205205
* Returns given project refs, where last changed are on top.
206206
*
207-
* @param string $project_path Path.
207+
* @param string $project_path Path.
208+
* @param integer $revision Revision.
209+
* @param boolean $project_deleted Project is deleted.
208210
*
209211
* @return array
210212
*/
211-
protected function getLastChangedRefPaths($project_path)
213+
protected function getLastChangedRefPaths($project_path, $revision, $project_deleted)
212214
{
213215
$own_nesting_level = substr_count($project_path, '/') - 1;
214216

215217
$where_clause = array(
216218
'Path LIKE :parent_path',
217219
'PathNestingLevel BETWEEN :from_level AND :to_level',
218-
'RevisionDeleted IS NULL',
219220
);
220221

222+
if ( $project_deleted ) {
223+
// For deleted project scan paths, that existed at project removal time.
224+
$where_clause[] = 'RevisionDeleted > ' . $revision;
225+
}
226+
else {
227+
// For active project scan paths, that are not deleted.
228+
$where_clause[] = 'RevisionDeleted IS NULL';
229+
}
230+
221231
$sql = 'SELECT Path, RevisionLastSeen
222232
FROM Paths
223233
WHERE (' . implode(') AND (', $where_clause) . ')';
@@ -234,9 +244,9 @@ protected function getLastChangedRefPaths($project_path)
234244

235245
$filtered_paths = array();
236246

237-
foreach ( $paths as $path => $revision ) {
247+
foreach ( $paths as $path => $last_seen_revision ) {
238248
if ( $this->isRef($path) ) {
239-
$filtered_paths[$path] = $revision;
249+
$filtered_paths[$path] = $last_seen_revision;
240250
}
241251
}
242252

tests/SVNBuddy/Repository/RevisionLog/Plugin/BugsPluginTest.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,12 @@ public function testProcessDetectsMissingBugRegexps($project_deleted)
162162
->addPath('A', '/path/to/project/branches/branch-name/', '', '/path/to/project/')
163163
->addPath('A', '/path/to/project/branches/branch-name/file.txt', '', '/path/to/project/');
164164

165+
if ( $project_deleted ) {
166+
$this->commitBuilder
167+
->addCommit(300, 'user', 0, 'message')
168+
->addPath('D', '/path/to/project/', '', '/path/to/project/');
169+
}
170+
165171
$this->commitBuilder->build();
166172

167173
// Assuming that project id would be "1".
@@ -211,6 +217,12 @@ public function testBugRegexpsRefresh($project_deleted)
211217
->addPath('A', '/path/to/project/branches/branch-name/', '', '/path/to/project/')
212218
->addPath('A', '/path/to/project/branches/branch-name/file.txt', '', '/path/to/project/');
213219

220+
if ( $project_deleted ) {
221+
$this->commitBuilder
222+
->addCommit(300, 'user', 0, 'message')
223+
->addPath('D', '/path/to/project/', '', '/path/to/project/');
224+
}
225+
214226
$this->commitBuilder->build();
215227

216228
// Assuming that project id would be "1".
@@ -280,8 +292,8 @@ public function setBugRegexpExpectation($project_deleted, $expression)
280292
public static function processDetectsMissingBugRegexpsDataProvider()
281293
{
282294
return array(
283-
'project deleted' => array('0'),
284-
'project not deleted' => array('1'),
295+
'project alive' => array('0'),
296+
'project deleted' => array('1'),
285297
);
286298
}
287299

0 commit comments

Comments
 (0)