Commit b40f27b1 authored by drumm's avatar drumm
Browse files

Issue #3266212 by drumm: Use GitLab API call to list tags/branches for creating releases

parent 3a9a7f3d
......@@ -954,14 +954,14 @@ function drush_drupalorg_release_hashes($project_argument, $version) {
file_prepare_directory($directory, FILE_CREATE_DIRECTORY);
// Generate & save hashes for git clone.
if (empty($node->versioncontrol_release['label']['name'])) {
if (empty($node->field_release_vcs_label[LANGUAGE_NONE][0]['value'])) {
watchdog('drupalorg_hashes', 'Label missing for !release', [
'!release' => l($node->title, 'node/' . $node->nid),
], WATCHDOG_NOTICE);
}
else {
try {
if (!drush_shell_cd_and_exec($workspace, 'git clone --depth 1 --branch %s %s clone', $node->versioncontrol_release['label']['name'], variable_get('git_base_url', 'https://git.drupalcode.org/project/') . $wrapper->field_release_project->value()->versioncontrol_project['repo']->name . '.git')) {
if (!drush_shell_cd_and_exec($workspace, 'git clone --depth 1 --branch %s %s clone', $node->field_release_vcs_label[LANGUAGE_NONE][0]['value'], variable_get('git_base_url', 'https://git.drupalcode.org/project/') . $wrapper->field_release_project->value()->versioncontrol_project['repo']->name . '.git')) {
throw new Exception(t('Could clone !release archive: <pre>@output</pre>', [
'!release' => l($node->title, 'node/' . $node->nid),
'@output' => implode("\n", drush_shell_exec_output()),
......
......@@ -804,13 +804,6 @@ function drupalorg_schema() {
'not null' => TRUE,
'default' => '',
],
'versioncontrol_label_id' => [
'description' => 'Foreign key (referring to {versioncontrol_labels}.label_id) for the reference.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
],
],
'primary key' => ['job_id'],
'indexes' => [
......@@ -6864,3 +6857,10 @@ function drupalorg_update_7156() {
}
}
}
/**
* Drop {drupalorg_packaging_job}.versioncontrol_label_id column.
*/
function drupalorg_update_7157() {
db_drop_field('drupalorg_packaging_job', 'versioncontrol_label_id');
}
......@@ -1931,13 +1931,13 @@ function drupalorg_issue_fork_block_form(array $form, array $form_state, EntityD
],
],
];
if (($release = pift_ci_find_dynamic_release($node_wrapper->raw())) && !empty($release->versioncontrol_release['label']['name'])) {
if (($release = pift_ci_find_dynamic_release($node_wrapper->raw())) && !empty($release->field_release_vcs_label[LANGUAGE_NONE][0]['value'])) {
$default = $node_wrapper->getIdentifier() . '-' . preg_replace('/[^0-9a-z-.]/', '', drupal_strtolower(implode('-', array_slice(explode(' ', $node_wrapper->title->value(), 4), 0, 3))));
$form['branch'] = [
'#prefix' => '<div class="create-new-branch">',
'#type' => 'checkbox',
'#title' => t('with new branch from <code>@label</code>', [
'@label' => $release->versioncontrol_release['label']['name'],
'@label' => $release->field_release_vcs_label[LANGUAGE_NONE][0]['value'],
]),
'#default_value' => TRUE,
];
......@@ -5627,9 +5627,9 @@ function drupalorg_preprocess_field(&$v) {
$text = $release_wrapper->field_release_build_type->value() === 'dynamic' ? t('Git branch') : t('Git tag');
$v['items'][0]['#prefix'] = '<img src="' . url(drupal_get_path('module', 'drupalorg') . '/images/vcs_label/' . $release_wrapper->field_release_build_type->value() . '.svg') . '" alt="' . $text . '" title="' . $text . '" class="icon-inline gray"> ';
// Link to Git repository.
if (isset($v['element']['#object']->versioncontrol_release['label'])) {
if ($vcs_label = $release_wrapper->field_release_vcs_label->value()) {
$repository = versioncontrol_repository_load($release_wrapper->field_release_project->value()->versioncontrol_project['repo_id']);
$v['items'][0]['#markup'] = l($v['items'][0]['#markup'], $repository->getUrlHandler()->getRepositoryViewUrl((object) $v['element']['#object']->versioncontrol_release['label']), [
$v['items'][0]['#markup'] = l($v['items'][0]['#markup'], $repository->getUrlHandler()->getRepositoryViewUrl((object) ['name' => $vcs_label]), [
'external' => TRUE,
]);
}
......@@ -10043,7 +10043,6 @@ function drupalorg_project_reserved_names() {
* creates a packaging job from a thing.
*/
function drupalorg_create_packaging_job($release_node) {
// Gather all the data from the database to create the job from the release
$is_security = 0;
if (project_release_is_security_update($release_node)) {
......@@ -10053,21 +10052,17 @@ function drupalorg_create_packaging_job($release_node) {
$release_wrapper = entity_metadata_wrapper('node', $release_node);
$project_nid = $release_wrapper->field_release_project->nid->value();
$project_machine_name = $release_wrapper->field_release_project->field_project_machine_name->value();
$project_git_url = variable_get('git_base_url', 'https://git.drupalcode.org/project/') . $release_wrapper->field_release_project->value()->versioncontrol_project['repo']->name . '.git';
$repository = versioncontrol_project_repository_load($project_nid);
$project_git_url = variable_get('git_base_url', 'https://git.drupalcode.org/project/') . $repository->name . '.git';
$last_packaged_commit_id = $release_wrapper->field_packaged_git_sha1->value();
// Load the versioncontrol tag data from the db as it might not be on the node, as well as the new_sha1 for this release.
$versionconrol_release_data = db_query_range('SELECT vcl.label_id, vcl.name, vcl.type, vged.new_sha1 FROM {versioncontrol_labels} vcl INNER JOIN {versioncontrol_release_labels} vcrl ON vcl.label_id = vcrl.label_id INNER JOIN {versioncontrol_git_event_data} vged ON vged.label_id = vcl.label_id WHERE vcrl.release_nid = (:release_nid) ORDER BY vged.elid desc', 0, 1, [':release_nid' => $release_node->nid])->fetchAssoc();
$reference = $versionconrol_release_data['name'];
$versioncontrol_label_id = $versionconrol_release_data['label_id'];
$release_build_type = $versionconrol_release_data['type'] == VERSIONCONTROL_LABEL_BRANCH ? 'branch' : 'tag';
$release_build_type = $release_wrapper->field_release_build_type->value() === 'dynamic' ? 'branch' : 'tag';
$reference = $release_wrapper->field_release_vcs_label->value();
$commit_id = versioncontrol_gitlab_get_client()->api('repositories')->commit($repository->gitlab_project_id, $reference)['id'];
// If this is a new, tagged core release, attempt to derive the
// last_packaged_commit_id from the dev release and pass that on.
if ($release_build_type == 'tag' && $project_nid == '3060' && $release_wrapper->field_release_category->value() == 'current') {
$dev_branch_version = project_release_get_branch($reference) . "x";
$dev_branch_version = project_release_get_branch($release_wrapper->field_release_vcs_label->value()) . 'x';
$dev_release_node = project_release_get_release_for_vcs_label($project_nid, $dev_branch_version);
$dev_release_wrapper = entity_metadata_wrapper('node', $dev_release_node);
$last_packaged_commit_id = $dev_release_wrapper->field_packaged_git_sha1->value();
......@@ -10095,8 +10090,8 @@ function drupalorg_create_packaging_job($release_node) {
// Is actually being packaged.
if (isset($result['drupalorg_packaging_job'])) {
foreach (entity_load('drupalorg_packaging_job', array_keys($result['drupalorg_packaging_job'])) as $job) {
$job->commit_id = $versionconrol_release_data['new_sha1'];
if ($job->status == DRUPALORG_JOB_STATUS_STUCK ) {
$job->commit_id = $commit_id;
if ($job->status == DRUPALORG_JOB_STATUS_STUCK) {
// set it back to 'queued' if it was previously stuck and let it try again.
$job->status = DRUPALORG_JOB_STATUS_QUEUE;
$job->save();
......@@ -10115,14 +10110,12 @@ function drupalorg_create_packaging_job($release_node) {
'project_git_url' => $project_git_url,
'reference' => $reference,
'release_build_type' => $release_build_type,
'commit_id' => $versionconrol_release_data['new_sha1'],
'commit_id' => $commit_id,
'last_commit_id' => $last_packaged_commit_id,
'versioncontrol_label_id' => $versioncontrol_label_id,
]);
$job->save();
$job->queueJob();
}
}
/**
......
......@@ -131,7 +131,7 @@ class DrupalorgIssueFork extends Entity {
if ($project_info['import_status'] === 'finished') {
if ($branch !== NULL) {
try {
versioncontrol_gitlab_get_client($git_username)->api('repositories')->createBranch($this->gitlab_project_id, $branch, $this->getDevRelease()->versioncontrol_release['label']['name']);
versioncontrol_gitlab_get_client($git_username)->api('repositories')->createBranch($this->gitlab_project_id, $branch, $this->getDevRelease()->field_release_vcs_label[LANGUAGE_NONE][0]['value']);
}
catch (Exception $e) {
$uri = $this->uri();
......@@ -1005,7 +1005,7 @@ function drupalorg_issue_fork_open_merge_request_form_submit(array $form, array
$gitlab_api = versioncontrol_gitlab_get_client($GLOBALS['user']->git_username)->api('merge_requests');
$merge_request = $gitlab_api->create($issue_fork->gitlab_project_id, NULL, NULL, NULL, [
'source_branch' => $branch,
'target_branch' => $issue_fork->getDevRelease()->versioncontrol_release['label']['name'],
'target_branch' => $issue_fork->getDevRelease()->field_release_vcs_label[LANGUAGE_NONE][0]['value'],
'title' => 'Issue #' . $issue_wrapper->getIdentifier() . ': ' . $issue_wrapper->label(),
'target_project_id' => versioncontrol_project_repository_load($issue_wrapper->field_project->raw())->gitlab_project_id,
'squash' => TRUE,
......
......@@ -80,11 +80,6 @@ class DrupalorgPackagingJob extends Entity {
*/
public $last_commit_id = '';
/**
* @var int Related versioncontrol label key.
*/
public $versioncontrol_label_id;
/**
* @var \GuzzleHttp\Client
*/
......
......@@ -151,38 +151,6 @@ class DrupalorgProjectPackageRelease implements ProjectReleasePackagerInterface
return TRUE;
}
protected function isAlreadyPackaged() {
// Look for a commit on the branch with a parent commit of the currently
// packaged release.
$result = (new EntityFieldQuery())->entityCondition('entity_type', 'versioncontrol_operation')
->propertyCondition('repo_id', $this->project_node->versioncontrol_project['repo_id'])
->propertyCondition('label_id', $this->release_node->versioncontrol_release['label']['label_id'])
->propertyCondition('parent_commit', $this->release_node_wrapper->field_packaged_git_sha1->value())
->count()->execute();
if ($result == 0) {
// Load the release’s previously-packaged commit.
$result = (new EntityFieldQuery())->entityCondition('entity_type', 'versioncontrol_operation')
->propertyCondition('repo_id', $this->project_node->versioncontrol_project['repo_id'])
->propertyCondition('revision', $this->release_node_wrapper->field_packaged_git_sha1->value())
->execute();
if (isset($result['versioncontrol_operation']) && ($packaged_commit = entity_load_single('versioncontrol_operation', array_keys($result['versioncontrol_operation'])[0]))) {
// Look for commits on the branch with a commit date after the
// currently packaged release.
$result = (new EntityFieldQuery())->entityCondition('entity_type', 'versioncontrol_operation')
->propertyCondition('repo_id', $this->project_node->versioncontrol_project['repo_id'])
->propertyCondition('label_id', $this->release_node->versioncontrol_release['label']['label_id'])
->propertyCondition('committer_date', $packaged_commit->committer_date, '>')
->count()->execute();
if ($result == 0) {
// Neither was found.
drush_log(dt('Commit @field_packaged_git_sha1 already packaged.', ['@field_packaged_git_sha1' => $this->release_node_wrapper->field_packaged_git_sha1->value()]), 'notice');
return TRUE;
}
}
}
return FALSE;
}
/**
* @param $files
*
......@@ -199,12 +167,13 @@ class DrupalorgProjectPackageRelease implements ProjectReleasePackagerInterface
// Check to make sure we're not redundantly packaging a commit hash
// That we have already packaged.
if ($this->release_node_wrapper->field_release_build_type->value() === 'dynamic' && $this->build_type == 'rebuild' && $this->release_node_wrapper->field_packaged_git_sha1->value()) {
if ($this->isAlreadyPackaged()) {
$head_commit = versioncontrol_gitlab_get_client()->api('repositories')->commit(versioncontrol_project_repository_load($this->project_node->nid)->gitlab_project_id, $this->release_node_wrapper->field_release_vcs_label->value())['id'];
if ($head_commit['id'] === $this->release_node_wrapper->field_packaged_git_sha1->value()) {
drush_log(dt('Commit @field_packaged_git_sha1 already packaged.', ['@field_packaged_git_sha1' => $this->release_node_wrapper->field_packaged_git_sha1->value()]), 'notice');
return 'no-op';
}
}
if (empty($this->git_url)) {
throw new Exception(format_string('%project_title does not have a VCS repository defined', ['%project_title' => $this->project_node->title]));
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment