Skip to content

Commit

Permalink
Merge branch 'release/1.3.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
eliashaeussler committed Nov 3, 2022
2 parents 8d7ae2a + 16ccdf0 commit 8025a0a
Show file tree
Hide file tree
Showing 15 changed files with 834 additions and 49 deletions.
12 changes: 12 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
2022-11-03 [RELEASE] Release of frontend-asset-handler 1.3.0 (Elias Häußler)
2022-11-03 20ad80d [DOCS] Mention required scope for GitLab access tokens (Elias Häußler)
2022-11-03 183b8a5 [DOCS] Improve documentation about VCS providers (Elias Häußler)
2022-11-03 5455408 [BUGFIX] Harden check for latest deployment status (Elias Häußler)
2022-11-03 6f17b3f [TASK] Ask for additional variables on initializing GitHub VCS provider (Elias Häußler)
2022-11-02 9f03ae8 [BUGFIX] Disable invalid behavior of ReadOnlyPropertyRector (Elias Häußler)
2022-09-16 777b3cc [FEATURE] Add support for GitHub as VCS provider (Elias Häußler)
2022-11-03 5216a21 [TASK] Make codebase compatible with PHPStan 1.9.x (Elias Häußler)
2022-11-03 61f19d0 [TASK]: Bump phpstan/phpstan from 1.8.11 to 1.9.0 (dependabot[bot])
2022-11-02 6167440 [BUGFIX] Promote all properties in GitlabVcsProvider (Elias Häußler)
2022-11-02 a618d1e [TASK]: Bump friendsofphp/php-cs-fixer from 3.12.0 to 3.13.0 (dependabot[bot])

2022-11-02 [RELEASE] Release of frontend-asset-handler 1.2.6 (Elias Häußler)
2022-11-02 b573e13 [DOCS] Use less badges in README.md (Elias Häußler)
2022-11-01 2ed4e53 [TASK] Enable Dependabot auto-merge for minor and patch updates (Elias Häußler)
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"ergebnis/json-normalizer": ">= 1.0 < 3.0",
"ergebnis/json-printer": "^3.0",
"ergebnis/json-schema-validator": "^2.0",
"gmostafa/php-graphql-client": "^1.13",
"guzzlehttp/guzzle": "^7.0",
"guzzlehttp/psr7": ">= 1.8 < 3.0",
"justinrainbow/json-schema": "^5.2",
Expand Down
97 changes: 81 additions & 16 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 31 additions & 0 deletions docs/components/vcs-providers.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,40 @@
# VCS Providers

The Frontend Assets Handler is able to interact with the asset sources on VCS through
specific providers. Each VCS provider requires configuration. Consult the appropriate
provider classes to find out what configuration is expected.

## [`GithubVcsProvider`](../../src/Vcs/GithubVcsProvider.php)

Interacting with assets on GitHub requires an access token with `repo` scope.

It supports the following additional configuration:

### `access-token`

An access token to identify requests to the GitLab API. This token is supplied as a
`Authorization` header with each request.

* Required: **yes**
* Default: ****

### `repository`

Name of the project in the form `<owner>/<name>` providing the Frontend assets. It
is used to lookup revisions and current deployments.

* Require: **yes**
* Default: ****

## [`GitlabVcsProvider`](../../src/Vcs/GitlabVcsProvider.php)

Using this VCS Provider, GitLab can be interacted with as the VCS for the requested
Frontend assets. This is necessary, for example, to query an active deployment of the
requested assets.

Interacting with assets on GitLab requires either a [project access token][1] of the
appropriate project or an access token with at least `read_api` scope.

It supports the following additional configuration:

### `base-url`
Expand All @@ -31,3 +60,5 @@ current deployments.

* Require: **yes**
* Default: ****

