Answer the question
In order to leave comments, you need to log in
Why doesn't commit via api work?
trying to commit
https://docs.gitlab.com/ee/api/commits.html#create...
def create_commit(self, project: str, ref: str) -> dict:
self.auth.update({"Content-Type": "application/json"})
data = {
"branch": ref,
"commit_message": "create",
"actions": [
{"action": "create", "file_path": "1.json", "content": "test"}
],
}
res = requests.post(
url=f"{self.base_path}/api/v4/projects/{project}/repository/commits",
headers=self.auth,
data=json.dumps(data),
)
res.raise_for_status()
return res.json()
Answer the question
In order to leave comments, you need to log in
The soremix
recommendation is correct. Successful request:
import requests
url = 'https://gitlab.com/api/v4/projects/123/repository/commits'
data = {"branch": "main", "commit_message": "create", "actions": [{"action": "create", "file_path": "1.json", "content": "test"}]}
headers={'PRIVATE-TOKEN': 'token'}
res = requests.post(url, headers=headers, json=data)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question