Skip to content

Commit

Permalink
兼容 gogs
Browse files Browse the repository at this point in the history
  • Loading branch information
hustcc committed Oct 28, 2016
1 parent bcf26af commit fb6c109
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 5 deletions.
7 changes: 3 additions & 4 deletions README.md
Expand Up @@ -2,7 +2,7 @@

> 一个使用 Python Flask + SQLAchemy + Celery + Redis + React 开发的用于迅速搭建并使用 WebHook 进行自动化部署和运维系统,支持:**Github / GitLab / GitOsc**
[![Build Status](https://travis-ci.org/NetEaseGame/git-webhook.svg?branch=master)](https://travis-ci.org/NetEaseGame/git-webhook) ![GitHub](http://shields.hust.cc/Supported-GitHub-brightgreen.svg) ![GitLab](http://shields.hust.cc/Supported-GitLab-green.svg) ![GitOsc](http://shields.hust.cc/Supported-GitOsc-blue.svg)
[![Build Status](https://travis-ci.org/NetEaseGame/git-webhook.svg?branch=master)](https://travis-ci.org/NetEaseGame/git-webhook) ![GitHub](http://shields.hust.cc/Supported-GitHub-brightgreen.svg) ![GitLab](http://shields.hust.cc/Supported-GitLab-green.svg) ![GitOsc](http://shields.hust.cc/Supported-GitOsc-blue.svg) ![Gogs](http://shields.hust.cc/Supported-Gogs-yellowgreen.svg)

- 技术栈简单,**部署**容易;
- 代码简洁易懂,**二次开发**毫无压力;
Expand Down Expand Up @@ -98,11 +98,10 @@ Online DEMO Website: [http://webhook.hust.cc/](http://webhook.hust.cc/),使用

所以整体项目代码非常简单,大部分都能够修改和更新代码,并提交 Pull Request,目前系统 TODO 包括,我个人也将注意完善:

- 数据的修改功能(包括 WebHook 的修改,Server 服务器信息的修改);
- Celery 进程情况显示(当 Celery 进程没有执行的时候,在页面上提示,类似于 Sentry);
- 系统状态和统计(任务队列实时情况,WebHook 执行的统计图表);
- 系统状态和统计(任务队列实时情况,WebHook 执行的统计图表等);
- **发布为 pip 包,使得安装部署更加容易**
- Document 使用文档 & 帮助文档
- Document 使用文档 & 帮助文档完善


## LICENSE
Expand Down
1 change: 1 addition & 0 deletions app/__init__.py
Expand Up @@ -24,6 +24,7 @@
platforms.C_FORCE_ROOT = True
app.config['CELERY_BROKER_URL'] = config.CELERY_BROKER_URL
app.config['CELERY_RESULT_BACKEND'] = config.CELERY_RESULT_BACKEND
app.config['CELERY_ACCEPT_CONTENT'] = ['pickle', 'json', 'msgpack', 'yaml']
celeryInstance = Celery(app.name, broker=app.config['CELERY_BROKER_URL'])
celeryInstance.conf.update(app.config)

Expand Down
67 changes: 67 additions & 0 deletions app/test/WebhookData.py
Expand Up @@ -258,3 +258,70 @@
}
}
'''

gogs = '''
{
"sender": {
"username": "hustcc",
"avatar_url": "https://secure.gravatar.com/avatar/89b00603405ed96c59206c65a4f2358e",
"id": 1,
"full_name": "",
"email": "wzwahl36@qq.com"
},
"repository": {
"fork": false,
"website": "",
"open_issues_count": 0,
"description": "test_webhook",
"default_branch": "master",
"created_at": "2016-10-28T15:11:35+08:00",
"forks_count": 0,
"html_url": "http://127.0.0.1:3000/hustcc/test_webhook",
"private": false,
"updated_at": "2016-10-28T15:11:36+08:00",
"stars_count": 0,
"clone_url": "http://127.0.0.1:3000/hustcc/test_webhook.git",
"watchers_count": 1,
"full_name": "hustcc/test_webhook",
"ssh_url": "hzwangzhiwei@127.0.0.1:hustcc/test_webhook.git",
"owner": {
"username": "hustcc",
"avatar_url": "https://secure.gravatar.com/avatar/89b00603405ed96c59206c65a4f2358e",
"id": 1,
"full_name": "",
"email": "wzwahl36@qq.com"
},
"id": 1,
"name": "test_webhook"
},
"pusher": {
"username": "hustcc",
"avatar_url": "https://secure.gravatar.com/avatar/89b00603405ed96c59206c65a4f2358e",
"id": 1,
"full_name": "",
"email": "wzwahl36@qq.com"
},
"commits": [
{
"committer": {
"username": "hustcc",
"name": "hustcc",
"email": "wzwahl36@qq.com"
},
"author": {
"username": "hustcc",
"name": "hustcc",
"email": "wzwahl36@qq.com"
},
"url": "http://127.0.0.1:3000/hustcc/test_webhook/commit/331293f63684868be6b27da0104e35e3564059ad",
"timestamp": "2016-10-28T15:15:21+08:00",
"message": "test.txt",
"id": "331293f63684868be6b27da0104e35e3564059ad"
}
],
"after": "331293f63684868be6b27da0104e35e3564059ad",
"compare_url": "http://127.0.0.1:3000/hustcc/test_webhook/compare/b51fdb16830e2206a528aa00e778fb0163506c05...331293f63684868be6b27da0104e35e3564059ad",
"secret": "",
"ref": "refs/heads/master",
"before": "b51fdb16830e2206a528aa00e778fb0163506c05"
}'''
42 changes: 41 additions & 1 deletion app/utils/HookDataParse.py
Expand Up @@ -30,7 +30,10 @@ def get_push_name(hook_data):
uid = hook_data.get('user_name', None) # gitlib 格式
if uid:
return uid

uid = hook_data.get('pusher', {}).get('username', None) # gogs 格式
if uid:
return uid

uid = hook_data.get('push_data', {}).get('user', {}).get('name', None) # gitosc的data格式
if uid:
return uid
Expand All @@ -50,3 +53,40 @@ def get_push_email(hook_data):
if uid:
return uid
return ''


if __name__ == '__main__':
import json
from app.test import WebhookData
# for github
print '====for github==========================='
hook_data = json.loads(WebhookData.github)
print get_repo_name(hook_data)
print get_repo_branch(hook_data)
print get_push_name(hook_data)
print get_push_email(hook_data)
print '====end for github===========================\n'
# for gogs
print '====for gitlab==========================='
hook_data = json.loads(WebhookData.gitlab)
print get_repo_name(hook_data)
print get_repo_branch(hook_data)
print get_push_name(hook_data)
print get_push_email(hook_data)
print '====end for gitlab===========================\n'
# for gogs
print '====for gitosc==========================='
hook_data = json.loads(WebhookData.gitosc)
print get_repo_name(hook_data)
print get_repo_branch(hook_data)
print get_push_name(hook_data)
print get_push_email(hook_data)
print '====end for gitosc===========================\n'
# for gogs
print '====for gogs==========================='
hook_data = json.loads(WebhookData.gogs)
print get_repo_name(hook_data)
print get_repo_branch(hook_data)
print get_push_name(hook_data)
print get_push_email(hook_data)
print '====end for gogs==========================='

0 comments on commit fb6c109

Please sign in to comment.