Skip to content
Snippets Groups Projects
Commit b52c30cd authored by Lidia Matei's avatar Lidia Matei Committed by Yas Naoi
Browse files

Issue #3222352 by XLD, yas: Support access tokens for GitHub operations

parent b899f653
No related branches found
No related tags found
No related merge requests found
......@@ -19,6 +19,32 @@ use Drupal\field\Entity\FieldStorageConfig;
use Drupal\views\ViewExecutable;
use Drupal\cloud\Entity\CloudLaunchTemplateInterface;
/**
* Polyfill for PHP 4-7, safe to use with PHP 8.
*/
if (!function_exists('str_contains')) {
/**
* Polyfill for str_contains().
*
* @param string $haystack
* The String to be checked.
* @param string $needle
* The String that is searched for.
*
* @return bool
* Whether or not the string contains the needle.
*
* When the project is moved to support PHP ^8,
* we can refactor the below into native str_contains().
* @see https://www.php.net/manual/en/function.str-contains.php
*/
function str_contains(string $haystack, string $needle): bool {
return empty($needle) || mb_strpos($haystack, $needle) !== FALSE;
}
}
/**
* Implements hook_help().
*/
......
......@@ -16,6 +16,12 @@ settings:
-
value: git
label: Git
-
value: github
label: GitHub
-
value: gitlab
label: GitLab
-
value: yml
label: YAML
......
......@@ -3233,3 +3233,13 @@ function k8s_update_8330(): void {
// Clear cache.
drupal_flush_all_caches();
}
/**
* Update Storage for K8s Launch Template Source Type field.
*/
function k8s_update_8331(): void {
$files = [
'field.storage.cloud_server_template.field_source_type.yml',
];
\Drupal::service('cloud')->updateYmlDefinitions($files, 'k8s');
}
This diff is collapsed.
......@@ -54,7 +54,7 @@ class YamlUrlConstraintValidator extends ConstraintValidator implements Containe
$detail = $entity->get('field_detail')->value;
$source_type = $entity->get('field_source_type')->value;
if ($source_type === 'git') {
if (str_contains($source_type, 'git')) {
if (empty($yaml_url)) {
$this->context
->buildViolation($constraint->requiredGitUrl)
......
......@@ -266,7 +266,7 @@ class K8sCloudLaunchTemplatePlugin extends CloudPluginBase implements CloudLaunc
$this->k8sService->setCloudContext($cloud_server_template->getCloudContext());
if ($source_type === 'git') {
if (str_contains($source_type, 'git')) {
$this->launchByGitYamlFiles($cloud_server_template, $form_state, $launch_uid);
return $route;
}
......@@ -386,6 +386,7 @@ class K8sCloudLaunchTemplatePlugin extends CloudPluginBase implements CloudLaunc
$form['cloud_context']['widget'][0]['value']['#ajax'] = [
'callback' => 'k8s_ajax_callback_get_fields',
];
unset(
$form['cloud_context']['widget'][0]['value']['#size'],
$form['cloud_context']['widget'][0]['value']['#description']
......@@ -418,12 +419,12 @@ class K8sCloudLaunchTemplatePlugin extends CloudPluginBase implements CloudLaunc
];
$git_available = $this->k8sService->isGitCommandAvailable();
if (!$git_available && $source_type === 'git') {
if (!$git_available && str_contains($source_type, 'git')) {
$this->messenger->addError(t('A git command could not be found on the server. Please install the git command and try again.'));
$this->handleError($form, $fieldsets_def);
return;
}
if ($source_type === 'git') {
if (str_contains($source_type, 'git')) {
$git_url_value = $entity->get('field_yaml_url')->getValue();
$git_url = $git_url_value[0]['uri'];
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment