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()
    
    
    
  • 相关阅读:
    聊聊.net程序设计
    使用ftp自动下载上传文件
    Microsoft .NET Framework 2.0对文件传输协议(FTP)操作(异步上传,下载等)实现汇总2
    一个的FTP类
    网站需要提高安全性
    极速理解设计模式系列【目录索引】
    NPOI 1.2教程
    Agile Tour 2011北京站“让敏捷落地”
    Asp.net程序中用NPOI生成标准Excel报表,导入导出一应俱全[转]
    网站性能优化之HTTP请求过程
  • 原文地址:https://www.cnblogs.com/zzhaolei/p/11067979.html
Copyright © 2011-2022 走看看