gitwebhooks 2.1.4__tar.gz → 2.2.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 (106) hide show
  1. {gitwebhooks-2.1.4 → gitwebhooks-2.2.0}/CLAUDE.md +10 -1
  2. {gitwebhooks-2.1.4 → gitwebhooks-2.2.0}/PKG-INFO +41 -3
  3. {gitwebhooks-2.1.4 → gitwebhooks-2.2.0}/README.md +40 -2
  4. {gitwebhooks-2.1.4 → gitwebhooks-2.2.0}/README.zh.md +40 -2
  5. {gitwebhooks-2.1.4 → gitwebhooks-2.2.0}/gitwebhooks/__init__.py +1 -1
  6. gitwebhooks-2.2.0/gitwebhooks/main/__init__.py +182 -0
  7. {gitwebhooks-2.1.4 → gitwebhooks-2.2.0}/gitwebhooks.egg-info/PKG-INFO +41 -3
  8. {gitwebhooks-2.1.4 → gitwebhooks-2.2.0}/gitwebhooks.egg-info/SOURCES.txt +2 -0
  9. {gitwebhooks-2.1.4 → gitwebhooks-2.2.0}/pyproject.toml +1 -1
  10. gitwebhooks-2.2.0/tests/integration/test_config_discovery.py +328 -0
  11. gitwebhooks-2.2.0/tests/unit/test_main.py +341 -0
  12. gitwebhooks-2.1.4/gitwebhooks/main/__init__.py +0 -117
  13. {gitwebhooks-2.1.4 → gitwebhooks-2.2.0}/.editorconfig +0 -0
  14. {gitwebhooks-2.1.4 → gitwebhooks-2.2.0}/LICENSE +0 -0
  15. {gitwebhooks-2.1.4 → gitwebhooks-2.2.0}/MANIFEST.in +0 -0
  16. {gitwebhooks-2.1.4 → gitwebhooks-2.2.0}/doc/custom-body.png +0 -0
  17. {gitwebhooks-2.1.4 → gitwebhooks-2.2.0}/doc/custom-header.png +0 -0
  18. {gitwebhooks-2.1.4 → gitwebhooks-2.2.0}/doc/custom-response.png +0 -0
  19. {gitwebhooks-2.1.4 → gitwebhooks-2.2.0}/doc/gitee-success.png +0 -0
  20. {gitwebhooks-2.1.4 → gitwebhooks-2.2.0}/doc/gitee.png +0 -0
  21. {gitwebhooks-2.1.4 → gitwebhooks-2.2.0}/doc/github-success.png +0 -0
  22. {gitwebhooks-2.1.4 → gitwebhooks-2.2.0}/doc/github.png +0 -0
  23. {gitwebhooks-2.1.4 → gitwebhooks-2.2.0}/doc/gitlab-success.png +0 -0
  24. {gitwebhooks-2.1.4 → gitwebhooks-2.2.0}/doc/gitlab.png +0 -0
  25. {gitwebhooks-2.1.4 → gitwebhooks-2.2.0}/doc/install.png +0 -0
  26. {gitwebhooks-2.1.4 → gitwebhooks-2.2.0}/doc/uninstall.png +0 -0
  27. {gitwebhooks-2.1.4 → gitwebhooks-2.2.0}/gitwebhooks/__main__.py +0 -0
  28. {gitwebhooks-2.1.4 → gitwebhooks-2.2.0}/gitwebhooks/auth/__init__.py +0 -0
  29. {gitwebhooks-2.1.4 → gitwebhooks-2.2.0}/gitwebhooks/auth/custom.py +0 -0
  30. {gitwebhooks-2.1.4 → gitwebhooks-2.2.0}/gitwebhooks/auth/factory.py +0 -0
  31. {gitwebhooks-2.1.4 → gitwebhooks-2.2.0}/gitwebhooks/auth/gitee.py +0 -0
  32. {gitwebhooks-2.1.4 → gitwebhooks-2.2.0}/gitwebhooks/auth/github.py +0 -0
  33. {gitwebhooks-2.1.4 → gitwebhooks-2.2.0}/gitwebhooks/auth/gitlab.py +0 -0
  34. {gitwebhooks-2.1.4 → gitwebhooks-2.2.0}/gitwebhooks/auth/verifier.py +0 -0
  35. {gitwebhooks-2.1.4 → gitwebhooks-2.2.0}/gitwebhooks/cli/__init__.py +0 -0
  36. {gitwebhooks-2.1.4 → gitwebhooks-2.2.0}/gitwebhooks/cli/config.py +0 -0
  37. {gitwebhooks-2.1.4 → gitwebhooks-2.2.0}/gitwebhooks/cli/init_wizard.py +0 -0
  38. {gitwebhooks-2.1.4 → gitwebhooks-2.2.0}/gitwebhooks/cli/prompts.py +0 -0
  39. {gitwebhooks-2.1.4 → gitwebhooks-2.2.0}/gitwebhooks/cli/service.py +0 -0
  40. {gitwebhooks-2.1.4 → gitwebhooks-2.2.0}/gitwebhooks/config/__init__.py +0 -0
  41. {gitwebhooks-2.1.4 → gitwebhooks-2.2.0}/gitwebhooks/config/loader.py +0 -0
  42. {gitwebhooks-2.1.4 → gitwebhooks-2.2.0}/gitwebhooks/config/models.py +0 -0
  43. {gitwebhooks-2.1.4 → gitwebhooks-2.2.0}/gitwebhooks/config/registry.py +0 -0
  44. {gitwebhooks-2.1.4 → gitwebhooks-2.2.0}/gitwebhooks/config/server.py +0 -0
  45. {gitwebhooks-2.1.4 → gitwebhooks-2.2.0}/gitwebhooks/handlers/__init__.py +0 -0
  46. {gitwebhooks-2.1.4 → gitwebhooks-2.2.0}/gitwebhooks/handlers/base.py +0 -0
  47. {gitwebhooks-2.1.4 → gitwebhooks-2.2.0}/gitwebhooks/handlers/custom.py +0 -0
  48. {gitwebhooks-2.1.4 → gitwebhooks-2.2.0}/gitwebhooks/handlers/factory.py +0 -0
  49. {gitwebhooks-2.1.4 → gitwebhooks-2.2.0}/gitwebhooks/handlers/gitee.py +0 -0
  50. {gitwebhooks-2.1.4 → gitwebhooks-2.2.0}/gitwebhooks/handlers/github.py +0 -0
  51. {gitwebhooks-2.1.4 → gitwebhooks-2.2.0}/gitwebhooks/handlers/gitlab.py +0 -0
  52. {gitwebhooks-2.1.4 → gitwebhooks-2.2.0}/gitwebhooks/handlers/request.py +0 -0
  53. {gitwebhooks-2.1.4 → gitwebhooks-2.2.0}/gitwebhooks/logging/__init__.py +0 -0
  54. {gitwebhooks-2.1.4 → gitwebhooks-2.2.0}/gitwebhooks/logging/setup.py +0 -0
  55. {gitwebhooks-2.1.4 → gitwebhooks-2.2.0}/gitwebhooks/main/__main__.py +0 -0
  56. {gitwebhooks-2.1.4 → gitwebhooks-2.2.0}/gitwebhooks/models/__init__.py +0 -0
  57. {gitwebhooks-2.1.4 → gitwebhooks-2.2.0}/gitwebhooks/models/provider.py +0 -0
  58. {gitwebhooks-2.1.4 → gitwebhooks-2.2.0}/gitwebhooks/models/request.py +0 -0
  59. {gitwebhooks-2.1.4 → gitwebhooks-2.2.0}/gitwebhooks/models/result.py +0 -0
  60. {gitwebhooks-2.1.4 → gitwebhooks-2.2.0}/gitwebhooks/server.py +0 -0
  61. {gitwebhooks-2.1.4 → gitwebhooks-2.2.0}/gitwebhooks/utils/__init__.py +0 -0
  62. {gitwebhooks-2.1.4 → gitwebhooks-2.2.0}/gitwebhooks/utils/constants.py +0 -0
  63. {gitwebhooks-2.1.4 → gitwebhooks-2.2.0}/gitwebhooks/utils/exceptions.py +0 -0
  64. {gitwebhooks-2.1.4 → gitwebhooks-2.2.0}/gitwebhooks/utils/executor.py +0 -0
  65. {gitwebhooks-2.1.4 → gitwebhooks-2.2.0}/gitwebhooks/utils/systemd.py +0 -0
  66. {gitwebhooks-2.1.4 → gitwebhooks-2.2.0}/gitwebhooks.egg-info/dependency_links.txt +0 -0
  67. {gitwebhooks-2.1.4 → gitwebhooks-2.2.0}/gitwebhooks.egg-info/entry_points.txt +0 -0
  68. {gitwebhooks-2.1.4 → gitwebhooks-2.2.0}/gitwebhooks.egg-info/requires.txt +0 -0
  69. {gitwebhooks-2.1.4 → gitwebhooks-2.2.0}/gitwebhooks.egg-info/top_level.txt +0 -0
  70. {gitwebhooks-2.1.4 → gitwebhooks-2.2.0}/gitwebhooks.ini.sample +0 -0
  71. {gitwebhooks-2.1.4 → gitwebhooks-2.2.0}/setup.cfg +0 -0
  72. {gitwebhooks-2.1.4 → gitwebhooks-2.2.0}/tests/__init__.py +0 -0
  73. {gitwebhooks-2.1.4 → gitwebhooks-2.2.0}/tests/__main__.py +0 -0
  74. {gitwebhooks-2.1.4 → gitwebhooks-2.2.0}/tests/conftest.py +0 -0
  75. {gitwebhooks-2.1.4 → gitwebhooks-2.2.0}/tests/fixtures/__init__.py +0 -0
  76. {gitwebhooks-2.1.4 → gitwebhooks-2.2.0}/tests/fixtures/custom_payloads.py +0 -0
  77. {gitwebhooks-2.1.4 → gitwebhooks-2.2.0}/tests/fixtures/gitee_payloads.py +0 -0
  78. {gitwebhooks-2.1.4 → gitwebhooks-2.2.0}/tests/fixtures/github_payloads.py +0 -0
  79. {gitwebhooks-2.1.4 → gitwebhooks-2.2.0}/tests/fixtures/gitlab_payloads.py +0 -0
  80. {gitwebhooks-2.1.4 → gitwebhooks-2.2.0}/tests/fixtures/signature_builder.py +0 -0
  81. {gitwebhooks-2.1.4 → gitwebhooks-2.2.0}/tests/integration/__init__.py +0 -0
  82. {gitwebhooks-2.1.4 → gitwebhooks-2.2.0}/tests/integration/test_command_execution.py +0 -0
  83. {gitwebhooks-2.1.4 → gitwebhooks-2.2.0}/tests/integration/test_config_view_integration.py +0 -0
  84. {gitwebhooks-2.1.4 → gitwebhooks-2.2.0}/tests/integration/test_custom_webhook.py +0 -0
  85. {gitwebhooks-2.1.4 → gitwebhooks-2.2.0}/tests/integration/test_edge_cases.py +0 -0
  86. {gitwebhooks-2.1.4 → gitwebhooks-2.2.0}/tests/integration/test_gitee_webhook.py +0 -0
  87. {gitwebhooks-2.1.4 → gitwebhooks-2.2.0}/tests/integration/test_github_webhook.py +0 -0
  88. {gitwebhooks-2.1.4 → gitwebhooks-2.2.0}/tests/integration/test_gitlab_webhook.py +0 -0
  89. {gitwebhooks-2.1.4 → gitwebhooks-2.2.0}/tests/test_auth/__init__.py +0 -0
  90. {gitwebhooks-2.1.4 → gitwebhooks-2.2.0}/tests/test_config/__init__.py +0 -0
  91. {gitwebhooks-2.1.4 → gitwebhooks-2.2.0}/tests/test_handlers/__init__.py +0 -0
  92. {gitwebhooks-2.1.4 → gitwebhooks-2.2.0}/tests/test_integration/__init__.py +0 -0
  93. {gitwebhooks-2.1.4 → gitwebhooks-2.2.0}/tests/unit/__init__.py +0 -0
  94. {gitwebhooks-2.1.4 → gitwebhooks-2.2.0}/tests/unit/cli/__init__.py +0 -0
  95. {gitwebhooks-2.1.4 → gitwebhooks-2.2.0}/tests/unit/cli/test_config_view.py +0 -0
  96. {gitwebhooks-2.1.4 → gitwebhooks-2.2.0}/tests/unit/cli/test_init_wizard.py +0 -0
  97. {gitwebhooks-2.1.4 → gitwebhooks-2.2.0}/tests/unit/test_config_loading.py +0 -0
  98. {gitwebhooks-2.1.4 → gitwebhooks-2.2.0}/tests/unit/test_data_parsing.py +0 -0
  99. {gitwebhooks-2.1.4 → gitwebhooks-2.2.0}/tests/unit/test_provider_detection.py +0 -0
  100. {gitwebhooks-2.1.4 → gitwebhooks-2.2.0}/tests/unit/test_request_handler.py +0 -0
  101. {gitwebhooks-2.1.4 → gitwebhooks-2.2.0}/tests/unit/test_signature_verification.py +0 -0
  102. {gitwebhooks-2.1.4 → gitwebhooks-2.2.0}/tests/utils/__init__.py +0 -0
  103. {gitwebhooks-2.1.4 → gitwebhooks-2.2.0}/tests/utils/certificate_generator.py +0 -0
  104. {gitwebhooks-2.1.4 → gitwebhooks-2.2.0}/tests/utils/coverage_runner.py +0 -0
  105. {gitwebhooks-2.1.4 → gitwebhooks-2.2.0}/tests/utils/http_client.py +0 -0
  106. {gitwebhooks-2.1.4 → gitwebhooks-2.2.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,7 @@ 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)
295
304
 
296
305
  ## Recent Changes
297
306
  - 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.2.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>
@@ -291,9 +291,47 @@ pip uninstall gitwebhooks
291
291
 
292
292
  ## Usage
293
293
 
294
+ ### Configuration File Auto-Discovery
295
+
296
+ The `gitwebhooks-cli` automatically searches for configuration files in the following order (priority):
297
+
298
+ 1. **User level**: `~/.gitwebhooks.ini` (highest priority)
299
+ 2. **Local level**: `/usr/local/etc/gitwebhooks.ini`
300
+ 3. **System level**: `/etc/gitwebhooks.ini` (lowest priority)
301
+
302
+ You can run `gitwebhooks-cli` without specifying `-c` parameter, and it will automatically use the first existing configuration file.
303
+
304
+ ```bash
305
+ # Auto-discover and use configuration file
306
+ gitwebhooks-cli
307
+
308
+ # The server will display which config file is being used
309
+ # Using configuration file: /home/user/.gitwebhooks.ini
310
+ ```
311
+
312
+ If you want to use a specific configuration file, use the `-c` parameter:
313
+
314
+ ```bash
315
+ # Use a specific configuration file
316
+ gitwebhooks-cli -c /path/to/custom.ini
317
+ ```
318
+
319
+ If no configuration file is found, a friendly error message will display all searched paths:
320
+
321
+ ```
322
+ Error: Configuration file not found.
323
+ Searched paths:
324
+ 1. /home/user/.gitwebhooks.ini
325
+ 2. /usr/local/etc/gitwebhooks.ini
326
+ 3. /etc/gitwebhooks.ini
327
+
328
+ You can create a configuration file using:
329
+ gitwebhooks-cli config init
330
+ ```
331
+
294
332
  ### 1. Configure Repository
