Skip to content
Merged
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
50 changes: 50 additions & 0 deletions .github/workflows/generate-docs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: 📚 Generate Documentation

on:
push:
branches: [ main ]
paths:
- 'context.json'
workflow_dispatch: # Allow manual trigger
release:
types: [ published ]

jobs:
generate-docs:
runs-on: ubuntu-latest
permissions:
contents: write # Needed to push updates back to the repository
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.2'
coverage: none

- name: Download context-generator
run: |
wget https://github.com/butschster/context-generator/releases/download/1.5.0/context-generator.phar
chmod +x context-generator.phar
./context-generator.phar version

- name: Generate documentation
run: |
./context-generator.phar

- name: List generated documents
run: |
find .context -type f | sort
echo "Generated documentation files in .context directory"

- name: 📤 Upload documentation as release assets
uses: softprops/[email protected]
if: github.event_name == 'release'
with:
token: "${{ secrets.GITHUB_TOKEN }}"
files: |
.context/**/*
239 changes: 237 additions & 2 deletions json-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,214 @@
}
}
},
"php-docs": {
"type": "object",
"properties": {
"include_private_methods": {
"type": "boolean",
"description": "Whether to include private methods in documentation",
"default": false
},
"include_protected_methods": {
"type": "boolean",
"description": "Whether to include protected methods in documentation",
"default": true
},
"include_private_properties": {
"type": "boolean",
"description": "Whether to include private properties in documentation",
"default": false
},
"include_protected_properties": {
"type": "boolean",
"description": "Whether to include protected properties in documentation",
"default": true
},
"include_implementations": {
"type": "boolean",
"description": "Whether to include method implementations in code blocks",
"default": true
},
"include_property_defaults": {
"type": "boolean",
"description": "Whether to include property default values",
"default": true
},
"include_constants": {
"type": "boolean",
"description": "Whether to include class constants",
"default": true
},
"code_block_format": {
"type": "string",
"description": "Language identifier for code blocks (e.g., 'php')",
"default": "php"
},
"class_heading_level": {
"type": "integer",
"description": "Heading level for class names (1-6)",
"minimum": 1,
"maximum": 6,
"default": 1
},
"extract_routes": {
"type": "boolean",
"description": "Whether to extract route information from annotations/attributes",
"default": true
},
"keep_doc_comments": {
"type": "boolean",
"description": "Whether to keep doc comments in the output",
"default": true
}
}
},
"sanitizer": {
"type": "object",
"properties": {
"rules": {
"type": "array",
"description": "Array of sanitization rules to apply",
"items": {
"type": "object",
"oneOf": [
{
"type": "object",
"properties": {
"type": {
"type": "string",
"enum": [
"keyword"
],
"description": "Keyword removal rule"
},
"name": {
"type": "string",
"description": "Optional unique rule name"
},
"keywords": {
"type": "array",
"items": {
"type": "string"
},
"description": "Array of keywords to search for and remove"
},
"replacement": {
"type": "string",
"description": "Text to replace the found keywords with"
},
"caseSensitive": {
"type": "boolean",
"description": "Whether matching should be case-sensitive"
},
"removeLines": {
"type": "boolean",
"description": "Whether to remove entire lines containing the keyword"
}
},
"required": [
"type",
"keywords"
]
},
{
"type": "object",
"properties": {
"type": {
"type": "string",
"enum": [
"regex"
],
"description": "Regular expression replacement rule"
},
"name": {
"type": "string",
"description": "Optional unique rule name"
},
"patterns": {
"type": "object",
"additionalProperties": {
"type": "string"
},
"description": "Object mapping regex patterns to their replacements"
},
"usePatterns": {
"type": "array",
"items": {
"type": "string",
"enum": [
"credit-card",
"email",
"api-key",
"ip-address",
"jwt",
"phone-number",
"password-field",
"url",
"social-security",
"aws-key",
"private-key",
"database-conn"
]
},
"description": "Predefined pattern aliases to use"
}
},
"required": [
"type"
]
},
{
"type": "object",
"properties": {
"type": {
"type": "string",
"enum": [
"comment"
],
"description": "Comment insertion rule"
},
"name": {
"type": "string",
"description": "Optional unique rule name"
},
"fileHeaderComment": {
"type": "string",
"description": "Comment to insert at the top of file"
},
"classComment": {
"type": "string",
"description": "Comment to insert before class definitions"
},
"methodComment": {
"type": "string",
"description": "Comment to insert before method definitions"
},
"frequency": {
"type": "integer",
"minimum": 0,
"description": "How often to insert random comments (0 = disabled, 1 = every line, 5 = every 5th line)"
},
"randomComments": {
"type": "array",
"items": {
"type": "string"
},
"description": "Array of random comments to insert"
}
},
"required": [
"type"
]
}
],
"required": [
"type"
]
}
}
}
},
"modifiers": {
"type": "array",
"description": "List of content modifiers to apply",
Expand All @@ -551,7 +759,8 @@
"type": "string",
"description": "Modifier identifier",
"enum": [
"php-content-filter"
"php-signature",
"php-docs"
]
}
},
Expand All @@ -569,7 +778,9 @@
"type": "string",
"description": "Modifier identifier",
"enum": [
"php-content-filter"
"php-content-filter",
"php-docs",
"sanitizer"
]
},
"options": {
Expand All @@ -586,6 +797,30 @@
"then": {
"$ref": "#/definitions/php-content-filter"
}
},
{
"if": {
"properties": {
"name": {
"const": "php-docs"
}
}
},
"then": {
"$ref": "#/definitions/php-docs"
}
},
{
"if": {
"properties": {
"name": {
"const": "sanitizer"
}
}
},
"then": {
"$ref": "#/definitions/sanitizer"
}
}
]
}
Expand Down
10 changes: 8 additions & 2 deletions src/Cli/ContextGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
use Butschster\ContextGenerator\Loader\CompositeDocumentsLoader;
use Butschster\ContextGenerator\Loader\ConfigDocumentsLoader;
use Butschster\ContextGenerator\Loader\JsonConfigDocumentsLoader;
use Butschster\ContextGenerator\Modifier\AstDocTransformer;
use Butschster\ContextGenerator\Modifier\ContextSanitizerModifier;
use Butschster\ContextGenerator\Modifier\PhpContentFilter;
use Butschster\ContextGenerator\Modifier\PhpSignature;
use Butschster\ContextGenerator\Modifier\SourceModifierRegistry;
Expand Down Expand Up @@ -48,8 +50,12 @@ protected function execute(InputInterface $input, OutputInterface $output): int
{
$files = new Files();
$modifiers = new SourceModifierRegistry();
$modifiers->register(new PhpSignature());
$modifiers->register(new PhpContentFilter());
$modifiers->register(
new PhpSignature(),
new ContextSanitizerModifier(),
new PhpContentFilter(),
new AstDocTransformer(),
);

// Create GitHub-related components
$githubToken = \getenv('GITHUB_TOKEN') ?: null;
Expand Down
2 changes: 0 additions & 2 deletions src/Fetcher/FileSourceFetcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,8 @@
$fileName = $file->getFilename();
$filePath = empty($relativePath) ? $fileName : "$relativePath/$fileName";

$content .= "```\n";
$content .= "// Path: {$filePath}\n";
$content .= $this->getContent($file, $source) . "\n\n";
$content .= "```\n";
}

return $content;
Expand All @@ -79,7 +77,7 @@
$content = $file->getContents();

// Apply modifiers if available and the source is a FileSource
foreach ($source->modifiers as $modifierId) {

Check failure on line 80 in src/Fetcher/FileSourceFetcher.php

View workflow job for this annotation

GitHub Actions / psalm (ubuntu-latest, 8.2, locked)

NoInterfaceProperties

src/Fetcher/FileSourceFetcher.php:80:18: NoInterfaceProperties: Interfaces cannot have properties (see https://psalm.dev/028)

Check failure on line 80 in src/Fetcher/FileSourceFetcher.php

View workflow job for this annotation

GitHub Actions / psalm (ubuntu-latest, 8.2, locked)

NoInterfaceProperties

src/Fetcher/FileSourceFetcher.php:80:18: NoInterfaceProperties: Interfaces cannot have properties (see https://psalm.dev/028)
if ($this->modifiers->has($modifierId)) {
$modifier = $this->modifiers->get($modifierId);
if ($modifier->supports($file->getFilename())) {
Expand Down
Loading
Loading