I have been trying to make a git commit using gitlab python module and this code works fine when executed from main -
private_token = "xxxxxx"
gl = gitlab.Gitlab('https://gitlab.xyz.net/', private_token)
project_id = 10000
my_project = gl.projects.get(project_id)
data = {
'branch': 'master',
'commit_message': 'Commit message 1',
'actions': [
{
'action': 'create',
'file_path': 'gitUpload.txt',
'content': "Hello this is upload test",
},
]
}
commit = my_project.commits.create(data)
When I create a function for the same code and call it from main, it gives me the following error -
gitlab.exceptions.GitlabCreateError: 400: You can only create or edit files when you are on a branch
def create_commit():
private_token = 'xxxxxx'
gl = gitlab.Gitlab('https://gitlab.xyz.net/', private_token)
project_id = 10000
my_project = gl.projects.get(project_id)
data = {
'branch': 'master',
'commit_message': 'Commit message 2',
'actions': [
{
'action': 'create',
'file_path': 'gitUpload.txt',
'content': 'Hello this is a test2',
},
]
}
commit = my_project.commits.create(data)
create_commit()