public function pull_request($payload) { $headLabel = $payload->pull_request->head->label; $labelComponents = explode(':', $headLabel); $jobNumber = trim($labelComponents[1]); // Try to extract job number from head repository label if (preg_match('/^[0-9]{3,}$/', $labelComponents[1])) { $workItem = new WorkItem(); // We have what looks like a workitem number, see if it exists // and if it does, we set job to completed and post comment to // journal if ($workItem->idExists($jobNumber) && $payload->pull_request->state == 'closed') { $workItem->loadById($jobNumber); $pullRequestNumber = $payload->pull_request->number; $pullRequestURL = $payload->pull_request->html_url; $pullRequestBase = $payload->pull_request->base->label; $pullRequestStatus = $payload->pull_request->merged == 'true' ? "closed and merged" : "closed but not merged"; $message = "#{$jobNumber} - Pull request {$pullRequestNumber}\n\n" . "({$pullRequestURL}) has been {$pullRequestStatus} into {$pullRequestBase}"; Utils::systemNotification($message); if ($payload->pull_request->merged == 'true') { $journal_message = "Job #" . $jobNumber . ' has been automatically set to *Merged*'; Utils::systemNotification($journal_message); $workItem->setStatus('Completed'); $workItem->addFeesToCompletedJob(true); $workItem->save(); } } } }
function autoPassSuggestedJobs() { $con = mysql_connect(DB_SERVER, DB_USER, DB_PASSWORD); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db(DB_NAME, $con); $sql = "SELECT id FROM `" . WORKLIST . "` WHERE status IN ( 'Suggestion', 'Bidding') AND DATEDIFF(now() , status_changed) > 30"; $result = mysql_query($sql); $delay = 0; if (mysql_num_rows($result) > 1) { $delay = 5; } while ($row = mysql_fetch_assoc($result)) { $status = 'Pass'; $workitem = new WorkItem($row['id']); $prev_status = $workitem->getStatus(); // change status of the workitem to PASS. $workitem->setStatus($status); if ($workitem->save()) { $recipients = array('creator'); $emails = array(); $data = array('prev_status' => $prev_status); if ($prev_status == 'Bidding') { $recipients[] = 'usersWithBids'; $emails = preg_split('/[\\s]+/', ADMINS_EMAILS); } //notify Notification::workitemNotify(array('type' => 'auto-pass', 'workitem' => $workitem, 'recipients' => $recipients, 'emails' => $emails), $data); $journal_message = "\\\\#" . $workitem->getId() . " updated by @Otto. Status set to " . $status; Utils::systemNotification(stripslashes($journal_message)); } else { error_log("Otto failed to update the status of workitem #" . $workitem->getId() . " to " . $status); } sleep($delay); } mysql_free_result($result); mysql_close($con); }
public function updateSandboxUrl($id) { $this->view = null; try { $workitem = new WorkItem($id); $user = User::find(Session::uid()); if ($workitem->getMechanicId() != $user->getId() && !$workitem->getIsRelRunner() || $workitem->getStatus() == 'Done') { throw new Exception('Action not allowed'); } $url = trim($_POST['url']); $notes = trim($_POST['notes']) ? trim($_POST['notes']) : null; $workitem->setSandbox($url); $workitem->save(); if ($notes) { //add review notes $fee_amount = 0.0; $fee_desc = 'Review Notes: ' . $notes; $mechanic_id = $workitem->getMechanicId(); $itemid = $workitem->getId(); $is_expense = 1; $fee_category = ''; Fee::add($itemid, $fee_amount, $fee_category, $fee_desc, $mechanic_id, $is_expense); } $journal_message = '\\#' . $workitem->getId() . ' updated by @' . $user->getNickname() . " Branch URL: {$url}"; Utils::systemNotification($journal_message); echo json_encode(array('success' => false, 'message' => $journal_message)); } catch (Exception $e) { echo json_encode(array('success' => false, 'message' => $e->getMessage())); } }