295
333
 
296
- Edit `~/.gitwebhook.ini`:
334
+ Edit your configuration file (e.g., `~/.gitwebhooks.ini`):
297
335
 
298
336
  ```ini
299
337
  [your_name/repository]
@@ -307,7 +345,7 @@ cmd=git fetch --all && git reset --hard origin/master && git pull
307
345
  # If running as a service
308
346
  systemctl restart gitwebhooks
309
347
 
310
- # Or run directly:
348
+ # Or run directly (auto-discovers config file):
311
349
  gitwebhooks-cli
312
350
  ```
313
351
 
@@ -251,9 +251,47 @@ pip uninstall gitwebhooks
251
251
 
252
252
  ## Usage
253
253
 
254
+ ### Configuration File Auto-Discovery
255
+
256
+ The `gitwebhooks-cli` automatically searches for configuration files in the following order (priority):
257
+
258
+ 1. **User level**: `~/.gitwebhooks.ini` (highest priority)
259
+ 2. **Local level**: `/usr/local/etc/gitwebhooks.ini`
260
+ 3. **System level**: `/etc/gitwebhooks.ini` (lowest priority)
261
+
262
+ You can run `gitwebhooks-cli` without specifying `-c` parameter, and it will automatically use the first existing configuration file.
263
+
264
+ ```bash
265
+ # Auto-discover and use configuration file
266
+ gitwebhooks-cli
267
+
268
+ # The server will display which config file is being used
269
+ # Using configuration file: /home/user/.gitwebhooks.ini
270
+ ```
271
+
272
+ If you want to use a specific configuration file, use the `-c` parameter:
273
+
274
+ ```bash
275
+ # Use a specific configuration file
276
+ gitwebhooks-cli -c /path/to/custom.ini
277
+ ```
278
+
279
+ If no configuration file is found, a friendly error message will display all searched paths:
280
+
281
+ ```
282
+ Error: Configuration file not found.
283
+ Searched paths:
284
+ 1. /home/user/.gitwebhooks.ini
285
+ 2. /usr/local/etc/gitwebhooks.ini
286
+ 3. /etc/gitwebhooks.ini
287
+
288
+ You can create a configuration file using:
289
+ gitwebhooks-cli config init
290
+ ```
291
+
254
292
  ### 1. Configure Repository
