示例:

#!/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()

GitLab通过API创建项目的更多相关文章

  1. gitlab通过api创建组、项目、成员

    前戏 获取gitlab中admin用户的private_token Groups API 获取某个组的详细 curl --header "PRIVATE-TOKEN: *********&q ...

  2. Gitlab-通过API管理项目

    Gitlab有一个非常强大的API,几乎可以通过API管理在Gitlab服务器中的所有项目. 在这里我们只是测试终端点的API, 因此我们需要一个程序来进行测试 .在这里我使用的是针对Google浏览 ...

  3. 【从零开始搭建自己的.NET Core Api框架】(一)创建项目并集成swagger:1.1 创建

    系列目录 一.  创建项目并集成swagger 1.1 创建 1.2 完善 二. 搭建项目整体架构 三. 集成轻量级ORM框架——SqlSugar 3.1 搭建环境 3.2 实战篇:利用SqlSuga ...

  4. 从零开始学习 asp.net core 2.1 web api 后端api基础框架(二)-创建项目

    原文:从零开始学习 asp.net core 2.1 web api 后端api基础框架(二)-创建项目 版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.ne ...

  5. 01GitLab的使用——创建项目并上传到GitLab

    借鉴:https://jingyan.baidu.com/article/9c69d48fe68cce13c9024e9c.html 登录GitLab网站,创建一个项目上传地址:https://blo ...

  6. Centos 7搭建Gitlab服务器以及操作(创建项目,创建群组,创建用户,添加密钥)

    一. 安装并配置依赖包 在CentOS系统上安装所需的依赖:ssh,防火墙,postfix(用于邮件通知) ,wget,以下这些命令也会打开 系统防火墙中的HTTP和SSH端口访问 安装前准备 命令: ...

  7. ASP.NET+MVC入门踩坑笔记 (一) 创建项目 项目配置运行 以及简单的Api搭建

    哈喽各位 我又回来了! 前段时间研究了下ASP.NET,刚开始也是随便找网上的各种教程来看,但是鉴于本人技术有限,还是走了相当长的一段弯路的.所以我写下了这篇文章.希望各位刚刚入坑的ASP.NET开发 ...

  8. gitlab怎么删除创建的项目

    在gitlab新建了一个项目,怎么将此项目删除呢?打开这个工程,点击右上角的“settings”拉到最下面,有个show them to me,点击~在下拉选项的最后,有个remove框,点击即可以彻 ...

  9. gitlab官方api使用

    目录 一.简介 二.技术要点 三.案例 一.简介 Gitlab作为一个开源.强大的分布式版本控制系统,已经成为互联网公司.软件开发公司的主流版本管理工具.使用过Gitlab的都知道,想要提交一段代码, ...

随机推荐

  1. C++ Primer Plus的若干收获--(十一)

    本篇主要讲了转换函数的利与弊以及简要介绍流与iostream文件 因为在本篇仍然要使用上篇的Stonewt类,这里首先给出其代码 <span style="font-size:18px ...

  2. Swagger 生成API文档

    1.打开程序包管理控制台输入: Install-Package Swashbuckle 2.打开App_Start文件夹下的SwaggerConfig.cs文件找到 c.IncludeXmlComme ...

  3. 从入门机器学习的零单排:OctaveMatlab经常使用绘图知识

    OctaveMatlab经常使用绘图知识 之前一段时间在coursera看了Andrew ng的机器学习的课程,感觉还不错,算是入门了.这次打算以该课程的作业为主线,对机器学习基本知识做一下总结.小弟 ...

  4. symfony中doctrine常用属性

    转 http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/basic-mapping.html 1. d ...

  5. spring boot 配置swagger UI

    springboot集成swaggerUI 有这样的需求 1.在每个接口上都增加一个字段: 2.接口文档只展示满足一定条件URL的接口 配置文件 详细看代码 import org.springfram ...

  6. 浅谈 Swift 中的 Optionals

    input[type="date"].form-control,.input-group-sm>input[type="date"].input-grou ...

  7. MySQL 执行原生sql

    public class MySqlHelper { private YourContext _context; public MySqlHelper(YourContext context) { _ ...

  8. WPF 数据模板DataType属性的使用,不用指定ItemTemplate

    <Window x:Class="CollectionBinding.MainWindow"        xmlns="http://schemas.micros ...

  9. SQLServer2005数据库快照的简单使用

    原文:SQLServer2005数据库快照的简单使用                                                  SQLServer2005数据库快照的简单使用 ...

  10. WPF 中RichTextBox控件用法细讲

    1. 取得已被选中的内容:(1)使用RichTextBox.Document.Selection属性(2)访问RichTextBox.Document.Blocks属性的“blocks”中的Text ...