public function push($payload)
 {
     $config = $this->_getUserConfig($payload['repository']['full_name'] . '/' . $payload['commits'][0]['id']);
     $ports = array();
     foreach ($payload['commits'] as $commit) {
         foreach ($commit['added'] as $file) {
             $port = substr($file, 0, strpos($file, '/', strpos($file, '/') + 1));
             if (preg_match('/^([a-zA-Z0-9_+.-]+)\\/([a-zA-Z0-9_+.-]+)$/', $port) == 1 && strlen($port) < 100) {
                 $ports[] = $port;
             }
         }
         foreach ($commit['modified'] as $file) {
             $port = substr($file, 0, strpos($file, '/', strpos($file, '/') + 1));
             if (preg_match('/^([a-zA-Z0-9_+.-]+)\\/([a-zA-Z0-9_+.-]+)$/', $port) == 1 && strlen($port) < 100) {
                 $ports[] = $port;
             }
         }
     }
     $data = array('commit' => array('id' => $payload['head_commit']['id'], 'url' => $payload['head_commit']['url'], 'message' => $payload['head_commit']['message'], 'time' => $payload['head_commit']['timestamp']), 'committer' => array('name' => $payload['head_commit']['committer']['name'], 'email' => $payload['head_commit']['committer']['email']), 'repository' => array('url' => $payload['repository']['url']));
     $ports = array_unique($ports);
     $jobgroupname = sprintf('github:%s:%s', $payload['repository']['owner']['name'], $payload['repository']['name']);
     $jobgroup = new Jobgroup($jobgroupname);
     $countjobs = $jobgroup->countJobs();
     $jails = new Jails();
     foreach ($config['jails'] as $jail) {
         if (!$jails->exists($jail)) {
             continue;
         }
         $queue = new Queue('preparequeue', $jail);
         foreach ($ports as $port) {
             $data['port'] = $port;
             if ($queue->createJob($data, $jobgroup) !== true) {
                 return false;
             }
         }
     }
     if ($jobgroup->countJobs() > $countjobs) {
         $args = array('jobgroup' => $jobgroup->getJobgroupId(), 'repository' => $data['repository']['url'], 'commit' => $data['commit']['id'], 'created' => time());
         \Resque::enqueue('default', '\\Redports\\Master\\Task\\TaskPreparePortstree', $args);
     }
     return true;
 }
Example #2
0
    $job = new Job($jobid);
    if ($job === false) {
        textResponse(204);
    }
    $machine = new Machine(Session::getMachineId());
    if (!$machine->hasJob($job->getJobId())) {
        textResponse(403, 'Job not assigned to you');
    }
    $job->unset('machine');
    $job->set('buildstatus', $_POST['buildstatus']);
    $job->set('buildreason', $_POST['buildreason']);
    $job->moveToQueue('archivequeue');
    jsonResponse(200, $job->getJobData());
})->conditions(array('jobid' => '[0-9]'));
/* Jobgroup - List details of jobgroup */
$app->get('/group/:groupid/', 'isAllowed', function ($groupid) use($app) {
    $jobgroup = new Jobgroup($groupid);
    if (!$jobgroup->exists()) {
        textResponse(404, 'Jobgroup not found');
    }
    jsonResponse(200, $jobgroup->getGroupInfo());
});
/* 404 - not found */
$app->notFound(function () use($app) {
    textResponse(404, 'Not found');
});
/* 500 - internal server error */
$app->error(function (\Exception $e) use($app) {
    textResponse(500, 'Internal Server Error');
});
$app->run();