最近在為公司書寫項目的api文檔,計划利用碼雲的wiki管理整個項目,公司自有git作為項目內容依托,這樣全員都可參與,而我定期向碼雲推送就可以了。
問題
根據需求遇見了這樣一個問題:我每次從git上拉取更新再向碼雲wiki推送,最后再通過釘釘向大家通知的過程,過於繁瑣。於是計划用Python實現部分流程自動化
代碼
1.引入的頭文件
#!/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
2.add 方法
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()
3.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()
4.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
})
5.最后調用
add()
注意
代碼調用順序
由此除了項目成員向wiki推送狀態無法獲取外其他事件基本可以省去很多手動操作。如果大家知道更好的辦法歡迎討論指導