Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions src/tools/ignore.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
import requests
from catfood.functions.files import open_file
from catfood.functions.print import 消息头
from catfood.functions.terminal import runCommand
from colorama import Fore

from function.constant.general import RETRY_INTERVAL
from function.git.format import branchName
from function.github.token import read_token
from function.maintain.config import 读取配置
Expand Down Expand Up @@ -193,7 +195,8 @@ def main(args: list[str]) -> int:
print(f"{消息头.信息} 开始同步...")
subprocess.run(["git", "checkout", "main"], check=True)
print(f"{消息头.信息} 已签出到 main 分支")
subprocess.run(["git", "pull"], check=True)
if e := runCommand(["git", "pull"], retry=RETRY_INTERVAL):
return 1
print(f"{消息头.信息} 已拉取远程修改")
except subprocess.CalledProcessError as e:
print(f"{消息头.错误} 同步失败:\n{Fore.RED}{e}{Fore.RESET}")
Expand Down Expand Up @@ -232,7 +235,8 @@ def main(args: list[str]) -> int:
print(f"{消息头.信息} 开始提交和推送...")
subprocess.run(["git", "add", 检测程序], check=True)
subprocess.run(["git", "commit", "-m", f"[Auto] 自动忽略追加 - {忽略字段}"], check=True)
subprocess.run(["git", "push", "--set-upstream", "origin", 新分支名], check=True)
if e := runCommand(["git", "push", "--set-upstream", "origin", 新分支名], retry=RETRY_INTERVAL):
return 1
print(f"{消息头.成功} 成功推送到远程")
if not 创建拉取请求(新分支名, owner, 忽略字段):
失败 = True
Expand All @@ -248,7 +252,8 @@ def main(args: list[str]) -> int:
print(f"{消息头.信息} 开始提交和推送...")
subprocess.run(["git", "add", 检测程序], check=True)
subprocess.run(["git", "commit", "-m", f"[Auto] 自动忽略移除 - {格式化忽略字段}"], check=True)
subprocess.run(["git", "push", "--set-upstream", "origin", 新分支名], check=True)
if e := runCommand(["git", "push", "--set-upstream", "origin", 新分支名], retry=RETRY_INTERVAL):
return 1
print(f"{消息头.成功} 成功推送到远程")
if not 创建拉取请求(新分支名, owner, 忽略字段, 理由):
失败 = True
Expand All @@ -261,7 +266,8 @@ def main(args: list[str]) -> int:
print(f"{消息头.信息} 开始提交和推送...")
subprocess.run(["git", "add", 检测程序], check=True)
subprocess.run(["git", "commit", "-m", "chore(checker): 更新忽略字段"], check=True)
subprocess.run(["git", "push", "--set-upstream", "origin", 新分支名], check=True)
if e := runCommand(["git", "push", "--set-upstream", "origin", 新分支名], retry=RETRY_INTERVAL):
return 1
print(f"{消息头.成功} 成功推送到远程")
if not 创建拉取请求(新分支名, owner, 理由="edit"):
失败 = True
Expand Down
16 changes: 10 additions & 6 deletions src/tools/modify.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@
from catfood.functions.files import open_file
from catfood.functions.github.api import 这是谁的Token
from catfood.functions.print import 消息头
from catfood.functions.terminal import runCommand
from colorama import Fore

from function.constant.general import PR_TOOL_NOTE
import tools.sync
from function.constant.general import PR_TOOL_NOTE, RETRY_INTERVAL
from function.files.manifest import FormatManifest, 获取清单目录
from function.git.format import branchName
from function.github.token import read_token
Expand Down Expand Up @@ -247,9 +249,8 @@ def 修改版本(版本文件夹: str):
新分支 = branchName(f"Modify-S-{包标识符}-{版本文件夹}-{int(time.time())}")
print(f" 创建并切换到新分支: {新分支}")
写入日志(f" Create and checkout to a new branch: {新分支}")
subprocess.run(["git", "checkout", "master"], check=True) # 确保从 master 分支开始
subprocess.run(["git", "fetch", "upstream"], check=True) # 拉取上游修改
subprocess.run(["git", "rebase", "upstream/master"], check=True) # 变基上游修改
if e := tools.sync.main():
return e
subprocess.run(["git", "checkout", "-b", 新分支], check=True) # 创建并切换到新的分支

# 遍历该版本文件夹中的所有文件
Expand Down Expand Up @@ -325,8 +326,11 @@ def 修改版本(版本文件夹: str):
# 推送更改到远程仓库
print(" 推送更改到远程仓库")
写入日志(" Pushing changes to remote (origin) repository")
subprocess.run(["git", "push", "origin", 新分支], check=True)
print(f" {Fore.GREEN}推送到远程成功: {新分支}")
if e := runCommand(["git", "push", "origin", 新分支], retry=RETRY_INTERVAL):
print(f"{消息头.错误} 推送到远程失败: Git 返回退出代码 {e}")
return e
else:
print(f" {Fore.GREEN}推送到远程成功: {新分支}")
写入日志(f" Successfully pushed to remote (origin): {新分支}")

# 创建拉取请求
Expand Down
27 changes: 11 additions & 16 deletions src/tools/prune.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import os
import subprocess

from catfood.exceptions.operation import OperationFailed
from catfood.functions.print import 消息头
from catfood.functions.terminal import runCommand
from colorama import Fore

from function.constant.general import RETRY_INTERVAL
from function.maintain.config import 读取配置


Expand All @@ -13,23 +13,18 @@ def main() -> int:
for 仓库 in ["winget-pkgs", "winget-tools"]:
仓库路径 = 读取配置(f"paths.{仓库}")
if isinstance(仓库路径, str):
清理远程(仓库, 仓库路径)
os.chdir(仓库路径)
print(f"清理 {Fore.BLUE}{仓库}{Fore.RESET} 仓库的远程已删除分支...")
if e := runCommand(["git", "remote", "prune", "origin"], retry=RETRY_INTERVAL):
print(f"{消息头.错误} 清理 {Fore.BLUE}{仓库}{Fore.RESET} 的远程已删除分支时出错: Git 返回退出代码 {e}")
return e
else:
print(f"{Fore.GREEN}✓{Fore.RESET} 清理完毕")
else:
raise OperationFailed
raise ValueError
except KeyboardInterrupt:
print(f"{消息头.错误} 已取消操作")
return 1
except OperationFailed:
except ValueError:
return 1
return 0


def 清理远程(仓库: str, 仓库路径: str):
try:
print(f"清理 {Fore.BLUE}{仓库}{Fore.RESET} 仓库的远程已删除分支...")
os.chdir(仓库路径)
subprocess.run(["git", "remote", "prune", "origin"], check=True)
print(f"{Fore.GREEN}✓{Fore.RESET} 清理完毕")
except subprocess.CalledProcessError as e:
print(f"{消息头.错误} 清理 {Fore.BLUE}{仓库}{Fore.RESET} 的远程已删除分支时出错,git 返回 {Fore.BLUE}{e.returncode}{Fore.RESET}")
raise OperationFailed
10 changes: 7 additions & 3 deletions src/tools/remove.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@
from catfood.exceptions.operation import OperationFailed
from catfood.functions.github.api import 这是谁的Token
from catfood.functions.print import 消息头
from catfood.functions.terminal import runCommand
from colorama import Fore
from translate import Translator # type: ignore

import tools.cat as cat
import tools.sync as sync
from function.constant.general import PR_TOOL_NOTE
from function.constant.general import PR_TOOL_NOTE, RETRY_INTERVAL
from function.files.manifest import 获取清单目录, 获取现有包版本
from function.git.format import branchName
from function.github.token import read_token
Expand Down Expand Up @@ -208,8 +209,11 @@ def main(args: list[str]) -> int:
subprocess.run(["git", "commit", "-m", f"Remove version: {包标识符} version {包版本} (Auto)"], check=True)
print(f"{Fore.BLUE} 已提交修改")

subprocess.run(["git", "push"], check=True)
print(f"{Fore.BLUE} 已推送修改")
if e := runCommand(["git", "push"], retry=RETRY_INTERVAL):
print(f"{消息头.错误} 推送到远程失败: Git 返回退出代码 {e}")
return e
else:
print(f"{Fore.BLUE} 已推送修改")

while (not 理由):
理由 = input("移除此包版本的理由: ")
Expand Down
59 changes: 26 additions & 33 deletions src/tools/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@

from catfood.constant import YES
from catfood.functions.print import 消息头
from catfood.functions.terminal import runCommand
from colorama import Fore

from function.constant.general import RETRY_INTERVAL
from function.maintain.config import 读取配置


