コード例 #1
0
ファイル: Project.php プロジェクト: MaitreyaBuddha/worklist
 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();
             }
         }
     }
 }
コード例 #2
0
ファイル: api.php プロジェクト: MaitreyaBuddha/worklist
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);
}
コード例 #3
0
ファイル: Job.php プロジェクト: MaitreyaBuddha/worklist
 public function add()
 {
     $this->view = null;
     if (isset($_POST['api_key'])) {
         Utils::validateAPIKey();
         $user = User::find($_POST['creator']);
         $userId = $user->getId();
     } else {
         Utils::checkLogin();
         $userId = Session::uid();
     }
     if (!$userId) {
         header('HTTP/1.1 401 Unauthorized', true, 401);
         echo json_encode(array('error' => "Invalid parameters !"));
         return;
     }
     if ($_SERVER['REQUEST_METHOD'] != 'POST') {
         $this->view = new AddJobView();
         parent::run();
         return;
     }
     $this->view = null;
     $journal_message = '';
     $workitem_added = false;
     $nick = '';
     $workitem = new WorkItem();
     Utils::initUserById($userId);
     $user = new User();
     $user->findUserById($userId);
     $nick = $user->getNickname();
     $runner_id = Project::isAllowedRunnerForProject($user->getId(), $_REQUEST['project_id']) ? $userId : '';
     $itemid = $_REQUEST['itemid'];
     $summary = $_REQUEST['summary'];
     $project_id = $_REQUEST['project_id'];
     $labels = $_REQUEST['labels'];
     $status = Project::isAllowedRunnerForProject($user->getId(), $_REQUEST['project_id']) || $user->getIs_admin() == 1 && $user->getIs_runner() ? $_REQUEST['status'] : 'Suggestion';
     $notes = $_REQUEST['notes'];
     $is_expense = $_REQUEST['is_expense'];
     $is_rewarder = $_REQUEST['is_rewarder'];
     $is_internal = $_REQUEST['is_internal'];
     $fileUpload = $_REQUEST['fileUpload'];
     $assigned_id = 0;
     if ((int) $_REQUEST['assigned']) {
         $assignedUser = User::find($_REQUEST['assigned']);
         if ($assignedUser->isInternal()) {
             $assigned_id = $assignedUser->getId();
         }
     }
     if (!empty($_POST['itemid'])) {
         $workitem->loadById($_POST['itemid']);
     } else {
         $workitem->setCreatorId($userId);
         $workitem_added = true;
     }
     $workitem->setSummary($summary);
     $labelsArr = explode(',', $labels);
     $workitem->setRunnerId($runner_id);
     $workitem->setProjectId($project_id);
     $workitem->setStatus($status);
     $workitem->setNotes($notes);
     $workitem->setWorkitemLabels($labelsArr);
     $workitem->setIs_internal($is_internal);
     $workitem->setAssigned_id($assigned_id);
     $workitem->save();
     $related = $this->getRelated($notes);
     Notification::massStatusNotify($workitem);
     if ($assigned_id) {
         $emailTemplate = 'job-assigned';
         $data = array('job_id' => $workitem->getId(), 'summary' => $workitem->getSummary(), 'assigner' => $user->getNickname(), 'assigned' => $assignedUser->getNickname());
         $senderEmail = 'Worklist - ' . $user->getNickname() . ' <*****@*****.**> ';
         Utils::sendTemplateEmail($assignedUser->getUsername(), $emailTemplate, $data, $senderEmail);
     }
     // if files were uploaded, update their workitem id
     $file = new File();
     // update images first
     if (isset($fileUpload['uploads'])) {
         foreach ($fileUpload['uploads'] as $image) {
             $file->findFileById($image);
             $file->setWorkitem($workitem->getId());
             $file->save();
         }
     }
     if (empty($_POST['itemid'])) {
         $bid_fee_itemid = $workitem->getId();
         $journal_message .= "\\\\#" . $bid_fee_itemid . ' created by @' . $nick . ' Status set to ' . $status;
         if (!empty($_POST['files'])) {
             $files = explode(',', $_POST['files']);
             foreach ($files as $file) {
                 $sql = 'UPDATE `' . FILES . '` SET `workitem` = ' . $bid_fee_itemid . ' WHERE `id` = ' . (int) $file;
                 mysql_query($sql);
             }
         }
     } else {
         $bid_fee_itemid = $itemid;
         $journal_message .= '\\#' . $bid_fee_itemid . ' updated by ' . $nick . 'Status set to ' . $status;
     }
     $journal_message .= "{$related}. ";
     // don't send any journal notifications for DRAFTS
     if (!empty($journal_message) && $status != 'Draft') {
         Utils::systemNotification(stripslashes($journal_message));
         if ($workitem_added) {
             $options = array('type' => 'workitem-add', 'workitem' => $workitem);
             $data = array('notes' => $notes, 'nick' => $nick, 'status' => $status);
             Notification::workitemNotifyHipchat($options, $data);
         }
         // workitem mentions
         $matches = array();
         if (preg_match_all('/@(\\w+)/', $workitem->getNotes(), $matches, PREG_SET_ORDER)) {
             foreach ($matches as $mention) {
                 // validate the username actually exists
                 if ($recipient = User::find($mention[1])) {
                     // exclude creator, designer, developer and followers
                     if ($recipient->getId() != $workitem->getRunnerId() && $recipient->getId() != $workitem->getMechanicId() && $recipient->getId() != $workitem->getCreatorId() && !$workitem->isUserFollowing($recipient->getId())) {
                         $emailTemplate = 'workitem-mention';
                         $data = array('job_id' => $workitem->getId(), 'summary' => $workitem->getSummary(), 'author' => $_SESSION['nickname'], 'text' => $workitem->getNotes(), 'link' => '<a href="' . WORKLIST_URL . $workitem->getId() . '">See the workitem</a>');
                         $senderEmail = 'Worklist - ' . $_SESSION['nickname'] . ' <*****@*****.**> ';
                         Utils::sendTemplateEmail($recipient->getUsername(), $emailTemplate, $data, $senderEmail);
                     }
                 }
             }
         }
     }
     // Notify Runners of new suggested task
     if ($status == 'Suggestion' && $project_id != '') {
         $options = array('type' => 'suggested', 'workitem' => $workitem, 'recipients' => array('projectRunners'));
         $data = array('notes' => $notes, 'nick' => $nick, 'status' => $status);
         Notification::workitemNotify($options, $data);
     }
     echo json_encode(array('return' => "Done!", 'workitem' => $workitem->getId()));
 }