zoukankan      html  css  js  c++  java
  • GitLab通过API创建项目

    示例:

    #!/usr/bin/python
    # -*- coding:utf-8 -*-
    
    
    import os
    import json
    import requests
    import subprocess
    
    from ast import literal_eval
    
    
    root = "/root/develop"
    
    headers = {
        "PRIVATE-TOKEN": "aljdhaguiqwackjaerigczx"
    }
    
    fromdata = {
        "namespace_id": "41"
    }
    
    url = "http://ip:port/api/v4/projects"
    
    def delete():
        """删除项目"""
        response = requests.get(url, headers=headers)
        tmp = json.loads(response.text)
        for i in tmp:
            project_name = i["name"]
            requests.delete("http://ip:port/api/v4/projects/myscan-master%2f{}".format(project_name), headers=headers)
    
    def create():
        """创建项目,复制代码"""
        os.chdir("./deploy/")
        names = os.listdir("./")
        for i in names:
            if os.path.isdir(i):
                if i == ".git":
                    continue
    
                fromdata["name"] = i
                fromdata["path"] = i
    
                if i != "component_all":
                    os.chdir(i)
                    subprocess.call("rm -rf .git build dist *.egg-info .idea .DS_Store ", shell=True)
                    pwd_1 = os.getcwd()
    
                    ssh_url = requests.post(url, data=fromdata, headers=headers)
                    subprocess.call("git clone -b develop {} {}/{}".format(ssh_url, root, i), shell=True)
                    os.chdir("{}/{}".format(root, i))
                    pwd_2 = os.getcwd()
                    subprocess.call("cp -rf {}/* {}/".format(pwd_1, pwd_2), shell=True)
                    subprocess.call("git push --set-upstream origin develop", shell=True)
                    subprocess.call('git add -A && git commit -m "create" && git push'.format(j), shell=True)
    
                    subprocess.call("rm -rf {}/{}".format(root, i))
                    os.chdir(pwd_1)
                    os.chdir("../")
                else:
                    pass
    
    def component():
        """组件"""
        fromdata["name"] = "component_all"
        fromdata["path"] = "component_all"
        ssh_url = requests.post(url, data=fromdata, headers=headers)
        subprocess.call("git clone -b develop {} {}/component_all".format(ssh_url, root), shell=True)
    
        os.chdir("./deploy/component_all")
        path = os.getcwd()
        names = os.listdir("./")
        for i in names:
            os.chdir("{}/{}".format(path, i))
            if os.path.isdir(i):
                if i == ".git" or i == "README.md":
                    continue
    
                subprocess.call("rm -rf .git build dist *.egg-info .idea .DS_Store ", shell=True)
                pwd_1 = os.getcwd()
    
                os.makedirs("{}/component_all/{}".format(root, i))
                os.chdir("{}/component_all/{}".format(root, i))
                pwd_2 = os.getcwd()
                subprocess.call("cp -rf {}/* {}/".format(pwd_1, pwd_2), shell=True)
                subprocess.call("git push --set-upstream origin develop", shell=True)
                subprocess.call('git add -A && git commit -m "添加{}组件" && git push'.format(i), shell=True)
    
    
    if __name__ == '__main__':
        # 删除项目
        delete()
    
        # 复制项目
        create()
    
        # 复制组件
        component()
    
    
    
  • 相关阅读:
    [LOJ537] DNA 序列
    yum安装jdk
    centos7添加tomcat自启服务
    ajax下载文件的方法 php下载图片的方法
    kali linux dpkg安装和删除的方法
    javascript 曲线流光动画
    javascript获取曲线路径每个像素的坐标
    抓取微信小程序源码的方法
    javascript canvas拖尾效果
    php错误execution timed out (118.236064 sec), terminating解决方法
  • 原文地址:https://www.cnblogs.com/zzhaolei/p/11067979.html
Copyright © 2011-2022 走看看