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()
    
    
    
  • 相关阅读:
    Smarty 模板 insert 局部刷新不缓存功能
    批量选择图片上传的jquery插件
    (转)国外15个前端开发CSS框架介绍
    IE6 下 zindex 设置的 DIV 偏移位置的解决方法
    ecshop的 transport.js 文件和 Jquery 冲突解决方案
    (转) javascript 匿名函数的理解,js括号中括function 如(function(){})
    (转)javascript匿名函数
    jQuery 的 hover 方法等同于 mouseenter + mouseleave 方法
    php set_magic_quotes_runtime() 函数过时
    同域名不同主机下的iframe高度调整
  • 原文地址:https://www.cnblogs.com/zzhaolei/p/11067979.html
Copyright © 2011-2022 走看看