gitwebhooks 2.1.4__tar.gz → 2.3.0__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.
Files changed (115) hide show
  1. {gitwebhooks-2.1.4 → gitwebhooks-2.3.0}/CLAUDE.md +14 -1
  2. {gitwebhooks-2.1.4 → gitwebhooks-2.3.0}/PKG-INFO +71 -14
  3. {gitwebhooks-2.1.4 → gitwebhooks-2.3.0}/README.md +70 -13
  4. {gitwebhooks-2.1.4 → gitwebhooks-2.3.0}/README.zh.md +70 -13
  5. {gitwebhooks-2.1.4 → gitwebhooks-2.3.0}/gitwebhooks/__init__.py +1 -1
  6. gitwebhooks-2.3.0/gitwebhooks/cli/__init__.py +203 -0
  7. gitwebhooks-2.3.0/gitwebhooks/cli/help.py +155 -0
  8. {gitwebhooks-2.1.4 → gitwebhooks-2.3.0}/gitwebhooks/cli/prompts.py +48 -1
  9. gitwebhooks-2.3.0/gitwebhooks/cli/serve.py +151 -0
  10. {gitwebhooks-2.1.4 → gitwebhooks-2.3.0}/gitwebhooks/cli/service.py +81 -7
  11. gitwebhooks-2.3.0/gitwebhooks/main/__init__.py +254 -0
  12. gitwebhooks-2.3.0/gitwebhooks/main/version.py +24 -0
  13. {gitwebhooks-2.1.4 → gitwebhooks-2.3.0}/gitwebhooks/models/__init__.py +2 -0
  14. gitwebhooks-2.3.0/gitwebhooks/models/config.py +74 -0
  15. {gitwebhooks-2.1.4 → gitwebhooks-2.3.0}/gitwebhooks/utils/constants.py +49 -0
  16. {gitwebhooks-2.1.4 → gitwebhooks-2.3.0}/gitwebhooks/utils/systemd.py +3 -3
  17. {gitwebhooks-2.1.4 → gitwebhooks-2.3.0}/gitwebhooks.egg-info/PKG-INFO +71 -14
  18. {gitwebhooks-2.1.4 → gitwebhooks-2.3.0}/gitwebhooks.egg-info/SOURCES.txt +14 -0
  19. {gitwebhooks-2.1.4 → gitwebhooks-2.3.0}/pyproject.toml +1 -1
  20. gitwebhooks-2.3.0/tests/integration/test_config_discovery.py +336 -0
  21. gitwebhooks-2.3.0/tests/unit/test_config_level.py +105 -0
  22. gitwebhooks-2.3.0/tests/unit/test_install_service_logic.py +251 -0
  23. gitwebhooks-2.3.0/tests/unit/test_main.py +341 -0
  24. gitwebhooks-2.3.0/tests/unit/test_prompts_config_level.py +168 -0
  25. gitwebhooks-2.3.0/tests/unit/test_service_install_context.py +145 -0
  26. gitwebhooks-2.1.4/gitwebhooks/cli/__init__.py +0 -107
  27. gitwebhooks-2.1.4/gitwebhooks/main/__init__.py +0 -117
  28. {gitwebhooks-2.1.4 → gitwebhooks-2.3.0}/.editorconfig +0 -0
  29. {gitwebhooks-2.1.4 → gitwebhooks-2.3.0}/LICENSE +0 -0
  30. {gitwebhooks-2.1.4 → gitwebhooks-2.3.0}/MANIFEST.in +0 -0
  31. {gitwebhooks-2.1.4 → gitwebhooks-2.3.0}/doc/custom-body.png +0 -0
  32. {gitwebhooks-2.1.4 → gitwebhooks-2.3.0}/doc/custom-header.png +0 -0
  33. {gitwebhooks-2.1.4 → gitwebhooks-2.3.0}/doc/custom-response.png +0 -0
  34. {gitwebhooks-2.1.4 → gitwebhooks-2.3.0}/doc/gitee-success.png +0 -0
  35. {gitwebhooks-2.1.4 → gitwebhooks-2.3.0}/doc/gitee.png +0 -0
  36. {gitwebhooks-2.1.4 → gitwebhooks-2.3.0}/doc/github-success.png +0 -0
  37. {gitwebhooks-2.1.4 → gitwebhooks-2.3.0}/doc/github.png +0 -0
  38. {gitwebhooks-2.1.4 → gitwebhooks-2.3.0}/doc/gitlab-success.png +0 -0
  39. {gitwebhooks-2.1.4 → gitwebhooks-2.3.0}/doc/gitlab.png +0 -0
  40. {gitwebhooks-2.1.4 → gitwebhooks-2.3.0}/doc/install.png +0 -0
  41. {gitwebhooks-2.1.4 → gitwebhooks-2.3.0}/doc/uninstall.png +0 -0
  42. {gitwebhooks-2.1.4 → gitwebhooks-2.3.0}/gitwebhooks/__main__.py +0 -0
  43. {gitwebhooks-2.1.4 → gitwebhooks-2.3.0}/gitwebhooks/auth/__init__.py +0 -0
  44. {gitwebhooks-2.1.4 → gitwebhooks-2.3.0}/gitwebhooks/auth/custom.py +0 -0
  45. {gitwebhooks-2.1.4 → gitwebhooks-2.3.0}/gitwebhooks/auth/factory.py +0 -0
  46. {gitwebhooks-2.1.4 → gitwebhooks-2.3.0}/gitwebhooks/auth/gitee.py +0 -0
  47. {gitwebhooks-2.1.4 → gitwebhooks-2.3.0}/gitwebhooks/auth/github.py +0 -0
  48. {gitwebhooks-2.1.4 → gitwebhooks-2.3.0}/gitwebhooks/auth/gitlab.py +0 -0
  49. {gitwebhooks-2.1.4 → gitwebhooks-2.3.0}/gitwebhooks/auth/verifier.py +0 -0
  50. {gitwebhooks-2.1.4 → gitwebhooks-2.3.0}/gitwebhooks/cli/config.py +0 -0
  51. {gitwebhooks-2.1.4 → gitwebhooks-2.3.0}/gitwebhooks/cli/init_wizard.py +0 -0
  52. {gitwebhooks-2.1.4 → gitwebhooks-2.3.0}/gitwebhooks/config/__init__.py +0 -0
  53. {gitwebhooks-2.1.4 → gitwebhooks-2.3.0}/gitwebhooks/config/loader.py +0 -0
  54. {gitwebhooks-2.1.4 → gitwebhooks-2.3.0}/gitwebhooks/config/models.py +0 -0
  55. {gitwebhooks-2.1.4 → gitwebhooks-2.3.0}/gitwebhooks/config/registry.py +0 -0
  56. {gitwebhooks-2.1.4 → gitwebhooks-2.3.0}/gitwebhooks/config/server.py +0 -0
  57. {gitwebhooks-2.1.4 → gitwebhooks-2.3.0}/gitwebhooks/handlers/__init__.py +0 -0
  58. {gitwebhooks-2.1.4 → gitwebhooks-2.3.0}/gitwebhooks/handlers/base.py +0 -0
  59. {gitwebhooks-2.1.4 → gitwebhooks-2.3.0}/gitwebhooks/handlers/custom.py +0 -0
  60. {gitwebhooks-2.1.4 → gitwebhooks-2.3.0}/gitwebhooks/handlers/factory.py +0 -0
  61. {gitwebhooks-2.1.4 → gitwebhooks-2.3.0}/gitwebhooks/handlers/gitee.py +0 -0
  62. {gitwebhooks-2.1.4 → gitwebhooks-2.3.0}/gitwebhooks/handlers/github.py +0 -0
  63. {gitwebhooks-2.1.4 → gitwebhooks-2.3.0}/gitwebhooks/handlers/gitlab.py +0 -0
  64. {gitwebhooks-2.1.4 → gitwebhooks-2.3.0}/gitwebhooks/handlers/request.py +0 -0
  65. {gitwebhooks-2.1.4 → gitwebhooks-2.3.0}/gitwebhooks/logging/__init__.py +0 -0
  66. {gitwebhooks-2.1.4 → gitwebhooks-2.3.0}/gitwebhooks/logging/setup.py +0 -0
  67. {gitwebhooks-2.1.4 → gitwebhooks-2.3.0}/gitwebhooks/main/__main__.py +0 -0
  68. {gitwebhooks-2.1.4 → gitwebhooks-2.3.0}/gitwebhooks/models/provider.py +0 -0
  69. {gitwebhooks-2.1.4 → gitwebhooks-2.3.0}/gitwebhooks/models/request.py +0 -0
  70. {gitwebhooks-2.1.4 → gitwebhooks-2.3.0}/gitwebhooks/models/result.py +0 -0
  71. {gitwebhooks-2.1.4 → gitwebhooks-2.3.0}/gitwebhooks/server.py +0 -0
  72. {gitwebhooks-2.1.4 → gitwebhooks-2.3.0}/gitwebhooks/utils/__init__.py +0 -0
  73. {gitwebhooks-2.1.4 → gitwebhooks-2.3.0}/gitwebhooks/utils/exceptions.py +0 -0
  74. {gitwebhooks-2.1.4 → gitwebhooks-2.3.0}/gitwebhooks/utils/executor.py +0 -0
  75. {gitwebhooks-2.1.4 → gitwebhooks-2.3.0}/gitwebhooks.egg-info/dependency_links.txt +0 -0
  76. {gitwebhooks-2.1.4 → gitwebhooks-2.3.0}/gitwebhooks.egg-info/entry_points.txt +0 -0
  77. {gitwebhooks-2.1.4 → gitwebhooks-2.3.0}/gitwebhooks.egg-info/requires.txt +0 -0
  78. {gitwebhooks-2.1.4 → gitwebhooks-2.3.0}/gitwebhooks.egg-info/top_level.txt +0 -0
  79. {gitwebhooks-2.1.4 → gitwebhooks-2.3.0}/gitwebhooks.ini.sample +0 -0
  80. {gitwebhooks-2.1.4 → gitwebhooks-2.3.0}/setup.cfg +0 -0
  81. {gitwebhooks-2.1.4 → gitwebhooks-2.3.0}/tests/__init__.py +0 -0
  82. {gitwebhooks-2.1.4 → gitwebhooks-2.3.0}/tests/__main__.py +0 -0
  83. {gitwebhooks-2.1.4 → gitwebhooks-2.3.0}/tests/conftest.py +0 -0
  84. {gitwebhooks-2.1.4 → gitwebhooks-2.3.0}/tests/fixtures/__init__.py +0 -0
  85. {gitwebhooks-2.1.4 → gitwebhooks-2.3.0}/tests/fixtures/custom_payloads.py +0 -0
  86. {gitwebhooks-2.1.4 → gitwebhooks-2.3.0}/tests/fixtures/gitee_payloads.py +0 -0
  87. {gitwebhooks-2.1.4 → gitwebhooks-2.3.0}/tests/fixtures/github_payloads.py +0 -0
  88. {gitwebhooks-2.1.4 → gitwebhooks-2.3.0}/tests/fixtures/gitlab_payloads.py +0 -0
  89. {gitwebhooks-2.1.4 → gitwebhooks-2.3.0}/tests/fixtures/signature_builder.py +0 -0
  90. {gitwebhooks-2.1.4 → gitwebhooks-2.3.0}/tests/integration/__init__.py +0 -0
  91. {gitwebhooks-2.1.4 → gitwebhooks-2.3.0}/tests/integration/test_command_execution.py +0 -0
  92. {gitwebhooks-2.1.4 → gitwebhooks-2.3.0}/tests/integration/test_config_view_integration.py +0 -0
  93. {gitwebhooks-2.1.4 → gitwebhooks-2.3.0}/tests/integration/test_custom_webhook.py +0 -0
  94. {gitwebhooks-2.1.4 → gitwebhooks-2.3.0}/tests/integration/test_edge_cases.py +0 -0
  95. {gitwebhooks-2.1.4 → gitwebhooks-2.3.0}/tests/integration/test_gitee_webhook.py +0 -0
  96. {gitwebhooks-2.1.4 → gitwebhooks-2.3.0}/tests/integration/test_github_webhook.py +0 -0
  97. {gitwebhooks-2.1.4 → gitwebhooks-2.3.0}/tests/integration/test_gitlab_webhook.py +0 -0
  98. {gitwebhooks-2.1.4 → gitwebhooks-2.3.0}/tests/test_auth/__init__.py +0 -0
  99. {gitwebhooks-2.1.4 → gitwebhooks-2.3.0}/tests/test_config/__init__.py +0 -0
  100. {gitwebhooks-2.1.4 → gitwebhooks-2.3.0}/tests/test_handlers/__init__.py +0 -0
  101. {gitwebhooks-2.1.4 → gitwebhooks-2.3.0}/tests/test_integration/__init__.py +0 -0
  102. {gitwebhooks-2.1.4 → gitwebhooks-2.3.0}/tests/unit/__init__.py +0 -0
  103. {gitwebhooks-2.1.4 → gitwebhooks-2.3.0}/tests/unit/cli/__init__.py +0 -0
  104. {gitwebhooks-2.1.4 → gitwebhooks-2.3.0}/tests/unit/cli/test_config_view.py +0 -0
  105. {gitwebhooks-2.1.4 → gitwebhooks-2.3.0}/tests/unit/cli/test_init_wizard.py +0 -0
  106. {gitwebhooks-2.1.4 → gitwebhooks-2.3.0}/tests/unit/test_config_loading.py +0 -0
  107. {gitwebhooks-2.1.4 → gitwebhooks-2.3.0}/tests/unit/test_data_parsing.py +0 -0
  108. {gitwebhooks-2.1.4 → gitwebhooks-2.3.0}/tests/unit/test_provider_detection.py +0 -0
  109. {gitwebhooks-2.1.4 → gitwebhooks-2.3.0}/tests/unit/test_request_handler.py +0 -0
  110. {gitwebhooks-2.1.4 → gitwebhooks-2.3.0}/tests/unit/test_signature_verification.py +0 -0
  111. {gitwebhooks-2.1.4 → gitwebhooks-2.3.0}/tests/utils/__init__.py +0 -0
  112. {gitwebhooks-2.1.4 → gitwebhooks-2.3.0}/tests/utils/certificate_generator.py +0 -0
  113. {gitwebhooks-2.1.4 → gitwebhooks-2.3.0}/tests/utils/coverage_runner.py +0 -0
  114. {gitwebhooks-2.1.4 → gitwebhooks-2.3.0}/tests/utils/http_client.py +0 -0
  115. {gitwebhooks-2.1.4 → gitwebhooks-2.3.0}/tests/utils/server_manager.py +0 -0
