示例:

#!/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. WCF寄宿与IIS里时遇到的问题

    [问题总结]WCF寄宿与IIS里时遇到的问题 最近在公司做了一个小的视频处理网站,由于视频处理,网站在不同的服务器上,所以处理视频的时候得在网站服务器上通过wcf请求视频处理服务器处理视频,并将结果返 ...

  2. wpf实现仿qq消息提示框

    原文:wpf实现仿qq消息提示框 版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/huangli321456/article/details/5052 ...

  3. 持续集成及部署利器:Go(不要和Google的编程语言Go混淆了!)

    Go是一款先进的持续集成和发布管理系统,由ThoughtWorks开发.(不要和Google的编程语言Go混淆了!)其前身为CruiseControl,是ThoughtWorks在做咨询和交付交付项目 ...

  4. sql学习目录

    sql like N'%...%' 在C#里的写法 sql 循环 随机数创建数据 使用StringBuilder与SqlParameter 跨库查询数据 sql 多列求和 sql SCOPE_IDEN ...

  5. vagrant up 无法加载映像目录

    错误代码显示: ==> default: Attempting graceful shutdown of VM... ==> default: Clearing any previousl ...

  6. QML中实现setTimeout和setInterval

    Qt的QML中,js未提供setTimeout和setInterval,可以通过下面的代码实现. Timer {id: timer} function setTimeout(cb,delayTime) ...

  7. SQL Server 2016新特性:DROP IF EXISTS

    原文:SQL Server 2016新特性:DROP IF EXISTS  在我们写T-SQL要删除某个对象(表.存储过程等)时,一般会习惯先用IF语句判断该对象是否存在,然后DROP,比如: 旧 ...

  8. 中国2017 Google 开发者大会第二天简单回顾

    昨天早晨发布了第一天的开发者大会回顾文章后,就匆匆忙忙赶去会场继续享受高科技的盛宴,接下来简单回顾一下第二天的大会参与情况. 昨天早晨下着小雨,并带着微风,在外面还是挺冷的,这里不得不给工作人员点个赞 ...

  9. Tensorflow-常见报错解决方案

    1. AttributeError: 'module' object has no attribute 'SummaryWriter' tf.train.SummaryWriter 改为:tf.sum ...

  10. [Leetcode]Single Number && Single Number II

    Given an array of integers, every element appears twice except for one. Find that single one. 非常简单的一 ...