• 利用Python和webhook实现自动提交代码


    最近在为公司书写项目的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文档 : 
    
    已更新,请注意查看! 
    " +"
    更新信息: {}".format(
                    commitMessage),
                "text": time.strftime("%Y/%m/%d %H:%M"),
                "error": False
            })
    

    5.最后调用

    add()
    

    注意
    代码调用顺序

    由此除了项目成员向wiki推送状态无法获取外其他事件基本可以省去很多手动操作。如果大家知道更好的办法欢迎讨论指导

  • 相关阅读:
    verilog中的function用法与例子
    HDMI IP学习笔记
    include使用中注意的问题
    PCIE学习
    HDMI学习
    (转)modelsim10.0C编译ISE14.7的xilinx库(xilinx ip核)
    2014年七月华为校招机试题目--最难的一道, 呵呵!
    欧拉函数
    素数高效率筛选法
    树-二叉树的编号
  • 原文地址:https://www.cnblogs.com/tig666666/p/9700655.html
Copyright © 2020-2023  润新知