Exemplo n.º 1
0
function main($post_data)
{
    $db = new Database();
    if (!$db->connect()) {
        exit_with_error('DatabaseConnectionFailure');
    }
    $report = json_decode($post_data, true);
    verify_slave($db, $report);
    $commits = array_get($report, 'commits', array());
    foreach ($commits as $commit_info) {
        if (!array_key_exists('repository', $commit_info)) {
            exit_with_error('MissingRepositoryName', array('commit' => $commit_info));
        }
        if (!array_key_exists('revision', $commit_info)) {
            exit_with_error('MissingRevision', array('commit' => $commit_info));
        }
        require_format('Revision', $commit_info['revision'], '/^[A-Za-z0-9 \\.]+$/');
        if (array_key_exists('author', $commit_info) && !is_array($commit_info['author'])) {
            exit_with_error('InvalidAuthorFormat', array('commit' => $commit_info));
        }
    }
    $db->begin_transaction();
    foreach ($commits as $commit_info) {
        $repository_id = $db->select_or_insert_row('repositories', 'repository', array('name' => $commit_info['repository']));
        if (!$repository_id) {
            $db->rollback_transaction();
            exit_with_error('FailedToInsertRepository', array('commit' => $commit_info));
        }
        $author = array_get($commit_info, 'author');
        $committer_id = NULL;
        if ($author) {
            $account = array_get($author, 'account');
            $committer_query = array('repository' => $repository_id, 'account' => $account);
            $committer_data = $committer_query;
            $name = array_get($author, 'name');
            if ($name) {
                $committer_data['name'] = $name;
            }
            $committer_id = $db->update_or_insert_row('committers', 'committer', $committer_query, $committer_data);
            if (!$committer_id) {
                $db->rollback_transaction();
                exit_with_error('FailedToInsertCommitter', array('committer' => $committer_data));
            }
        }
        $parent_revision = array_get($commit_info, 'parent');
        $parent_id = NULL;
        if ($parent_revision) {
            $parent_commit = $db->select_first_row('commits', 'commit', array('repository' => $repository_id, 'revision' => $parent_revision));
            if (!$parent_commit) {
                $db->rollback_transaction();
                exit_with_error('FailedToFindParentCommit', array('commit' => $commit_info));
            }
            $parent_id = $parent_commit['commit_id'];
        }
        $data = array('repository' => $repository_id, 'revision' => $commit_info['revision'], 'parent' => $parent_id, 'order' => array_get($commit_info, 'order'), 'time' => array_get($commit_info, 'time'), 'committer' => $committer_id, 'message' => array_get($commit_info, 'message'), 'reported' => true);
        $db->update_or_insert_row('commits', 'commit', array('repository' => $repository_id, 'revision' => $data['revision']), $data);
    }
    $db->commit_transaction();
    exit_with_success();
}
Exemplo n.º 2
0
function main()
{
    $data = ensure_privileged_api_data_and_token();
    $analysis_task_id = array_get($data, 'task');
    $bug_tracker_id = array_get($data, 'bugTracker');
    $bug_number = array_get($data, 'number');
    $bug_id = array_get($data, 'bugToDelete');
    $db = connect();
    $db->begin_transaction();
    if ($bug_id) {
        require_format('BugToDelete', $bug_id, '/^\\d+$/');
        $count = $db->query_and_get_affected_rows("DELETE FROM bugs WHERE bug_id = \$1", array($bug_id));
        if ($count != 1) {
            $db->rollback_transaction();
            exit_with_error('UnexpectedNumberOfAffectedRows', array('affectedRows' => $count));
        }
    } else {
        require_format('AnalysisTask', $analysis_task_id, '/^\\d+$/');
        require_format('BugTracker', $bug_tracker_id, '/^\\d+$/');
        require_format('BugNumber', $bug_number, '/^\\d+$/');
        $bug_id = $db->insert_row('bugs', 'bug', array('task' => $analysis_task_id, 'tracker' => $bug_tracker_id, 'number' => $bug_number));
    }
    $db->commit_transaction();
    exit_with_success(array('bugId' => $bug_id));
}
Exemplo n.º 3
0
function require_existence_of($array, $list_of_arguments, $prefix = '')
{
    if ($prefix) {
        $prefix .= '_';
    }
    foreach ($list_of_arguments as $key => $pattern) {
        $name = camel_case_words_separated_by_underscore($prefix . $key);
        if (!array_key_exists($key, $array)) {
            exit_with_error($name . 'NotSpecified');
        }
        require_format($name, $array[$key], $pattern);
    }
}
Exemplo n.º 4
0
function main()
{
    $data = ensure_privileged_api_data_and_token();
    $analysis_task_id = array_get($data, 'task');
    $repository_id = array_get($data, 'repository');
    $revision = array_get($data, 'revision');
    $kind = array_get($data, 'kind');
    $commit_id_to_diassociate = array_get($data, 'commit');
    $db = connect();
    $db->begin_transaction();
    require_format('AnalysisTask', $analysis_task_id, '/^\\d+$/');
    if ($commit_id_to_diassociate) {
        require_format('Commit', $commit_id_to_diassociate, '/^\\d*$/');
        $count = $db->query_and_get_affected_rows("DELETE FROM task_commits WHERE taskcommit_task = \$1 AND taskcommit_commit = \$2", array($analysis_task_id, $commit_id_to_diassociate));
        if ($count != 1) {
            $db->rollback_transaction();
            exit_with_error('UnexpectedNumberOfAffectedRows', array('affectedRows' => $count));
        }
    } else {
        require_format('Repository', $repository_id, '/^\\d+$/');
        require_format('Kind', $kind, '/^(cause|fix)$/');
        $commit_info = array('repository' => $repository_id, 'revision' => $revision);
        $commit_rows = $db->query_and_fetch_all('SELECT commit_id FROM commits WHERE commit_repository = $1 AND commit_revision LIKE $2 LIMIT 2', array($repository_id, '%' . Database::escape_for_like($revision) . '%'));
        if (count($commit_rows) > 1) {
            $db->rollback_transaction();
            exit_with_error('AmbiguousRevision', $commit_info);
        } else {
            if (!$commit_rows) {
                $db->rollback_transaction();
                exit_with_error('CommitNotFound', $commit_info);
            }
        }
        $commit_id = $commit_rows[0]['commit_id'];
        $association = array('task' => $analysis_task_id, 'commit' => $commit_id, 'is_fix' => Database::to_database_boolean($kind == 'fix'));
        $commit_id = $db->update_or_insert_row('task_commits', 'taskcommit', array('task' => $analysis_task_id, 'commit' => $commit_id), $association, 'commit');
        if (!$commit_id) {
            $db->rollback_transaction();
            exit_with_error('FailedToAssociateCommit', $association);
        }
    }
    $db->commit_transaction();
    exit_with_success();
}
Exemplo n.º 5
0
function main()
{
    require_existence_of($_POST, array('master' => '/[A-Za-z0-9\\.]+/', 'builder_name' => '/^[A-Za-z0-9 \\(\\)\\-_]+$/', 'build_number' => '/^[0-9]+?$/', 'build_slave' => '/^[A-Za-z0-9\\-_]+$/', 'revisions' => '/^.+?$/', 'start_time' => '/^[0-9]+(\\.[0-9]+)?$/', 'end_time' => '/^[0-9]+(\\.[0-9]+)?$/'));
    $master = $_POST['master'];
    $builder_name = $_POST['builder_name'];
    $build_number = intval($_POST['build_number']);
    $start_time = float_to_time($_POST['start_time']);
    $end_time = float_to_time($_POST['end_time']);
    $revisions = json_decode(str_replace('\\', '', $_POST['revisions']), TRUE);
    foreach ($revisions as $repository_name => $revision_data) {
        require_format('repository_name', $repository_name, '/^\\w+$/');
        require_existence_of($revision_data, array('revision' => '/^[a-z0-9]+$/', 'timestamp' => '/^[a-z0-9\\-\\.:TZ]+$/'), 'revision');
    }
    if (!array_key_exists('file', $_FILES) or !array_key_exists('tmp_name', $_FILES['file']) or count($_FILES['file']['tmp_name']) <= 0) {
        exit_with_error('ResultsJSONNotIncluded');
    }
    $json_path = $_FILES['file']['tmp_name'];
    $db = connect();
    store_results($db, $master, $builder_name, $build_number, $start_time, $end_time, $revisions, $json_path);
    echo_success();
}
Exemplo n.º 6
0
function main()
{
    $data = ensure_privileged_api_data_and_token();
    $analysis_task_id = array_get($data, 'task');
    $bug_tracker_id = array_get($data, 'bugTracker');
    $bug_number = array_get($data, 'number');
    $bug_id = array_get($data, 'bugToDelete');
    $should_delete = array_get($data, 'shouldDelete');
    $db = connect();
    $db->begin_transaction();
    if ($bug_id) {
        // V2 compatibility
        require_format('BugToDelete', $bug_id, '/^\\d+$/');
        $count = $db->query_and_get_affected_rows("DELETE FROM bugs WHERE bug_id = \$1", array($bug_id));
        if ($count != 1) {
            $db->rollback_transaction();
            exit_with_error('UnexpectedNumberOfAffectedRows', array('affectedRows' => $count));
        }
    } else {
        require_format('AnalysisTask', $analysis_task_id, '/^\\d+$/');
        require_format('BugTracker', $bug_tracker_id, '/^\\d+$/');
        require_format('BugNumber', $bug_number, '/^\\d+$/');
        if ($should_delete) {
            // V3
            $count = $db->query_and_get_affected_rows("DELETE FROM bugs WHERE bug_task = \$1 AND bug_tracker = \$2 AND bug_number = \$3", array($analysis_task_id, $bug_tracker_id, $bug_number));
            if ($count < 1) {
                // FIXME: We should forbid duplicate bugs (same bug number on same tracker for same task)
                $db->rollback_transaction();
                exit_with_error('UnexpectedNumberOfAffectedRows', array('affectedRows' => $count));
            }
        } else {
            $bug_id = $db->insert_row('bugs', 'bug', array('task' => $analysis_task_id, 'tracker' => $bug_tracker_id, 'number' => $bug_number));
        }
    }
    $db->commit_transaction();
    exit_with_success(array('bugId' => $bug_id));
}
Exemplo n.º 7
0
function recursively_add_test_results($db, $build_id, $tests, $full_name)
{
    if (!array_key_exists('expected', $tests) and !array_key_exists('actual', $tests)) {
        $prefix = $full_name ? $full_name . '/' : '';
        foreach ($tests as $name => $subtests) {
            require_format('test_name', $name, '/^[A-Za-z0-9 +_\\-\\.]+$/');
            recursively_add_test_results($db, $build_id, $subtests, $prefix . $name);
        }
        return;
    }
    require_format('expected_result', $tests['expected'], '/^[A-Za-z \\+]+$/');
    require_format('actual_result', $tests['actual'], '/^[A-Za-z \\+]+$/');
    require_format('test_time', $tests['time'], '/^\\d*$/');
    $modifiers = array_get($tests, 'modifiers');
    if ($modifiers) {
        require_format('test_modifiers', $modifiers, '/^[A-Za-z0-9 \\.\\/]+$/');
    } else {
        $modifiers = NULL;
    }
    $category = 'LayoutTest';
    // FIXME: Support other test categories.
    $test_id = $db->select_or_insert_row('tests', NULL, array('name' => $full_name), array('name' => $full_name, 'reftest_type' => json_encode(array_get($tests, 'reftest_type')), 'category' => $category));
    $db->insert_row('results', NULL, array('test' => $test_id, 'build' => $build_id, 'expected' => $tests['expected'], 'actual' => $tests['actual'], 'time' => $tests['time'], 'modifiers' => $tests['modifiers']));
}
Exemplo n.º 8
0
<?php

