Skip to content

Instantly share code, notes, and snippets.

@crigertg
Last active February 14, 2023 10:26
Show Gist options
  • Save crigertg/2596606b82a82148b0ebabcee4d70d79 to your computer and use it in GitHub Desktop.
Save crigertg/2596606b82a82148b0ebabcee4d70d79 to your computer and use it in GitHub Desktop.
In case many merge requests in a gitlab group have to be deleted according to the title this snippet can be used
#!/bin/bash
PRIVATE_TOKEN=$1
GROUP_ID=$2
TITLE_REGEX=$3
MR_STATUS=${4:-opened}
PAGE_SIZE=${5:-100}
for MR in $(curl -s --header "PRIVATE-TOKEN: $PRIVATE_TOKEN" \
"https://gitlab.com/api/v4/groups/$GrOUP_ID/merge_requests?state=$MR_STATUS&per_page=$PAGE_SIZE" \
| jq '.[] | select(.title | test("$TITLE_REGEX")) | [.project_id, .iid] | @csv')
do
echo curl -XDELETE --header "PRIVATE-TOKEN: $PRIVATE_TOKEN" https://gitlab.com/api/v4/projects/${MR/,*}/merge_requests/${MR/*,}
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment