gitwebhooks 2.1.4__py3-none-any.whl → 2.2.0__py3-none-any.whl
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.
- gitwebhooks/__init__.py +1 -1
- gitwebhooks/main/__init__.py +76 -11
- {gitwebhooks-2.1.4.dist-info → gitwebhooks-2.2.0.dist-info}/METADATA +41 -3
- {gitwebhooks-2.1.4.dist-info → gitwebhooks-2.2.0.dist-info}/RECORD +8 -8
- {gitwebhooks-2.1.4.dist-info → gitwebhooks-2.2.0.dist-info}/WHEEL +0 -0
- {gitwebhooks-2.1.4.dist-info → gitwebhooks-2.2.0.dist-info}/entry_points.txt +0 -0
- {gitwebhooks-2.1.4.dist-info → gitwebhooks-2.2.0.dist-info}/licenses/LICENSE +0 -0
- {gitwebhooks-2.1.4.dist-info → gitwebhooks-2.2.0.dist-info}/top_level.txt +0 -0
gitwebhooks/__init__.py
CHANGED
gitwebhooks/main/__init__.py
CHANGED
|
@@ -6,10 +6,11 @@ Command-line interface module providing compatibility with the original gitwebho
|
|
|
6
6
|
import argparse
|
|
7
7
|
import sys
|
|
8
8
|
from pathlib import Path
|
|
9
|
-
from typing import List
|
|
9
|
+
from typing import List, Optional
|
|
10
10
|
|
|
11
11
|
from gitwebhooks.server import WebhookServer
|
|
12
12
|
from gitwebhooks.utils.exceptions import ConfigurationError
|
|
13
|
+
from gitwebhooks.utils.constants import CONFIG_SEARCH_PATHS
|
|
13
14
|
|
|
14
15
|
# Try to import subcommands, may not be available in older versions
|
|
15
16
|
try:
|
|
@@ -19,6 +20,56 @@ except ImportError:
|
|
|
19
20
|
HAS_SUBCOMMANDS = False
|
|
20
21
|
|
|
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
|
+
|
|
22
73
|
def main(argv: List[str] = None) -> int:
|
|
23
74
|
"""Main entry point
|
|
24
75
|
|
|
@@ -33,14 +84,18 @@ def main(argv: List[str] = None) -> int:
|
|
|
33
84
|
|
|
34
85
|
Command Line Arguments:
|
|
35
86
|
-h, --help Show help message and exit
|
|
36
|
-
-c, --config Specify configuration file path
|
|
87
|
+
-c, --config Specify configuration file path (optional)
|
|
37
88
|
service Service management subcommands
|
|
38
89
|
config Configuration management subcommands
|
|
39
90
|
|
|
40
|
-
|
|
41
|
-
|
|
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)
|
|
42
96
|
|
|
43
97
|
Examples:
|
|
98
|
+
python3 -m gitwebhooks.main
|
|
44
99
|
python3 -m gitwebhooks.main -c /path/to/config.ini
|
|
45
100
|
gitwebhooks-cli --config /etc/webhooks.ini
|
|
46
101
|
gitwebhooks-cli service install
|
|
@@ -49,9 +104,6 @@ def main(argv: List[str] = None) -> int:
|
|
|
49
104
|
if argv is None:
|
|
50
105
|
argv = sys.argv[1:]
|
|
51
106
|
|
|
52
|
-
# Default configuration file path (changed to user home directory)
|
|
53
|
-
default_config = '~/.gitwebhook.ini'
|
|
54
|
-
|
|
55
107
|
# Create main argument parser
|
|
56
108
|
parser = argparse.ArgumentParser(
|
|
57
109
|
prog='gitwebhooks-cli',
|
|
@@ -60,8 +112,8 @@ def main(argv: List[str] = None) -> int:
|
|
|
60
112
|
)
|
|
61
113
|
parser.add_argument(
|
|
62
114
|
'-c', '--config',
|
|
63
|
-
default=
|
|
64
|
-
help='Path to INI configuration file (default:
|
|
115
|
+
default=None,
|
|
116
|
+
help='Path to INI configuration file (default: auto-discover)'
|
|
65
117
|
)
|
|
66
118
|
|
|
67
119
|
# Add subcommands if available
|
|
@@ -80,15 +132,25 @@ def main(argv: List[str] = None) -> int:
|
|
|
80
132
|
return args.func(args)
|
|
81
133
|
|
|
82
134
|
|
|
83
|
-
def run_server(config_file: str) -> int:
|
|
135
|
+
def run_server(config_file: Optional[str]) -> int:
|
|
84
136
|
"""Run the webhook server
|
|
85
137
|
|
|
86
138
|
Args:
|
|
87
|
-
config_file: Path to configuration file
|
|
139
|
+
config_file: Path to configuration file, or None to auto-discover
|
|
88
140
|
|
|
89
141
|
Returns:
|
|
90
142
|
Exit code (0 = success, 1 = error)
|
|
91
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
|
+
|
|
92
154
|
# Expand user path
|
|
93
155
|
config_path = Path(config_file).expanduser()
|
|
94
156
|
|
|
@@ -97,6 +159,9 @@ def run_server(config_file: str) -> int:
|
|
|
97
159
|
print(f'Error: Configuration file not found: {config_path}', file=sys.stderr)
|
|
98
160
|
return 1
|
|
99
161
|
|
|
162
|
+
# Print configuration file being used
|
|
163
|
+
print(f'Using configuration file: {config_path}')
|
|
164
|
+
|
|
100
165
|
# Create and run server
|
|
101
166
|
try:
|
|
102
167
|
server = WebhookServer(config_path=str(config_path))
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: gitwebhooks
|
|
3
|
-
Version: 2.
|
|
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 `~/.
|
|
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
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
gitwebhooks/__init__.py,sha256=
|
|
1
|
+
gitwebhooks/__init__.py,sha256=KUi3jpqSom1NA9r8du8t2kG1mZ0NN8Jtdbl9wlxr5bg,422
|
|
2
2
|
gitwebhooks/__main__.py,sha256=DW1lmngPDSFHJKSyaG2Dd5k3UguGSuYPUM2xKR8DhTo,189
|
|
3
3
|
gitwebhooks/server.py,sha256=keQcfOysoitx7cINcTkaDvhe6nScIFL2K8dCCViFF-o,3986
|
|
4
4
|
gitwebhooks/auth/__init__.py,sha256=Hu88BS6aOickrWBBWM2ppTzy2xOJfWODYkp752bPTPM,532
|
|
@@ -28,7 +28,7 @@ gitwebhooks/handlers/gitlab.py,sha256=UkK3R_KSKSt0s7XAtH1_G_uid85tqiL12qND8_Pnos
|
|
|
28
28
|
gitwebhooks/handlers/request.py,sha256=GsKH-R7L7j7h9GKEAse-O4tnmXeQMkbsT8WK_J8ACl8,9184
|
|
29
29
|
gitwebhooks/logging/__init__.py,sha256=CmL5WD2RgZ76uhrxzwnIfOEd_HgTZMTtTjjqYSY06GA,146
|
|
30
30
|
gitwebhooks/logging/setup.py,sha256=scu4nfEJTLR6QpmO4exXbKaMcTU11qHR2Jv8fEpEMD8,2095
|
|
31
|
-
gitwebhooks/main/__init__.py,sha256=
|
|
31
|
+
gitwebhooks/main/__init__.py,sha256=kg7QtoWHljnEkysei5XoIwXMjveNHf_bdPwfei5Vypw,5559
|
|
32
32
|
gitwebhooks/main/__main__.py,sha256=qE-72BSpj15NeV6-oWpMXR3ARmATeSGUO8VUB98sxF8,223
|
|
33
33
|
gitwebhooks/models/__init__.py,sha256=DmZBPoNeh7eB9Ntr6d4T9QY6-LckvrHNGg8FVcpuvP0,273
|
|
34
34
|
gitwebhooks/models/provider.py,sha256=lmjJvGjklD1VTKB6UF9V-gZCPwXhiip8DR8qXs_A-F8,451
|
|
@@ -39,9 +39,9 @@ gitwebhooks/utils/constants.py,sha256=V_SFYrHpkX-fKSfVwx8fXwBjZe2f4EjoVz925RZryr
|
|
|
39
39
|
gitwebhooks/utils/exceptions.py,sha256=Mfz-FOCiHZiYmpSQDw36S9HarLE2wPLfFbkeHfWJnkk,627
|
|
40
40
|
gitwebhooks/utils/executor.py,sha256=-zQUV5t-eq0JF6T4EvsUlvg4lnBtahRGrV8N3iVgx_c,923
|
|
41
41
|
gitwebhooks/utils/systemd.py,sha256=00k55_vcstkTmJi99RrSfx-RIuI1dwTlggCPRPfbhNU,7901
|
|
42
|
-
gitwebhooks-2.
|
|
43
|
-
gitwebhooks-2.
|
|
44
|
-
gitwebhooks-2.
|
|
45
|
-
gitwebhooks-2.
|
|
46
|
-
gitwebhooks-2.
|
|
47
|
-
gitwebhooks-2.
|
|
42
|
+
gitwebhooks-2.2.0.dist-info/licenses/LICENSE,sha256=NV5F0xpN-DVJuhc0qzOsXtLjf3l8X18zehW_7F4qI50,1083
|
|
43
|
+
gitwebhooks-2.2.0.dist-info/METADATA,sha256=gPht52jk7aXxx3AhQEZCHNpij_IrFY97UUYHEIvOyLM,14346
|
|
44
|
+
gitwebhooks-2.2.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
45
|
+
gitwebhooks-2.2.0.dist-info/entry_points.txt,sha256=kcbGwiZPNGnfEYlsrOaNQinGC1rTkiaDOF2NJ6S_5MU,58
|
|
46
|
+
gitwebhooks-2.2.0.dist-info/top_level.txt,sha256=9a6CxnHxBD53HL38GUeZETIvnUhUKcgDRIGJkCqwc3o,12
|
|
47
|
+
gitwebhooks-2.2.0.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|