更新多个文件 python-gitlab

问题描述

我想使用 python-gitlab 更新我的 Gitlab 存储库中的多个文件。我知道如何更新单个文件,但我不想一个一个地更新每个文件

通常,我们使用以下命令来实现:

  1. 进行更改
  2. git 添加
  3. Git 提交
  4. git 推送

有没有办法使用 python-gitlab 来实现这一点?

dictionary

解决方法

参考此处https://python-gitlab.readthedocs.io/en/stable/gl_objects/commits.html

从上面的链接看这部分

# See https://docs.gitlab.com/ce/api/commits.html#create-a-commit-with-multiple-files-and-actions
# for actions detail
data = {
    'branch': 'master','commit_message': 'blah blah blah','actions': [
        {
            'action': 'create','file_path': 'README.rst','content': open('path/to/file.rst').read(),},{
            # Binary files need to be base64 encoded
            'action': 'create','file_path': 'logo.png','content': base64.b64encode(open('logo.png').read()),'encoding': 'base64',}
    ]
}

commit = project.commits.create(data)