Skip to content

Commit 873376d

Browse files
committed
feat: repo structure and mermaid graph
1 parent 6d5fc96 commit 873376d

File tree

8 files changed

+392
-1
lines changed

8 files changed

+392
-1
lines changed

.github/workflows/graph-git-repo.yml

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
name: graph-git-repo
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
workflow_dispatch:
8+
inputs:
9+
exclude_patterns:
10+
description: 'Patterns to exclude (e.g., ".git|*.log|node_modules")'
11+
required: false
12+
default: '.git|.DS_Store|.idea|*.log|*.tmp|__pycache__'
13+
depth:
14+
description: 'tree depth to consider'
15+
required: false
16+
default: '2'
17+
18+
jobs:
19+
build:
20+
runs-on: ubuntu-latest
21+
22+
steps:
23+
- name: Checkout code
24+
uses: actions/checkout@v3
25+
26+
- name: Set up Node.js
27+
uses: actions/setup-node@v3
28+
with:
29+
node-version: '18'
30+
31+
- name: Install Tree Command
32+
run: sudo apt-get install -y tree
33+
34+
- name: Generate Repo Structure
35+
run: |
36+
chmod +x scripts/script.sh
37+
./base.sh '${{ github.event.inputs.exclude_patterns }}' '${{ github.event.inputs.depth }}'
38+
39+
- name: Set up Python
40+
uses: actions/setup-python@v3
41+
with:
42+
python-version: '3.10'
43+
44+
- name: Install Python dependencies
45+
run: pip install openai
46+
47+
- name: Generate Mermaid Diagram using ChatGPT
48+
env:
49+
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
50+
run: python scripts/tree_to_gpt.py
51+
52+
- name: Commit and push results
53+
run: |
54+
git config --global user.name "github-actions[bot]"
55+
git config --global user.email "github-actions[bot]@users.noreply.github.com"
56+
git add REPO_STRUCTURE.md MERMAID_DIAGRAM.md
57+
git commit -m "Update repository structure and Mermaid diagram"
58+
git push
59+
env:
60+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.gitignore

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
# Byte-compiled / optimized / DLL files
2+
__pycache__/
3+
*.py[cod]
4+
*$py.class
5+
*.disabled
6+
# Virtual environments
7+
.venv/
8+
env/
9+
venv/
10+
ENV/
11+
12+
# Distribution / packaging
13+
.Python
14+
build/
15+
develop-eggs/
16+
dist/
17+
downloads/
18+
eggs/
19+
.eggs/
20+
lib/
21+
lib64/
22+
parts/
23+
sdist/
24+
var/
25+
wheels/
26+
share/python-wheels/
27+
*.egg-info/
28+
.installed.cfg
29+
*.egg
30+
MANIFEST
31+
# Byte-compiled / optimized / DLL files
32+
__pycache__/
33+
*.py[cod]
34+
*$py.class
35+
*.disabled
36+
# Virtual environments
37+
.venv/
38+
env/
39+
venv/
40+
ENV/
41+
42+
# Distribution / packaging
43+
.Python
44+
build/
45+
develop-eggs/
46+
dist/
47+
downloads/
48+
eggs/
49+
.eggs/
50+
lib/
51+
lib64/
52+
parts/
53+
sdist/
54+
var/
55+
wheels/
56+
share/python-wheels/
57+
*.egg-info/
58+
.installed.cfg
59+
*.egg
60+
MANIFEST
61+
62+
# PyCharm project files
63+
.idea/
64+
65+
# VS Code project files
66+
.vscode/
67+
68+
# Jupyter Notebook files
69+
.ipynb_checkpoints/
70+
71+
# Logs
72+
*.log
73+
74+
# macOS files
75+
.DS_Store
76+
77+
# other
78+
*.tmpl
79+
*.tmp
80+
*repo_structure*
81+
# PyCharm project files
82+
.idea/
83+
84+
# VS Code project files
85+
.vscode/
86+
87+
# Jupyter Notebook files
88+
.ipynb_checkpoints/
89+
90+
# Logs
91+
*.log
92+
93+
# macOS files
94+
.DS_Store
95+
96+
# other
97+
*.tmpl
98+
*.tmp

MERMAID_DIAGRAM.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Mermaid Diagram
2+
3+
```mermaid
4+
graph TB
5+
%% Repository Structure
6+
subgraph graph_git_repo
7+
root[graph-git-repo]:::folder
8+
root --> gitignore[.gitignore]:::file
9+
root --> README[README.md]:::file
10+
root --> REPO_STRUCTURE[REPO_STRUCTURE.md]:::file
11+
root --> base[base.sh]:::file
12+
root --> tree_to_gpt[tree_to_gpt.py]:::file
13+
end
14+
style graph_git_repo fill:#e0f7fa,stroke:#333,stroke-width:2px;
15+
classDef folder fill:#80deea,stroke:#006064,stroke-width:2px;
16+
classDef file fill:#ffffff,stroke:#004d40,stroke-width:2px;
17+
```

README.md

