function project_synchronize_repositories($project)
{
    git_log('Synchronizing project ' . $project->short_name);
    $releases = project_releases($project);
    if (empty($releases)) {
        git_log('Project has no releases, nothing to do.');
        return;
    }
    // Create a temporary directory.
    $temporary_dir = _create_temporary_directory();
    chdir($temporary_dir);
    // Checkout the repository.
    $repository = $project->repository;
    if (!file_exists($repository)) {
        mkdir('repo');
        chdir('repo');
        git_invoke('git init');
        git_invoke('git remote add origin ' . escapeshellarg($repository));
    } else {
        git_invoke('git clone ' . escapeshellarg($repository) . ' repo');
        chdir('repo');
    }
    $new_releases = FALSE;
    $tags = git_get_tags('.git');
    foreach ($releases as $release) {
        if (isset($tags[$release['version']]) || empty($release['download_link'])) {
            continue;
        }
        $new_releases |= git_import_release($project, $release, $release['branch']);
    }
    if ($new_releases) {
        git_log('Pushing releases for project ' . $project->short_name);
        if (!file_exists($repository)) {
            mkdir($repository, 0777, TRUE);
            git_invoke('git init', FALSE, $repository);
        }
        // Push the resulting repository.
        git_invoke('git push --all origin');
        git_invoke('git push --tags origin');
        // Update the HEAD branch of the repository.
        git_update_head($project, $releases);
    }
    git_invoke('rm -Rf ' . escapeshellarg($temporary_dir));
}
Ejemplo n.º 2
0
function convert_project_tags($project, $destination_dir, $match, $trans_map)
{
    $all_tags = $tags = $new_tags = $nonconforming_tags = array();
    try {
        $all_tags = git_invoke('git tag -l', FALSE, $destination_dir);
        $all_tags = array_filter(explode("\n", $all_tags));
        // array-ify & remove empties
    } catch (Exception $e) {
        git_log("Tag list retrieval failed with error '{$e}'", 'WARN', $project);
        return;
    }
    // Convert only tags that match naming conventions
    $tags = preg_grep($match, $all_tags);
    if ($nonconforming_tags = array_diff($all_tags, $tags)) {
        git_log("Project has the following nonconforming tags: " . implode(', ', $nonconforming_tags), 'NORMAL', $project);
    }
    if (empty($tags)) {
        // No conforming tags to work with, bail out.
        $string = empty($all_tags) ? "Project has no tags at all." : "Project has no conforming tags.";
        git_log($string, 'NORMAL', $project);
        return;
    }
    // Everything needs the initial DRUPAL- stripped out.
    $trans_map = array_merge(array('/^DRUPAL-/' => ''), $trans_map);
    $new_tags = preg_replace(array_keys($trans_map), array_values($trans_map), $tags);
    foreach (array_combine($tags, $new_tags) as $old_tag => $new_tag) {
        // Lowercase all remaining characters (should be just ALPHA/BETA/RC, etc.)
        $new_tag = strtolower($new_tag);
        // Add the new tag.
        try {
            git_invoke("git tag {$new_tag} {$old_tag}", FALSE, $destination_dir);
            git_log("Created new tag '{$new_tag}' from old tag '{$old_tag}'", 'INFO', $project);
        } catch (Exception $e) {
            git_log("Creation of new tag '{$new_tag}' from old tag '{$old_tag}' failed with message {$e}", 'WARN', $project);
        }
        // Delete the old tag.
        try {
            git_invoke("git tag -d {$old_tag}", FALSE, $destination_dir);
            git_log("Deleted old tag '{$old_tag}'", 'INFO', $project);
        } catch (Exception $e) {
            git_log("Deletion of old tag '{$old_tag}' in project '{$project}' failed with message {$e}", 'WARN', $project);
        }
    }
}