Skip to content

Commit 6d96427

Browse files
committed
feat: implement GitLab source fetching
1 parent a270749 commit 6d96427

File tree

15 files changed

+721
-5
lines changed

15 files changed

+721
-5
lines changed

src/Console/GenerateCommand.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ public function __invoke(Container $container, DirectoriesInterface $dirs): int
157157
$result[] = [
158158
'output_path' => $compiledDocument->outputPath,
159159
'context_path' => $compiledDocument->contextPath,
160-
'errors' => \iterator_to_array($compiledDocument->errors->getIterator()),
160+
'errors' => $compiledDocument->errors,
161161
];
162162
}
163163
}

src/Document/Compiler/Error/ErrorCollection.php

+9-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* @template TError of \Stringable|string
1010
* @implements \IteratorAggregate<TError>
1111
*/
12-
final class ErrorCollection implements \Countable, \IteratorAggregate
12+
final class ErrorCollection implements \Countable, \IteratorAggregate, \JsonSerializable
1313
{
1414
public function __construct(
1515
/**
@@ -50,4 +50,12 @@ public function getIterator(): \Traversable
5050
{
5151
return new \ArrayIterator($this->errors);
5252
}
53+
54+
public function jsonSerialize(): array
55+
{
56+
return \array_map(
57+
static fn(\Stringable|string $error): string => (string) $error,
58+
$this->errors,
59+
);
60+
}
5361
}

src/Lib/PathFilter/ExcludePathFilter.php

+4
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ public function apply(array $items): array
5353
*/
5454
private function matchesPattern(string $string, string $pattern): bool
5555
{
56+
if (\str_contains($string, $pattern)) {
57+
return true;
58+
}
59+
5660
if (FileHelper::isRegex($pattern)) {
5761
return (bool) \preg_match($pattern, $string);
5862
}

src/Source/Gitlab/GitlabFinder.php

-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
use Butschster\ContextGenerator\Lib\TreeBuilder\FileTreeBuilder;
1717
use Butschster\ContextGenerator\Lib\Variable\VariableResolver;
1818
use Butschster\ContextGenerator\Source\Fetcher\FilterableSourceInterface;
19-
use Butschster\ContextGenerator\Source\Gitlab\Config\ServerRegistry;
2019

2120
final class GitlabFinder implements FinderInterface
2221
{
@@ -29,7 +28,6 @@ final class GitlabFinder implements FinderInterface
2928

3029
public function __construct(
3130
private readonly GitlabClientInterface $gitlabClient,
32-
private readonly ServerRegistry $serverRegistry,
3331
private readonly VariableResolver $variableResolver = new VariableResolver(),
3432
private readonly FileTreeBuilder $fileTreeBuilder = new FileTreeBuilder(),
3533
) {}

src/Source/Gitlab/GitlabSourceFetcher.php

+4
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ public function fetch(SourceInterface $source, ModifiersApplierInterface $modifi
6464
->create()
6565
->addTitle($source->getDescription(), 2);
6666

67+
if (!$source->server) {
68+
throw new \RuntimeException('GitLab server is not set');
69+
}
70+
6771
// Determine server URL from source or default
6872
$serverUrl = $source->server->url;
6973

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
documents:
2+
- description: "Basic GitLab Source Test"
3+
outputPath: "gitlab-source.md"
4+
sources:
5+
- type: gitlab
6+
description: "Basic GitLab Source Test"
7+
repository: "group/project"
8+
sourcePaths: "src"
9+
server:
10+
url: "https://gitlab.com"
11+
token: "your_gitlab_token"
12+
filePattern: "*.php"
13+
branch: "main"
14+
showTreeView: true
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
documents:
2+
- description: "Custom Server GitLab Test"
3+
outputPath: "custom-server-gitlab.md"
4+
sources:
5+
- type: gitlab
6+
description: "Custom Server GitLab Test"
7+
repository: "group/project"
8+
sourcePaths: "src"
9+
filePattern: "*.php"
10+
branch: "main"
11+
showTreeView: true
12+
server:
13+
url: "https://custom-gitlab.example.com"
14+
token: "${GITLAB_TOKEN}"
15+
headers:
16+
X-Custom-Header: "custom-value"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
documents:
2+
- description: "Filtered GitLab Source"
3+
outputPath: "filtered-gitlab.md"
4+
sources:
5+
- type: gitlab
6+
description: "Filtered GitLab Source"
7+
repository: "group/project"
8+
sourcePaths: "src"
9+
filePattern: "*.php"
10+
path: "Controller"
11+
notPath:
12+
- "Model"
13+
branch: "main"
14+
showTreeView: true
15+
server:
16+
url: "https://gitlab.com"
17+
token: "your_gitlab_token"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
documents:
2+
- description: "Basic GitLab Source Test"
3+
outputPath: "gitlab-source.md"
4+
sources:
5+
- type: gitlab
6+
description: "Basic GitLab Source Test"
7+
repository: "group/project"
8+
sourcePaths: "src"
9+
filePattern: "*.php"
10+
branch: "main"
11+
showTreeView: true
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
documents:
2+
- description: "Multiple Paths GitLab Source"
3+
outputPath: "multiple-paths-gitlab.md"
4+
sources:
5+
- type: gitlab
6+
description: "Multiple Paths GitLab Source"
7+
repository: "group/project"
8+
sourcePaths:
9+
- "src/Controller"
10+
- "tests"
11+
filePattern: "*.php"
12+
branch: "main"
13+
showTreeView: true
14+
server:
15+
url: "https://gitlab.com"
16+
token: "your_gitlab_token"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
documents:
2+
- description: "GitLab Tree View Test"
3+
outputPath: "tree-view-gitlab.md"
4+
sources:
5+
- type: gitlab
6+
description: "GitLab Tree View Test"
7+
repository: "group/project"
8+
sourcePaths: "src"
9+
filePattern: "*.php"
10+
branch: "main"
11+
showTreeView: true
12+
treeView:
13+
enabled: true
14+
showSize: true
15+
showLastModified: true
16+
includeFiles: true
17+
server:
18+
url: "https://gitlab.com"
19+
token: "your_gitlab_token"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
documents:
2+
- description: "Private GitLab Repository"
3+
outputPath: "private-gitlab.md"
4+
sources:
5+
- type: gitlab
6+
description: "Private GitLab Repository"
7+
repository: "group/private-project"
8+
sourcePaths: "src"
9+
filePattern: "*.php"
10+
branch: "main"
11+
showTreeView: true
12+
server:
13+
url: "https://gitlab.com"
14+
token: "${GITLAB_TOKEN}"

tests/src/Feature/Console/GenerateCommand/CompilingResult.php

-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ public function assertDocumentError(string $document, array $contains): self
9797
{
9898
foreach ($this->result['result'] as $documentData) {
9999
if ($documentData['context_path'] === $document) {
100-
trap($documentData['errors']);
101100
foreach ($contains as $string) {
102101
TestCase::assertStringContainsString(
103102
$string,

0 commit comments

Comments
 (0)