Expand All @@ -14,62 +16,53 @@ def main() -> int:
if not isinstance(winget_pkgs目录, str):
return 1

# 入口
os.chdir(winget_pkgs目录)

try:
subprocess.run(["git", "checkout", "master"], check=True) # 确保从 master 分支开始
print(f"{Fore.BLUE} 已签出到 master 分支")
subprocess.run(["git", "checkout", "master"], check=True)
print(f"{消息头.信息} 已签出到 master 分支")
except subprocess.CalledProcessError as e:
print(f"{消息头.错误} 签出到 master 分支失败:\n{Fore.RED}{e}{Fore.RESET}")
return 1

while True:
try:
subprocess.run(["git", "fetch", "upstream"], check=True) # 拉取上游修改
print(f"{Fore.BLUE} 已获取上游修改")
break
except subprocess.CalledProcessError as e:
print(f"{消息头.错误} 获取上游修改失败:\n{Fore.RED}{e}{Fore.RESET}")
if input(f"{消息头.问题} 是否重试?(默认为{Fore.GREEN}是{Fore.RESET}): ").lower() not in (*YES, ""):
print(f"{消息头.消息} 已取消操作")
return 1
if e := runCommand(["git", "fetch", "upstream"], retry=RETRY_INTERVAL):
print(f"{消息头.错误} 获取上游修改失败: Git 返回退出代码 {e}")
return e
else:
print(f"{消息头.信息} 已获取上游修改")

try:
subprocess.run(["git", "fetch", "origin"], check=True) # 拉取远程修改
print(f"{Fore.BLUE} 已获取远程修改")
except subprocess.CalledProcessError as e:
print(f"{消息头.警告} 拉取远程修改失败:\n{Fore.YELLOW}{e}{Fore.RESET}")
# 不影响...不影响
if e := runCommand(["git", "fetch", "origin"], retry=RETRY_INTERVAL):
print(f"{消息头.错误} 获取远程修改失败: Git 返回退出代码 {e}")
return e
else:
print(f"{消息头.信息} 已获取远程修改")

try:
subprocess.run(["git", "rebase", "upstream/master"], check=True) # 变基合并上游修改
print(f"{Fore.BLUE} 已变基上游修改")
print(f"{消息头.信息} 已变基上游修改")
except subprocess.CalledProcessError as e:
print(f"{消息头.错误} 变基上游修改失败:\n{Fore.RED}{e}{Fore.RESET}")
if input(f"{消息头.问题} 是否尝试替换 master 分支?(默认为{Fore.YELLOW}否{Fore.RESET}): ").lower() in YES:
try:
subprocess.run(["git", "checkout", "upstream/master"], check=True) # 签出到上游 master 分支
print(f"{Fore.BLUE} 已签出到上游 master 分支")
print(f"{消息头.信息} 已签出到上游 master 分支")
subprocess.run(["git", "branch", "-D", "master"], check=True) # 移除旧的 master 分支
print(f"{Fore.BLUE} 已移除旧 master 分支")
print(f"{消息头.信息} 已移除旧 master 分支")
subprocess.run(["git", "switch", "-c", "master"], check=True) # 创建并签出到 master 分支
print(f"{Fore.BLUE} 已创建并签出到 master 分支")
print(f"{消息头.信息} 已创建并签出到 master 分支")
except subprocess.CalledProcessError as e:
print(f"{消息头.错误} 替换 master 分支失败:\n{Fore.RED}{e}{Fore.RESET}")
return 1
else:
print(f"{消息头.消息} 已取消操作")
return 1
raise KeyboardInterrupt

try:
# 推送 master
subprocess.run(["git", "push", "origin", "master"], check=True)
print(f"{Fore.BLUE} 已推送 master 分支")
except subprocess.CalledProcessError as e:
print(f"{消息头.错误} 推送 master 分支失败:\n{Fore.RED}{e}{Fore.RESET}")
return 1
if e := runCommand(["git", "push", "origin", "master"], retry=RETRY_INTERVAL):
print(f"{消息头.错误} 推送到远程失败: Git 返回退出代码 {e}")
return e
else:
print(f"{消息头.信息} 已推送到远程")

print(f"{Fore.GREEN}✓{Fore.RESET} 同步完成")
print(f"{消息头.成功} 同步完成")
except KeyboardInterrupt:
print(f"{消息头.错误} 用户已取消操作")
return 1
Expand Down
Loading