/** Update the test numbers */ function UpdateTestNumbers($numberTestsPassed, $numberTestsFailed, $numberTestsNotRun) { if (!is_numeric($numberTestsPassed) || !is_numeric($numberTestsFailed) || !is_numeric($numberTestsNotRun)) { return; } // If this is a subproject build, we also have to update its parents test numbers. $newFailed = $numberTestsFailed - $this->GetNumberOfFailedTests(); $newNotRun = $numberTestsNotRun - $this->GetNumberOfNotRunTests(); $newPassed = $numberTestsPassed - $this->GetNumberOfPassedTests(); $this->ParentId = $this->GetParentBuildId(); $this->UpdateParentTestNumbers($newFailed, $newNotRun, $newPassed); // Update this build's test numbers. pdo_query("UPDATE build SET testnotrun='{$numberTestsNotRun}',\n testfailed='{$numberTestsFailed}',\n testpassed='{$numberTestsPassed}' WHERE id=" . qnum($this->Id)); add_last_sql_error("Build:UpdateTestNumbers", $this->ProjectId, $this->Id); // Check if we should post test failures to a pull request. if (isset($this->PullRequest) && $numberTestsFailed > 0) { $idToNotify = $this->Id; if ($this->ParentId > 0) { $idToNotify = $this->ParentId; } $notified = true; $row = pdo_single_row_query("SELECT notified FROM build WHERE id=" . qnum($idToNotify)); if ($row && array_key_exists('notified', $row)) { $notified = $row['notified']; } if (!$notified) { $url = get_server_URI(false); $url .= "/viewTest.php?onlyfailed&buildid={$this->Id}"; post_pull_request_comment($this->ProjectId, $this->PullRequest, "This build experienced failing tests.", $url); pdo_query("UPDATE build SET notified='1' WHERE id=" . qnum($idToNotify)); } } }
private function NotifyPullRequest($message, $url) { // Figure out if we should notify this build or its parent. $idToNotify = $this->Id; if ($this->ParentId > 0) { $idToNotify = $this->ParentId; } // Return early if this build already posted a comment on this PR. $notified = true; $row = pdo_single_row_query('SELECT notified FROM build WHERE id=' . qnum($idToNotify)); if ($row && array_key_exists('notified', $row)) { $notified = $row['notified']; } if ($notified) { return; } // Mention which SubProject caused this error (if any). if ($this->GetSubProjectName()) { $message .= " during {$this->SubProjectName}"; } $message .= '.'; // Post the PR comment & mark this build as 'notified'. post_pull_request_comment($this->ProjectId, $this->PullRequest, $message, $url); pdo_query("UPDATE build SET notified='1' WHERE id=" . qnum($idToNotify)); }