[1]: https://docs.gitlab.com/ee/user/project/settings/project_access_tokens.html
2 changes: 2 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,7 @@ parameters:
symfony:
consoleApplicationLoader: tests/Build/console-application.php
containerXmlPath: var/cache/container_test.xml
stubFiles:
- tests/Build/Stubs/GraphQL/QueryBuilder.stub
scanFiles:
- var/cache/container_test.php
7 changes: 6 additions & 1 deletion src/Asset/Environment/Map/Map.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
use IteratorAggregate;
use Traversable;

use function array_values;
use function ksort;

/**
* Map.
*
Expand Down Expand Up @@ -62,7 +65,9 @@ public function merge(self $map): self

$mergedMap = array_replace($this->pairs, $otherPairs);

return new self($mergedMap);
ksort($mergedMap);

return new self(array_values($mergedMap));
}

/**
Expand Down
3 changes: 2 additions & 1 deletion src/Command/ConfigAssetsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
use Symfony\Component\Console;

use function count;
use function explode;

/**
* ConfigAssetsCommand.
Expand Down Expand Up @@ -302,7 +303,7 @@ private function buildAndValidatePath(array $assetDefinitions, string $path): st

private function decoratePath(string $path): string
{
$pathSegments = array_map(fn (string $segment): string => sprintf('[%s]', $segment), str_getcsv($path, '/'));
$pathSegments = array_map(fn (string $segment): string => sprintf('[%s]', $segment), explode('/', $path));

return implode('', $pathSegments);
}
Expand Down
92 changes: 66 additions & 26 deletions src/Config/Initialization/Step/VcsConfigStep.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,32 +93,15 @@ public function execute(Config\Initialization\InitializationRequest $request): b
);
$request->setOption('vcs-type', $vcsType);

// Additional variables for GitlabVcsProvider only
if (Vcs\GitlabVcsProvider::getName() === $vcsType) {
$this->askForAdditionalVariable(
$request,
'Base URL',
'base-url',
$additionalVariables,
'https://gitlab.com',
['notEmpty', 'url'],
);

$this->askForAdditionalVariable(
$request,
'Access token',
'access-token',
$additionalVariables,
validator: 'notEmpty',
);

$this->askForAdditionalVariable(
$request,
'Project ID',
'project-id',
$additionalVariables,
validator: 'integer',
);
// Additional variables for specific providers
switch ($vcsType) {
case Vcs\GitlabVcsProvider::getName():
$this->requestAdditionalVariablesForGitlabVcsProvider($request, $additionalVariables);
break;

case Vcs\GithubVcsProvider::getName():
$this->requestAdditionalVariablesForGithubVcsProvider($request, $additionalVariables);
break;
}

// VCS config extra
Expand Down Expand Up @@ -147,6 +130,63 @@ public function execute(Config\Initialization\InitializationRequest $request): b
return true;
}

/**
* @param array<string, mixed> $additionalVariables
*/
private function requestAdditionalVariablesForGitlabVcsProvider(
Config\Initialization\InitializationRequest $request,
array &$additionalVariables,
): void {
$this->askForAdditionalVariable(
$request,
'Base URL',
'base-url',
$additionalVariables,
'https://gitlab.com',
['notEmpty', 'url'],
);

$this->askForAdditionalVariable(
$request,
'Access token',
'access-token',
$additionalVariables,
validator: 'notEmpty',
);

$this->askForAdditionalVariable(
$request,
'Project ID',
'project-id',
$additionalVariables,
validator: 'integer',
);
}

/**
* @param array<string, mixed> $additionalVariables
*/
private function requestAdditionalVariablesForGithubVcsProvider(
Config\Initialization\InitializationRequest $request,
array &$additionalVariables,
): void {
$this->askForAdditionalVariable(
$request,
'Access token',
'access-token',
$additionalVariables,
validator: 'notEmpty',
);

$this->askForAdditionalVariable(
$request,
'Repository (<owner>/<name>)',
'repository',
$additionalVariables,
validator: 'notEmpty',
);
}

private function buildVcs(Config\Initialization\InitializationRequest $request): void
{
$config = $request->getConfig();
Expand Down
Loading

0 comments on commit 8025a0a

Please sign in to comment.