itcpr 2.1.3__tar.gz → 2.1.6__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {itcpr-2.1.3/itcpr.egg-info → itcpr-2.1.6}/PKG-INFO +208 -22
- {itcpr-2.1.3 → itcpr-2.1.6}/README.md +206 -19
- {itcpr-2.1.3 → itcpr-2.1.6}/itcpr/__init__.py +1 -1
- {itcpr-2.1.3 → itcpr-2.1.6}/itcpr/api.py +61 -0
- itcpr-2.1.6/itcpr/cli.py +834 -0
- {itcpr-2.1.3 → itcpr-2.1.6}/itcpr/gitops.py +103 -2
- itcpr-2.1.6/itcpr/service.py +327 -0
- {itcpr-2.1.3 → itcpr-2.1.6/itcpr.egg-info}/PKG-INFO +208 -22
- {itcpr-2.1.3 → itcpr-2.1.6}/itcpr.egg-info/SOURCES.txt +1 -0
- {itcpr-2.1.3 → itcpr-2.1.6}/itcpr.egg-info/requires.txt +1 -3
- {itcpr-2.1.3 → itcpr-2.1.6}/pyproject.toml +2 -2
- {itcpr-2.1.3 → itcpr-2.1.6}/setup.py +2 -2
- itcpr-2.1.3/itcpr/cli.py +0 -272
- {itcpr-2.1.3 → itcpr-2.1.6}/LICENSE +0 -0
- {itcpr-2.1.3 → itcpr-2.1.6}/MANIFEST.in +0 -0
- {itcpr-2.1.3 → itcpr-2.1.6}/itcpr/auth.py +0 -0
- {itcpr-2.1.3 → itcpr-2.1.6}/itcpr/config.py +0 -0
- {itcpr-2.1.3 → itcpr-2.1.6}/itcpr/storage.py +0 -0
- {itcpr-2.1.3 → itcpr-2.1.6}/itcpr/sync.py +0 -0
- {itcpr-2.1.3 → itcpr-2.1.6}/itcpr/utils.py +0 -0
- {itcpr-2.1.3 → itcpr-2.1.6}/itcpr.egg-info/dependency_links.txt +0 -0
- {itcpr-2.1.3 → itcpr-2.1.6}/itcpr.egg-info/entry_points.txt +0 -0
- {itcpr-2.1.3 → itcpr-2.1.6}/itcpr.egg-info/top_level.txt +0 -0
- {itcpr-2.1.3 → itcpr-2.1.6}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: itcpr
|
|
3
|
-
Version: 2.1.
|
|
3
|
+
Version: 2.1.6
|
|
4
4
|
Summary: CLI tool for syncing GitHub repositories from ITCPR Cloud
|
|
5
5
|
Home-page: https://itcpr.org
|
|
6
6
|
Author: ITCPR
|
|
@@ -21,12 +21,11 @@ Requires-Dist: click>=8.0.0
|
|
|
21
21
|
Requires-Dist: requests>=2.28.0
|
|
22
22
|
Requires-Dist: keyring>=23.0.0
|
|
23
23
|
Requires-Dist: tomli-w>=1.0.0
|
|
24
|
+
Requires-Dist: PyYAML>=6.0
|
|
24
25
|
Provides-Extra: dev
|
|
25
26
|
Requires-Dist: pytest; extra == "dev"
|
|
26
27
|
Requires-Dist: black; extra == "dev"
|
|
27
28
|
Requires-Dist: flake8; extra == "dev"
|
|
28
|
-
Provides-Extra: yaml
|
|
29
|
-
Requires-Dist: PyYAML>=6.0; extra == "yaml"
|
|
30
29
|
Dynamic: author
|
|
31
30
|
Dynamic: home-page
|
|
32
31
|
Dynamic: license-file
|
|
@@ -39,8 +38,10 @@ A command-line tool for syncing GitHub repositories from ITCPR Cloud to your loc
|
|
|
39
38
|
## Features
|
|
40
39
|
|
|
41
40
|
- 🔐 Device-based authentication with ITCPR Cloud
|
|
41
|
+
- 🆕 Create new repositories in the organization
|
|
42
42
|
- 📦 Automatic repository synchronization
|
|
43
43
|
- 🔄 Manual or continuous sync modes
|
|
44
|
+
- 🚀 Background service daemon (auto-start on boot)
|
|
44
45
|
- 💾 Local SQLite database for metadata tracking
|
|
45
46
|
- 🔒 Secure token storage using OS keyring
|
|
46
47
|
- 🛡️ Safe git operations with conflict detection
|
|
@@ -159,7 +160,44 @@ Or specify a custom path:
|
|
|
159
160
|
itcpr clone paperport-itcpr --path ~/projects/paperport
|
|
160
161
|
```
|
|
161
162
|
|
|
162
|
-
### 5.
|
|
163
|
+
### 5. Initialize a New Repository
|
|
164
|
+
|
|
165
|
+
Create a new repository in the current folder using the project template:
|
|
166
|
+
|
|
167
|
+
```bash
|
|
168
|
+
itcpr init
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
This will:
|
|
172
|
+
- Create a new repository in the organization (using current directory name)
|
|
173
|
+
- Use `ITCPR/project-template` as the template
|
|
174
|
+
- Fetch and copy template files to current directory
|
|
175
|
+
- Add you as an admin collaborator
|
|
176
|
+
- Initialize git repository
|
|
177
|
+
- Set up remote origin
|
|
178
|
+
- Create an initial commit with template files
|
|
179
|
+
|
|
180
|
+
With options:
|
|
181
|
+
|
|
182
|
+
```bash
|
|
183
|
+
# Custom repository name (creates private repo by default)
|
|
184
|
+
itcpr init --name my-new-repo
|
|
185
|
+
|
|
186
|
+
# With description
|
|
187
|
+
itcpr init --name my-repo --description "My awesome project"
|
|
188
|
+
|
|
189
|
+
# Create public repository (default is private)
|
|
190
|
+
itcpr init --public
|
|
191
|
+
|
|
192
|
+
# Initialize and push immediately
|
|
193
|
+
itcpr init --push
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
**Note:**
|
|
197
|
+
- If the repository name already exists in the organization, you'll be prompted to choose a different name.
|
|
198
|
+
- Template files from `ITCPR/project-template` are automatically copied to your directory. Existing files are preserved (not overwritten).
|
|
199
|
+
|
|
200
|
+
### 6. Sync Repositories
|
|
163
201
|
|
|
164
202
|
Sync all cloned repositories:
|
|
165
203
|
|
|
@@ -179,7 +217,53 @@ With custom interval:
|
|
|
179
217
|
itcpr sync --watch --interval 120 # Sync every 2 minutes
|
|
180
218
|
```
|
|
181
219
|
|
|
182
|
-
|
|
220
|
+
**Note:** Watch mode runs in the foreground and will block your terminal. Press `Ctrl+C` to stop.
|
|
221
|
+
|
|
222
|
+
For background operation, use the **service** commands (see below).
|
|
223
|
+
|
|
224
|
+
### 7. Run as Background Service
|
|
225
|
+
|
|
226
|
+
Run sync as a background service that starts automatically:
|
|
227
|
+
|
|
228
|
+
```bash
|
|
229
|
+
# Start service in background
|
|
230
|
+
itcpr service start
|
|
231
|
+
|
|
232
|
+
# Start with custom interval
|
|
233
|
+
itcpr service start --interval 120 # Sync every 2 minutes
|
|
234
|
+
|
|
235
|
+
# Check service status
|
|
236
|
+
itcpr service status
|
|
237
|
+
|
|
238
|
+
# View service logs
|
|
239
|
+
itcpr service logs
|
|
240
|
+
|
|
241
|
+
# Stop service
|
|
242
|
+
itcpr service stop
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
**Install as System Service (Auto-start on boot):**
|
|
246
|
+
|
|
247
|
+
```bash
|
|
248
|
+
# Install service (Linux - requires sudo)
|
|
249
|
+
sudo itcpr service install
|
|
250
|
+
|
|
251
|
+
# Install with custom interval
|
|
252
|
+
sudo itcpr service install --interval 120
|
|
253
|
+
|
|
254
|
+
# On macOS (no sudo needed)
|
|
255
|
+
itcpr service install
|
|
256
|
+
|
|
257
|
+
# On Windows (may require admin)
|
|
258
|
+
itcpr service install
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
After installation:
|
|
262
|
+
- **Linux (systemd):** `sudo systemctl enable itcpr && sudo systemctl start itcpr`
|
|
263
|
+
- **macOS (launchd):** `launchctl load ~/Library/LaunchAgents/org.itcpr.sync.plist`
|
|
264
|
+
- **Windows (Task Scheduler):** The service will start automatically on user logon. To start immediately: `schtasks /Run /TN "ITCPR Sync Service"`
|
|
265
|
+
|
|
266
|
+
### 8. Logout
|
|
183
267
|
|
|
184
268
|
Clear stored credentials:
|
|
185
269
|
|
|
@@ -218,6 +302,50 @@ Clones a repository from GitHub using short-lived installation tokens.
|
|
|
218
302
|
Options:
|
|
219
303
|
- `--path, -p`: Custom local path for the repository
|
|
220
304
|
|
|
305
|
+
### `itcpr init`
|
|
306
|
+
|
|
307
|
+
Creates a new repository in the organization and initializes it in the current folder using the `ITCPR/project-template` template. The repository name defaults to the current directory name, or you can specify a custom name.
|
|
308
|
+
|
|
309
|
+
**Options:**
|
|
310
|
+
- `--name, -n`: Repository name (defaults to current directory name)
|
|
311
|
+
- `--description, -d`: Repository description
|
|
312
|
+
- `--public`: Create a public repository (default: private)
|
|
313
|
+
- `--push`: Push initial commit to remote immediately
|
|
314
|
+
|
|
315
|
+
**What it does:**
|
|
316
|
+
1. Creates a new repository in the organization from `ITCPR/project-template` template via GitHub API
|
|
317
|
+
2. Fetches the template repository (`ITCPR/project-template`)
|
|
318
|
+
3. Copies template files to current directory (preserves existing files)
|
|
319
|
+
4. Adds you (the device owner) as an admin collaborator
|
|
320
|
+
5. Initializes git repository if not already initialized
|
|
321
|
+
6. Sets up remote origin with authentication
|
|
322
|
+
7. Creates an initial commit with template files
|
|
323
|
+
8. Optionally pushes to remote if `--push` is used
|
|
324
|
+
|
|
325
|
+
**Template Behavior:**
|
|
326
|
+
- The repository is created from the `ITCPR/project-template` template repository
|
|
327
|
+
- Template files are automatically copied to your current directory
|
|
328
|
+
- Existing files in the directory are preserved (not overwritten)
|
|
329
|
+
- The `.git` directory from the template is excluded
|
|
330
|
+
|
|
331
|
+
**Example:**
|
|
332
|
+
|
|
333
|
+
```bash
|
|
334
|
+
# Create repo with current directory name (private by default)
|
|
335
|
+
cd my-project
|
|
336
|
+
itcpr init
|
|
337
|
+
|
|
338
|
+
# Create repo with custom name
|
|
339
|
+
itcpr init --name awesome-project --description "My awesome project"
|
|
340
|
+
|
|
341
|
+
# Create public repo and push immediately
|
|
342
|
+
itcpr init --public --push
|
|
343
|
+
```
|
|
344
|
+
|
|
345
|
+
**Error handling:**
|
|
346
|
+
- If the repository name already exists, you'll see: "Repository 'name' already exists in the organization. Please choose a different name."
|
|
347
|
+
- If your GitHub account is not connected, you'll be prompted to connect it first.
|
|
348
|
+
|
|
221
349
|
### `itcpr sync`
|
|
222
350
|
|
|
223
351
|
Synchronizes all cloned repositories. By default, performs a one-time sync.
|
|
@@ -233,22 +361,76 @@ You can configure per-repository sync behavior by creating an `itcpr.yml` file i
|
|
|
233
361
|
```yaml
|
|
234
362
|
sync:
|
|
235
363
|
enabled: true # Enable/disable sync for this repo (default: true)
|
|
236
|
-
auto_commit: true # Auto-commit local changes (default: true)
|
|
237
|
-
auto_push: true # Auto-push local commits (default: true)
|
|
364
|
+
auto_commit: true # Auto-commit uncommitted local changes (default: true)
|
|
365
|
+
auto_push: true # Auto-push local commits to remote (default: true)
|
|
238
366
|
branch: main # Optional: specific branch to sync
|
|
239
367
|
ignore: # Optional: patterns to ignore
|
|
240
368
|
- "*.log"
|
|
241
369
|
- "temp/"
|
|
242
370
|
```
|
|
243
371
|
|
|
244
|
-
**Note:**
|
|
372
|
+
**Note:** `auto_commit` and `auto_push` are independent settings:
|
|
373
|
+
- `auto_commit`: Automatically commits uncommitted changes in your working directory
|
|
374
|
+
- `auto_push`: Automatically pushes local commits to the remote repository
|
|
375
|
+
- If both are enabled (default), the tool will commit uncommitted changes and then push them automatically
|
|
376
|
+
- You can set `auto_commit: true, auto_push: false` to commit locally without pushing
|
|
377
|
+
- If `itcpr.yml` doesn't exist, the tool uses default values (all enabled). The configuration file is optional.
|
|
378
|
+
|
|
379
|
+
### `itcpr service`
|
|
380
|
+
|
|
381
|
+
Manage the sync service as a background daemon.
|
|
382
|
+
|
|
383
|
+
**Commands:**
|
|
384
|
+
- `start`: Start the service in background
|
|
385
|
+
- `stop`: Stop the running service
|
|
386
|
+
- `status`: Show service status and information
|
|
387
|
+
- `logs`: View service logs
|
|
388
|
+
- `install`: Install as system service (auto-start on boot)
|
|
389
|
+
- `uninstall`: Remove system service
|
|
390
|
+
|
|
391
|
+
**Options:**
|
|
392
|
+
- `--interval, -i`: Sync interval in seconds (default: 60)
|
|
393
|
+
- `--foreground, -f`: Run in foreground (don't daemonize)
|
|
394
|
+
- `--user`: User to run service as (for system service installation)
|
|
395
|
+
|
|
396
|
+
**Examples:**
|
|
245
397
|
|
|
246
398
|
```bash
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
399
|
+
# Start service in background
|
|
400
|
+
itcpr service start
|
|
401
|
+
|
|
402
|
+
# Start with custom interval
|
|
403
|
+
itcpr service start --interval 300 # 5 minutes
|
|
404
|
+
|
|
405
|
+
# Check if service is running
|
|
406
|
+
itcpr service status
|
|
407
|
+
|
|
408
|
+
# View recent logs
|
|
409
|
+
itcpr service logs
|
|
410
|
+
|
|
411
|
+
# Install to start on boot (Linux)
|
|
412
|
+
sudo itcpr service install
|
|
413
|
+
|
|
414
|
+
# Install to start on boot (macOS)
|
|
415
|
+
itcpr service install
|
|
416
|
+
|
|
417
|
+
# Install to start on boot (Windows - may require admin)
|
|
418
|
+
itcpr service install
|
|
419
|
+
|
|
420
|
+
# Uninstall system service
|
|
421
|
+
itcpr service uninstall
|
|
250
422
|
```
|
|
251
423
|
|
|
424
|
+
**Service Features:**
|
|
425
|
+
- Runs as background daemon (cross-platform)
|
|
426
|
+
- Automatic restart on failure (when installed as system service)
|
|
427
|
+
- Logs to `~/.itcpr/itcpr-service.log` (or `%USERPROFILE%\.itcpr\itcpr-service.log` on Windows)
|
|
428
|
+
- PID file management
|
|
429
|
+
- System service support:
|
|
430
|
+
- **Linux**: systemd service
|
|
431
|
+
- **macOS**: launchd agent
|
|
432
|
+
- **Windows**: Task Scheduler task
|
|
433
|
+
|
|
252
434
|
## How It Works
|
|
253
435
|
|
|
254
436
|
### Authentication Flow
|
|
@@ -355,6 +537,21 @@ The repository must be assigned to your device in ITCPR Cloud. Make sure you've:
|
|
|
355
537
|
|
|
356
538
|
If the issue persists, contact an administrator.
|
|
357
539
|
|
|
540
|
+
### "Repository already exists" error (init command)
|
|
541
|
+
|
|
542
|
+
When running `itcpr init`, if you see this error, it means a repository with that name already exists in the organization. Choose a different name:
|
|
543
|
+
|
|
544
|
+
```bash
|
|
545
|
+
itcpr init --name different-name
|
|
546
|
+
```
|
|
547
|
+
|
|
548
|
+
### "GitHub account not connected" error (init command)
|
|
549
|
+
|
|
550
|
+
The `init` command requires your GitHub account to be connected. Make sure you've:
|
|
551
|
+
1. Visited [cloud.itcpr.org](https://cloud.itcpr.org)
|
|
552
|
+
2. Connected your GitHub account
|
|
553
|
+
3. Then run `itcpr init` again
|
|
554
|
+
|
|
358
555
|
### Merge Conflicts
|
|
359
556
|
|
|
360
557
|
If a merge conflict is detected during sync:
|
|
@@ -421,17 +618,6 @@ itcpr --help
|
|
|
421
618
|
|
|
422
619
|
Contributions are welcome! Please ensure your code follows the project's style guidelines and includes appropriate tests.
|
|
423
620
|
|
|
424
|
-
## API Endpoints
|
|
425
|
-
|
|
426
|
-
The CLI communicates with these backend endpoints:
|
|
427
|
-
|
|
428
|
-
- `POST /api/device/start` - Start device authentication
|
|
429
|
-
- `GET /api/device/poll` - Poll for authentication approval
|
|
430
|
-
- `POST /api/device/revoke` - Revoke device token
|
|
431
|
-
- `GET /api/agent/me` - Get device/user information
|
|
432
|
-
- `GET /api/agent/repos` - Get assigned repositories
|
|
433
|
-
- `POST /api/agent/token` - Get GitHub installation token
|
|
434
|
-
|
|
435
621
|
## License
|
|
436
622
|
|
|
437
623
|
MIT License - see LICENSE file for details.
|
|
@@ -5,8 +5,10 @@ A command-line tool for syncing GitHub repositories from ITCPR Cloud to your loc
|
|
|
5
5
|
## Features
|
|
6
6
|
|
|
7
7
|
- 🔐 Device-based authentication with ITCPR Cloud
|
|
8
|
+
- 🆕 Create new repositories in the organization
|
|
8
9
|
- 📦 Automatic repository synchronization
|
|
9
10
|
- 🔄 Manual or continuous sync modes
|
|
11
|
+
- 🚀 Background service daemon (auto-start on boot)
|
|
10
12
|
- 💾 Local SQLite database for metadata tracking
|
|
11
13
|
- 🔒 Secure token storage using OS keyring
|
|
12
14
|
- 🛡️ Safe git operations with conflict detection
|
|
@@ -125,7 +127,44 @@ Or specify a custom path:
|
|
|
125
127
|
itcpr clone paperport-itcpr --path ~/projects/paperport
|
|
126
128
|
```
|
|
127
129
|
|
|
128
|
-
### 5.
|
|
130
|
+
### 5. Initialize a New Repository
|
|
131
|
+
|
|
132
|
+
Create a new repository in the current folder using the project template:
|
|
133
|
+
|
|
134
|
+
```bash
|
|
135
|
+
itcpr init
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
This will:
|
|
139
|
+
- Create a new repository in the organization (using current directory name)
|
|
140
|
+
- Use `ITCPR/project-template` as the template
|
|
141
|
+
- Fetch and copy template files to current directory
|
|
142
|
+
- Add you as an admin collaborator
|
|
143
|
+
- Initialize git repository
|
|
144
|
+
- Set up remote origin
|
|
145
|
+
- Create an initial commit with template files
|
|
146
|
+
|
|
147
|
+
With options:
|
|
148
|
+
|
|
149
|
+
```bash
|
|
150
|
+
# Custom repository name (creates private repo by default)
|
|
151
|
+
itcpr init --name my-new-repo
|
|
152
|
+
|
|
153
|
+
# With description
|
|
154
|
+
itcpr init --name my-repo --description "My awesome project"
|
|
155
|
+
|
|
156
|
+
# Create public repository (default is private)
|
|
157
|
+
itcpr init --public
|
|
158
|
+
|
|
159
|
+
# Initialize and push immediately
|
|
160
|
+
itcpr init --push
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
**Note:**
|
|
164
|
+
- If the repository name already exists in the organization, you'll be prompted to choose a different name.
|
|
165
|
+
- Template files from `ITCPR/project-template` are automatically copied to your directory. Existing files are preserved (not overwritten).
|
|
166
|
+
|
|
167
|
+
### 6. Sync Repositories
|
|
129
168
|
|
|
130
169
|
Sync all cloned repositories:
|
|
131
170
|
|
|
@@ -145,7 +184,53 @@ With custom interval:
|
|
|
145
184
|
itcpr sync --watch --interval 120 # Sync every 2 minutes
|
|
146
185
|
```
|
|
147
186
|
|
|
148
|
-
|
|
187
|
+
**Note:** Watch mode runs in the foreground and will block your terminal. Press `Ctrl+C` to stop.
|
|
188
|
+
|
|
189
|
+
For background operation, use the **service** commands (see below).
|
|
190
|
+
|
|
191
|
+
### 7. Run as Background Service
|
|
192
|
+
|
|
193
|
+
Run sync as a background service that starts automatically:
|
|
194
|
+
|
|
195
|
+
```bash
|
|
196
|
+
# Start service in background
|
|
197
|
+
itcpr service start
|
|
198
|
+
|
|
199
|
+
# Start with custom interval
|
|
200
|
+
itcpr service start --interval 120 # Sync every 2 minutes
|
|
201
|
+
|
|
202
|
+
# Check service status
|
|
203
|
+
itcpr service status
|
|
204
|
+
|
|
205
|
+
# View service logs
|
|
206
|
+
itcpr service logs
|
|
207
|
+
|
|
208
|
+
# Stop service
|
|
209
|
+
itcpr service stop
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
**Install as System Service (Auto-start on boot):**
|
|
213
|
+
|
|
214
|
+
```bash
|
|
215
|
+
# Install service (Linux - requires sudo)
|
|
216
|
+
sudo itcpr service install
|
|
217
|
+
|
|
218
|
+
# Install with custom interval
|
|
219
|
+
sudo itcpr service install --interval 120
|
|
220
|
+
|
|
221
|
+
# On macOS (no sudo needed)
|
|
222
|
+
itcpr service install
|
|
223
|
+
|
|
224
|
+
# On Windows (may require admin)
|
|
225
|
+
itcpr service install
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
After installation:
|
|
229
|
+
- **Linux (systemd):** `sudo systemctl enable itcpr && sudo systemctl start itcpr`
|
|
230
|
+
- **macOS (launchd):** `launchctl load ~/Library/LaunchAgents/org.itcpr.sync.plist`
|
|
231
|
+
- **Windows (Task Scheduler):** The service will start automatically on user logon. To start immediately: `schtasks /Run /TN "ITCPR Sync Service"`
|
|
232
|
+
|
|
233
|
+
### 8. Logout
|
|
149
234
|
|
|
150
235
|
Clear stored credentials:
|
|
151
236
|
|
|
@@ -184,6 +269,50 @@ Clones a repository from GitHub using short-lived installation tokens.
|
|
|
184
269
|
Options:
|
|
185
270
|
- `--path, -p`: Custom local path for the repository
|
|
186
271
|
|
|
272
|
+
### `itcpr init`
|
|
273
|
+
|
|
274
|
+
Creates a new repository in the organization and initializes it in the current folder using the `ITCPR/project-template` template. The repository name defaults to the current directory name, or you can specify a custom name.
|
|
275
|
+
|
|
276
|
+
**Options:**
|
|
277
|
+
- `--name, -n`: Repository name (defaults to current directory name)
|
|
278
|
+
- `--description, -d`: Repository description
|
|
279
|
+
- `--public`: Create a public repository (default: private)
|
|
280
|
+
- `--push`: Push initial commit to remote immediately
|
|
281
|
+
|
|
282
|
+
**What it does:**
|
|
283
|
+
1. Creates a new repository in the organization from `ITCPR/project-template` template via GitHub API
|
|
284
|
+
2. Fetches the template repository (`ITCPR/project-template`)
|
|
285
|
+
3. Copies template files to current directory (preserves existing files)
|
|
286
|
+
4. Adds you (the device owner) as an admin collaborator
|
|
287
|
+
5. Initializes git repository if not already initialized
|
|
288
|
+
6. Sets up remote origin with authentication
|
|
289
|
+
7. Creates an initial commit with template files
|
|
290
|
+
8. Optionally pushes to remote if `--push` is used
|
|
291
|
+
|
|
292
|
+
**Template Behavior:**
|
|
293
|
+
- The repository is created from the `ITCPR/project-template` template repository
|
|
294
|
+
- Template files are automatically copied to your current directory
|
|
295
|
+
- Existing files in the directory are preserved (not overwritten)
|
|
296
|
+
- The `.git` directory from the template is excluded
|
|
297
|
+
|
|
298
|
+
**Example:**
|
|
299
|
+
|
|
300
|
+
```bash
|
|
301
|
+
# Create repo with current directory name (private by default)
|
|
302
|
+
cd my-project
|
|
303
|
+
itcpr init
|
|
304
|
+
|
|
305
|
+
# Create repo with custom name
|
|
306
|
+
itcpr init --name awesome-project --description "My awesome project"
|
|
307
|
+
|
|
308
|
+
# Create public repo and push immediately
|
|
309
|
+
itcpr init --public --push
|
|
310
|
+
```
|
|
311
|
+
|
|
312
|
+
**Error handling:**
|
|
313
|
+
- If the repository name already exists, you'll see: "Repository 'name' already exists in the organization. Please choose a different name."
|
|
314
|
+
- If your GitHub account is not connected, you'll be prompted to connect it first.
|
|
315
|
+
|
|
187
316
|
### `itcpr sync`
|
|
188
317
|
|
|
189
318
|
Synchronizes all cloned repositories. By default, performs a one-time sync.
|
|
@@ -199,22 +328,76 @@ You can configure per-repository sync behavior by creating an `itcpr.yml` file i
|
|
|
199
328
|
```yaml
|
|
200
329
|
sync:
|
|
201
330
|
enabled: true # Enable/disable sync for this repo (default: true)
|
|
202
|
-
auto_commit: true # Auto-commit local changes (default: true)
|
|
203
|
-
auto_push: true # Auto-push local commits (default: true)
|
|
331
|
+
auto_commit: true # Auto-commit uncommitted local changes (default: true)
|
|
332
|
+
auto_push: true # Auto-push local commits to remote (default: true)
|
|
204
333
|
branch: main # Optional: specific branch to sync
|
|
205
334
|
ignore: # Optional: patterns to ignore
|
|
206
335
|
- "*.log"
|
|
207
336
|
- "temp/"
|
|
208
337
|
```
|
|
209
338
|
|
|
210
|
-
**Note:**
|
|
339
|
+
**Note:** `auto_commit` and `auto_push` are independent settings:
|
|
340
|
+
- `auto_commit`: Automatically commits uncommitted changes in your working directory
|
|
341
|
+
- `auto_push`: Automatically pushes local commits to the remote repository
|
|
342
|
+
- If both are enabled (default), the tool will commit uncommitted changes and then push them automatically
|
|
343
|
+
- You can set `auto_commit: true, auto_push: false` to commit locally without pushing
|
|
344
|
+
- If `itcpr.yml` doesn't exist, the tool uses default values (all enabled). The configuration file is optional.
|
|
345
|
+
|
|
346
|
+
### `itcpr service`
|
|
347
|
+
|
|
348
|
+
Manage the sync service as a background daemon.
|
|
349
|
+
|
|
350
|
+
**Commands:**
|
|
351
|
+
- `start`: Start the service in background
|
|
352
|
+
- `stop`: Stop the running service
|
|
353
|
+
- `status`: Show service status and information
|
|
354
|
+
- `logs`: View service logs
|
|
355
|
+
- `install`: Install as system service (auto-start on boot)
|
|
356
|
+
- `uninstall`: Remove system service
|
|
357
|
+
|
|
358
|
+
**Options:**
|
|
359
|
+
- `--interval, -i`: Sync interval in seconds (default: 60)
|
|
360
|
+
- `--foreground, -f`: Run in foreground (don't daemonize)
|
|
361
|
+
- `--user`: User to run service as (for system service installation)
|
|
362
|
+
|
|
363
|
+
**Examples:**
|
|
211
364
|
|
|
212
365
|
```bash
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
366
|
+
# Start service in background
|
|
367
|
+
itcpr service start
|
|
368
|
+
|
|
369
|
+
# Start with custom interval
|
|
370
|
+
itcpr service start --interval 300 # 5 minutes
|
|
371
|
+
|
|
372
|
+
# Check if service is running
|
|
373
|
+
itcpr service status
|
|
374
|
+
|
|
375
|
+
# View recent logs
|
|
376
|
+
itcpr service logs
|
|
377
|
+
|
|
378
|
+
# Install to start on boot (Linux)
|
|
379
|
+
sudo itcpr service install
|
|
380
|
+
|
|
381
|
+
# Install to start on boot (macOS)
|
|
382
|
+
itcpr service install
|
|
383
|
+
|
|
384
|
+
# Install to start on boot (Windows - may require admin)
|
|
385
|
+
itcpr service install
|
|
386
|
+
|
|
387
|
+
# Uninstall system service
|
|
388
|
+
itcpr service uninstall
|
|
216
389
|
```
|
|
217
390
|
|
|
391
|
+
**Service Features:**
|
|
392
|
+
- Runs as background daemon (cross-platform)
|
|
393
|
+
- Automatic restart on failure (when installed as system service)
|
|
394
|
+
- Logs to `~/.itcpr/itcpr-service.log` (or `%USERPROFILE%\.itcpr\itcpr-service.log` on Windows)
|
|
395
|
+
- PID file management
|
|
396
|
+
- System service support:
|
|
397
|
+
- **Linux**: systemd service
|
|
398
|
+
- **macOS**: launchd agent
|
|
399
|
+
- **Windows**: Task Scheduler task
|
|
400
|
+
|
|
218
401
|
## How It Works
|
|
219
402
|
|
|
220
403
|
### Authentication Flow
|
|
@@ -321,6 +504,21 @@ The repository must be assigned to your device in ITCPR Cloud. Make sure you've:
|
|
|
321
504
|
|
|
322
505
|
If the issue persists, contact an administrator.
|
|
323
506
|
|
|
507
|
+
### "Repository already exists" error (init command)
|
|
508
|
+
|
|
509
|
+
When running `itcpr init`, if you see this error, it means a repository with that name already exists in the organization. Choose a different name:
|
|
510
|
+
|
|
511
|
+
```bash
|
|
512
|
+
itcpr init --name different-name
|
|
513
|
+
```
|
|
514
|
+
|
|
515
|
+
### "GitHub account not connected" error (init command)
|
|
516
|
+
|
|
517
|
+
The `init` command requires your GitHub account to be connected. Make sure you've:
|
|
518
|
+
1. Visited [cloud.itcpr.org](https://cloud.itcpr.org)
|
|
519
|
+
2. Connected your GitHub account
|
|
520
|
+
3. Then run `itcpr init` again
|
|
521
|
+
|
|
324
522
|
### Merge Conflicts
|
|
325
523
|
|
|
326
524
|
If a merge conflict is detected during sync:
|
|
@@ -387,17 +585,6 @@ itcpr --help
|
|
|
387
585
|
|
|
388
586
|
Contributions are welcome! Please ensure your code follows the project's style guidelines and includes appropriate tests.
|
|
389
587
|
|
|
390
|
-
## API Endpoints
|
|
391
|
-
|
|
392
|
-
The CLI communicates with these backend endpoints:
|
|
393
|
-
|
|
394
|
-
- `POST /api/device/start` - Start device authentication
|
|
395
|
-
- `GET /api/device/poll` - Poll for authentication approval
|
|
396
|
-
- `POST /api/device/revoke` - Revoke device token
|
|
397
|
-
- `GET /api/agent/me` - Get device/user information
|
|
398
|
-
- `GET /api/agent/repos` - Get assigned repositories
|
|
399
|
-
- `POST /api/agent/token` - Get GitHub installation token
|
|
400
|
-
|
|
401
588
|
## License
|
|
402
589
|
|
|
403
590
|
MIT License - see LICENSE file for details.
|
|
@@ -112,4 +112,65 @@ class APIClient:
|
|
|
112
112
|
raise
|
|
113
113
|
except Exception:
|
|
114
114
|
return False
|
|
115
|
+
|
|
116
|
+
def create_repo(self, name: str, description: str = "", private: bool = False, template: Optional[str] = "project-template") -> Dict[str, Any]:
|
|
117
|
+
"""Create a new repository in the organization."""
|
|
118
|
+
use_mock = config.mock_mode or (MOCK_AVAILABLE and _mock_api is not None)
|
|
119
|
+
|
|
120
|
+
payload = {
|
|
121
|
+
"name": name,
|
|
122
|
+
"description": description,
|
|
123
|
+
"visibility": "private" if private else "public"
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
if template:
|
|
127
|
+
payload["template"] = template
|
|
128
|
+
|
|
129
|
+
try:
|
|
130
|
+
response = self._request("POST", "/cloud/app/org/repos", json=payload)
|
|
131
|
+
response.raise_for_status()
|
|
132
|
+
return response.json()
|
|
133
|
+
except requests.HTTPError as e:
|
|
134
|
+
if e.response.status_code == 422:
|
|
135
|
+
# GitHub API returns 422 when repo already exists
|
|
136
|
+
error_data = e.response.json()
|
|
137
|
+
error_message = error_data.get("message", "Repository already exists")
|
|
138
|
+
if "already exists" in error_message.lower() or "name already exists" in error_message.lower():
|
|
139
|
+
raise ValueError(f"Repository '{name}' already exists in the organization. Please choose a different name.")
|
|
140
|
+
raise ValueError(error_message)
|
|
141
|
+
if use_mock and e.response.status_code == 404:
|
|
142
|
+
logger.info("Backend unavailable, using mock API")
|
|
143
|
+
if MOCK_AVAILABLE:
|
|
144
|
+
return _mock_api.create_repo(name, description, private)
|
|
145
|
+
raise
|
|
146
|
+
except (requests.RequestException, Exception) as e:
|
|
147
|
+
if use_mock:
|
|
148
|
+
logger.info("Backend unavailable, using mock API")
|
|
149
|
+
if MOCK_AVAILABLE:
|
|
150
|
+
return _mock_api.create_repo(name, description, private)
|
|
151
|
+
raise
|
|
152
|
+
|
|
153
|
+
def add_collaborator(self, owner: str, repo: str, username: str, permission: str = "admin") -> bool:
|
|
154
|
+
"""Add a collaborator to a repository."""
|
|
155
|
+
use_mock = config.mock_mode or (MOCK_AVAILABLE and _mock_api is not None)
|
|
156
|
+
|
|
157
|
+
payload = {"permission": permission}
|
|
158
|
+
|
|
159
|
+
try:
|
|
160
|
+
response = self._request("PUT", f"/cloud/app/repos/{owner}/{repo}/collaborators/{username}", json=payload)
|
|
161
|
+
response.raise_for_status()
|
|
162
|
+
return True
|
|
163
|
+
except requests.HTTPError as e:
|
|
164
|
+
if use_mock and e.response.status_code == 404:
|
|
165
|
+
logger.info("Backend unavailable, using mock API")
|
|
166
|
+
# Mock would silently succeed
|
|
167
|
+
return True
|
|
168
|
+
logger.warning(f"Failed to add collaborator: {e}")
|
|
169
|
+
raise
|
|
170
|
+
except (requests.RequestException, Exception) as e:
|
|
171
|
+
if use_mock:
|
|
172
|
+
logger.info("Backend unavailable, using mock API")
|
|
173
|
+
return True
|
|
174
|
+
logger.warning(f"Failed to add collaborator: {e}")
|
|
175
|
+
raise
|
|
115
176
|
|