@@ -42,7 +42,7 @@ sudo gitwebhooks-cli service uninstall
42
42
  # 方式1: 使用模块入口
43
43
  python3 -m gitwebhooks.cli -c /path/to/config.ini
44
44
 
45
- # 方式2: 使用 CLI 工具(使用默认配置)
45
+ # 方式2: 使用 CLI 工具(自动查找配置文件)
46
46
  gitwebhooks-cli
47
47
 
48
48
  # 方式3: 指定配置文件
@@ -55,6 +55,14 @@ systemctl restart gitwebhooks
55
55
  systemctl status gitwebhooks
56
56
  ```
57
57
 
58
+ **配置文件自动查找**:
59
+ - 不指定 `-c` 参数时,系统按优先级自动查找配置文件:
60
+ 1. `~/.gitwebhooks.ini`(用户级,最高优先级)
61
+ 2. `/usr/local/etc/gitwebhooks.ini`(本地级)
62
+ 3. `/etc/gitwebhooks.ini`(系统级)
63
+ - 启动时会显示正在使用的配置文件路径
64
+ - 找不到配置文件时显示友好的错误消息
65
+
58
66
  ### 测试开发
59
67
  ```bash
60
68
  # 直接运行(开发模式)
@@ -292,6 +300,11 @@ gitwebhooks/
292
300
  - INI 配置文件,systemd 服务单元文件 (001-install-method-guidance)
