一、代码如下
import git from del_folder import del_folder import time from send_Dmessage import send_message from send_gift import send_gift # 设置远程仓库路径 remote_url = 'xxx' # 本地仓库路径 local_path = 'xxx' # webhook地址和密钥 webhook_url = "xxx" secret = "xxxf" # 密钥(选填) # 历史提交列表 commit_list = [] def monitor_commits(): while True: # 先删除之前的文件夹 folder_path = '/Users/mozili/Documents/xxx' del_folder(folder_path) # 克隆远程仓库到本地 repo = git.Repo.clone_from(remote_url, local_path) # 切换到特定分支 target_branch = "dev" repo.git.checkout(target_branch) try: # 查看最新提交记录 commits = list(repo.iter_commits())[0] # 最新提交的加入commit_list if commits.hexsha not in commit_list: print(commits.hexsha, commits.author.name, commits.message) commit_list.append(commits.hexsha) content = send_gift() if content !='': send_message(content,webhook_url,secret) else: print('送礼无异常报警') else: print('没有新提交!') # 每个5分钟查看一次是否有新提交 time.sleep(300) except KeyboardInterrupt: break if __name__== '__main__': monitor_commits()
标签:提交,Python,commits,list,send,监控,import,folder From: https://www.cnblogs.com/lxmtx/p/18234888