Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configurable Github/Gitea urls #163

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions config/parameters.yml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ parameters:
admin.users: ~
composer.home: "%kernel.project_dir%/var/composer"
github.secret: ~
github.source_urls: ['git_url', 'ssh_url', 'clone_url', 'svn_url']
gitlab.secret: ~
gitlab.auto_add_repo: false
gitlab.auto_add_repo_type: ~
gitlab.prefer_ssh_url_type: false
gitea.secret: ~
gitea.source_urls: ['git_url', 'ssh_url', 'clone_url', 'svn_url']
devops.secret: ~
4 changes: 3 additions & 1 deletion src/Playbloom/Satisfy/Resources/config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,13 @@ services:
public: true
arguments:
$secret: "%github.secret%"
$sourceUrls: "%github.source_urls%"

Playbloom\Satisfy\Webhook\GiteaWebhook:
public: true
arguments:
$secret: "%gitea.secret%"
$sourceUrls: "%gitea.source_urls%"

Playbloom\Satisfy\Webhook\GitlabWebhook:
public: true
Expand All @@ -105,4 +107,4 @@ services:
autowire: true
public: true
arguments:
$secret: "%devops.secret%"
$secret: "%devops.secret%"
21 changes: 19 additions & 2 deletions src/Playbloom/Satisfy/Webhook/GithubWebhook.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,18 @@

class GithubWebhook extends AbstractWebhook
{
public function __construct(Manager $manager, EventDispatcherInterface $dispatcher, ?string $secret = null)
/** @var array */
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please define array shape

protected $sourceUrls = ['git_url', 'ssh_url', 'clone_url', 'svn_url'];

public function __construct(
Manager $manager, EventDispatcherInterface $dispatcher,
?string $secret = null,
?array $sourceUrls = null
)
{
parent::__construct($manager, $dispatcher);
$this->secret = $secret;
$this->setSourceUrls($sourceUrls);
}

public function setSecret(string $secret = null): self
Expand All @@ -38,6 +46,15 @@ public function setSecret(string $secret = null): self
return $this;
}

public function setSourceUrls(?array $sourceUrls = null): self
{
if ($sourceUrls !== null) {
$this->sourceUrls = $sourceUrls;
}

return $this;
}

public function getResponse(Request $request): Response
{
try {
Expand Down Expand Up @@ -97,7 +114,7 @@ protected function getRepository(Request $request): RepositoryInterface
$repositoryData = $payload['repository'] ?? [];

$urls = [];
foreach (['git_url', 'ssh_url', 'clone_url', 'svn_url'] as $key) {
foreach ($this->sourceUrls as $key) {
$url = $repositoryData[$key] ?? null;
if (!empty($url)) {
$urls[] = $this->getUrlPattern($url);
Expand Down