python gitlab操作git

# E:\python\test\pyGitlab03.py

# coding:utf-8

# 参考文档 https://python-gitlab.readthedocs.io/en/stable/gl_objects/projects.html

import gitlab

import base64

# 获取url

urlHead = 'https://xxxx.xx.com'

token = 'xxxx'

'''

1.credit

2.user

3.platform

4.kylin-query

5.api-web

6.flow

7.convert

8.asset

9.acctdayend

10.acctcenter

11.router

'''

 

 

# 更改的模块

update_proj = ''

base_proj = ''

# 更改的文件名

file_name = 'version.properties'

 

n = int(raw_input("1.credit\n2.user\n3.platform\n4.kylin-query\n5.api-web\n6.flow\n7.convert\n8.asset\n9.acctdayend\n10.acctcenter\n11.router\nchoose project:"))

 

# business

if n == 1:

    base_proj = 'credit'

    update_proj = 'credit/project/business/' + base_proj  # 这里不要加/前缀

elif n == 2:

    base_proj = 'user'

    update_proj = 'credit/project/business/' + base_proj

elif n == 3:

    base_proj = 'platform'

    update_proj = 'credit/project/business/' + base_proj

# channel

elif n == 4:

    base_proj = 'kylin-query'

    update_proj = 'credit/project/channel/hsjry-server/' + base_proj

elif n == 5:

    base_proj = 'api-web'

    update_proj = 'credit/project/channel/hsjry-server/' + base_proj

# flow

elif n == 6:

    base_proj = 'flow'

    update_proj = 'credit/project/base/' + base_proj

# accounting

elif n == 7:

    base_proj = 'convert'

    update_proj = 'credit/project/accounting/' + base_proj

elif n == 8:

    base_proj = 'asset'

    update_proj = 'credit/project/accounting/' + base_proj

# accounting/bigacct

elif n == 9:

    base_proj = 'acctdayend'

    update_proj = 'credit/project/accounting/bigacct/' + base_proj

elif n == 10:

    base_proj = 'acctcenter'

    update_proj = 'credit/project/accounting/bigacct/' + base_proj

# router

elif n == 11:

    base_proj = 'router'

    update_proj = 'credit/project/bigdata/' + base_proj

 

# 更改的分支

# branch = 'patch-1'

branch = raw_input("branch1:feature-hebao\nbranch2:feature-hebao-sit\nsetting by self:")

if branch == '1':

    branch = 'feature-hebao'

elif branch == '2':

    branch = 'feature-hebao-sit'

else:

    branch = branch

 

# 补全项目git路径

update_file = "hsjry-project-%s-web" % base_proj

 

 

# 版本号统一包路径

package_path = '/src/main/resources/'

# 补全版本号路径

update_file = update_file + package_path + file_name

print update_file

 

# 登录

# gl = gitlab.Gitlab(url, token)

def login():

    return gitlab.Gitlab(urlHead, token)

 

# 获取项目

proj = login().projects.get(update_proj)

 

# 读取版本号文件

f = proj.files.get(file_path=update_file, ref=branch)

# print(f.decode())

 

# 修改版本号

update_content = f.decode() + "a"

# print update_content

f.content = base64.b64encode(update_content).decode()

# 提交

f.save(branch=branch, commit_message='update version', encoding='base64')

 

# 回显修改

f2 = proj.files.get(file_path=update_file, ref=branch)

print(f2.decode())

发布了66 篇原创文章 · 获赞 23 · 访问量 12万+

猜你喜欢

转载自blog.csdn.net/Tanganq/article/details/103410476
今日推荐