2 Star 3 Fork 1

user_1413365/gitchecker

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
Main.py 4.04 KB
一键复制 编辑 原始数据 按行查看 历史
user_1413365 提交于 2023-04-25 18:00 +08:00 . 优化commit提取
#coding=utf-8
#!/usr/bin/env python
# pylint: disable-msg=W0122, E0602
# Copyright 2008 German Aerospace Center (DLR)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""
http://svnchecker.tigris.org
"""
import os
import sys
from modules import Config, Transaction
##########################################################
# 迁移到SqlChecker中
#if not "XXXX" in os.getenv("GL_PROJECT_PATH"):
# exit(0)
hook = ""
# initialize configuration and transaction
try:
''' https://www.cnblogs.com/K2154952/p/5963184.html
该脚本在pre-receive或post-receive钩子中被调用,也可以直接将该文件作为git的钩子使用
若钩子为shell脚本,则需要加入以下代码调用该脚本:
while read line;do
echo $line | python $PATH/pre-receive.py
done
当用户执行git push的时候会在远程版本库上触发此脚本
该脚本的主要作用:获取用户提交至版本库的文件列表,提交者及时间信息
'''
oldrev, newrev, ref = sys.stdin.readline().strip().split(' ')
hook = sys.argv[1]
#print(hook)
#print(oldrev, newrev, ref)
if hook not in ["pre-receive", "update", "post-receive", "PreCommit", "PostCommit"]:
raise IndexError()
except IndexError:
sys.stderr.write("""Usage: Main.py
hook: pre-receive OR update OR post-receive
""")
sys.exit(1)
repo = os.getcwd()
basedir = os.path.join(repo, "..")
#print(basedir)
#exit(1)
reposPath = repo
os.chdir(os.path.join(reposPath, "hooks"))
#print(os.getcwd())
#exit(1)
transaction = Transaction.Transaction(oldrev, newrev, ref)
#print("1111",transaction.getFiles().keys())
#print("22222",transaction.getFiles().values())
#exit(1)
def finish(code):
transaction.cleanup()
sys.exit(code)
configFilename = "gitcheckerconfig.ini"
localConfig = os.path.join(reposPath, "hooks", configFilename)
globalConfig = os.path.join(os.path.dirname(os.path.abspath(sys.argv[0])), configFilename)
#print(localConfig)
#print(globalConfig)
config = Config.Config(globalConfig, localConfig)
config.setHooksLocation(os.path.join(reposPath, "hooks"))
# which files do not belong to a profile
files = transaction.getFiles().keys()
toRemove = []
for profile in config.getProfiles():
config.setProfile(profile)
transaction.setProfile(config.getString('Main.Regex', "^$"))
toRemove += [filename for filename in transaction.getFiles() if filename in files]
for filename in toRemove:
files.remove(filename)
default = "^("
for filename in files:
default += filename + "|"
default = default.strip("|")
default += ")$"
for profile in config.getProfiles() + [Config.DEFAULTSECT]:
config.setProfile(profile)
if profile == Config.DEFAULTSECT:
transaction.setProfile(default)
else:
transaction.setProfile(config.getString('Main.Regex', "^$"))
# if there are no files in this profile continue
if len(transaction.getFiles()) == 0:
continue
# run the configured checks
for check in config.getArray('Main.%sChecks' % hook):
exec("from checks.%s import run" % check)
(msg, exitCode) = run(transaction, config)
if not msg:
continue
if exitCode == 1:
handlers = config.getArray('%s.FailureHandlers' % check)
else:
handlers = config.getArray('%s.SuccessHandlers' % check)
# run the configured handlers
for handler in handlers:
exec("from handlers.%s import run" % handler)
run(transaction, config, check, msg, exitCode)
if exitCode == 1:
finish(exitCode)
finish(0)
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/lqzkcx3/gitchecker.git
git@gitee.com:lqzkcx3/gitchecker.git
lqzkcx3
gitchecker
gitchecker
master

搜索帮助