Github Actions: Get PR Author Email Address

Viewed 633

I want to access the Github PR Author's email address. Im using Databricks Repo with Files enabled. Since my codebase contains non-notebook files, I decided to go with Repos. As part of my CI pipeline , I need to perform nutter tests for databricks notebooks. My idea is to update a Testing folder inside of user level repo folder with the latest code from github.head_ref. Since the structure of path in Databricks Repos is /Repos/<EMAIL>/... , I need to access the email from PR details.

2 Answers

If you're trying to do this on a pull request, there isn't an e-mail associated to the user on a PR. However, if you have access to the branch where the PR came from, you can do this by checking out the branch that the PR came from.

This is using github actions to automate it.

  - name: Checks out repository
    uses: actions/checkout@v3
    with:
      fetch-depth: 0 # You need this to grab all of the branches.
  - name: Get user's e-mail
    id: user_email
    run: |
      git checkout remotes/origin/${{ github.head_ref }}
      echo "::set-output name=user_email::$(git log -n 1 --pretty=format:%ae)"

Edit: I was having an issue where merges into the branch don't have the e-mail address. But just an edge case you're going to have to deal with. Fixed it with an awk. I'm sure there are other ways to do this but here's an example:

git log --pretty=format:%ae | awk '/<pattern>/ && !line{line=$0} END{print line}'

You can use github.event.pusher.email. Eg:

- name: Get PR Author Email Address
  run: |
      echo "The name of the pusher: ${{ github.event.pusher.name }}"
      echo "The email of the pusher: ${{ github.event.pusher.email }}"
Related