summaryrefslogtreecommitdiff
path: root/doc/configuration.md
blob: 230cac66fc20cd4714b6fb3738a57f0f4ccfff60 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
# GitSyncer Configuration Guide

## Overview

GitSyncer uses a JSON configuration file to define organizations, repositories, and sync behavior. The configuration file can be placed in several locations or specified via command line.

## Configuration File Locations

GitSyncer looks for configuration files in the following order:

1. Path specified by `--config` flag
2. `./gitsyncer.json` (current directory)
3. `~/.config/gitsyncer/config.json`
4. `~/.gitsyncer.json`

## Configuration Structure

### Basic Structure

```json
{
  "organizations": [
    {
      "host": "git@github.com",
      "name": "myorg",
      "github_token": "ghp_xxxxxxxxxxxx"
    },
    {
      "host": "git@codeberg.org",
      "name": "myorg"
    }
  ],
  "repositories": [
    "repo1",
    "repo2"
  ],
  "exclude_branches": [
    "^temp-",
    "-wip$"
  ],
  "showcase_stats_branches": {
    "foo.zone": "content-gemtext"
  }
}
```

### Configuration Fields

#### organizations (required)
Array of organization objects. At least one organization must be configured.

##### Organization Object
- **host** (string, required): Git host URL
  - Format: `git@hostname` for SSH
  - Format: `file:///path/to/repos` for local repositories
  - Examples: `git@github.com`, `git@codeberg.org`, `git@gitlab.com`
- **name** (string, required): Organization or username
- **github_token** (string, optional): GitHub personal access token
  - Only needed for GitHub organizations
  - Can also be set via environment variable or file
- **codeberg_token** (string, optional): Codeberg personal access token
  - Only needed for Codeberg organizations
  - Can also be set via environment variable or file

#### repositories (optional)
Array of repository names to sync. If empty, use `--sync-codeberg-public` or `--sync-github-public` to discover repositories.

#### exclude_branches (optional)
Array of regex patterns for branches to exclude from synchronization.

#### skip_releases (optional)
Map of repository names to an array of tag names for which releases should not be created on any platform (GitHub and Codeberg). Useful to suppress auto-release for specific historical tags.

Example:
```json
{
  "skip_releases": {
    "fapi": ["0.0.1", "0.0.2"],
    "another-repo": ["v1.0.0"]
  }
}
```

#### showcase_stats_branches (optional)
Map of repository names to the branch that should be used when generating showcase statistics and cached code snippets. This is useful when the primary content for a repo lives on a non-default branch.

Example:
```json
{
  "showcase_stats_branches": {
    "foo.zone": "content-gemtext"
  }
}
```

## Examples

### Minimal Configuration

Sync between GitHub and Codeberg:

```json
{
  "organizations": [
    {"host": "git@github.com", "name": "myusername"},
    {"host": "git@codeberg.org", "name": "myusername"}
  ]
}
```

### With Specific Repositories

```json
{
  "organizations": [
    {"host": "git@github.com", "name": "myorg"},
    {"host": "git@codeberg.org", "name": "myorg"}
  ],
  "repositories": [
    "project1",
    "project2",
    "project3"
  ]
}
```

### With Branch Filtering

```json
{
  "organizations": [
    {"host": "git@github.com", "name": "myorg"},
    {"host": "git@codeberg.org", "name": "myorg"}
  ],
  "repositories": ["myproject"],
  "exclude_branches": [
    "^feature/experimental-",
    "^temp-",
    "-wip$",
    "^old-"
  ],
  "showcase_stats_branches": {
    "foo.zone": "content-gemtext"
  }
}
```

### Multiple Organizations

```json
{
  "organizations": [
    {"host": "git@github.com", "name": "personal"},
    {"host": "git@github.com", "name": "work"},
    {"host": "git@codeberg.org", "name": "personal"},
    {"host": "git@gitlab.com", "name": "personal"}
  ],
  "repositories": ["shared-project"]
}
```

### Local Mirror Configuration

```json
{
  "organizations": [
    {"host": "git@github.com", "name": "myorg"},
    {"host": "file:///home/user/git-mirror", "name": "myorg"}
  ],
  "repositories": ["important-project"]
}
```

## GitHub Token Configuration

GitHub tokens are required for:
- Creating repositories (`--create-github-repos`)
- Listing private repositories
- Higher API rate limits

### Token Sources (in order of precedence)

