You've already forked gitea-bundle
Initial commit
This commit is contained in:
6
.gitignore
vendored
Normal file
6
.gitignore
vendored
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
/.phpunit.result.cache
|
||||||
|
/.phpunit.cache
|
||||||
|
/composer.lock
|
||||||
|
/phpunit.xml
|
||||||
|
/vendor/
|
||||||
|
*~
|
||||||
21
LICENSE
Normal file
21
LICENSE
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
The MIT license
|
||||||
|
|
||||||
|
Copyright (c) 2021-2022 Marco Grätsch <magdev3.0@gmail.com>
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is furnished
|
||||||
|
to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
THE SOFTWARE.
|
||||||
35
composer.json
Normal file
35
composer.json
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
{
|
||||||
|
"name": "magdev/gitea-bundle",
|
||||||
|
"description": "Symfony bundle to integrate Gitea",
|
||||||
|
"type": "symfony-bundle",
|
||||||
|
"require": {
|
||||||
|
"owenvoke/gitea": "^0.1.6",
|
||||||
|
"guzzlehttp/guzzle": "^7.4",
|
||||||
|
"http-interop/http-factory-guzzle": "^1.2"
|
||||||
|
},
|
||||||
|
"require-dev": {
|
||||||
|
"phpunit/phpunit": "^9.5",
|
||||||
|
"symfony/http-kernel": "^5.4",
|
||||||
|
"symfony/dependency-injection": "^5.4",
|
||||||
|
"symfony/config": "^5.4",
|
||||||
|
"symfony/phpunit-bridge": "^6.0"
|
||||||
|
},
|
||||||
|
"license": "MIT",
|
||||||
|
"autoload": {
|
||||||
|
"psr-4": {
|
||||||
|
"Magdev\\GiteaBundle\\": "src/"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"autoload-dev": {
|
||||||
|
"psr-4": {
|
||||||
|
"Magdev\\GiteaBundle\\Tests\\": "tests/"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"authors": [
|
||||||
|
{
|
||||||
|
"name": "magdev",
|
||||||
|
"email": "magdev3.0@gmail.com"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"minimum-stability": "stable"
|
||||||
|
}
|
||||||
34
phpunit.xml.dist
Normal file
34
phpunit.xml.dist
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
||||||
|
<!-- https://phpunit.readthedocs.io/en/latest/configuration.html -->
|
||||||
|
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
|
||||||
|
backupGlobals="false"
|
||||||
|
colors="true"
|
||||||
|
bootstrap="vendor/autoload.php"
|
||||||
|
convertDeprecationsToExceptions="false"
|
||||||
|
>
|
||||||
|
<php>
|
||||||
|
<ini name="display_errors" value="1" />
|
||||||
|
<ini name="error_reporting" value="-1" />
|
||||||
|
<server name="APP_ENV" value="test" force="true" />
|
||||||
|
<server name="SHELL_VERBOSITY" value="-1" />
|
||||||
|
<server name="SYMFONY_PHPUNIT_REMOVE" value="" />
|
||||||
|
</php>
|
||||||
|
|
||||||
|
<testsuites>
|
||||||
|
<testsuite name="Project Test Suite">
|
||||||
|
<directory>tests</directory>
|
||||||
|
</testsuite>
|
||||||
|
</testsuites>
|
||||||
|
|
||||||
|
<coverage processUncoveredFiles="true">
|
||||||
|
<include>
|
||||||
|
<directory suffix=".php">src</directory>
|
||||||
|
</include>
|
||||||
|
</coverage>
|
||||||
|
|
||||||
|
<listeners>
|
||||||
|
<listener class="Symfony\Bridge\PhpUnit\SymfonyTestsListener" />
|
||||||
|
</listeners>
|
||||||
|
</phpunit>
|
||||||
42
src/DependencyInjection/Configuration.php
Normal file
42
src/DependencyInjection/Configuration.php
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Magdev\GiteaBundle\DependencyInjection;
|
||||||
|
|
||||||
|
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
|
||||||
|
use Symfony\Component\Config\Definition\ConfigurationInterface;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Marco Grätsch <magdev3.0@gmail.com>
|
||||||
|
*/
|
||||||
|
final class Configuration implements ConfigurationInterface
|
||||||
|
{
|
||||||
|
public function getConfigTreeBuilder(): TreeBuilder
|
||||||
|
{
|
||||||
|
$treeBuilder = new TreeBuilder('magdev_gitea');
|
||||||
|
$rootNode = $treeBuilder->getRootNode();
|
||||||
|
$rootNode->fixXmlConfig('connection')
|
||||||
|
->children()
|
||||||
|
->arrayNode('connections')
|
||||||
|
->useAttributeAsKey('name')
|
||||||
|
->normalizeKeys(false)
|
||||||
|
->arrayPrototype()
|
||||||
|
->children()
|
||||||
|
->scalarNode('baseurl')
|
||||||
|
->isRequired()
|
||||||
|
->info('The base URL of the gitea instance')
|
||||||
|
->end()
|
||||||
|
->scalarNode('token')
|
||||||
|
->isRequired()
|
||||||
|
->info('The Gitea access token')
|
||||||
|
->end()
|
||||||
|
->end()
|
||||||
|
->end()
|
||||||
|
->end()
|
||||||
|
->scalarNode('default_connection')->end()
|
||||||
|
;
|
||||||
|
|
||||||
|
return $treeBuilder;
|
||||||
|
}
|
||||||
|
}
|
||||||
35
src/DependencyInjection/MagdevGiteaExtension.php
Normal file
35
src/DependencyInjection/MagdevGiteaExtension.php
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
<?php
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Magdev\GiteaBundle\DependencyInjection;
|
||||||
|
|
||||||
|
use OwenVoke\Gitea\Client;
|
||||||
|
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||||
|
use Symfony\Component\DependencyInjection\Extension\Extension;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Marco Grätsch <magdev3.0@gmail.com>
|
||||||
|
*/
|
||||||
|
final class MagdevGiteaExtension extends Extension
|
||||||
|
{
|
||||||
|
public function load(array $configs, ContainerBuilder $container)
|
||||||
|
{
|
||||||
|
$config = $this->processConfiguration(new Configuration(), $configs);
|
||||||
|
|
||||||
|
if (!isset($config['default_connection'])) {
|
||||||
|
$config['default_connection'] = array_key_first($config['connections']);
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($config['connections'] as $name => $connection) {
|
||||||
|
$id = sprintf('magdev.gitea.%s', $name);
|
||||||
|
$container->register($id, Client::class)
|
||||||
|
->setArguments([null, null, $connection['baseurl']])
|
||||||
|
->addMethodCall('authenticate', [$connection['token'], null, Client::AUTH_ACCESS_TOKEN]);
|
||||||
|
$container->registerAliasForArgument($id, Client::class, "{$name}Client");
|
||||||
|
|
||||||
|
if ($name === $config['default_connection']) {
|
||||||
|
$container->setAlias(Client::class, $id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
14
src/MagdevGiteaBundle.php
Normal file
14
src/MagdevGiteaBundle.php
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Magdev\GiteaBundle;
|
||||||
|
|
||||||
|
use Symfony\Component\HttpKernel\Bundle\Bundle;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Marco Grätsch <magdev3.0@gmail.com>
|
||||||
|
*/
|
||||||
|
final class MagdevGiteaBundle extends Bundle
|
||||||
|
{
|
||||||
|
}
|
||||||
41
tests/DependencyInjection/ConfigurationTest.php
Normal file
41
tests/DependencyInjection/ConfigurationTest.php
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Magdev\GiteaBundle\Tests\DependencyInjection;
|
||||||
|
|
||||||
|
use Magdev\GiteaBundle\DependencyInjection\Configuration;
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
use Symfony\Component\Config\Definition\Processor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Marco Grätsch <magdev3.0@gmail.com>
|
||||||
|
*/
|
||||||
|
class ConfigurationTest extends TestCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @dataProvider configsProvider
|
||||||
|
*/
|
||||||
|
public function testConfig(array $configs): void
|
||||||
|
{
|
||||||
|
$config = (new Processor())->processConfiguration(new Configuration(), $configs);
|
||||||
|
$this->assertSame('foo', $config['connections']['default']['token']);
|
||||||
|
$this->assertSame('bar', $config['connections']['default']['baseurl']);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function configsProvider(): iterable
|
||||||
|
{
|
||||||
|
yield [
|
||||||
|
[
|
||||||
|
'magdev_gitea' => [
|
||||||
|
'connections' => [
|
||||||
|
'default' => [
|
||||||
|
'token' => 'foo',
|
||||||
|
'baseurl' => 'bar'
|
||||||
|
],
|
||||||
|
],
|
||||||
|
],
|
||||||
|
],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
40
tests/DependencyInjection/MagdevGiteaExtensionTest.php
Normal file
40
tests/DependencyInjection/MagdevGiteaExtensionTest.php
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Magdev\GiteaBundle\Tests\DependencyInjection;
|
||||||
|
|
||||||
|
use Magdev\GiteaBundle\DependencyInjection\MagdevGiteaExtension;
|
||||||
|
use OwenVoke\Gitea\Client;
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Marco Grätsch <magdev3.0@gmail.com>
|
||||||
|
*/
|
||||||
|
class MagdevGiteaExtensionTest extends TestCase
|
||||||
|
{
|
||||||
|
public function testExtension(): void
|
||||||
|
{
|
||||||
|
$container = new ContainerBuilder();
|
||||||
|
|
||||||
|
(new MagdevGiteaExtension())->load([
|
||||||
|
'magdev_gitea' => [
|
||||||
|
'connections' => [
|
||||||
|
'primary' => ['baseurl' => 'http://foo1', 'token' => 'bar1'],
|
||||||
|
'secondary' => ['baseurl' => 'http://foo2', 'token' => 'bar2'],
|
||||||
|
],
|
||||||
|
],
|
||||||
|
], $container);
|
||||||
|
|
||||||
|
$this->assertTrue($container->has('magdev.gitea.primary'));
|
||||||
|
$this->assertTrue($container->has('magdev.gitea.secondary'));
|
||||||
|
|
||||||
|
$this->assertTrue($container->hasAlias(Client::class));
|
||||||
|
$this->assertTrue($container->hasAlias(Client::class.' $primaryClient'));
|
||||||
|
$this->assertTrue($container->hasAlias(Client::class.' $secondaryClient'));
|
||||||
|
|
||||||
|
$this->assertInstanceOf(Client::class, $container->get('magdev.gitea.primary'));
|
||||||
|
$this->assertInstanceOf(Client::class, $container->get('magdev.gitea.secondary'));
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user