最近在爲公司書寫項目的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