1. **Configuration file**: `github_token` field in organization object
2. **Environment variable**: `GITHUB_TOKEN`
3. **Token file**: `~/.gitsyncer_github_token`

### Creating a GitHub Token

1. Go to GitHub Settings → Developer settings → Personal access tokens
2. Click "Generate new token (classic)"
3. Select scopes:
   - `repo` (full control of private repositories)
   - `read:org` (read organization membership)
4. Save the token securely

### Setting the Token

#### Method 1: Configuration File
```json
{
  "organizations": [
    {
      "host": "git@github.com",
      "name": "myorg",
      "github_token": "ghp_xxxxxxxxxxxx"
    }
  ]
}
```

#### Method 2: Environment Variable
```bash
export GITHUB_TOKEN="ghp_xxxxxxxxxxxx"
gitsyncer --sync-all
```

#### Method 3: Token File
```bash
echo "ghp_xxxxxxxxxxxx" > ~/.gitsyncer_github_token
chmod 600 ~/.gitsyncer_github_token
```

### Testing Token

```bash
gitsyncer --test-github-token
```

## Codeberg Token Configuration

Codeberg tokens are required for:
- Creating repositories (`--create-codeberg-repos`)
- Listing private repositories

### Token Sources (in order of precedence)

1. **Configuration file**: `codeberg_token` field in organization object
2. **Environment variable**: `CODEBERG_TOKEN`
3. **Token file**: `~/.gitsyncer_codeberg_token`

### Creating a Codeberg Token

1. Go to Codeberg Settings → Applications → Manage Access Tokens
2. Click "Generate New Token"
3. Select scopes:
   - `repository` (full control of repositories)
4. Save the token securely

### Setting the Token

#### Method 1: Configuration File
```json
{
  "organizations": [
    {
      "host": "git@codeberg.org",
      "name": "myorg",
      "codeberg_token": "xxxxxxxxxxxx"
    }
  ]
}
```

#### Method 2: Environment Variable
```bash
export CODEBERG_TOKEN="xxxxxxxxxxxx"
gitsyncer --sync-all
```

#### Method 3: Token File
```bash
echo "xxxxxxxxxxxx" > ~/.gitsyncer_codeberg_token
chmod 600 ~/.gitsyncer_codeberg_token
```

## Branch Exclusion Patterns

The `exclude_branches` field accepts regular expressions to filter out branches from synchronization.

### Common Patterns

- `^temp-` - Exclude branches starting with "temp-"
- `-wip$` - Exclude branches ending with "-wip"
- `^feature/experimental-` - Exclude experimental feature branches
- `^(dev|development)$` - Exclude specific branch names
- `^release/\d+\.` - Exclude release branches (e.g., release/1.x)

### Pattern Testing

To see which branches are excluded:
```bash
gitsyncer --sync repo-name
# Output will show excluded branches and patterns
```

## Best Practices

### 1. Start Simple
Begin with a minimal configuration and add complexity as needed.

### 2. Use Dry Run
Test your configuration with `--dry-run` before actual synchronization:
```bash
gitsyncer --sync-all --dry-run
```

### 3. Secure Your Tokens
- Never commit tokens to version control
- Use environment variables or token files for sensitive data
- Restrict token permissions to minimum required

### 4. Regular Expressions
- Test regex patterns before adding to configuration
- Use online regex testers to validate patterns
- Document complex patterns with comments

### 5. Organization Naming
- Keep organization names consistent across platforms
- Use the same name on GitHub and Codeberg when possible

## Troubleshooting

### Configuration Not Found
```bash
$ gitsyncer --sync myrepo
No configuration file found. Please create one of:
  - ./gitsyncer.json
  - /home/user/.config/gitsyncer/config.json
  - /home/user/.gitsyncer.json
```

**Solution**: Create a configuration file in one of the suggested locations.

### Invalid JSON
```bash
$ gitsyncer --list-orgs
Failed to load configuration: invalid character '}' looking for beginning of object key string
```

**Solution**: Validate your JSON syntax using a JSON validator.

### No Organizations Configured
```bash
$ gitsyncer --sync myrepo
Configuration must have at least one organization
```

**Solution**: Add at least one organization to the `organizations` array.

### Token Issues
```bash
$ gitsyncer --test-github-token
ERROR: Token test failed: authentication failed (401)
```

**Solution**: 
- Verify token is correct and not expired
- Check token has required permissions
- Ensure no extra whitespace in token