|
| 1 | +# Using Git Repository Sources |
| 2 | + |
| 3 | +As an alternative to local files, pgEdge Document Loader can clone and process |
| 4 | +documentation directly from Git repositories. This is useful for: |
| 5 | + |
| 6 | +- Loading documentation from remote repositories without manual cloning |
| 7 | +- Processing specific branches or tags (e.g., versioned documentation) |
| 8 | +- Automated pipelines that fetch and load docs from source control |
| 9 | + |
| 10 | +## Git Source Options |
| 11 | + |
| 12 | +| Option | Required | Description | |
| 13 | +|------------------|----------|--------------------------------------------------| |
| 14 | +| `--git-url` | Yes* | Git repository URL to clone | |
| 15 | +| `--git-branch` | No | Branch to checkout (default: repository default) | |
| 16 | +| `--git-tag` | No | Tag to checkout (mutually exclusive with branch) | |
| 17 | +| `--git-doc-path` | No | Path within repository to process | |
| 18 | +| `--git-clone-dir`| No | Directory to store cloned repositories | |
| 19 | +| `--git-keep-clone`| No | Keep cloned repository after processing | |
| 20 | +| `--git-skip-fetch`| No | Skip fetch if repository already exists | |
| 21 | + |
| 22 | +*Either `--source` or `--git-url` is required, but not both. |
| 23 | + |
| 24 | +## Basic Usage |
| 25 | + |
| 26 | +Clone a repository and process all supported files from the root: |
| 27 | + |
| 28 | +```bash |
| 29 | +pgedge-docloader \ |
| 30 | + --git-url https://github.com/org/docs-repo.git \ |
| 31 | + --db-host localhost \ |
| 32 | + --db-name mydb \ |
| 33 | + --db-user myuser \ |
| 34 | + --db-table documents \ |
| 35 | + --col-doc-content content \ |
| 36 | + --col-file-name filename |
| 37 | +``` |
| 38 | + |
| 39 | +## Processing a Specific Directory |
| 40 | + |
| 41 | +Use `--git-doc-path` to process files from a specific directory within the |
| 42 | +repository: |
| 43 | + |
| 44 | +```bash |
| 45 | +pgedge-docloader \ |
| 46 | + --git-url https://github.com/org/project.git \ |
| 47 | + --git-doc-path docs/api \ |
| 48 | + --db-host localhost \ |
| 49 | + --db-name mydb \ |
| 50 | + --db-user myuser \ |
| 51 | + --db-table documents \ |
| 52 | + --col-doc-content content |
| 53 | +``` |
| 54 | + |
| 55 | +The `--git-doc-path` option supports glob patterns: |
| 56 | + |
| 57 | +```bash |
| 58 | +# Process only markdown files in the docs directory |
| 59 | +pgedge-docloader \ |
| 60 | + --git-url https://github.com/org/project.git \ |
| 61 | + --git-doc-path "docs/**/*.md" \ |
| 62 | + --config config.yml |
| 63 | +``` |
| 64 | + |
| 65 | +## Working with Branches and Tags |
| 66 | + |
| 67 | +### Checkout a Specific Branch |
| 68 | + |
| 69 | +```bash |
| 70 | +pgedge-docloader \ |
| 71 | + --git-url https://github.com/org/docs.git \ |
| 72 | + --git-branch main \ |
| 73 | + --git-doc-path docs \ |
| 74 | + --config config.yml |
| 75 | +``` |
| 76 | + |
| 77 | +### Checkout a Specific Tag |
| 78 | + |
| 79 | +Use tags for versioned documentation: |
| 80 | + |
| 81 | +```bash |
| 82 | +pgedge-docloader \ |
| 83 | + --git-url https://github.com/org/project.git \ |
| 84 | + --git-tag v2.0.0 \ |
| 85 | + --git-doc-path docs \ |
| 86 | + --set-column version="2.0.0" \ |
| 87 | + --config config.yml |
| 88 | +``` |
| 89 | + |
| 90 | +!!! note |
| 91 | + |
| 92 | + `--git-branch` and `--git-tag` are mutually exclusive. You cannot specify |
| 93 | + both options at the same time. |
| 94 | + |
| 95 | +## Persistent Clone Directory |
| 96 | + |
| 97 | +By default, repositories are cloned to a temporary directory and removed after |
| 98 | +processing. For repeated runs, you can specify a persistent clone directory: |
| 99 | + |
| 100 | +```bash |
| 101 | +pgedge-docloader \ |
| 102 | + --git-url https://github.com/org/docs.git \ |
| 103 | + --git-clone-dir /var/cache/docloader/repos \ |
| 104 | + --git-keep-clone \ |
| 105 | + --config config.yml |
| 106 | +``` |
| 107 | + |
| 108 | +On subsequent runs with `--git-skip-fetch`, the tool will reuse the existing |
| 109 | +clone without fetching updates: |
| 110 | + |
| 111 | +```bash |
| 112 | +pgedge-docloader \ |
| 113 | + --git-url https://github.com/org/docs.git \ |
| 114 | + --git-clone-dir /var/cache/docloader/repos \ |
| 115 | + --git-keep-clone \ |
| 116 | + --git-skip-fetch \ |
| 117 | + --config config.yml |
| 118 | +``` |
| 119 | + |
| 120 | +## Configuration File Example |
| 121 | + |
| 122 | +Git source options can also be specified in a configuration file: |
| 123 | + |
| 124 | +```yaml |
| 125 | +# Git source configuration |
| 126 | +git-url: https://github.com/org/docs-repo.git |
| 127 | +git-branch: main |
| 128 | +git-doc-path: docs |
| 129 | +git-clone-dir: /var/cache/docloader/repos |
| 130 | +git-keep-clone: true |
| 131 | + |
| 132 | +# Database configuration |
| 133 | +db-host: localhost |
| 134 | +db-name: mydb |
| 135 | +db-user: myuser |
| 136 | +db-table: documents |
| 137 | + |
| 138 | +# Column mappings |
| 139 | +col-doc-content: content |
| 140 | +col-file-name: filename |
| 141 | +col-doc-title: title |
| 142 | + |
| 143 | +# Custom metadata |
| 144 | +custom-columns: |
| 145 | + source: "git-repo" |
| 146 | + project: "my-project" |
| 147 | +``` |
| 148 | +
|
| 149 | +Then run with: |
| 150 | +
|
| 151 | +```bash |
| 152 | +pgedge-docloader --config config.yml |
| 153 | +``` |
| 154 | + |
| 155 | +## Authentication |
| 156 | + |
| 157 | +### HTTPS URLs |
| 158 | + |
| 159 | +For public repositories, use the HTTPS URL directly: |
| 160 | + |
| 161 | +```bash |
| 162 | +--git-url https://github.com/org/public-repo.git |
| 163 | +``` |
| 164 | + |
| 165 | +For private repositories, you can use a personal access token in the URL: |
| 166 | + |
| 167 | +```bash |
| 168 | +--git-url https://TOKEN@github.com/org/private-repo.git |
| 169 | +``` |
| 170 | + |
| 171 | +Or configure Git credential helpers before running the tool. |
| 172 | + |
| 173 | +### SSH URLs |
| 174 | + |
| 175 | +For SSH authentication, ensure your SSH keys are configured: |
| 176 | + |
| 177 | +```bash |
| 178 | +--git-url git@github.com:org/repo.git |
| 179 | +``` |
| 180 | + |
| 181 | +## Error Handling |
| 182 | + |
| 183 | +The tool will fail with a clear error message if: |
| 184 | + |
| 185 | +- Git is not installed on the system |
| 186 | +- The repository URL is invalid or inaccessible |
| 187 | +- The specified branch or tag does not exist |
| 188 | +- The `--git-doc-path` does not exist in the repository |
| 189 | + |
| 190 | +## Best Practices |
| 191 | + |
| 192 | +1. **Use tags for versioned docs**: When loading documentation for specific |
| 193 | + software versions, use `--git-tag` to ensure consistency. |
| 194 | + |
| 195 | +2. **Cache clones for repeated runs**: Use `--git-clone-dir` and |
| 196 | + `--git-keep-clone` to avoid re-cloning on every run. |
| 197 | + |
| 198 | +3. **Use `--git-skip-fetch` carefully**: Only skip fetching when you're sure |
| 199 | + the local clone is up-to-date. |
| 200 | + |
| 201 | +4. **Set version metadata**: Use `--set-column` to add version information |
| 202 | + when processing tagged releases: |
| 203 | + |
| 204 | + ```bash |
| 205 | + --git-tag v1.2.3 --set-column version="1.2.3" |
| 206 | + ``` |
0 commit comments