githubyamlgithub-actions

How to get the title of a Pull Request with Github Actions


In GitHub I have a pull request called [WIP] Dev-123 Sample Pull Request.

I want to get this title in a GitHub Actions yaml pipeline.

In the GitHub Docs Context I can't seem to find which object I need to reference.


Solution

  • This answer is functionally correct but has a security risk of script injection, see Yaron Avital's answer for the way recommended by GitHub

    The title of the Pull Request can be accessed by github.event.pull_request.title

    The workflow to use this would be:

    on:
      push:
      pull_request:
       types: [opened, synchronize]
    
      print_title_of_pr:
        runs-on: ubuntu-20.04
        steps:
        - name : Print Title of PR
          run: echo The Title of your PR is ${{ github.event.pull_request.title }}