Run job in CI pipeline only on merge branch into the master and get merged branch name

Does someone have a clean minimal script just for determining whether we are on the default branch and the pipeline trigger was such a merge commit? I’m thinking of:

cleanup:
  stage: .post
  rules:
    - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
  script: | 
    if [[ WHAT_SHOULD_I_PLACE_HERE ]] # Easiest way would be to parse $CI_COMMIT_MESSAGE ?
    then
      echo "This is a merge commit"
    else
      echo "This is not a merge commit"
    fi