293
301
  - Python 3.7+ (项目要求) + Python 标准库仅(无外部依赖) (001-fix-config-init-bug)
294
302
  - INI 配置文件 (configparser) (001-fix-config-init-bug)
303
+ - Python 3.7+ (项目要求) + Python 标准库(pathlib, configparser, argparse) (001-config-priority)
304
+ - Python 3.6+ (与项目要求一致,实际支持 3.6-3.14) + argparse (Python 标准库) (002-cli-commands-refactor)
305
+ - N/A (CLI 重构,不涉及存储) (002-cli-commands-refactor)
306
+ - Python 3.6+(项目要求),实际支持 3.6-3.14 + Python 标准库 `argparse`(命令行参数解析) (002-cli-commands-refactor)
307
+ - N/A(CLI 重构,不涉及存储) (002-cli-commands-refactor)
295
308
 
296
309
  ## Recent Changes
297
310
  - 001-config-init-wizard: 添加 `config init` 交互式向导,支持配置级别选择、平台配置和仓库配置
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: gitwebhooks
3
- Version: 2.1.4
3
+ Version: 2.3.0
4
4
  Summary: A lightweight Git webhook server for automated deployment supporting GitHub, Gitee, GitLab, and custom webhooks
5
5
  Author-email: Troy Tse <troy@holyhi.net>
