更新多个文件 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)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...