From the GITLAB API documentation,I want to create several commits on a single branch,and after that create a merge request in bash script.
curl -i --request POST --header "PRIVATE-TOKEN: privatekey" --header "Content-Type: application/json" --data "$PAYLOAD" "https://hostgit/api/v4/projects/1234/repository/commits"
and about PAYLOAD
PAYLOAD=$(cat << JSON
{
"branch": "mybranch",
"commit_message": "some commit message",
"actions": [
{
"action": "update",
"file_path": "roles/test.j2"
},
{
"action": "update",
"file_path": "roles/prod.j2"
}
]
}
JSON
)
script update the files so after this commit i use create MR but its an empty MR.why its empty ?? commit changes are 0. also i use to content in actions a file path but its didn't work and commits still empty.
For the update
action, you have to specify the content of the file, and it should be the entire file content, not just the updated parts. Gitlab will then generate the diff and commit the changes correctly. You would need to update your payload so it looks something like:
PAYLOAD=$(cat << JSON
{
"branch": "mybranch",
"commit_message": "some commit message",
"actions": [
{
"action": "update",
"file_path": "roles/test.j2",
"content": "this is the entire content in the test.j2 file after updating it"
},
{
"action": "update",
"file_path": "roles/prod.j2",
"content": "This is the entire content in the prod.j2 file after updating it"
}
]
}
JSON
)
You can see all the optional and required parameters in the docs. ]