255
293
 
256
- Edit `~/.gitwebhook.ini`:
294
+ Edit your configuration file (e.g., `~/.gitwebhooks.ini`):
257
295
 
258
296
  ```ini
259
297
  [your_name/repository]
@@ -267,7 +305,7 @@ cmd=git fetch --all && git reset --hard origin/master && git pull
267
305
  # If running as a service
268
306
  systemctl restart gitwebhooks
269
307
 
270
- # Or run directly:
308
+ # Or run directly (auto-discovers config file):
271
309
  gitwebhooks-cli
272
310
  ```
273
311
 
@@ -251,9 +251,47 @@ pip uninstall gitwebhooks
251
251
 
252
252
  ## 使用
253
253
 
254
+ ### 配置文件自动查找
255
+
256
+ `gitwebhooks-cli` 会自动按以下顺序(优先级)搜索配置文件:
257
+
258
+ 1. **用户级**:`~/.gitwebhooks.ini`(最高优先级)
259
+ 2. **本地级**:`/usr/local/etc/gitwebhooks.ini`
260
+ 3. **系统级**:`/etc/gitwebhooks.ini`(最低优先级)
261
+
262
+ 您可以直接运行 `gitwebhooks-cli` 而无需指定 `-c` 参数,系统会自动使用第一个存在的配置文件。
263
+
264
+ ```bash
265
+ # 自动查找并使用配置文件
266
+ gitwebhooks-cli
267
+
268
+ # 服务器会显示正在使用的配置文件
269
+ # Using configuration file: /home/user/.gitwebhooks.ini
270
+ ```
271
+
272
+ 如果需要使用特定的配置文件,可以使用 `-c` 参数:
273
+
274
+ ```bash
275
+ # 使用指定的配置文件
276
+ gitwebhooks-cli -c /path/to/custom.ini
277
+ ```
278
+
279
+ 如果找不到配置文件,会显示友好的错误消息并列出所有搜索路径:
280
+
281
+ ```
282
+ Error: Configuration file not found.
283
+ Searched paths:
284
+ 1. /home/user/.gitwebhooks.ini
285
+ 2. /usr/local/etc/gitwebhooks.ini
286
+ 3. /etc/gitwebhooks.ini
287
+
288
+ You can create a configuration file using:
289
+ gitwebhooks-cli config init
290
+ ```
291
+
254
292
  ### 1. 配置仓库
255
293
 
256
- 编辑 `~/.gitwebhook.ini`:
294
+ 编辑您的配置文件(例如 `~/.gitwebhooks.ini`):
257
295
 
258
296
  ```ini
259
297
  [your_name/repository]
@@ -267,7 +305,7 @@ cmd=git fetch --all && git reset --hard origin/master && git pull
267
305
  # 如果作为服务运行
268
306
  systemctl restart gitwebhooks
269
307
 
270
- # 或直接运行:
308
+ # 或直接运行(自动查找配置文件):
271
309
  gitwebhooks-cli
272
310
  ```
273
311
 
@@ -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.2.0'
7
7
 
8
8
  # Export main classes for convenient import paths
9
9
  from .server import WebhookServer
@@ -0,0 +1,182 @@
1
+ """CLI main function
2
+
3
+ Command-line interface module providing compatibility with the original gitwebhooks.py.
4
+ """
5
+
6
+ import argparse
7
+ import sys
8
+ from pathlib import Path
9
+ from typing import List, Optional
10
+
11
+ from gitwebhooks.server import WebhookServer
12
+ from gitwebhooks.utils.exceptions import ConfigurationError
13
+ from gitwebhooks.utils.constants import CONFIG_SEARCH_PATHS
14
+
15
+ # Try to import subcommands, may not be available in older versions
16
+ try:
17
+ from gitwebhooks.cli import register_subparsers
18
+ HAS_SUBCOMMANDS = True
19
+ except ImportError:
20
+ HAS_SUBCOMMANDS = False
21
+
22
+
23
+ def find_config_file() -> Optional[str]:
24
+ """Find configuration file by priority order.
25
+
26
+ Searches for configuration files in the following order:
27
+ 1. User level: ~/.gitwebhooks.ini
28
+ 2. Local level: /usr/local/etc/gitwebhooks.ini
29
+ 3. System level: /etc/gitwebhooks.ini
30
+
31
+ Returns:
32
+ Path string of the first existing configuration file, or None if not found.
33
+
34
+ Examples:
35
+ >>> find_config_file() # doctest: +SKIP
36
+ '/home/user/.gitwebhooks.ini'
37
+ >>> find_config_file() # doctest: +SKIP
38
+ None
39
+ """
40
+ for config_path in CONFIG_SEARCH_PATHS:
41
+ expanded_path = Path(config_path).expanduser().resolve()
42
+ if expanded_path.exists():
43
+ return str(expanded_path)
44
+ return None
45
+
46
+
47
+ def format_config_error(searched_paths: List[Path]) -> str:
48
+ """Format user-friendly error message for missing configuration file.
49
+
50
+ Args:
51
+ searched_paths: List of paths that were searched.
52
+
53
+ Returns:
54
+ Formatted error message string.
55
+
56
+ Examples:
57
+ >>> paths = [Path('/home/user/.gitwebhooks.ini')]
58
+ >>> format_config_error(paths) # doctest: +SKIP
59
+ 'Error: Configuration file not found.\\nSearched paths:\\n 1. /home/user/.gitwebhooks.ini\\n\\nYou can create a configuration file using:\\n gitwebhooks-cli config init'
60
+ """
61
+ lines = [
62
+ 'Error: Configuration file not found.',
63
+ 'Searched paths:'
64
+ ]
65
+ for i, path in enumerate(searched_paths, 1):
66
+ lines.append(f' {i}. {path}')
67
+ lines.append('')
68
+ lines.append('You can create a configuration file using:')
69
+ lines.append(' gitwebhooks-cli config init')
70
+ return '\n'.join(lines)
71
+
72
+
73
+ def main(argv: List[str] = None) -> int:
74
+ """Main entry point
75
+
76
+ Args:
77
+ argv: Command-line argument list (defaults to sys.argv[1:])
78
+
79
+ Returns:
80
+ Exit code (0 = success, 1 = error)
81
+
82
+ Raises:
83
+ SystemExit: Exit on error
84
+
85
+ Command Line Arguments:
86
+ -h, --help Show help message and exit
87
+ -c, --config Specify configuration file path (optional)
88
+ service Service management subcommands
89
+ config Configuration management subcommands
90
+
91
+ Config Discovery:
92
+ When -c is not specified, searches in order:
93
+ 1. ~/.gitwebhooks.ini (user level)
94
+ 2. /usr/local/etc/gitwebhooks.ini (local level)
95
+ 3. /etc/gitwebhooks.ini (system level)
96
+
97
+ Examples:
98
+ python3 -m gitwebhooks.main
99
+ python3 -m gitwebhooks.main -c /path/to/config.ini
100
+ gitwebhooks-cli --config /etc/webhooks.ini
101
+ gitwebhooks-cli service install
102
+ gitwebhooks-cli config init
103
+ """
104
+ if argv is None:
105
+ argv = sys.argv[1:]
106
+
107
+ # Create main argument parser
108
+ parser = argparse.ArgumentParser(
109
+ prog='gitwebhooks-cli',
110
+ description='Git Webhooks Server - Automated deployment webhook handler',
111
+ add_help=True
112
+ )
113
+ parser.add_argument(
114
+ '-c', '--config',
115
+ default=None,
116
+ help='Path to INI configuration file (default: auto-discover)'
117
+ )
118
+
119
+ # Add subcommands if available
120
+ if HAS_SUBCOMMANDS:
121
+ subparsers = parser.add_subparsers(dest='command', help='Subcommands')
122
+ register_subparsers(subparsers)
123
+
124
+ # Parse arguments
125
+ args = parser.parse_args(argv)
126
+
127
+ # If no subcommand, run server (backward compatible behavior)
128
+ if not hasattr(args, 'func'):
129
+ return run_server(args.config)
130
+
131
+ # Execute subcommand
132
+ return args.func(args)
133
+
134
+
135
+ def run_server(config_file: Optional[str]) -> int:
136
+ """Run the webhook server
137
+
138
+ Args:
139
+ config_file: Path to configuration file, or None to auto-discover
140
+
141
+ Returns:
142
+ Exit code (0 = success, 1 = error)
143
+ """
144
+ # Auto-discover config file if not specified
145
+ if config_file is None:
146
+ config_file = find_config_file()
147
+ if config_file is None:
148
+ # No config found - format error with all search paths
149
+ searched_paths = [Path(p).expanduser().resolve() for p in CONFIG_SEARCH_PATHS]
150
+ error_msg = format_config_error(searched_paths)
151
+ print(error_msg, file=sys.stderr)
152
+ return 1
153
+
154
+ # Expand user path
155
+ config_path = Path(config_file).expanduser()
156
+
157
+ # Check configuration file exists
158
+ if not config_path.exists():
159
+ print(f'Error: Configuration file not found: {config_path}', file=sys.stderr)
160
+ return 1
161
+
162
+ # Print configuration file being used
163
+ print(f'Using configuration file: {config_path}')
164
+
165
+ # Create and run server
166
+ try:
167
+ server = WebhookServer(config_path=str(config_path))
168
+ server.run()
169
+ return 0
170
+ except ConfigurationError as e:
171
+ print(f'Configuration error: {e}', file=sys.stderr)
172
+ return 1
173
+ except KeyboardInterrupt:
174
+ print('\nServer stopped by user')
175
+ return 0
176
+ except Exception as e:
177
+ print(f'Error: {e}', file=sys.stderr)
178
+ return 1
179
+
180
+
181
+ if __name__ == '__main__':
182
+ sys.exit(main())
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: gitwebhooks
3
- Version: 2.1.4
3
+ Version: 2.2.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>
@@ -291,9 +291,47 @@ pip uninstall gitwebhooks
291
291
 
