Trigger different `main` workflow based on which branch got merged

Hi,

I would like to build a pipeline with two different main workflows so that conditionally one or the other gets triggered based on the branch name that got merged into main.

Let’s say I merge into main a branch whose name starts with feat/..., I want main_1 workflow to trigger
But if I merge a branch into main whose name starts with themes/... I want to trigger main_2

How do I do it? Is that possible?

I was checking the pipeline parameter and the closest one I could find was
<< pipeline.git.branch >> but we use it always to simply fire the main workflow doing

  main:
    when:
      and:
        - equal: [main, << pipeline.git.branch >>]

Definitely not what I need!

Hope someone has some answers, thank you.

After quite a bit of digging on git commands on how to get it, I used the circleci/github-cli@1.0.4 orb and ran:

            LAST_MAIN_MERGED_PR_INFO=$(gh pr list -s merged -B main -L 1)
            echo "Last merged main pr info: $LAST_MAIN_MERGED_PR_INFO"
      
            LAST_MAIN_MERGED_PR_INFO_ARR=($LAST_MAIN_MERGED_PR_INFO)

            # Takes the branch name from the GH info received.
            LAST_MAIN_MERGED_PR_BRANCH=${LAST_MAIN_MERGED_PR_INFO_ARR[-2]}

Like that I got the last merged or branch.