Lines changed: 100 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,100 @@
1-
# graph-git-repo
1+
# Generate [mermaid](https://github.com/mermaid-js/mermaid) Repo Structure Action
2+
3+
[![GitHub Release](https://img.shields.io/github/v/release/PGSch/graph-git-repo?logo=github)](https://github.com/PGSch/graph-git-repo/releases)
4+
[![GitHub License](https://img.shields.io/github/license/PGSch/graph-git-repo)](https://github.com/PGSch/graph-git-repo/blob/main/LICENSE)
5+
[![Sponsor](https://img.shields.io/badge/sponsor-♥-f06292)](https://github.com/sponsors/PGSch)
6+
[![Twitter Follow](https://img.shields.io/twitter/follow/pgschdev?style=social)](https://twitter.com/intent/follow?screen_name=pgschdev)
7+
8+
## Overview
9+
10+
**Generate Repo Structure Action** is a GitHub Action designed to automatically generate a visual representation of your repository's structure using the `tree` command. This action allows users to exclude specific files or directories using customizable patterns, and outputs a structured Markdown file (`REPO_STRUCTURE.md`) with the current repository's layout.
11+
12+
## Features
13+
14+
- **Customizable Exclusions**: Specify patterns to exclude files or directories from the generated structure.
15+
- **Automatic Markdown Output**: Generates a `REPO_STRUCTURE.md` file with the current repository structure.
16+
- **Easy Integration**: Simply add this action to your workflow to keep your repository structure up-to-date.
17+
18+
## How It Works
19+
20+
1. **Define the Workflow**: Include this action in your GitHub workflow.
21+
2. **Customize Exclusions**: Specify which files or directories to exclude through the `exclude_patterns` input.
22+
3. **Generate Structure**: The action runs a script that creates a `REPO_STRUCTURE.md` file, which is committed back to your repository.
23+
24+
## Usage
25+
26+
To use this action in your repository, include it in your GitHub workflow YAML file. Below is an example configuration:
27+
28+
### Example Workflow
29+
30+
```yaml
31+
name: Generate Repo Structure
32+
33+
on:
34+
push:
35+
branches:
36+
- main
37+
workflow_dispatch:
38+
inputs:
39+
exclude_patterns:
40+
description: 'Patterns to exclude (e.g., ".git|*.log|node_modules")'
41+
required: false
42+
default: '.git|.DS_Store|.idea|*.log|*.tmp|__pycache__'
43+
44+
jobs:
45+
generate-structure:
46+
runs-on: ubuntu-latest
47+
48+
steps:
49+
- uses: actions/checkout@v3
50+
51+
- name: Generate Repo Structure
52+
uses: your-username/[email protected]
53+
with:
54+
exclude_patterns: '${{ github.event.inputs.exclude_patterns }}'
55+
56+
- name: Download Repo Structure
57+
uses: actions/download-artifact@v3
58+
with:
59+
name: repo-structure
60+
path: .
61+
```
62+
63+
### Inputs
64+
65+
| Input Name | Required | Description |
66+
|--------------------|----------|----------------------------------------------------------------------------------------------------------|
67+
| `exclude_patterns` | `false` | Patterns to exclude from the tree structure (e.g., ".git|*.log|node_modules"). Default is provided. |
68+
69+
### Outputs
70+
71+
The action generates a `REPO_STRUCTURE.md` file that contains a Markdown-based representation of the repository's structure, excluding specified files and directories.
72+
73+
### Required Permissions
74+
75+
This action requires the following permissions to function properly:
76+
77+
- **Contents**: `write` (to commit the generated structure back to the repository)
78+
79+
## Advanced Configuration
80+
81+
### Customizing Exclusions
82+
83+
You can specify patterns to exclude directly in your workflow file:
84+
85+
```yaml
86+
with:
87+
exclude_patterns: '.git|node_modules|*.log|*.env'
88+
```
89+
90+
### Triggering the Action
91+
92+
The action will be triggered based on your workflow settings, either automatically on a push or manually through the GitHub UI.
93+
94+
## Contributing
95+
96+
We welcome contributions to improve **Generate Repo Structure Action**! Please open an issue or submit a pull request for any features or bug fixes you’d like to see.
97+
98+
## License
99+
100+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

REPO_STRUCTURE.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Repository Structure
2+
```markdown
3+
graph-git-repo
4+
├── .gitignore
5+
├── README.md
6+
├── REPO_STRUCTURE.md
7+
├── base.sh
8+
└── tree_to_gpt.py
9+
```

base.sh

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/bin/bash
2+
3+
# Define the output file and the directory name
4+
OUTPUT_FILE="REPO_STRUCTURE.md"
5+
REPO_NAME=$(basename "$PWD")
6+
7+
# Read excluded patterns from the input argument or use default ones
8+
EXCLUDE_PATTERNS=${1:-'.git|.DS_Store|.idea|.github|*.sample|logs|objects|refs|pack|exclude|*.txt|*.csv|*.pkl|*.ipynb|__pycache__|venv|.venv'}
9+
DEPTH=${2:-'2'}
10+
11+
# Generate the header with the repository name
12+
echo "# Repository Structure" > $OUTPUT_FILE
13+
echo "\`\`\`markdown" >> "$OUTPUT_FILE"
14+
echo "$REPO_NAME" >> "$OUTPUT_FILE"
15+
16+
# Generate the tree structure, excluding the specified patterns
17+
#tree -a -L "$DEPTH" -n -I "$EXCLUDE_PATTERNS" | tail -n +2 | head -n -1 >> "$OUTPUT_FILE"
18+
tree -a -L "$DEPTH" -n -I "$EXCLUDE_PATTERNS" | sed '1d;$d;$d' | awk 'NR==1{printf "%s", $0; next}{printf "\n%s", $0}' >> "$OUTPUT_FILE"
19+
20+
# Display a message indicating the script has finished
21+
echo "\`\`\`" >> "$OUTPUT_FILE"
22+
echo "Repository structure written to $OUTPUT_FILE"

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
openai

0 commit comments

Comments
 (0)