Skip to content

Commit 763aee0

Browse files
Merge pull request #1076 from Kitware/dynamic_delete
Fix dynamic build rule deletion bug
2 parents cc3c3cb + a35a9fe commit 763aee0

File tree

2 files changed

+43
-6
lines changed

2 files changed

+43
-6
lines changed

app/cdash/public/api/v1/manageBuildGroup.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
use App\Services\PageTimer;
2121
use CDash\Database;
2222
use CDash\Model\Project;
23+
use CDash\Model\Site;
2324
use CDash\Model\UserProject;
2425

2526
$pageTimer = new PageTimer();
@@ -112,9 +113,9 @@
112113
$response['error'] = 'Database error during site lookup';
113114
}
114115

115-
$sites = array();
116+
$sites = [];
116117
while ($row = $stmt->fetch()) {
117-
$site = array();
118+
$site = [];
118119
$site['id'] = $row['siteid'];
119120
$site['name'] = $row['name'];
120121
$sites[] = $site;
@@ -169,13 +170,20 @@
169170
$rule_response['sitename'] = 'Any';
170171
$rule_response['siteid'] = 0;
171172
} else {
173+
$rule_response['siteid'] = $siteid;
174+
$found = false;
172175
foreach ($sites as $site) {
173176
if ($site['id'] == $siteid) {
174177
$rule_response['sitename'] = $site['name'];
175-
$rule_response['siteid'] = $site['id'];
178+
$found = true;
176179
break;
177180
}
178181
}
182+
if (!$found) {
183+
$site = new Site();
184+
$site->Id = $siteid;
185+
$rule_response['sitename'] = $site->GetName();
186+
}
179187
}
180188

181189
$parentgroupid = $rule->ParentGroupId;

app/cdash/tests/test_putdynamicbuilds.php

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
require_once 'include/pdo.php';
1010

1111
use CDash\Database;
12-
use CDash\Model\BuildConfigure;
12+
use CDash\Model\BuildGroup;
13+
use CDash\Model\Site;
1314

1415
class PutDynamicBuildsTestCase extends KWWebTestCase
1516
{
@@ -31,10 +32,17 @@ public function testPutDynamicBuildsDiff()
3132

3233
// Get one of the default buildgroups for this project.
3334
$stmt = $this->PDO->prepare(
34-
'SELECT id FROM buildgroup WHERE projectid = :projectid LIMIT 2');
35+
'SELECT id FROM buildgroup WHERE projectid = :projectid LIMIT 1');
3536
$this->PDO->execute($stmt, [':projectid' => $this->ProjectId]);
3637
$this->ParentGroupId = $stmt->fetchColumn();
37-
$this->ChildGroupId = $stmt->fetchColumn();
38+
39+
// Create a 'Latest' buildgroup for this project.
40+
$buildgroup = new BuildGroup();
41+
$buildgroup->SetProjectId($this->ProjectId);
42+
$buildgroup->SetName('latest results');
43+
$buildgroup->SetType('Latest');
44+
$buildgroup->Save();
45+
$this->ChildGroupId = $buildgroup->GetId();
3846

3947
// Use the API PUT a list of builds.
4048
$client = $this->getGuzzleClient();
@@ -74,6 +82,27 @@ public function testPutDynamicBuildsDiff()
7482
$this->assertTrue(strtotime($endtime) > strtotime('-1 week'));
7583
}
7684

85+
// Verify that we can associate a dynamic build group with a rule that
86+
// hasn't submitted any builds to this project yet.
87+
$site = new Site();
88+
$site->Id = 1;
89+
$site_name = $site->GetName();
90+
$build_rules = [
91+
[ 'match' => 'foo', 'parentgroupid' => $this->ParentGroupId, 'site' => $site_name ],
92+
];
93+
$starttime_stmt = $this->PDO->prepare("
94+
SELECT starttime FROM build2grouprule
95+
WHERE buildname = :buildname AND
96+
parentgroupid = :parentgroupid AND
97+
siteid = $site->Id");
98+
$this->verifyListGetsCreated($client, $starttime_stmt, $build_rules);
99+
$this->login();
100+
$this->get($this->url . "/api/v1/manageBuildGroup.php?projectid={$this->ProjectId}");
101+
$content = $this->getBrowser()->getContent();
102+
$jsonobj = json_decode($content, true);
103+
$this->assertEqual($jsonobj['dynamics'][0]['rules'][0]['match'], 'foo');
104+
$this->assertEqual($jsonobj['dynamics'][0]['rules'][0]['siteid'], 1);
105+
77106
// Clean up.
78107
$this->deleteProject($this->ProjectId);
79108
}

0 commit comments

Comments
 (0)