292
292
  ## Usage
293
293
 
294
+ ### Configuration File Auto-Discovery
295
+
296
+ The `gitwebhooks-cli` automatically searches for configuration files in the following order (priority):
297
+
298
+ 1. **User level**: `~/.gitwebhooks.ini` (highest priority)
299
+ 2. **Local level**: `/usr/local/etc/gitwebhooks.ini`
300
+ 3. **System level**: `/etc/gitwebhooks.ini` (lowest priority)
301
+
302
+ You can run `gitwebhooks-cli` without specifying `-c` parameter, and it will automatically use the first existing configuration file.
303
+
304
+ ```bash
305
+ # Auto-discover and use configuration file
306
+ gitwebhooks-cli
307
+
308
+ # The server will display which config file is being used
309
+ # Using configuration file: /home/user/.gitwebhooks.ini
310
+ ```
311
+
312
+ If you want to use a specific configuration file, use the `-c` parameter:
313
+
314
+ ```bash
315
+ # Use a specific configuration file
316
+ gitwebhooks-cli -c /path/to/custom.ini
317
+ ```
318
+
319
+ If no configuration file is found, a friendly error message will display all searched paths:
320
+
321
+ ```
322
+ Error: Configuration file not found.
323
+ Searched paths:
324
+ 1. /home/user/.gitwebhooks.ini
325
+ 2. /usr/local/etc/gitwebhooks.ini
326
+ 3. /etc/gitwebhooks.ini
327
+
328
+ You can create a configuration file using:
329
+ gitwebhooks-cli config init
330
+ ```
331
+
294
332
  ### 1. Configure Repository