6
6
  Maintainer-email: Troy Tse <troy@holyhi.net>
@@ -169,28 +169,40 @@ This will create a configuration file with secure permissions (0600).
169
169
  The service installation command automatically detects your installation type (pipx, venv, or system) and generates the appropriate service file.
170
170
 
171
171
  ```bash
172
- # Install and start as a systemd service
173
- sudo gitwebhooks-cli service install
172
+ # Install and start as a systemd service (interactive config level selection)
173
+ sudo gitwebhooks-cli serve install
174
+
175
+ # Install with specific config level (skip interactive selection)
176
+ sudo gitwebhooks-cli serve install --config-level user # User level (~/.gitwebhooks.ini)
177
+ sudo gitwebhooks-cli serve install --config-level local # Local level (/usr/local/etc/gitwebhooks.ini)
178
+ sudo gitwebhooks-cli serve install --config-level system # System level (/etc/gitwebhooks.ini)
179
+
180
+ # Use custom config file (backward compatibility)
181
+ sudo gitwebhooks-cli serve install -c /path/to/config.ini
174
182
 
175
183
  # Preview service file without installing (dry-run mode)
176
- sudo gitwebhooks-cli service install --dry-run
184
+ sudo gitwebhooks-cli serve install --dry-run
185
+ sudo gitwebhooks-cli serve install --config-level local --dry-run # Preview specific level
177
186
 
178
187
  # Install with verbose output
179
- sudo gitwebhooks-cli service install --verbose
180
- sudo gitwebhooks-cli service install -v # Basic verbosity
181
- sudo gitwebhooks-cli service install -vv # Extra verbosity
188
+ sudo gitwebhooks-cli serve install --verbose
182
189
 
183
190
  # Force overwrite existing service
184
- sudo gitwebhooks-cli service install --force
191
+ sudo gitwebhooks-cli serve install --force
185
192
 
186
193
  # Uninstall the service
187
- sudo gitwebhooks-cli service uninstall
194
+ sudo gitwebhooks-cli serve uninstall
188
195
  ```
189
196
 
197
+ **Configuration levels**:
198
+ - **user**: `~/.gitwebhooks.ini` - Single user configuration, highest priority
199
+ - **local**: `/usr/local/etc/gitwebhooks.ini` - Local system configuration, medium priority
200
+ - **system**: `/etc/gitwebhooks.ini` - Global system configuration, lowest priority
201
+
190
202
  **Service file auto-detection**:
191
203
  - **pipx installation**: Uses `gitwebhooks-cli` command directly
192
- - **venv/virtualenv**: Uses `python -m gitwebhooks.cli` with environment's Python
193
- - **System pip**: Uses system Python with `python -m gitwebhooks.cli`
204
+ - **venv/virtualenv**: Uses `python -m gitwebhooks.main` with environment's Python
205
+ - **System pip**: Uses system Python with `python -m gitwebhooks.main`
194
206
  - **conda**: Not supported - installation will be refused with clear error message
195
207
 
196
208
  ### Manual Installation
@@ -208,7 +220,14 @@ sudo ln "$(pwd)/gitwebhooks-cli" /usr/local/bin/gitwebhooks-cli
208
220
  ### Verify Installation
209
221
 
210
222
  ```bash
211
- gitwebhooks-cli --help
223
+ # Show version
224
+ gitwebhooks-cli -v
225
+
226
+ # Show help
227
+ gitwebhooks-cli help
228
+
229
+ # View configuration
230
+ gitwebhooks-cli config view
212
231
  ```
213
232
 
214
233
  ## Migrating from System pip Installation
@@ -291,9 +310,47 @@ pip uninstall gitwebhooks
291
310
 
292
311
  ## Usage
293
312
 
313
+ ### Configuration File Auto-Discovery
314
+
315
+ The `gitwebhooks-cli` automatically searches for configuration files in the following order (priority):
316
+
317
+ 1. **User level**: `~/.gitwebhooks.ini` (highest priority)
318
+ 2. **Local level**: `/usr/local/etc/gitwebhooks.ini`
319
+ 3. **System level**: `/etc/gitwebhooks.ini` (lowest priority)
320
+
321
+ You can run `gitwebhooks-cli` without specifying `-c` parameter, and it will automatically use the first existing configuration file.
322
+
323
+ ```bash
324
+ # Auto-discover and use configuration file
325
+ gitwebhooks-cli
326
+
327
+ # The server will display which config file is being used
328
+ # Using configuration file: /home/user/.gitwebhooks.ini
329
+ ```
330
+
331
+ If you want to use a specific configuration file, use the `-c` parameter:
332
+
333
+ ```bash
334
+ # Use a specific configuration file
335
+ gitwebhooks-cli -c /path/to/custom.ini
336
+ ```
337
+
338
+ If no configuration file is found, a friendly error message will display all searched paths:
339
+
340
+ ```
341
+ Error: Configuration file not found.
342
+ Searched paths:
343
+ 1. /home/user/.gitwebhooks.ini
344
+ 2. /usr/local/etc/gitwebhooks.ini
345
+ 3. /etc/gitwebhooks.ini
346
+
347
+ You can create a configuration file using:
348
+ gitwebhooks-cli config init
349
+ ```
350
+
294
351
  ### 1. Configure Repository
295
352
 
296
- Edit `~/.gitwebhook.ini`:
353
+ Edit your configuration file (e.g., `~/.gitwebhooks.ini`):
297
354
 
298
355
  ```ini
299
356
  [your_name/repository]
@@ -307,7 +364,7 @@ cmd=git fetch --all && git reset --hard origin/master && git pull
307
364
  # If running as a service
308
365
  systemctl restart gitwebhooks
309
366
 
310
- # Or run directly:
367
+ # Or run directly (auto-discovers config file):
311
368
  gitwebhooks-cli
312
369
  ```
313
370
 
@@ -129,28 +129,40 @@ This will create a configuration file with secure permissions (0600).
129
129
  The service installation command automatically detects your installation type (pipx, venv, or system) and generates the appropriate service file.
130
130
 
131
131
  ```bash
132
- # Install and start as a systemd service
133
- sudo gitwebhooks-cli service install
132
+ # Install and start as a systemd service (interactive config level selection)
133
+ sudo gitwebhooks-cli serve install
134
+
135
+ # Install with specific config level (skip interactive selection)
136
+ sudo gitwebhooks-cli serve install --config-level user # User level (~/.gitwebhooks.ini)
137
+ sudo gitwebhooks-cli serve install --config-level local # Local level (/usr/local/etc/gitwebhooks.ini)
138
+ sudo gitwebhooks-cli serve install --config-level system # System level (/etc/gitwebhooks.ini)
139
+
140
+ # Use custom config file (backward compatibility)
141
+ sudo gitwebhooks-cli serve install -c /path/to/config.ini
134
142
 
135
143
  # Preview service file without installing (dry-run mode)
136
- sudo gitwebhooks-cli service install --dry-run
144
+ sudo gitwebhooks-cli serve install --dry-run
145
+ sudo gitwebhooks-cli serve install --config-level local --dry-run # Preview specific level
137
146
 
138
147
  # Install with verbose output
139
- sudo gitwebhooks-cli service install --verbose
140
- sudo gitwebhooks-cli service install -v # Basic verbosity
141
- sudo gitwebhooks-cli service install -vv # Extra verbosity
148
+ sudo gitwebhooks-cli serve install --verbose
142
149
 
143
150
  # Force overwrite existing service
144
- sudo gitwebhooks-cli service install --force
151
+ sudo gitwebhooks-cli serve install --force
145
152
 
146
153
  # Uninstall the service
147
- sudo gitwebhooks-cli service uninstall
154
+ sudo gitwebhooks-cli serve uninstall
148
155
  ```
149
156
 
157
+ **Configuration levels**:
158
+ - **user**: `~/.gitwebhooks.ini` - Single user configuration, highest priority
159
+ - **local**: `/usr/local/etc/gitwebhooks.ini` - Local system configuration, medium priority
160
+ - **system**: `/etc/gitwebhooks.ini` - Global system configuration, lowest priority
161
+
150
162
  **Service file auto-detection**:
151
163
  - **pipx installation**: Uses `gitwebhooks-cli` command directly
152
- - **venv/virtualenv**: Uses `python -m gitwebhooks.cli` with environment's Python
153
- - **System pip**: Uses system Python with `python -m gitwebhooks.cli`
164
+ - **venv/virtualenv**: Uses `python -m gitwebhooks.main` with environment's Python
165
+ - **System pip**: Uses system Python with `python -m gitwebhooks.main`
154
166
  - **conda**: Not supported - installation will be refused with clear error message
155
167
 
156
168
  ### Manual Installation
@@ -168,7 +180,14 @@ sudo ln "$(pwd)/gitwebhooks-cli" /usr/local/bin/gitwebhooks-cli
168
180
  ### Verify Installation
169
181
 
