最近在为公司书写项目的api文档,计划利用码云的wiki管理整个项目,公司自有git做为项目内容依托,这样全员均可参与,而我按期向码云推送就能够了。python
#!/usr/bin/env python # -*- coding: utf-8 -*- # @Time : 2018/9/25 上午10:52 # @Author : liuyonghu # @Site : https://www.lyonghu.com # @File : autoGitPush.py # @Software: PyCharm import subprocess import time from tools.sendMessageToDD import sendMessage
def add(): cmd = "git add ." process = subprocess.Popen(cmd, shell=True) process.wait() returnCode = process.returncode if returnCode != 0: print(" add returnCode", returnCode) else: commit()
commitMessage = "" def commit(): global commitMessage commitMessage = time.strftime("%Y/%m/%d %H:%M") cmd = "git commit -m '{}'".format(commitMessage) # print("cmd = " + cmd) process = subprocess.Popen(cmd, shell=True) process.wait() push()
def push(): cmd = "git push origin master" process = subprocess.Popen(cmd, shell=True) process.wait() returnCode = process.returncode if returnCode != 0: print("push returnCode", returnCode) else: sendMessage({ "fileName": "api文档 : \n\n已更新,请注意查看! \n" +"\n更新信息: {}".format( commitMessage), "text": time.strftime("%Y/%m/%d %H:%M"), "error": False })
add()
注意
代码调用顺序git
由此除了项目成员向wiki推送状态没法获取外其余事件基本能够省去不少手动操做。若是你们知道更好的办法欢迎讨论指导shell