Extract a part of the PR title in github actions

Viewed 15

I managed to get the title of my Pull Request. But now I need to grab only part of the title.

Example, this is my title:

  • Test: AB#16845 try to return PR number

and I just need this part of the title,

AB#16845

How could I do it?

jobs:
      
 print_title_of_pr:
   runs-on: [self-hosted, linux, x64, dev]
   steps:
   - name : Print Title of PR
   run: echo The Title of your PR is ${{ github.event.pull_request.title }}
1 Answers

How about using https://github.com/actions-ecosystem/action-regex-match? Haven't tested it yet, but something like this?

jobs:
  print_title_of_pr:
    runs-on: [self-hosted, linux, x64, dev]
    steps:
    - uses: actions-ecosystem/action-regex-match@v2
      id: regex-match
      with:
        text: ${{ github.event.pull_request.title }} # e.g. "Test: AB#16845 try to return PR number"
        regex: '^\w+:\s(.+#\d+).*$'
    - name: Echo extracted title
      run: |
        echo "${{ steps.regex-match.outputs.group1 }}"
Related