170
182
  ```bash
171
- gitwebhooks-cli --help
183
+ # Show version
184
+ gitwebhooks-cli -v
185
+
186
+ # Show help
187
+ gitwebhooks-cli help
188
+
189
+ # View configuration
190
+ gitwebhooks-cli config view
172
191
  ```
173
192
 
174
193
  ## Migrating from System pip Installation
@@ -251,9 +270,47 @@ pip uninstall gitwebhooks
251
270
 
252
271
  ## Usage
253
272
 
273
+ ### Configuration File Auto-Discovery
274
+
275
+ The `gitwebhooks-cli` automatically searches for configuration files in the following order (priority):
276
+
277
+ 1. **User level**: `~/.gitwebhooks.ini` (highest priority)
278
+ 2. **Local level**: `/usr/local/etc/gitwebhooks.ini`
279
+ 3. **System level**: `/etc/gitwebhooks.ini` (lowest priority)
280
+
281
+ You can run `gitwebhooks-cli` without specifying `-c` parameter, and it will automatically use the first existing configuration file.
282
+
283
+ ```bash
284
+ # Auto-discover and use configuration file
285
+ gitwebhooks-cli
286
+
287
+ # The server will display which config file is being used
288
+ # Using configuration file: /home/user/.gitwebhooks.ini
289
+ ```
290
+
291
+ If you want to use a specific configuration file, use the `-c` parameter:
292
+
293
+ ```bash
294
+ # Use a specific configuration file
295
+ gitwebhooks-cli -c /path/to/custom.ini
296
+ ```
297
+
298
+ If no configuration file is found, a friendly error message will display all searched paths:
299
+
300
+ ```
301
+ Error: Configuration file not found.
302
+ Searched paths:
303
+ 1. /home/user/.gitwebhooks.ini
304
+ 2. /usr/local/etc/gitwebhooks.ini
305
+ 3. /etc/gitwebhooks.ini
306
+
307
+ You can create a configuration file using:
308
+ gitwebhooks-cli config init
309
+ ```
310
+
254
311
  ### 1. Configure Repository
255
312
 
256
- Edit `~/.gitwebhook.ini`:
313
+ Edit your configuration file (e.g., `~/.gitwebhooks.ini`):
257
314
 
258
315
  ```ini
259
316
  [your_name/repository]
@@ -267,7 +324,7 @@ cmd=git fetch --all && git reset --hard origin/master && git pull
267
324
  # If running as a service
268
325
  systemctl restart gitwebhooks
269
326
 
270
- # Or run directly:
327
+ # Or run directly (auto-discovers config file):
271
328
  gitwebhooks-cli
272
329
  ```
273
330
 
@@ -129,28 +129,40 @@ sudo gitwebhooks-cli config init system # 系统级(/etc/gitwebhooks.ini,需
129
129
  服务安装命令会自动检测您的安装类型(pipx、venv 或系统)并生成相应的服务文件。
130
130
 
131
131
  ```bash
132
- # 安装并启动为 systemd 服务
133
- sudo gitwebhooks-cli service install
132
+ # 安装并启动为 systemd 服务(交互式选择配置级别)
133
+ sudo gitwebhooks-cli serve install
134
+
135
+ # 使用指定配置级别安装(跳过交互式选择)
136
+ sudo gitwebhooks-cli serve install --config-level user # 用户级配置 (~/.gitwebhooks.ini)
137
+ sudo gitwebhooks-cli serve install --config-level local # 本地级配置 (/usr/local/etc/gitwebhooks.ini)
138
+ sudo gitwebhooks-cli serve install --config-level system # 系统级配置 (/etc/gitwebhooks.ini)
139
+
140
+ # 使用自定义配置文件(向后兼容)
141
+ sudo gitwebhooks-cli serve install -c /path/to/config.ini
134
142
 
135
143
  # 预览服务文件但不安装(dry-run 模式)
136
- sudo gitwebhooks-cli service install --dry-run
144
+ sudo gitwebhooks-cli serve install --dry-run
145
+ sudo gitwebhooks-cli serve install --config-level local --dry-run # 预览指定级别的配置
137
146
 
138
147
  # 安装并显示详细输出
139
- sudo gitwebhooks-cli service install --verbose
140
- sudo gitwebhooks-cli service install -v # 基本详细程度
141
- sudo gitwebhooks-cli service install -vv # 额外详细程度
148
+ sudo gitwebhooks-cli serve install --verbose
142
149
 
143
150
  # 强制覆盖现有服务
144
- sudo gitwebhooks-cli service install --force
151
+ sudo gitwebhooks-cli serve install --force
145
152
 
146
153
  # 卸载服务
147
- sudo gitwebhooks-cli service uninstall
154
+ sudo gitwebhooks-cli serve uninstall
148
155
  ```
149
156
 
157
+ **配置级别说明**:
158
+ - **user(用户级)**:`~/.gitwebhooks.ini` - 单用户配置,最高优先级
159
+ - **local(本地级)**:`/usr/local/etc/gitwebhooks.ini` - 本地系统配置,中等优先级
160
+ - **system(系统级)**:`/etc/gitwebhooks.ini` - 全局系统配置,最低优先级
161
+
150
162
  **服务文件自动检测**:
151
163
  - **pipx 安装**:直接使用 `gitwebhooks-cli` 命令
152
- - **venv/virtualenv**:使用环境的 Python 执行 `python -m gitwebhooks.cli`
153
- - **系统 pip**:使用系统 Python 执行 `python -m gitwebhooks.cli`
164
+ - **venv/virtualenv**:使用环境的 Python 执行 `python -m gitwebhooks.main`
165
+ - **系统 pip**:使用系统 Python 执行 `python -m gitwebhooks.main`
154
166
  - **conda**:不支持 - 安装将被拒绝并显示明确错误消息
155
167
 
156
168
  ### 手动安装
@@ -168,7 +180,14 @@ sudo ln "$(pwd)/gitwebhooks-cli" /usr/local/bin/gitwebhooks-cli
168
180
  ### 验证安装
169
181
 
170
182
  ```bash
171
- gitwebhooks-cli --help
183
+ # 显示版本
184
+ gitwebhooks-cli -v
185
+
186
+ # 显示帮助
187
+ gitwebhooks-cli help
188
+
189
+ # 查看配置
190
+ gitwebhooks-cli config view
172
191
  ```
173
192
 
174
193
  ## 从系统 pip 安装迁移
@@ -251,9 +270,47 @@ pip uninstall gitwebhooks
251
270
 
252
271
  ## 使用
253
272
 
273
+ ### 配置文件自动查找
274
+
275
+ `gitwebhooks-cli` 会自动按以下顺序(优先级)搜索配置文件:
276
+
277
+ 1. **用户级**:`~/.gitwebhooks.ini`(最高优先级)
278
+ 2. **本地级**:`/usr/local/etc/gitwebhooks.ini`
279
+ 3. **系统级**:`/etc/gitwebhooks.ini`(最低优先级)
280
+
281
+ 您可以直接运行 `gitwebhooks-cli` 而无需指定 `-c` 参数,系统会自动使用第一个存在的配置文件。
282
+
283
+ ```bash
284
+ # 自动查找并使用配置文件
285
+ gitwebhooks-cli
286
+
287
+ # 服务器会显示正在使用的配置文件
288
+ # Using configuration file: /home/user/.gitwebhooks.ini
289
+ ```
290
+
291
+ 如果需要使用特定的配置文件,可以使用 `-c` 参数:
292
+
293
+ ```bash
294
+ # 使用指定的配置文件
295
+ gitwebhooks-cli -c /path/to/custom.ini
296
+ ```
297
+
298
+ 如果找不到配置文件,会显示友好的错误消息并列出所有搜索路径:
299
+
300
+ ```
301
+ Error: Configuration file not found.
302
+ Searched paths:
303
+ 1. /home/user/.gitwebhooks.ini
304
+ 2. /usr/local/etc/gitwebhooks.ini
305
+ 3. /etc/gitwebhooks.ini
306
+
307
+ You can create a configuration file using:
308
+ gitwebhooks-cli config init
309
+ ```
310
+
254
311
  ### 1. 配置仓库
255
312
 
256
- 编辑 `~/.gitwebhook.ini`:
313
+ 编辑您的配置文件(例如 `~/.gitwebhooks.ini`):
257
314
 
258
315
  ```ini
259
316
  [your_name/repository]
@@ -267,7 +324,7 @@ cmd=git fetch --all && git reset --hard origin/master && git pull
267
324
  # 如果作为服务运行
268
325
  systemctl restart gitwebhooks
269
326
 
270
- # 或直接运行:
327
+ # 或直接运行(自动查找配置文件):
271
328
  gitwebhooks-cli
272
329
  ```
273
330
 
@@ -3,7 +3,7 @@
3
3
  Automated deployment server supporting GitHub, Gitee, GitLab, and custom webhooks.
