forked from vtsykun/packeton
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow to disable cron package auto update
- Loading branch information
Showing
10 changed files
with
350 additions
and
208 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Packeton\Form\Type\Package; | ||
|
||
use Doctrine\Persistence\ManagerRegistry; | ||
use Packeton\Entity\OAuthIntegration; | ||
use Packeton\Entity\Package; | ||
use Symfony\Component\Form\AbstractType; | ||
use Symfony\Component\Form\Extension\Core\Type\CheckboxType; | ||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType; | ||
use Symfony\Component\Form\FormBuilderInterface; | ||
use Symfony\Component\OptionsResolver\OptionsResolver; | ||
|
||
class SettingsPackageType extends AbstractType | ||
{ | ||
public function __construct(private ManagerRegistry $registry) | ||
{ | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function buildForm(FormBuilderInterface $builder, array $options): void | ||
{ | ||
$builder->add('disabledUpdate', CheckboxType::class, [ | ||
'required' => false, | ||
'label' => 'Disable cron auto-updates', | ||
]); | ||
|
||
if ($options['has_active_integration']) { | ||
$builder->add('pullRequestReview', ChoiceType::class, [ | ||
'required' => false, | ||
'label' => 'Pull Request composer diff review', | ||
'choices' => [ | ||
'Use global config settings' => null, | ||
'Enable PR Review' => true, | ||
], | ||
'priority' => -10, | ||
]); | ||
} | ||
} | ||
|
||
protected function hasActiveIntegration(): bool | ||
{ | ||
return (bool) $this->registry->getRepository(OAuthIntegration::class)->findOneBy([]); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function configureOptions(OptionsResolver $resolver): void | ||
{ | ||
$resolver->setDefault('data_class', Package::class); | ||
$resolver->setDefault('has_active_integration', $this->hasActiveIntegration()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,7 @@ | |
use Packeton\Entity\User; | ||
use Packeton\Entity\Version; | ||
use Packeton\Service\SubRepositoryHelper; | ||
use Packeton\Util\PacketonUtils; | ||
|
||
/** | ||
* @author Jordi Boggiano <[email protected]> | ||
|
@@ -186,6 +187,30 @@ private function getPackageNamesForQuery($query) | |
return $names; | ||
} | ||
|
||
public function filterByJson(array $packagesIds, callable $filter): array | ||
{ | ||
if (empty($packagesIds)) { | ||
return []; | ||
} | ||
|
||
$packages = $this->getConn()->fetchAllAssociative( | ||
"SELECT p.id, p.serialized_data FROM package p WHERE p.id IN (:ids)", | ||
['ids' => $packagesIds], | ||
['ids' => ArrayParameterType::INTEGER] | ||
); | ||
|
||
$packages = PacketonUtils::buildChoices($packages, 'id', 'serialized_data'); | ||
foreach ($packagesIds as $i => $packageId) { | ||
$data = $packages[$packageId] ?? null; | ||
$data = is_string($data) ? json_decode($data, true) : null; | ||
if (false === $filter(is_array($data) ? $data : [], $packageId)) { | ||
unset($packagesIds[$i]); | ||
} | ||
} | ||
|
||
return array_values($packagesIds); | ||
} | ||
|
||
public function getStalePackages($interval = null) | ||
{ | ||
$conn = $this->getEntityManager()->getConnection(); | ||
|
@@ -605,4 +630,9 @@ public function getMetadataChanges($since, $now = null, ?bool $stability = true) | |
|
||
return $updates; | ||
} | ||
|
||
private function getConn(): Connection | ||
{ | ||
return $this->getEntityManager()->getConnection(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{% extends "layout.html.twig" %} | ||
|
||
{% block title %} | ||
{{ 'packages.settings_title'|trans({ '%name%': package.name }) }} | ||
{% endblock %} | ||
|
||
{% block stylesheets %} | ||
<link rel="stylesheet" href="{{ asset('packeton/css/forms.css') }}" /> | ||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/select2.min.css"> | ||
{% endblock %} | ||
|
||
{% block scripts %} | ||
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/select2.min.js"></script> | ||
{% endblock %} | ||
|
||
{% block content %} | ||
<h2 class="title">{{ 'packages.settings_title'|trans({ '%name%': package.name }) }}</h2> | ||
|
||
<section class="row"> | ||
{{ form_start(form, { attr: { class: 'col-md-6' } }) }} | ||
{{ form_widget(form) }} | ||
<input class="btn btn-block btn-primary btn-lg" id="submit" type="submit" value="{{ 'edit.submit'|trans }}" /> | ||
{{ form_end(form) }} | ||
</section> | ||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters