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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ vendor
node_modules
.php-cs-fixer.cache
.context
runtime
runtime/*
147 changes: 147 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ It automates the process of building context files from various sources:

- code files,
- GitHub repositories,
- Git commit changes and diffs
- Web pages (URLs) with CSS selectors,
- and plain text.

Expand Down Expand Up @@ -186,6 +187,25 @@ Create a `context.json` file in your project root:
]
}
]
},
{
"description": "Recent Git Changes",
"outputPath": "docs/recent-changes.md",
"sources": [
{
"type": "text",
"description": "Documentation Header",
"content": "# Recent Git Changes\nThis document contains recent changes from the git repository."
},
{
"type": "git_diff",
"description": "Recent Commits (Last 1)",
"repository": ".",
"commit": "last",
"filePattern": "*.php",
"showStats": true
}
]
}
]
}
Expand Down Expand Up @@ -494,6 +514,113 @@ Pull files directly from a GitHub repository:
}
```

### Git Diff Source

The source allows you to include changes from Git commits, providing a streamlined way to show recent code changes:

```json
{
"type": "git_diff",
"description": "Recent Git Changes",
"commit": "last",
"filePattern": "*.php",
"notPath": [
"tests",
"vendor"
],
"path": "src",
"contains": "class",
"notContains": "@deprecated",
"showStats": true
}
```

#### Commit Range Presets

The Git diff source supports many convenient presets for `commit` parameter:


```json
{
"type": "git_diff",
"repository": ".",
"commit": "last-week",
"filePattern": "*.php"
}
```

Available presets include:

- **Basic ranges**:
- `last`: Last commit (HEAD~1..HEAD)
- `last-2`, `last-3`, `last-5`, `last-10`: Last N commits
- `staged`: Changes staged but not committed
- `unstaged`: Changes not yet staged

- **Time-based ranges**:
- `today`: Changes from today
- `last-24h`: Changes in the last 24 hours
- `yesterday`: Changes from yesterday
- `last-week`: Changes in the last week
- `last-2weeks`: Changes in the last two weeks
- `last-month`: Changes in the last month
- `last-quarter`: Changes in the last three months
- `last-year`: Changes in the last year

- **Branch comparisons**:
- `main-diff`: Differences between main and current branch
- `master-diff`: Differences between master and current branch
- `develop-diff`: Differences between develop and current branch

#### Advanced Commit Specifications

You can use more specific Git expressions:

```json
{
"type": "git_diff",
"repository": ".",
"commit": "abc1234",
"filePattern": "*.php"
}
```

```json
{
"type": "git_diff",
"repository": ".",
"commit": "abc1234:path/to/file.php",
"filePattern": "*.php"
}
```

```json
{
"type": "git_diff",
"repository": ".",
"commit": "v1.0.0..v2.0.0",
"filePattern": "*.php"
}
```

```json
{
"type": "git_diff",
"repository": ".",
"commit": "since:2023-01-15",
"filePattern": "*.php"
}
```

```json
{
"type": "git_diff",
"repository": ".",
"commit": "date:2023-01-15",
"filePattern": "*.php"
}
```

### URL Source

Fetch content from websites:
Expand Down Expand Up @@ -640,6 +767,26 @@ new GithubSource(
);
```

### CommitDiffSource

The `Butschster\ContextGenerator\Source\CommitDiffSource` allows you to include git diff content from commits or staged changes:

```php
use Butschster\ContextGenerator\Source\CommitDiffSource;

new CommitDiffSource(
repository: __DIR__, // Path to git repository (use current directory with __DIR__)
description: 'Recent changes', // Optional description
commit: 'last', // Commit range (preset, hash, or expression)
filePattern: '*.php', // Pattern to match files (default: *.php)
notPath: ['tests', 'vendor'], // Patterns to exclude
path: 'src/Controller', // Path filter to include
contains: 'namespace App', // Content pattern to include
notContains: '@deprecated', // Content pattern to exclude
showStats: true, // Whether to show git stats (default: true)
);
```

### UrlSource

The `Butschster\ContextGenerator\Source\UrlSource` allows you to fetch content from websites and extract specific
Expand Down
35 changes: 35 additions & 0 deletions context.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,26 @@
{
"documents": [
{
"description": "Recent Git Changes",
"outputPath": "docs/recent-changes.md",
"sources": [
{
"type": "text",
"description": "Documentation Header",
"content": "# Recent Git Changes\n\nThis document contains recent changes from the git repository.\n"
},
{
"type": "git_diff",
"description": "Recent Commits (Last 1)",
"commit": "staged",
"notPath": [
"vendor",
"tests"
],
"showStats": true
}
]
},
{
"description": "Context generator code.",
"outputPath": "code.md",
Expand All @@ -13,6 +34,20 @@
}
]
},
{
"description": "Git finder.",
"outputPath": "git_diff.md",
"sources": [
{
"type": "file",
"sourcePaths": [
"src/Fetcher/Git",
"src/Fetcher/FinderResult"
],
"filePattern": "*.php"
}
]
},
{
"description": "Context generator tests.",
"outputPath": "tests.md",
Expand Down
145 changes: 144 additions & 1 deletion json-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@
"php_class",
"url",
"text",
"github"
"github",
"git_diff"
],
"description": "Type of content source"
},
Expand Down Expand Up @@ -158,6 +159,18 @@
"then": {
"$ref": "#/definitions/githubSource"
}
},
{
"if": {
"properties": {
"type": {
"const": "git_diff"
}
}
},
"then": {
"$ref": "#/definitions/gitCommitDiffSource"
}
}
]
},
Expand Down Expand Up @@ -444,6 +457,136 @@
"description": "GitHub API token for private repositories (can use env var pattern ${TOKEN_NAME})"
}
}
},
"gitCommitDiffSource": {
"properties": {
"repository": {
"type": "string",
"description": "Path to the git repository"
},
"commit": {
"type": "string",
"enum": [
"last",
"last-5",
"last-10",
"last-week",
"last-month",
"unstaged",
"staged",
"wip",
"main-diff",
"master-diff",
"develop-diff",
"today",
"last-24h",
"yesterday",
"last-2weeks",
"last-quarter",
"last-year",
"stash",
"stash-last",
"stash-1",
"stash-2",
"stash-3",
"stash-all",
"stash-latest-2",
"stash-latest-3",
"stash-latest-5",
"stash-before-pull",
"stash-wip",
"stash-untracked",
"stash-index"
],
"description": "Git commit range (e.g., 'HEAD~5..HEAD')",
"default": "staged"
},
"filePattern": {
"oneOf": [
{
"type": "string",
"description": "Pattern to match files (e.g., *.php)"
},
{
"type": "array",
"description": "List of patterns to match files (e.g., ['*.php', '*.md'])",
"items": {
"type": "string"
}
}
],
"default": "*.*"
},
"path": {
"oneOf": [
{
"type": "string",
"description": "Pattern to include only files in specific paths"
},
{
"type": "array",
"description": "List of patterns to include only files in specific paths",
"items": {
"type": "string"
}
}
],
"default": []
},
"notPath": {
"type": "array",
"description": "Patterns to exclude files by path",
"items": {
"type": "string"
},
"default": []
},
"contains": {
"oneOf": [
{
"type": "string",
"description": "Pattern to include only diffs containing specific content"
},
{
"type": "array",
"description": "List of patterns to include only diffs containing specific content",
"items": {
"type": "string"
}
}
],
"default": []
},
"notContains": {
"oneOf": [
{
"type": "string",
"description": "Pattern to exclude diffs containing specific content"
},
{
"type": "array",
"description": "List of patterns to exclude diffs containing specific content",
"items": {
"type": "string"
}
}
],
"default": []
},
"showStats": {
"type": "boolean",
"description": "Whether to show commit stats in output",
"default": true
},
"modifiers": {
"type": "array",
"description": "List of content modifiers to apply",
"items": {
"type": "string"
},
"default": []
}
}
}
}
}
1 change: 0 additions & 1 deletion runtime/php-cs-fixer.cache

This file was deleted.

Loading
Loading