gitwebhooks 2.0.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.
- gitwebhooks-2.0.0/.editorconfig +12 -0
- gitwebhooks-2.0.0/CLAUDE.md +258 -0
- gitwebhooks-2.0.0/LICENSE +21 -0
- gitwebhooks-2.0.0/MANIFEST.in +8 -0
- gitwebhooks-2.0.0/PKG-INFO +312 -0
- gitwebhooks-2.0.0/README.md +272 -0
- gitwebhooks-2.0.0/README.zh.md +272 -0
- gitwebhooks-2.0.0/doc/custom-body.png +0 -0
- gitwebhooks-2.0.0/doc/custom-header.png +0 -0
- gitwebhooks-2.0.0/doc/custom-response.png +0 -0
- gitwebhooks-2.0.0/doc/gitee-success.png +0 -0
- gitwebhooks-2.0.0/doc/gitee.png +0 -0
- gitwebhooks-2.0.0/doc/github-success.png +0 -0
- gitwebhooks-2.0.0/doc/github.png +0 -0
- gitwebhooks-2.0.0/doc/gitlab-success.png +0 -0
- gitwebhooks-2.0.0/doc/gitlab.png +0 -0
- gitwebhooks-2.0.0/doc/install.png +0 -0
- gitwebhooks-2.0.0/doc/uninstall.png +0 -0
- gitwebhooks-2.0.0/git-webhooks-server.ini.sample +42 -0
- gitwebhooks-2.0.0/git-webhooks-server.service.sample +14 -0
- gitwebhooks-2.0.0/gitwebhooks/__init__.py +18 -0
- gitwebhooks-2.0.0/gitwebhooks/__main__.py +10 -0
- gitwebhooks-2.0.0/gitwebhooks/auth/__init__.py +20 -0
- gitwebhooks-2.0.0/gitwebhooks/auth/custom.py +40 -0
- gitwebhooks-2.0.0/gitwebhooks/auth/factory.py +73 -0
- gitwebhooks-2.0.0/gitwebhooks/auth/gitee.py +86 -0
- gitwebhooks-2.0.0/gitwebhooks/auth/github.py +52 -0
- gitwebhooks-2.0.0/gitwebhooks/auth/gitlab.py +29 -0
- gitwebhooks-2.0.0/gitwebhooks/auth/verifier.py +34 -0
- gitwebhooks-2.0.0/gitwebhooks/cli.py +107 -0
- gitwebhooks-2.0.0/gitwebhooks/config/__init__.py +17 -0
- gitwebhooks-2.0.0/gitwebhooks/config/loader.py +170 -0
- gitwebhooks-2.0.0/gitwebhooks/config/models.py +145 -0
- gitwebhooks-2.0.0/gitwebhooks/config/registry.py +104 -0
- gitwebhooks-2.0.0/gitwebhooks/config/server.py +85 -0
- gitwebhooks-2.0.0/gitwebhooks/handlers/__init__.py +22 -0
- gitwebhooks-2.0.0/gitwebhooks/handlers/base.py +107 -0
- gitwebhooks-2.0.0/gitwebhooks/handlers/custom.py +73 -0
- gitwebhooks-2.0.0/gitwebhooks/handlers/factory.py +83 -0
- gitwebhooks-2.0.0/gitwebhooks/handlers/gitee.py +113 -0
- gitwebhooks-2.0.0/gitwebhooks/handlers/github.py +43 -0
- gitwebhooks-2.0.0/gitwebhooks/handlers/gitlab.py +43 -0
- gitwebhooks-2.0.0/gitwebhooks/handlers/request.py +248 -0
- gitwebhooks-2.0.0/gitwebhooks/logging/__init__.py +10 -0
- gitwebhooks-2.0.0/gitwebhooks/logging/setup.py +57 -0
- gitwebhooks-2.0.0/gitwebhooks/models/__init__.py +14 -0
- gitwebhooks-2.0.0/gitwebhooks/models/provider.py +22 -0
- gitwebhooks-2.0.0/gitwebhooks/models/request.py +61 -0
- gitwebhooks-2.0.0/gitwebhooks/models/result.py +40 -0
- gitwebhooks-2.0.0/gitwebhooks/server.py +128 -0
- gitwebhooks-2.0.0/gitwebhooks/utils/__init__.py +14 -0
- gitwebhooks-2.0.0/gitwebhooks/utils/constants.py +42 -0
- gitwebhooks-2.0.0/gitwebhooks/utils/exceptions.py +34 -0
- gitwebhooks-2.0.0/gitwebhooks/utils/executor.py +34 -0
- gitwebhooks-2.0.0/gitwebhooks.egg-info/PKG-INFO +312 -0
- gitwebhooks-2.0.0/gitwebhooks.egg-info/SOURCES.txt +125 -0
- gitwebhooks-2.0.0/gitwebhooks.egg-info/dependency_links.txt +1 -0
- gitwebhooks-2.0.0/gitwebhooks.egg-info/entry_points.txt +2 -0
- gitwebhooks-2.0.0/gitwebhooks.egg-info/requires.txt +4 -0
- gitwebhooks-2.0.0/gitwebhooks.egg-info/top_level.txt +1 -0
- gitwebhooks-2.0.0/pyproject.toml +78 -0
- gitwebhooks-2.0.0/setup.cfg +4 -0
- gitwebhooks-2.0.0/tests/__init__.py +13 -0
- gitwebhooks-2.0.0/tests/__main__.py +96 -0
- gitwebhooks-2.0.0/tests/conftest.py +414 -0
- gitwebhooks-2.0.0/tests/fixtures/__init__.py +3 -0
- gitwebhooks-2.0.0/tests/fixtures/custom_payloads.py +249 -0
- gitwebhooks-2.0.0/tests/fixtures/gitee_payloads.py +207 -0
- gitwebhooks-2.0.0/tests/fixtures/github_payloads.py +257 -0
- gitwebhooks-2.0.0/tests/fixtures/gitlab_payloads.py +243 -0
- gitwebhooks-2.0.0/tests/fixtures/signature_builder.py +255 -0
- gitwebhooks-2.0.0/tests/integration/__init__.py +3 -0
- gitwebhooks-2.0.0/tests/integration/test_command_execution.py +315 -0
- gitwebhooks-2.0.0/tests/integration/test_custom_webhook.py +135 -0
- gitwebhooks-2.0.0/tests/integration/test_edge_cases.py +252 -0
- gitwebhooks-2.0.0/tests/integration/test_gitee_webhook.py +187 -0
- gitwebhooks-2.0.0/tests/integration/test_github_webhook.py +273 -0
- gitwebhooks-2.0.0/tests/integration/test_gitlab_webhook.py +149 -0
- gitwebhooks-2.0.0/tests/test_auth/__init__.py +2 -0
- gitwebhooks-2.0.0/tests/test_config/__init__.py +2 -0
- gitwebhooks-2.0.0/tests/test_handlers/__init__.py +2 -0
- gitwebhooks-2.0.0/tests/test_integration/__init__.py +2 -0
- gitwebhooks-2.0.0/tests/unit/__init__.py +3 -0
- gitwebhooks-2.0.0/tests/unit/test_config_loading.py +271 -0
- gitwebhooks-2.0.0/tests/unit/test_data_parsing.py +147 -0
- gitwebhooks-2.0.0/tests/unit/test_provider_detection.py +228 -0
- gitwebhooks-2.0.0/tests/unit/test_request_handler.py +174 -0
- gitwebhooks-2.0.0/tests/unit/test_signature_verification.py +220 -0
- gitwebhooks-2.0.0/tests/utils/__init__.py +3 -0
- gitwebhooks-2.0.0/tests/utils/certificate_generator.py +236 -0
- gitwebhooks-2.0.0/tests/utils/coverage_runner.py +329 -0
- gitwebhooks-2.0.0/tests/utils/http_client.py +304 -0
- gitwebhooks-2.0.0/tests/utils/server_manager.py +396 -0
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
# CLAUDE.md
|
|
2
|
+
|
|
3
|
+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
|
|
4
|
+
|
|
5
|
+
## 项目概述
|
|
6
|
+
|
|
7
|
+
这是一个用 Python 3 实现的 Git Webhooks 服务器,用于自动化 Git 仓库部署。支持 Github、Gitee、Gitlab 和自定义仓库的 Webhook 事件处理。
|
|
8
|
+
|
|
9
|
+
**架构特点**:
|
|
10
|
+
- 模块化 Python 包结构 (`gitwebhooks/`)
|
|
11
|
+
- 使用标准库 `http.server` 实现 HTTP 服务器
|
|
12
|
+
- 通过 INI 配置文件管理多个仓库的部署命令
|
|
13
|
+
- 可作为 systemd 服务安装运行
|
|
14
|
+
- 原地运行:CLI 从源码目录加载模块
|
|
15
|
+
|
|
16
|
+
## 常用命令
|
|
17
|
+
|
|
18
|
+
### 安装和卸载
|
|
19
|
+
```bash
|
|
20
|
+
# 安装(交互式)
|
|
21
|
+
./install.sh
|
|
22
|
+
|
|
23
|
+
# 卸载
|
|
24
|
+
./install.sh --uninstall
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
### 运行服务
|
|
28
|
+
```bash
|
|
29
|
+
# 方式1: 使用模块入口
|
|
30
|
+
python3 -m gitwebhooks.cli -c /path/to/config.ini
|
|
31
|
+
|
|
32
|
+
# 方式2: 使用 CLI 工具(安装后)
|
|
33
|
+
gitwebhooks-cli -c /path/to/config.ini
|
|
34
|
+
|
|
35
|
+
# systemd 服务管理
|
|
36
|
+
systemctl start git-webhooks-server
|
|
37
|
+
systemctl stop git-webhooks-server
|
|
38
|
+
systemctl restart git-webhooks-server
|
|
39
|
+
systemctl status git-webhooks-server
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
### 测试开发
|
|
43
|
+
```bash
|
|
44
|
+
# 直接运行(开发模式)
|
|
45
|
+
./gitwebhooks-cli -c git-webhooks-server.ini.sample
|
|
46
|
+
|
|
47
|
+
# 或使用模块方式
|
|
48
|
+
python3 -m gitwebhooks.cli -c git-webhooks-server.ini.sample
|
|
49
|
+
|
|
50
|
+
# 运行测试套件
|
|
51
|
+
python3 -m pytest tests/
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## 架构说明
|
|
55
|
+
|
|
56
|
+
### 核心组件
|
|
57
|
+
|
|
58
|
+
**模块化包结构** (`gitwebhooks/`)
|
|
59
|
+
- `__init__.py`: 包入口,导出主要类
|
|
60
|
+
- `__main__.py`: 模块入口,支持 `python3 -m gitwebhooks`
|
|
61
|
+
- `cli.py`: 命令行入口点
|
|
62
|
+
- `server.py`: 主服务器类 `WebhookServer`
|
|
63
|
+
|
|
64
|
+
**子模块**:
|
|
65
|
+
- `models/`: 数据模型(Provider、WebhookRequest、验证结果等)
|
|
66
|
+
- `config/`: 配置加载和注册(ConfigLoader、ConfigurationRegistry)
|
|
67
|
+
- `auth/`: 签名验证模块(各平台的验证器工厂)
|
|
68
|
+
- `handlers/`: Webhook 处理器(按平台分离的处理器)
|
|
69
|
+
- `utils/`: 工具类(常量、异常、命令执行器)
|
|
70
|
+
- `logging/`: 日志配置
|
|
71
|
+
|
|
72
|
+
**CLI 工具** (`gitwebhooks-cli`)
|
|
73
|
+
- Bash 包装脚本,自动检测并加载 `gitwebhooks` 包
|
|
74
|
+
- 支持从源码目录运行或已安装的包运行
|
|
75
|
+
|
|
76
|
+
**Provider 枚举** (`gitwebhooks/models/provider.py`)
|
|
77
|
+
- 定义支持的 Git 平台:Github、Gitee、Gitlab、Custom
|
|
78
|
+
|
|
79
|
+
**请求处理流程**:
|
|
80
|
+
1. `WebhookRequestHandler.do_POST()`: 接收 POST 请求
|
|
81
|
+
2. `_parse_provider()`: 通过 HTTP Header 识别平台类型
|
|
82
|
+
3. `_parse_data()`: 解析 POST 请求体(支持 JSON 和 form-urlencoded)
|
|
83
|
+
4. 平台处理器验证签名/token
|
|
84
|
+
5. 从请求数据中提取仓库名称
|
|
85
|
+
6. 在配置中查找对应的仓库配置
|
|
86
|
+
7. 执行配置的命令(通过 `subprocess.Popen`)
|
|
87
|
+
|
|
88
|
+
### 配置结构
|
|
89
|
+
|
|
90
|
+
配置文件采用 INI 格式,主要分为几部分:
|
|
91
|
+
|
|
92
|
+
```ini
|
|
93
|
+
[server] # 服务器配置:address、port、log_file
|
|
94
|
+
[ssl] # SSL 配置:enable、key_file、cert_file
|
|
95
|
+
[github] # Github 配置:handle_events、verify、secret
|
|
96
|
+
[gitee] # Gitee 配置
|
|
97
|
+
[gitlab] # Gitlab 配置
|
|
98
|
+
[custom] # 自定义配置:header_name、header_value、identifier_path
|
|
99
|
+
[repo/name] # 仓库配置:cwd、cmd
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
**仓库配置部分**:
|
|
103
|
+
- 每个仓库一节,节名为 `owner/repo` 格式
|
|
104
|
+
- `cwd`: 工作目录
|
|
105
|
+
- `cmd`: 收到 Webhook 时执行的 shell 命令
|
|
106
|
+
|
|
107
|
+
### 平台特定处理
|
|
108
|
+
|
|
109
|
+
**Github** (`gitwebhooks/handlers/github.py`)
|
|
110
|
+
- Header: `X-GitHub-Event`
|
|
111
|
+
- 签名验证: `X-Hub-Signature` (HMAC-SHA1)
|
|
112
|
+
- 仓库标识: `repository.full_name`
|
|
113
|
+
- 验证器: `auth/github.py`
|
|
114
|
+
|
|
115
|
+
**Gitee** (`gitwebhooks/handlers/gitee.py`)
|
|
116
|
+
- Header: `X-Gitee-Event`
|
|
117
|
+
- 支持签名验证或密码验证
|
|
118
|
+
- 仓库标识: `repository.full_name`
|
|
119
|
+
- 验证器: `auth/gitee.py`
|
|
120
|
+
|
|
121
|
+
**Gitlab** (`gitwebhooks/handlers/gitlab.py`)
|
|
122
|
+
- Header: `X-Gitlab-Event`
|
|
123
|
+
- Token 验证: `X-Gitlab-Token`
|
|
124
|
+
- 仓库标识: `project.path_with_namespace`
|
|
125
|
+
- 验证器: `auth/gitlab.py`
|
|
126
|
+
|
|
127
|
+
**Custom** (`gitwebhooks/handlers/custom.py`)
|
|
128
|
+
- 自定义 Header 识别
|
|
129
|
+
- 通过 JSON 路径提取仓库标识(如 `project.path_with_namespace`)
|
|
130
|
+
- 验证器: `auth/custom.py`
|
|
131
|
+
|
|
132
|
+
## 代码规范
|
|
133
|
+
|
|
134
|
+
### 编辑器配置
|
|
135
|
+
项目使用 `.editorconfig`:
|
|
136
|
+
- UTF-8 编码
|
|
137
|
+
- LF 换行符
|
|
138
|
+
- 4 空格缩进
|
|
139
|
+
- 末尾插入空行
|
|
140
|
+
- Markdown 文件保留行尾空格
|
|
141
|
+
|
|
142
|
+
### Python 代码风格
|
|
143
|
+
- 遵循 Python 3.6+ 标准
|
|
144
|
+
- 使用 `logging` 模块记录日志
|
|
145
|
+
- 私有方法使用单下划线前缀(如 `_parse_provider`)
|
|
146
|
+
- 公有 API 不使用下划线前缀
|
|
147
|
+
- 配置通过 `configparser.ConfigParser` 读取
|
|
148
|
+
- 类型提示使用 `typing` 模块
|
|
149
|
+
- 自定义异常继承自 `Exception`
|
|
150
|
+
|
|
151
|
+
### Shell 脚本
|
|
152
|
+
- `install.sh`: 交互式安装脚本
|
|
153
|
+
- `message.sh`: 提供 ANSI 颜色输出函数(INFO、WARN、ERR、QUES)
|
|
154
|
+
|
|
155
|
+
## 开发注意事项
|
|
156
|
+
|
|
157
|
+
### 命令执行
|
|
158
|
+
当前使用 `subprocess.Popen` 非阻塞执行命令(`gitwebhooks/utils/executor.py`)。命令在后台运行,不阻塞服务器进程。
|
|
159
|
+
|
|
160
|
+
### 日志配置
|
|
161
|
+
- 日志文件位置在配置文件的 `server.log_file` 指定
|
|
162
|
+
- 日志同时输出到文件和标准输出(如果配置了日志文件)
|
|
163
|
+
|
|
164
|
+
### SSL 支持
|
|
165
|
+
- 通过配置文件的 `[ssl]` 部分启用
|
|
166
|
+
- 需要提供证书文件和密钥文件路径
|
|
167
|
+
|
|
168
|
+
### 自定义平台
|
|
169
|
+
使用 `[custom]` 配置可以支持任意 Webhook 源:
|
|
170
|
+
- `header_name/header_value`: 识别请求来源
|
|
171
|
+
- `header_token`: token 验证的 header 名称
|
|
172
|
+
- `identifier_path`: JSON 路径,用于提取仓库标识
|
|
173
|
+
- `header_event`: 可选,事件类型 header 名称
|
|
174
|
+
|
|
175
|
+
## 文件结构
|
|
176
|
+
|
|
177
|
+
```
|
|
178
|
+
git-webhooks-server/
|
|
179
|
+
├── gitwebhooks-cli # CLI 命令行工具
|
|
180
|
+
├── gitwebhooks/ # 主包目录
|
|
181
|
+
│ ├── __init__.py # 包入口
|
|
182
|
+
│ ├── __main__.py # 模块入口
|
|
183
|
+
│ ├── cli.py # CLI 实现
|
|
184
|
+
│ ├── server.py # 主服务器类
|
|
185
|
+
│ ├── auth/ # 签名验证模块
|
|
186
|
+
│ │ ├── __init__.py
|
|
187
|
+
│ │ ├── factory.py # 验证器工厂
|
|
188
|
+
│ │ ├── verifier.py # 验证器基类
|
|
189
|
+
│ │ ├── github.py # GitHub 验证器
|
|
190
|
+
│ │ ├── gitee.py # Gitee 验证器
|
|
191
|
+
│ │ ├── gitlab.py # GitLab 验证器
|
|
192
|
+
│ │ └── custom.py # 自定义验证器
|
|
193
|
+
│ ├── config/ # 配置模块
|
|
194
|
+
│ │ ├── __init__.py
|
|
195
|
+
│ │ ├── loader.py # 配置加载器
|
|
196
|
+
│ │ ├── registry.py # 配置注册表
|
|
197
|
+
│ │ ├── models.py # 配置数据类
|
|
198
|
+
│ │ └── server.py # 服务器配置
|
|
199
|
+
│ ├── handlers/ # Webhook 处理器
|
|
200
|
+
│ │ ├── __init__.py
|
|
201
|
+
│ │ ├── request.py # 请求处理器基类
|
|
202
|
+
│ │ ├── factory.py # 处理器工厂
|
|
203
|
+
│ │ ├── github.py # GitHub 处理器
|
|
204
|
+
│ │ ├── gitee.py # Gitee 处理器
|
|
205
|
+
│ │ ├── gitlab.py # GitLab 处理器
|
|
206
|
+
│ │ └── custom.py # 自定义处理器
|
|
207
|
+
│ ├── models/ # 数据模型
|
|
208
|
+
│ │ ├── __init__.py
|
|
209
|
+
│ │ ├── provider.py # Provider 枚举
|
|
210
|
+
│ │ ├── request.py # 请求数据类
|
|
211
|
+
│ │ └── result.py # 验证结果类
|
|
212
|
+
│ ├── utils/ # 工具模块
|
|
213
|
+
│ │ ├── __init__.py
|
|
214
|
+
│ │ ├── constants.py # 常量定义
|
|
215
|
+
│ │ ├── exceptions.py # 自定义异常
|
|
216
|
+
│ │ └── executor.py # 命令执行器
|
|
217
|
+
│ └── logging/ # 日志模块
|
|
218
|
+
│ └── setup.py # 日志配置
|
|
219
|
+
├── tests/ # 测试套件
|
|
220
|
+
│ ├── unit/ # 单元测试
|
|
221
|
+
│ ├── integration/ # 集成测试
|
|
222
|
+
│ ├── utils/ # 测试工具
|
|
223
|
+
│ └── conftest.py # pytest 配置
|
|
224
|
+
├── git-webhooks-server.ini.sample # 配置文件模板
|
|
225
|
+
├── git-webhooks-server.service.sample # systemd 服务模板
|
|
226
|
+
├── install.sh # 安装/卸载脚本
|
|
227
|
+
├── message.sh # 颜色输出辅助脚本
|
|
228
|
+
├── README.md # 项目说明(英文)
|
|
229
|
+
├── README.zh.md # 项目说明(中文)
|
|
230
|
+
├── CLAUDE.md # Claude Code 项目指南
|
|
231
|
+
├── .editorconfig # 编辑器配置
|
|
232
|
+
├── .gitignore # Git 忽略文件
|
|
233
|
+
├── doc/ # 文档截图目录
|
|
234
|
+
└── .specify/ # SpecKit 工作流模板目录
|
|
235
|
+
├── templates/ # 功能规格、计划、任务模板
|
|
236
|
+
├── scripts/ # 辅助脚本
|
|
237
|
+
└── memory/ # 工作流记忆存储
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
## 配置文件位置
|
|
241
|
+
|
|
242
|
+
- 默认配置路径: `/usr/local/etc/git-webhooks-server.ini`
|
|
243
|
+
- 日志文件: `/var/log/git-webhooks-server.log`
|
|
244
|
+
- 安装后的 CLI: `/usr/local/bin/gitwebhooks-cli`
|
|
245
|
+
- systemd 服务: `/usr/lib/systemd/system/git-webhooks-server.service`
|
|
246
|
+
|
|
247
|
+
## Active Technologies
|
|
248
|
+
- Python 3.6+ + Python 标准库(无外部依赖)
|
|
249
|
+
- 模块化包结构 (`gitwebhooks/`)
|
|
250
|
+
- INI 配置文件 (configparser.ConfigParser)
|
|
251
|
+
- http.server (HTTP 服务器)
|
|
252
|
+
- subprocess (命令执行)
|
|
253
|
+
- ssl (HTTPS 支持)
|
|
254
|
+
- pytest (测试框架)
|
|
255
|
+
- Bash 4.0+ (安装脚本)
|
|
256
|
+
|
|
257
|
+
## Recent Changes
|
|
258
|
+
- 001-refactor-codebase: 重构为模块化包结构,保持向后兼容
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2020 Troy Tse <troy@holyhi.net>
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,312 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: gitwebhooks
|
|
3
|
+
Version: 2.0.0
|
|
4
|
+
Summary: A lightweight Git webhook server for automated deployment supporting GitHub, Gitee, GitLab, and custom webhooks
|
|
5
|
+
Author-email: Troy Tse <troy@holyhi.net>
|
|
6
|
+
Maintainer-email: Troy Tse <troy@holyhi.net>
|
|
7
|
+
License-Expression: MIT
|
|
8
|
+
Project-URL: Homepage, https://github.com/troytse/git-webhooks-server
|
|
9
|
+
Project-URL: Documentation, https://github.com/troytse/git-webhooks-server#readme
|
|
10
|
+
Project-URL: Repository, https://github.com/troytse/git-webhooks-server.git
|
|
11
|
+
Project-URL: Issues, https://github.com/troytse/git-webhooks-server/issues
|
|
12
|
+
Keywords: webhook,git,github,gitee,gitlab,deployment,automation,server,devops
|
|
13
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
14
|
+
Classifier: Environment :: No Input/Output (Daemon)
|
|
15
|
+
Classifier: Intended Audience :: Developers
|
|
16
|
+
Classifier: Intended Audience :: System Administrators
|
|
17
|
+
Classifier: Operating System :: OS Independent
|
|
18
|
+
Classifier: Programming Language :: Python :: 3
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.6
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.7
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
23
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
24
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
25
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
26
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
27
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
28
|
+
Classifier: Topic :: Internet :: WWW/HTTP :: HTTP Servers
|
|
29
|
+
Classifier: Topic :: Software Development :: Version Control :: Git
|
|
30
|
+
Classifier: Topic :: System :: Installation/Setup
|
|
31
|
+
Classifier: Topic :: System :: Systems Administration
|
|
32
|
+
Classifier: Typing :: Typed
|
|
33
|
+
Requires-Python: >=3.6
|
|
34
|
+
Description-Content-Type: text/markdown
|
|
35
|
+
License-File: LICENSE
|
|
36
|
+
Provides-Extra: dev
|
|
37
|
+
Requires-Dist: pytest>=6.0; extra == "dev"
|
|
38
|
+
Requires-Dist: pytest-cov>=2.0; extra == "dev"
|
|
39
|
+
Dynamic: license-file
|
|
40
|
+
|
|
41
|
+
# Simple Git Webhooks Server
|
|
42
|
+
|
|
43
|
+
[README](README.md) | [中文说明](README.zh.md)
|
|
44
|
+
|
|
45
|
+
## Table of Contents
|
|
46
|
+
- [Introduction](#introduction)
|
|
47
|
+
- [Architecture](#architecture)
|
|
48
|
+
- [Installation](#installation)
|
|
49
|
+
- [Uninstallation](#uninstallation)
|
|
50
|
+
- [Usage](#usage)
|
|
51
|
+
- [Github](#github)
|
|
52
|
+
- [Gitee](#gitee)
|
|
53
|
+
- [Gitlab](#gitlab)
|
|
54
|
+
- [Custom](#custom)
|
|
55
|
+
- [Configuration](#configuration)
|
|
56
|
+
- [Project Structure](#project-structure)
|
|
57
|
+
|
|
58
|
+
## Introduction
|
|
59
|
+
|
|
60
|
+
A lightweight Git webhook server for automated deployment.
|
|
61
|
+
|
|
62
|
+
- Implemented with Python 3.6+ (standard library only)
|
|
63
|
+
- Supports Github, Gitee, Gitlab, and custom repositories
|
|
64
|
+
- Custom working directory and command for different repositories
|
|
65
|
+
- Installable as a Systemd service
|
|
66
|
+
- Modular architecture for easy extension and testing
|
|
67
|
+
|
|
68
|
+
## Architecture
|
|
69
|
+
|
|
70
|
+
**Version 2.0** features a modular package structure:
|
|
71
|
+
|
|
72
|
+
```
|
|
73
|
+
gitwebhooks/
|
|
74
|
+
├── models/ # Data models (Provider, Request, Result)
|
|
75
|
+
├── config/ # Configuration management
|
|
76
|
+
├── auth/ # Signature verification
|
|
77
|
+
├── handlers/ # Webhook handlers
|
|
78
|
+
├── utils/ # Utilities
|
|
79
|
+
└── logging/ # Logging setup
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
**Key Features:**
|
|
83
|
+
- **Dependency Injection**: ConfigurationRegistry, VerifierFactory, HandlerFactory
|
|
84
|
+
- **Abstract Base Classes**: SignatureVerifier, WebhookHandler
|
|
85
|
+
- **No External Dependencies**: 100% Python standard library
|
|
86
|
+
- **In-Place Execution**: CLI runs from source directory
|
|
87
|
+
|
|
88
|
+
## Installation
|
|
89
|
+
|
|
90
|
+
### Prerequisites
|
|
91
|
+
|
|
92
|
+
- Python 3.6 or higher
|
|
93
|
+
- sudo/root access (for installation)
|
|
94
|
+
|
|
95
|
+
### Install from Source
|
|
96
|
+
|
|
97
|
+
```bash
|
|
98
|
+
# Clone or download the repository
|
|
99
|
+
git clone https://github.com/troytse/git-webhooks-server.git
|
|
100
|
+
cd git-webhooks-server
|
|
101
|
+
|
|
102
|
+
# Run the installation script
|
|
103
|
+
./install.sh
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
The installer will:
|
|
107
|
+
1. Create a hard link for `gitwebhooks-cli` in `/usr/local/bin`
|
|
108
|
+
2. Copy configuration file to `/usr/local/etc/git-webhooks-server.ini`
|
|
109
|
+
3. Optionally install as a systemd service
|
|
110
|
+
|
|
111
|
+

|
|
112
|
+
|
|
113
|
+
### Manual Installation
|
|
114
|
+
|
|
115
|
+
To install manually without the script:
|
|
116
|
+
|
|
117
|
+
```bash
|
|
118
|
+
# Make CLI executable
|
|
119
|
+
chmod +x gitwebhooks-cli
|
|
120
|
+
|
|
121
|
+
# Create hard link to system path
|
|
122
|
+
sudo ln "$(pwd)/gitwebhooks-cli" /usr/local/bin/gitwebhooks-cli
|
|
123
|
+
|
|
124
|
+
# Copy configuration
|
|
125
|
+
sudo cp git-webhooks-server.ini.sample /usr/local/etc/git-webhooks-server.ini
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
### Verify Installation
|
|
129
|
+
|
|
130
|
+
```bash
|
|
131
|
+
gitwebhooks-cli --help
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
## Uninstallation
|
|
135
|
+
|
|
136
|
+
```bash
|
|
137
|
+
cd git-webhooks-server
|
|
138
|
+
./install.sh --uninstall
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+