require_once '../include/json-shared.php';
require_once '../include/test-results.php';
$db = connect();
require_existence_of($_POST, array('master' => '/[A-Za-z0-9\\.]+/', 'builder_name' => '/^[A-Za-z0-9 \\(\\)\\-_]+$/', 'build_number' => '/^[0-9]+?$/', 'build_slave' => '/^[A-Za-z0-9\\-_]+$/', 'revisions' => '/^.+?$/', 'start_time' => '/^[0-9]+(\\.[0-9]+)?$/', 'end_time' => '/^[0-9]+(\\.[0-9]+)?$/'));
$master = $_POST['master'];
$builder_name = $_POST['builder_name'];
$build_number = intval($_POST['build_number']);
if (!array_key_exists('file', $_FILES) or !array_key_exists('tmp_name', $_FILES['file']) or count($_FILES['file']['tmp_name']) <= 0) {
    exit_with_error('ResultsJSONNotIncluded');
}
$revisions = json_decode(str_replace('\\', '', $_POST['revisions']), TRUE);
foreach ($revisions as $repository_name => $revision_data) {
    require_format('repository_name', $repository_name, '/^\\w+$/');
    require_existence_of($revision_data, array('revision' => '/^[a-z0-9]+$/', 'timestamp' => '/^[a-z0-9\\-\\.:TZ]+$/'), 'revision');
}
$test_results = fetch_and_parse_test_results_json($_FILES['file']['tmp_name']);
if (!$test_results) {
    exit_with_error('InvalidResultsJSON');
}
$start_time = float_to_time($_POST['start_time']);
$end_time = float_to_time($_POST['end_time']);
$builder_id = add_builder($db, $master, $builder_name);
if (!$builder_id) {
    exit_with_error('FailedToInsertBuilder', array('master' => $master, 'builderName' => $builder_name));
}
$build_id = add_build($db, $builder_id, $build_number);
if (!$build_id) {
    exit_with_error('FailedToInsertBuild', array('builderId' => $builder_id, 'buildNumber' => $build_number));
}