Browse the Filter Parameters Docs in order to set your needs. Once it is choosen, you can make a call to get the title of the merge request to doble check that the filter is working.
curl --header "PRIVATE-TOKEN: $GITLAB_TOKEN" "https://git.coopdevs.org/api/v4/merge_requests?wip=yes&view=simple" | jq ".[]| [.project_id, .iid, .title] "
If all is right, repeat the same call without asking for the title and format it to csv
curl --header "PRIVATE-TOKEN: $GITLAB_TOKEN" "https://git.coopdevs.org/api/v4/merge_requests?wip=yes&view=simple" | jq -r ".[]| [.project_id, .iid] | @csv" > ids.txt
Now, you can process the generated file with the following script:
#!/bin/bash
FILE=$1
TITLE="Bump odoo_provisioning_version to v0.7.12"
LINES=$(cat $FILE)
for LINE in $LINES
do IFS=,
read PROJECT_ID ID <<<$LINE
echo "project_id: $PROJECT_ID"
echo "id: $ID"
curl -X PUT --header "PRIVATE-TOKEN: $GITLAB_TOKEN" -d "title=$TITLE" https://git.coopdevs.org/api/v4/projects/$PROJECT_ID/merge_requests/$ID
done
#!/bin/bash
FILE=$1
LINES=$(cat $FILE)
for LINE in $LINES
do IFS=,
read PROJECT_ID ID <<<$LINE
curl -X PUT --header "PRIVATE-TOKEN: $GITLAB_TOKEN" -d "squash=true" https://git.coopdevs.org/api/v4/projects/$PROJECT_ID/merge_requests/$ID
done
In the Merge Request API Docs you can find all the accepted and required bodies
#!/bin/bash
LINES=$(curl -Ss --header "PRIVATE-TOKEN: $GITLAB_TOKEN" "https://git.coopdevs.org/api/v4/merge_requests?per_page=100" | jq -r "map(select(.upvotes== 1)) | map(select(.state== \"opened\")) | .[]| [.project_id, .iid] | @csv")
for LINE in $LINES
do IFS=,
read PROJECT_ID ID <<< $LINE
curl -X PUT --header "PRIVATE-TOKEN: $GITLAB_TOKEN" https://git.coopdevs.org/api/v4/projects/$PROJECT_ID/merge_requests/$ID/merge
done
Several examples of getting filtered merge requests and the bash loop to delete them can be found below.
#!/bin/bash
#LINES=$(curl -Ss --header "PRIVATE-TOKEN: $GITLAB_TOKEN" "https://git.coopdevs.org/api/v4/merge_requests?per_page=100&search=rm%20old%20dir&in=title" | jq -r " map(select(.state== \"opened\")) | .[]| [.project_id, .iid] | @csv")
#LINES=$(curl -Ss --header "PRIVATE-TOKEN: $GITLAB_TOKEN" "https://git.coopdevs.org/api/v4/merge_requests?per_page=100" | jq -r "map(select(.downvotes== 1)) | map(select(.state== \"opened\")) | .[]| [.project_id, .iid] | @csv")
#LINES=$(curl --header "PRIVATE-TOKEN: $GITLAB_TOKEN" "https://git.coopdevs.org/api/v4/merge_requests?view=simple&search=Bump&in=title&?per_page=100" | jq -r ".[]| [.project_id, .iid] | @csv")
for LINE in $LINES
do IFS=,
read PROJECT_ID ID <<< $LINE
echo $PROJECT_ID $ID
curl -X DELETE --header "PRIVATE-TOKEN: $GITLAB_TOKEN" https://git.coopdevs.org/api/v4/projects/$PROJECT_ID/merge_requests/$ID
done