4
4
  """
5
5
 
6
- __version__ = '2.0.0'
6
+ __version__ = '2.3.0'
7
7
 
8
8
  # Export main classes for convenient import paths
9
9
  from .server import WebhookServer
@@ -0,0 +1,203 @@
1
+ """CLI subcommands module
2
+
3
+ Provides subcommand registration and implementation for gitwebhooks-cli.
4
+ """
5
+
6
+ from gitwebhooks.cli.service import cmd_install, cmd_uninstall
7
+ from gitwebhooks.cli.config import cmd_init, cmd_view
8
+ from gitwebhooks.cli.help import cmd_help
9
+ from gitwebhooks.cli.serve import cmd_serve
10
+
11
+
12
+ def register_subparsers(subparsers):
13
+ """Register all CLI subparsers
14
+
15
+ Args:
16
+ subparsers: argparse subparsers object from ArgumentParser.add_subparsers()
17
+
18
+ Returns:
19
+ None
20
+ """
21
+ # Register help subcommand
22
+ register_help_subparser(subparsers)
23
+
24
+ # Register serve subcommand
25
+ register_serve_subparser(subparsers)
26
+
27
+ # Register config subcommand
28
+ register_config_subparser(subparsers)
29
+
30
+ # Register service subcommand (deprecated, for backward compatibility)
31
+ register_service_subparser(subparsers)
32
+
33
+
34
+ def register_serve_subparser(subparsers):
35
+ """Register serve subcommand and its actions
36
+
37
+ Args:
38
+ subparsers: argparse subparsers object
39
+
40
+ Returns:
41
+ None
42
+ """
43
+ serve_parser = subparsers.add_parser(
44
+ 'serve',
45
+ add_help=False,
46
+ help='Start webhook server or manage systemd service'
47
+ )
48
+ serve_parser.add_argument(
49
+ '-c', '--config',
50
+ dest='config',
51
+ help='Path to configuration file (default: auto-discover)'
52
+ )
53
+ serve_subparsers = serve_parser.add_subparsers(dest='serve_action')
54
+
55
+ # install action
56
+ install_parser = serve_subparsers.add_parser('install', add_help=False)
57
+ install_parser.add_argument(
58
+ '--force',
59
+ action='store_true',
60
+ help='Force overwrite existing service'
61
+ )
62
+ install_parser.add_argument(
63
+ '--verbose',
64
+ action='count',
65
+ default=0,
66
+ help='Increase verbosity'
67
+ )
68
+ install_parser.add_argument(
69
+ '--dry-run',
70
+ action='store_true',
71
+ help='Preview mode without making changes'
72
+ )
73
+ install_parser.add_argument(
74
+ '--config-level',
75
+ choices=['user', 'local', 'system'],
76
+ help='Configuration file level (user/local/system)'
77
+ )
78
+ install_parser.set_defaults(func=cmd_serve)
79
+
80
+ # uninstall action
81
+ uninstall_parser = serve_subparsers.add_parser('uninstall', add_help=False)
82
+ uninstall_parser.add_argument(
83
+ '--purge',
84
+ action='store_true',
85
+ help='Also remove configuration file'
86
+ )
87
+ uninstall_parser.set_defaults(func=cmd_serve)
88
+
89
+ # Set default function for serve (when no action specified)
90
+ serve_parser.set_defaults(func=cmd_serve)
91
+
92
+
93
+ def register_help_subparser(subparsers):
94
+ """Register help subcommand
95
+
96
+ Args:
97
+ subparsers: argparse subparsers object
98
+
99
+ Returns:
100
+ None
101
+ """
102
+ help_parser = subparsers.add_parser(
103
+ 'help',
104
+ add_help=False
105
+ )
106
+ help_parser.add_argument(
107
+ 'topic',
108
+ nargs='?',
109
+ help='Subcommand to show help for (serve, config)'
110
+ )
111
+ help_parser.set_defaults(func=cmd_help)
112
+
113
+
114
+ def register_service_subparser(subparsers):
115
+ """Register service subcommand and its actions (deprecated)
116
+
117
+ Args:
118
+ subparsers: argparse subparsers object
119
+
120
+ Returns:
121
+ None
122
+ """
123
+ service_parser = subparsers.add_parser(
124
+ 'service',
125
+ add_help=False,
126
+ help='Manage systemd service installation (deprecated, use "serve" instead)'
127
+ )
128
+ service_subparsers = service_parser.add_subparsers(dest='service_action')
129
+
130
+ # install action
131
+ install_parser = service_subparsers.add_parser('install', add_help=False)
132
+ install_parser.add_argument(
133
+ '--force',
134
+ action='store_true',
135
+ help='Force overwrite existing service'
136
+ )
137
+ install_parser.add_argument(
138
+ '-v', '--verbose',
139
+ action='count',
140
+ default=0,
141
+ help='Increase verbosity (can be used: -v, -vv)'
142
+ )
143
+ install_parser.add_argument(
144
+ '--dry-run',
145
+ action='store_true',
146
+ help='Preview service file without installing'
147
+ )
148
+ install_parser.add_argument(
149
+ '--config-level',
150
+ choices=['user', 'local', 'system'],
151
+ help='Configuration file level (user/local/system). If not specified, will be prompted.'
152
+ )
153
+ install_parser.set_defaults(func=cmd_install)
154
+
155
+ # uninstall action
156
+ uninstall_parser = service_subparsers.add_parser('uninstall', add_help=False)
157
+ uninstall_parser.add_argument(
158
+ '--purge',
159
+ action='store_true',
160
+ help='Also remove configuration file'
161
+ )
162
+ uninstall_parser.set_defaults(func=cmd_uninstall)
163
+
164
+
165
+ def register_config_subparser(subparsers):
166
+ """Register config subcommand and its actions
167
+
168
+ Args:
169
+ subparsers: argparse subparsers object
170
+
171
+ Returns:
172
+ None
173
+ """
174
+ config_parser = subparsers.add_parser(
175
+ 'config',
176
+ add_help=False,
177
+ help='Manage gitwebhooks configuration'
178
+ )
179
+ config_subparsers = config_parser.add_subparsers(dest='config_action')
180
+
181
+ # init action
182
+ init_parser = config_subparsers.add_parser(
183
+ 'init',
184
+ add_help=False,
185
+ help='Initialize configuration file using interactive wizard'
186
+ )
187
+ init_parser.add_argument(
188
+ 'level',
189
+ nargs='?',
190
+ choices=['system', 'local', 'user'],
191
+ help='Configuration level (system/local/user). If not specified, will be prompted.'
192
+ )
193
+ init_parser.set_defaults(func=cmd_init)
194
+
195
+ # view action
196
+ view_parser = config_subparsers.add_parser('view', add_help=False)
197
+ view_parser.add_argument(
198
+ '-c',
199
+ '--config',
200
+ dest='config',
201
+ help='Path to configuration file (default: auto-detect)'
202
+ )
203
+ view_parser.set_defaults(func=cmd_view)