From f348164bf5cbc997a890b020eab351eec042d018 Mon Sep 17 00:00:00 2001 From: Alex Date: Sat, 19 Oct 2024 20:11:51 +0300 Subject: [PATCH] Fixed detection of bug tracking expression for deleted projects --- CHANGELOG.md | 1 + .../DatabaseCollectorPlugin/BugsPlugin.php | 22 ++++++++++++++----- .../RevisionLog/Plugin/BugsPluginTest.php | 16 ++++++++++++-- 3 files changed, 31 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c62ae5e..726583d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -28,6 +28,7 @@ This project adheres to [Semantic Versioning](http://semver.org/). - Queue SVN-Buddy new repository commit discovery, after a new commit in SVN-Buddy was made. - The `log` and `merge` commands no longer fails with large (>999) revision lists on SQLite <= 3.32.0. - The deletion of project wasn't deleting its refs (branches/tags) resulting them to reported as existing. +- The attempt to detect a "bugtraq:logregex" of a deleted project failed. ## [0.7.0] - 2024-04-12 ### Added diff --git a/src/SVNBuddy/Repository/RevisionLog/Plugin/DatabaseCollectorPlugin/BugsPlugin.php b/src/SVNBuddy/Repository/RevisionLog/Plugin/DatabaseCollectorPlugin/BugsPlugin.php index 572b5d6..599e09d 100644 --- a/src/SVNBuddy/Repository/RevisionLog/Plugin/DatabaseCollectorPlugin/BugsPlugin.php +++ b/src/SVNBuddy/Repository/RevisionLog/Plugin/DatabaseCollectorPlugin/BugsPlugin.php @@ -178,7 +178,7 @@ protected function populateMissingBugRegExp($cache_overwrite = false) */ protected function detectProjectBugTraqRegEx($project_path, $revision, $project_deleted, $cache_overwrite = false) { - $ref_paths = $this->getLastChangedRefPaths($project_path); + $ref_paths = $this->getLastChangedRefPaths($project_path, $revision, $project_deleted); if ( !$ref_paths ) { return ''; @@ -204,20 +204,30 @@ protected function detectProjectBugTraqRegEx($project_path, $revision, $project_ /** * Returns given project refs, where last changed are on top. * - * @param string $project_path Path. + * @param string $project_path Path. + * @param integer $revision Revision. + * @param boolean $project_deleted Project is deleted. * * @return array */ - protected function getLastChangedRefPaths($project_path) + protected function getLastChangedRefPaths($project_path, $revision, $project_deleted) { $own_nesting_level = substr_count($project_path, '/') - 1; $where_clause = array( 'Path LIKE :parent_path', 'PathNestingLevel BETWEEN :from_level AND :to_level', - 'RevisionDeleted IS NULL', ); + if ( $project_deleted ) { + // For deleted project scan paths, that existed at project removal time. + $where_clause[] = 'RevisionDeleted > ' . $revision; + } + else { + // For active project scan paths, that are not deleted. + $where_clause[] = 'RevisionDeleted IS NULL'; + } + $sql = 'SELECT Path, RevisionLastSeen FROM Paths WHERE (' . implode(') AND (', $where_clause) . ')'; @@ -234,9 +244,9 @@ protected function getLastChangedRefPaths($project_path) $filtered_paths = array(); - foreach ( $paths as $path => $revision ) { + foreach ( $paths as $path => $last_seen_revision ) { if ( $this->isRef($path) ) { - $filtered_paths[$path] = $revision; + $filtered_paths[$path] = $last_seen_revision; } } diff --git a/tests/SVNBuddy/Repository/RevisionLog/Plugin/BugsPluginTest.php b/tests/SVNBuddy/Repository/RevisionLog/Plugin/BugsPluginTest.php index 01e9266..5f21909 100644 --- a/tests/SVNBuddy/Repository/RevisionLog/Plugin/BugsPluginTest.php +++ b/tests/SVNBuddy/Repository/RevisionLog/Plugin/BugsPluginTest.php @@ -162,6 +162,12 @@ public function testProcessDetectsMissingBugRegexps($project_deleted) ->addPath('A', '/path/to/project/branches/branch-name/', '', '/path/to/project/') ->addPath('A', '/path/to/project/branches/branch-name/file.txt', '', '/path/to/project/'); + if ( $project_deleted ) { + $this->commitBuilder + ->addCommit(300, 'user', 0, 'message') + ->addPath('D', '/path/to/project/', '', '/path/to/project/'); + } + $this->commitBuilder->build(); // Assuming that project id would be "1". @@ -211,6 +217,12 @@ public function testBugRegexpsRefresh($project_deleted) ->addPath('A', '/path/to/project/branches/branch-name/', '', '/path/to/project/') ->addPath('A', '/path/to/project/branches/branch-name/file.txt', '', '/path/to/project/'); + if ( $project_deleted ) { + $this->commitBuilder + ->addCommit(300, 'user', 0, 'message') + ->addPath('D', '/path/to/project/', '', '/path/to/project/'); + } + $this->commitBuilder->build(); // Assuming that project id would be "1". @@ -280,8 +292,8 @@ public function setBugRegexpExpectation($project_deleted, $expression) public static function processDetectsMissingBugRegexpsDataProvider() { return array( - 'project deleted' => array('0'), - 'project not deleted' => array('1'), + 'project alive' => array('0'), + 'project deleted' => array('1'), ); }