是的,我们在文档中找不到任何测试。这是您问题的基本答案。
如果您想要完整的工作脚本,我已将其附在此处: https ://github.com/torpidsnake/common_scripts/blob/main/automation_to_create_push_merge_in_gitlab/usecase_gitlab_python.py
分解以下步骤:
为您创建一个身份验证密钥:按照此处的步骤操作: https: //docs.gitlab.com/ee/user/profile/personal_access_tokens.html
创建项目的 gitlab 服务器实例
server = gitlab.Gitlab('https://gitlab.example.com', private_token=YOUR_API_TOKEN)
project = server.projects.get(PROJECT_ID)
Run Code Online (Sandbox Code Playgroud)
使用以下命令创建分支:
branch = project.branches.create(
{"branch": branch_name, "ref": project.default_branch}
)
Run Code Online (Sandbox Code Playgroud)
使用以下方式上传文件:
project.files.create(
{
"file_path": file_name,
"branch": branch.name,
"content": "data to be written",
"encoding": "text", # or 'base64'; useful for binary files
"author_email": AUTHOR_EMAIL, # Optional
"author_name": AUTHOR_NAME, # Optional
"commit_message": "Create file",
}
)
Run Code Online (Sandbox Code Playgroud)
使用以下命令创建合并请求:
project.mergerequests.create(
{
"source_branch": branch.name,
"target_branch": project.default_branch,
"title": "merge request title",
}
)
Run Code Online (Sandbox Code Playgroud)