示例:

#!/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. Linux性能测试 uptime命令

    uptime 命令用于查看服务器运行了多长时间以及有多少个用户登录,快速获知服务器的负荷情况. 以下是 uptime 的运行实例: :: up days, min, users, load avera ...

  2. POJ3723 Conscription 【并检查集合】

    Conscription Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8071   Accepted: 2810 Desc ...

  3. Win32 键盘事件 - 击键消息、字符消息、插入符号(光标)

    注:以下内容为学习笔记,多数是从书本.资料中得来,只为加深印象,及日后参考.然而本人表达能力较差,写的不好.因非翻译.非转载,只好选原创,但多数乃摘抄,实为惭愧.但若能帮助一二访客,幸甚! 以下内容主 ...

  4. hdu 4035 可能性DP 成都网络游戏

    http://acm.hdu.edu.cn/showproblem.php?pid=4035 获得: 1.首先推断是不是树.事实上,所有的感觉身影,既看边数==算-1是不成立 2.有时候,我告诉孩子来 ...

  5. 关于hibernate组件配置

    建立关系数据模型的一个重要原则是在不会导致数据冗余的前提下,尽可能减少数据库表的数目及表之间的外键参照关系.以员工信息为例,员工信息中有员工的家庭地址信息,如果把地址信息单独放在一张表中,然后建立员工 ...

  6. DELPHI7中 TObjectList sort排序问题

    网上收集了一点东西 TOBJECTLIST里,有自带的排序功能 TLIST,TSTRINGLIST也有,MS是一样的 SORT里有一个参数: Compare:TListSortCompare 那我们先 ...

  7. LeapMotion Demo2

    原文:LeapMotion Demo2    官方doc有四个手势,最近尝试实现对握拳的识别,并能在我的程序界面上体现出来.    调试过程较为繁琐,幸好最终效果还差强人意! 首先看看我的效果图:   ...

  8. GlyphRun 对象和 Glyphs 元素简介

    原文 GlyphRun 对象和 Glyphs 元素简介 GlyphRun 简介 Windows Presentation Foundation (WPF) 提供高级的文本支持包括直接访问的标志符号级标 ...

  9. ASP.NET CORE系列【六】Entity Framework Core 之数据迁移

    原文:ASP.NET CORE系列[六]Entity Framework Core 之数据迁移 前言 最近打算用.NET Core写一份简单的后台系统,来练练手 然后又用到了Entity Framew ...

  10. Win8 Metro(C#)数字图像处理--2.63图像指数增强

    原文:Win8 Metro(C#)数字图像处理--2.63图像指数增强  [函数名称]   指数增强      WriteableBitmap IndexenhanceProcess(Writea ...