295
333
 
296
- Edit `~/.gitwebhook.ini`:
334
+ Edit your configuration file (e.g., `~/.gitwebhooks.ini`):
297
335
 
298
336
  ```ini
299
337
  [your_name/repository]
@@ -307,7 +345,7 @@ cmd=git fetch --all && git reset --hard origin/master && git pull
307
345
  # If running as a service
308
346
  systemctl restart gitwebhooks
309
347
 
310
- # Or run directly:
348
+ # Or run directly (auto-discovers config file):
311
349
  gitwebhooks-cli
312
350
  ```
313
351
 
@@ -116,6 +116,7 @@ tests/fixtures/gitlab_payloads.py
116
116
  tests/fixtures/signature_builder.py
117
117
  tests/integration/__init__.py
118
118
  tests/integration/test_command_execution.py
119
+ tests/integration/test_config_discovery.py
119
120
  tests/integration/test_config_view_integration.py
120
121
  tests/integration/test_custom_webhook.py
121
122
  tests/integration/test_edge_cases.py
@@ -129,6 +130,7 @@ tests/test_integration/__init__.py
129
130
  tests/unit/__init__.py
130
131
  tests/unit/test_config_loading.py
131
132
  tests/unit/test_data_parsing.py
133
+ tests/unit/test_main.py
132
134
  tests/unit/test_provider_detection.py
133
135
  tests/unit/test_request_handler.py
134
136
  tests/unit/test_signature_verification.py
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "gitwebhooks"
7
- version = "2.1.4"
7
+ version = "2.2.0"
8
8
  description = "A lightweight Git webhook server for automated deployment supporting GitHub, Gitee, GitLab, and custom webhooks"
9
9
  readme = "README.md"
10
10
  license = "MIT"