init
This commit is contained in:
@@ -124,3 +124,66 @@ class GiteaWebhookHandler:
|
||||
f for f in files
|
||||
if any(f.endswith(ext) for ext in extensions)
|
||||
]
|
||||
|
||||
def parse_pull_request_event(self, payload: Dict[str, Any]) -> Dict[str, Any]:
|
||||
"""
|
||||
解析 Pull Request 事件
|
||||
|
||||
Args:
|
||||
payload: Webhook payload
|
||||
|
||||
Returns:
|
||||
解析后的 PR 信息
|
||||
"""
|
||||
action = payload.get('action', '')
|
||||
pr = payload.get('pull_request', {})
|
||||
repo = payload.get('repository', {})
|
||||
|
||||
# 只处理 PR 创建和更新事件
|
||||
if action not in ['opened', 'reopened', 'synchronize', 'ready_for_review']:
|
||||
return None
|
||||
|
||||
# 获取 PR 的源分支和目标分支
|
||||
head = pr.get('head', {})
|
||||
base = pr.get('base', {})
|
||||
|
||||
return {
|
||||
'action': action,
|
||||
'repo_name': repo.get('full_name', ''),
|
||||
'repo_url': repo.get('clone_url', ''),
|
||||
'web_url': repo.get('web_url', ''),
|
||||
'pr_number': pr.get('number', 0),
|
||||
'pr_title': pr.get('title', ''),
|
||||
'pr_body': pr.get('body', ''),
|
||||
'pr_url': pr.get('html_url', ''),
|
||||
'source_branch': head.get('ref', ''),
|
||||
'source_sha': head.get('sha', '')[:8],
|
||||
'target_branch': base.get('ref', ''),
|
||||
'target_sha': base.get('sha', '')[:8],
|
||||
'author': pr.get('user', {}).get('login', ''),
|
||||
'author_email': pr.get('user', {}).get('email', ''),
|
||||
'state': pr.get('state', ''),
|
||||
'merged': pr.get('merged', False),
|
||||
}
|
||||
|
||||
def get_pr_diff_files(self, payload: Dict[str, Any]) -> list:
|
||||
"""
|
||||
从 Pull Request 事件中获取变更的文件列表
|
||||
|
||||
Args:
|
||||
payload: Webhook payload
|
||||
|
||||
Returns:
|
||||
变更的文件列表
|
||||
"""
|
||||
pr = payload.get('pull_request', {})
|
||||
files = pr.get('changed_files', [])
|
||||
|
||||
# 如果没有 changed_files 字段,尝试从 commits 中获取
|
||||
if not files:
|
||||
commits = pr.get('commits', [])
|
||||
files = []
|
||||
for commit in commits:
|
||||
files.extend(self.get_changed_files(commit))
|
||||
|
||||
return files
|
||||
Reference in New Issue
Block a user