forked from Lesin/reposync
重整仓库
This commit is contained in:
parent
b773101cea
commit
0c05c8d1a1
|
|
@ -1,4 +1,4 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.9 (reposync) (2)" project-jdk-type="Python SDK" />
|
||||
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.9 (reposync)" project-jdk-type="Python SDK" />
|
||||
</project>
|
||||
|
|
@ -4,7 +4,7 @@
|
|||
<content url="file://$MODULE_DIR$">
|
||||
<excludeFolder url="file://$MODULE_DIR$/venv" />
|
||||
</content>
|
||||
<orderEntry type="jdk" jdkName="Python 3.9 (reposync) (2)" jdkType="Python SDK" />
|
||||
<orderEntry type="jdk" jdkName="Python 3.9 (reposync)" jdkType="Python SDK" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
<component name="PyDocumentationSettings">
|
||||
|
|
|
|||
|
|
@ -0,0 +1,124 @@
|
|||
import re
|
||||
|
||||
def parse_git_output(output):
|
||||
# 定义正则表达式模式
|
||||
commit_pattern = re.compile(r'commit\s+([a-f0-9]+)')
|
||||
author_pattern = re.compile(r'Author:\s+(.+)')
|
||||
date_pattern = re.compile(r'Date:\s+(.+)')
|
||||
|
||||
# 使用正则表达式搜索并提取信息
|
||||
commit_hash = commit_pattern.search(output).group(1) if commit_pattern.search(output) else None
|
||||
author = author_pattern.search(output).group(1) if author_pattern.search(output) else None
|
||||
date = date_pattern.search(output).group(1) if date_pattern.search(output) else None
|
||||
|
||||
return commit_hash, author, date
|
||||
|
||||
def extract_diff_content(git_diff_output):
|
||||
# 定义正则表达式,匹配从 'diff --git' 开始到 'index' 之前的文本
|
||||
pattern = re.compile(r'diff --git(.+?)(?=\nindex|$)', re.DOTALL)
|
||||
|
||||
# 使用正则表达式查找所有匹配项
|
||||
matches = pattern.findall(git_diff_output)
|
||||
|
||||
# 存储截取的内容
|
||||
extracted_contents = []
|
||||
|
||||
# 遍历所有匹配项
|
||||
for match in matches:
|
||||
# 去除每个匹配项中的空白行,并添加到结果列表
|
||||
cleaned_match = '\n'.join(line for line in match.strip().split('\n') if line)
|
||||
extracted_contents.append(cleaned_match)
|
||||
|
||||
return extracted_contents
|
||||
|
||||
def extract_changes_since_last_diff(diff_output):
|
||||
# 定义正则表达式,匹配 '+++ b' 后面的内容,直到下一个 'diff' 或文本末尾
|
||||
pattern = re.compile(r'\+\+\+ b/(.+?)(?=\ndiff --git|$)', re.DOTALL)
|
||||
|
||||
# 使用正则表达式查找所有匹配项
|
||||
matches = pattern.findall(diff_output)
|
||||
|
||||
# 处理匹配结果,每项匹配结果是一个元组,包含从 '+++ b/' 到下一个 'diff' 或文本末尾的内容
|
||||
extracted_content = []
|
||||
for match in matches:
|
||||
# 去除匹配内容中的 '\ No newline at end of file' 行
|
||||
content = '\n'.join([line for line in match.strip().split('\n') if line and line != '\\ No newline at end of file'])
|
||||
extracted_content.append(content)
|
||||
|
||||
return extracted_content
|
||||
|
||||
git_diff_output = """
|
||||
Last commit hash before push: commit d5f594d3bc9bf2fabf1f97cd375f1ca8be821d60
|
||||
Author: xmy <1926207361@qq.com>
|
||||
Date: Wed Jun 26 08:02:53 2024 +0800
|
||||
closer
|
||||
diff --git a/src/Merry_Christmas.txt b/src/Merry_Christmas.txt
|
||||
new file mode 100644
|
||||
index 0000000..8f3694f
|
||||
--- /dev/null
|
||||
+++ b/src/Merry_Christmas.txt
|
||||
@@ -0,0 +1 @@
|
||||
+坂本龙一
|
||||
\ No newline at end of file
|
||||
diff --git a/src/changsha.txt b/src/changsha.txt
|
||||
index 7df336a..f007879 100644
|
||||
--- a/src/changsha.txt
|
||||
+++ b/src/changsha.txt
|
||||
@@ -1 +1,3 @@
|
||||
-抗洪抢险 党员优先
|
||||
\ No newline at end of file
|
||||
+抗洪抢险 党员优先
|
||||
+
|
||||
+新增调试
|
||||
\ No newline at end of file
|
||||
"""
|
||||
|
||||
commit_hash, author, date = parse_git_output(git_diff_output)
|
||||
print("Commit Hash:", commit_hash)
|
||||
print("Author:", author)
|
||||
print("Date:", date)
|
||||
print("\n")
|
||||
|
||||
extracted_contents = extract_diff_content(git_diff_output)
|
||||
|
||||
# 提取 '+++ b' 后面的内容
|
||||
changes_since_last_diff = extract_changes_since_last_diff(git_diff_output)
|
||||
|
||||
# 打印提取的内容
|
||||
for content in extracted_contents:
|
||||
if 'new file' in content:
|
||||
pattern = re.compile(r' b/(.+?)(?=\nnew|$)', re.DOTALL)
|
||||
# 使用正则表达式查找所有匹配项
|
||||
matches = pattern.findall(content)
|
||||
# 存储截取的内容
|
||||
add_files = []
|
||||
# 遍历所有匹配项
|
||||
for match in matches:
|
||||
# 去除每个匹配项中的空白行,并添加到结果列表
|
||||
cleaned_match = '\n'.join(line for line in match.strip().split('\n') if line)
|
||||
add_files.append(cleaned_match)
|
||||
|
||||
print('ADD_FILES:', add_files)
|
||||
|
||||
for add_file in add_files:
|
||||
for change in changes_since_last_diff:
|
||||
if add_file in change:
|
||||
print("\n"+change)
|
||||
print("\n--- End of Extracted Content ---\n")
|
||||
else:
|
||||
pattern = re.compile(r'a/(.+?)(?=b|$)', re.DOTALL)
|
||||
# 使用正则表达式查找所有匹配项
|
||||
matches = pattern.findall(content)
|
||||
# 存储截取的内容
|
||||
modified_files = []
|
||||
# 遍历所有匹配项
|
||||
for match in matches:
|
||||
# 去除每个匹配项中的空白行,并添加到结果列表
|
||||
cleaned_match = '\n'.join(line for line in match.strip().split('\n') if line)
|
||||
modified_files.append(cleaned_match)
|
||||
print('MODIFIED_FILES:', modified_files)
|
||||
for modified_file in modified_files:
|
||||
for change in changes_since_last_diff:
|
||||
if modified_file in change:
|
||||
print("\n"+ change)
|
||||
print("\n--- End of Extracted Content ---\n")
|
||||
2
main.py
2
main.py
|
|
@ -25,7 +25,7 @@ app.include_router(LOG)
|
|||
app.include_router(AUTH)
|
||||
app.include_router(SYNC_CONFIG)
|
||||
|
||||
app.mount("/", StaticFiles(directory="web"), name="static")
|
||||
# app.mount("/", StaticFiles(directory="web/dist"), name="static")
|
||||
|
||||
if __name__ == '__main__':
|
||||
# workers 参数仅在命令行使用uvicorn启动时有效 或使用环境变量 WEB_CONCURRENCY
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
--同步仓库信息映射表
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `sync_repo_mapping` (
|
||||
`id` bigint unsigned NOT NULL AUTO_INCREMENT,
|
||||
|
|
@ -13,7 +12,6 @@ CREATE TABLE IF NOT EXISTS `sync_repo_mapping` (
|
|||
UNIQUE KEY (`repo_name`)
|
||||
) DEFAULT CHARACTER SET = utf8mb4 COMMENT = '同步仓库映射表';
|
||||
|
||||
--同步分支信息映射表
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `sync_branch_mapping`(
|
||||
`id` bigint unsigned NOT NULL AUTO_INCREMENT,
|
||||
|
|
@ -26,7 +24,6 @@ CREATE TABLE IF NOT EXISTS `sync_branch_mapping`(
|
|||
PRIMARY KEY (`id`)
|
||||
) DEFAULT CHARACTER SET = utf8mb4 COMMENT = '同步分支映射表';
|
||||
|
||||
--日志信息表
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `repo_sync_log`(
|
||||
`id` bigint unsigned NOT NULL AUTO_INCREMENT,
|
||||
|
|
|
|||
|
|
@ -38,11 +38,11 @@ class SyncDirection(Controller):
|
|||
dto: SyncRepoDTO = Body(..., description="绑定同步仓库信息")
|
||||
):
|
||||
api_log(LogType.INFO, f"用户 {user} 使用 POST 方法访问接口 {request.url.path} ", user)
|
||||
if not base.check_addr(dto.external_repo_address) or not base.check_addr(dto.internal_repo_address):
|
||||
return SYNCResponse(
|
||||
code_status=Status.REPO_ADDR_ILLEGAL.code,
|
||||
msg=Status.REPO_ADDR_ILLEGAL.msg
|
||||
)
|
||||
# if not base.check_addr(dto.external_repo_address) or not base.check_addr(dto.internal_repo_address):
|
||||
# return SYNCResponse(
|
||||
# code_status=Status.REPO_ADDR_ILLEGAL.code,
|
||||
# msg=Status.REPO_ADDR_ILLEGAL.msg
|
||||
# )
|
||||
|
||||
if dto.sync_granularity not in [1, 2]:
|
||||
return SYNCResponse(code_status=Status.SYNC_GRAN_ILLEGAL.code, msg=Status.SYNC_GRAN_ILLEGAL.msg)
|
||||
|
|
|
|||
|
|
@ -35,9 +35,9 @@ DB = {
|
|||
'test_env': {
|
||||
'host': getenv('CEROBOT_MYSQL_HOST', 'localhost'),
|
||||
'port': getenv('CEROBOT_MYSQL_PORT', 3306, int),
|
||||
'user': getenv('CEROBOT_MYSQL_USER', 'rtsw'),
|
||||
'passwd': getenv('CEROBOT_MYSQL_PWD', '123456'),
|
||||
'dbname': getenv('CEROBOT_MYSQL_DB', 'reposyncer')
|
||||
'user': getenv('CEROBOT_MYSQL_USER', 'root'),
|
||||
'passwd': getenv('CEROBOT_MYSQL_PWD', '185102xmy'),
|
||||
'dbname': getenv('CEROBOT_MYSQL_DB', 'reposyncer3'),
|
||||
},
|
||||
'local': {
|
||||
'host': getenv('CEROBOT_MYSQL_HOST', ''),
|
||||
|
|
|
|||
|
|
@ -112,14 +112,14 @@ class SyncService(Service):
|
|||
if repo is None:
|
||||
return SYNCException(Status.REPO_NOTFOUND)
|
||||
update_fields = {}
|
||||
if dto.internal_repo_address is not None:
|
||||
if not base.check_addr(dto.internal_repo_address):
|
||||
return SYNCException(Status.REPO_ADDR_ILLEGAL)
|
||||
update_fields['internal_repo_address'] = dto.internal_repo_address
|
||||
if dto.external_repo_address is not None:
|
||||
if not base.check_addr(dto.external_repo_address):
|
||||
return SYNCException(Status.REPO_ADDR_ILLEGAL)
|
||||
update_fields['external_repo_address'] = dto.external_repo_address
|
||||
# if dto.internal_repo_address is not None:
|
||||
# if not base.check_addr(dto.internal_repo_address):
|
||||
# return SYNCException(Status.REPO_ADDR_ILLEGAL)
|
||||
update_fields['internal_repo_address'] = dto.internal_repo_address
|
||||
# if dto.external_repo_address is not None:
|
||||
# if not base.check_addr(dto.external_repo_address):
|
||||
# return SYNCException(Status.REPO_ADDR_ILLEGAL)
|
||||
update_fields['external_repo_address'] = dto.external_repo_address
|
||||
if dto.inter_token is not None:
|
||||
update_fields['inter_token'] = dto.inter_token
|
||||
if dto.exter_token is not None:
|
||||
|
|
|
|||
|
|
@ -47,7 +47,6 @@ def sync_log(log_type: str, msg: str, log_name: str, user="robot"):
|
|||
datefmt='%Y-%m-%d %H:%M:%S')
|
||||
formatter.converter = time_formatter
|
||||
file_handler.setFormatter(formatter)
|
||||
|
||||
# 创建一个logger
|
||||
logger = logging.getLogger('logger')
|
||||
logger.setLevel(logging.INFO)
|
||||
|
|
|
|||
|
|
@ -1,4 +0,0 @@
|
|||
2024.06.07 8.20提交
|
||||
检验是否同步
|
||||
|
||||
8:28 第二次同步尝试
|
||||
|
|
@ -1,2 +0,0 @@
|
|||
2024.06.07
|
||||
时间 8:31
|
||||
Loading…
Reference in New Issue