|
|
142
|
+
|
|
143
|
+
## Usage
|
|
144
|
+
|
|
145
|
+
### 1. Configure Repository
|
|
146
|
+
|
|
147
|
+
Edit `/usr/local/etc/git-webhooks-server.ini`:
|
|
148
|
+
|
|
149
|
+
```ini
|
|
150
|
+
[your_name/repository]
|
|
151
|
+
cwd=/path/to/your/repository
|
|
152
|
+
cmd=git fetch --all && git reset --hard origin/master && git pull
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
### 2. Restart Service
|
|
156
|
+
|
|
157
|
+
```bash
|
|
158
|
+
systemctl restart git-webhooks-server
|
|
159
|
+
# Or run directly:
|
|
160
|
+
gitwebhooks-cli -c /usr/local/etc/git-webhooks-server.ini
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
### 3. Add Webhook
|
|
164
|
+
|
|
165
|
+
#### Github
|
|
166
|
+
|
|
167
|
+

|
|
168
|
+

|
|
169
|
+
|
|
170
|
+
#### Gitee
|
|
171
|
+
|
|
172
|
+

|
|
173
|
+

|
|
174
|
+
|
|
175
|
+
#### Gitlab
|
|
176
|
+
|
|
177
|
+

|
|
178
|
+

|
|
179
|
+
|
|
180
|
+
#### Custom
|
|
181
|
+
|
|
182
|
+
For custom webhook sources, configure like this:
|
|
183
|
+
|
|
184
|
+
```ini
|
|
185
|
+
[custom]
|
|
186
|
+
# Header to identify the source
|
|
187
|
+
header_name=X-Custom-Header
|
|
188
|
+
header_value=Custom-Git-Hookshot
|
|
189
|
+
# Header for token verification
|
|
190
|
+
header_token=X-Custom-Token
|
|
191
|
+
# Path to repository name in JSON payload
|
|
192
|
+
identifier_path=project.path_with_namespace
|
|
193
|
+
verify=True
|
|
194
|
+
secret=123456
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
The handler accepts POST data with `application/json` or `application/x-www-form-urlencoded` content type. See [Github](https://developer.github.com/webhooks/event-payloads/#example-delivery) / [Gitee](https://gitee.com/help/articles/4186) / [Gitlab](https://gitlab.com/help/user/project/integrations/webhooks#push-events) for payload examples.
|
|
198
|
+
|
|
199
|
+
Example payload:
|
|
200
|
+
```json
|
|
201
|
+
{
|
|
202
|
+
"project": {
|
|
203
|
+
"path_with_namespace": "your_name/repository"
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+

|
|
209
|
+

|
|
210
|
+

|
|
211
|
+
|
|
212
|
+
## Configuration
|
|
213
|
+
|
|
214
|
+
Default configuration file: `/usr/local/etc/git-webhooks-server.ini`
|
|
215
|
+
|
|
216
|
+
### Server Configuration
|
|
217
|
+
|
|
218
|
+
```ini
|
|
219
|
+
[server]
|
|
220
|
+
address=0.0.0.0 # Listen address
|
|
221
|
+
port=6789 # Listen port
|
|
222
|
+
log_file=/var/log/git-webhooks-server.log # Log file (empty = stdout only)
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
### SSL Configuration (Optional)
|
|
226
|
+
|
|
227
|
+
```ini
|
|
228
|
+
[ssl]
|
|
229
|
+
enable=False
|
|
230
|
+
key_file=/path/to/key.pem
|
|
231
|
+
cert_file=/path/to/cert.pem
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
### Provider Configuration
|
|
235
|
+
|
|
236
|
+
```ini
|
|
237
|
+
[github]
|
|
238
|
+
verify=True # Enable signature verification
|
|
239
|
+
secret=your_webhook_secret
|
|
240
|
+
handle_events=push,pull_request # Events to handle (empty = all)
|
|
241
|
+
|
|
242
|
+
[gitee]
|
|
243
|
+
verify=True
|
|
244
|
+
secret=your_webhook_secret
|
|
245
|
+
|
|
246
|
+
[gitlab]
|
|
247
|
+
verify=True
|
|
248
|
+
secret=your_webhook_token
|
|
249
|
+
|
|
250
|
+
[custom]
|
|
251
|
+
header_name=X-Custom-Header
|
|
252
|
+
header_value=Your-Identifier
|
|
253
|
+
header_token=X-Custom-Token
|
|
254
|
+
identifier_path=project.path_with_namespace
|
|
255
|
+
verify=True
|
|
256
|
+
secret=your_secret
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
### Repository Configuration
|
|
260
|
+
|
|
261
|
+
```ini
|
|
262
|
+
[owner/repository]
|
|
263
|
+
cwd=/path/to/repo # Working directory
|
|
264
|
+
cmd=your_command # Command to execute
|
|
265
|
+
```
|
|
266
|
+
|
|
267
|
+
## Project Structure
|
|
268
|
+
|
|
269
|
+
```
|
|
270
|
+
git-webhooks-server/
|
|
271
|
+
├── gitwebhooks/ # Python package (modular v2.0)
|
|
272
|
+
│ ├── __init__.py
|
|
273
|
+
│ ├── __main__.py
|
|
274
|
+
│ ├── cli.py # CLI entry point
|
|
275
|
+
│ ├── server.py # HTTP server
|
|
276
|
+
│ ├── models/ # Data models
|
|
277
|
+
│ ├── config/ # Configuration management
|
|
278
|
+
│ ├── auth/ # Signature verification
|
|
279
|
+
│ ├── handlers/ # Webhook handlers
|
|
280
|
+
│ ├── utils/ # Utilities
|
|
281
|
+
│ └── logging/ # Logging setup
|
|
282
|
+
├── gitwebhooks-cli # CLI wrapper script
|
|
283
|
+
├── install.sh # Installation script
|
|
284
|
+
├── git-webhooks-server.ini.sample
|
|
285
|
+
└── tests/ # Test suite
|
|
286
|
+
```
|
|
287
|
+
|
|
288
|
+
## Development
|
|
289
|
+
|
|
290
|
+
### Running from Source
|
|
291
|
+
|
|
292
|
+
```bash
|
|
293
|
+
# Method 1: Use CLI tool (recommended)
|
|
294
|
+
./gitwebhooks-cli -c git-webhooks-server.ini.sample
|
|
295
|
+
|
|
296
|
+
# Method 2: Use module entry
|
|
297
|
+
python3 -m gitwebhooks.cli -c git-webhooks-server.ini.sample
|
|
298
|
+
```
|
|
299
|
+
|
|
300
|
+
### Running Tests
|
|
301
|
+
|
|
302
|
+
```bash
|
|
303
|
+
# Using pytest
|
|
304
|
+
python3 -m pytest tests/
|
|
305
|
+
|
|
306
|
+
# Or using unittest
|
|
307
|
+
python3 -m unittest discover tests/
|
|
308
|
+
```
|
|
309
|
+
|
|
310
|
+
## License
|
|
311
|
+
|
|
312
|
+
MIT License
|