gogs 代码同步软件

hopaheal b99b3e3fcd 更新 'README.md' 5 anni fa
db f8bc22f43f readme 5 anni fa
doc 110fb7b114 first commit 5 anni fa
install 110fb7b114 first commit 5 anni fa
.gitignore 110fb7b114 first commit 5 anni fa
README.md b99b3e3fcd 更新 'README.md' 5 anni fa
config.py 8a3b05861b 删除无关代码 5 anni fa
core.py c5d4430791 删除无关代码 5 anni fa
requirements.txt c5d4430791 删除无关代码 5 anni fa
webhooks.py 8a3b05861b 删除无关代码 5 anni fa

README.md

1. 安装

下载 Python安装包要求 Python2.7 以上支持 Python 3.x,安装 Python 打开命令行

pip install flask 

2. 拷贝 webhooks 到 C:/programData 目录下

3. 下载 nssm 放置到 C:/windows/system32/

打开命令行

nssm install webhook

选择 Python.exe 路径选择webhooks 参数选择 webhooks.py

4. 导入数据库 修改密码

数据库在 db 目录下的data.sql里面数据库配置在 config.py 里面

   SQLALCHEMY_DATABASE_SQLITE_URI = "mysql+pymysql://root:password@localhost:3306/webhook?charset=utf8"
   

5. 使 nssm 自启动

   nssm start webhooks

测试

   curl -s http://localhost:21332/hookssync/38daa500-55a8-11e8-acd6-704d7b885ead

注意事项

  1. 如果在除了

    PATH_WHITE_LIST = [
       # 匹配所有
       '.*',
       # /app/web/test
       '^/app/web/.*',
       # /app/web/tests
       '^/var/www/html/.*',
       '/www/wwwroot/.*'
    ]
    

目录同步代码需要修改 config.py 文件

如果在同步过程中需要执行其他命令需要添加规则

#允许在webhooks执行时执行的命令 使用正则表达式进行匹配
EXEC_WHITE_LIST = [
     # 匹配所有
     '.*',
     # git pull origin master
    '^git pull \w+ \w+$',
     # git fetch origin master && git reset --hard origin/master
    '^git fetch \w+ \w+ && git reset --hard \w+/\w+$',
    # git pull origin master && supervisorctl restart webhooks
    '^git pull \w+ \w+ && supervisorctl restart \w+$',
    # git fetch origin master && git reset --hard origin/master && supervisorctl restart webhooks
    '^git fetch \w+ \w+ && git reset --hard \w+/\w+ && supervisorctl restart \w+$'
]