Skip to content

Instantly share code, notes, and snippets.

@ffflorian
Created August 4, 2020 14:17
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ffflorian/71de2e72a3788fbc63fa5ead8e3b5fde to your computer and use it in GitHub Desktop.
Save ffflorian/71de2e72a3788fbc63fa5ead8e3b5fde to your computer and use it in GitHub Desktop.
GH actions: Get commit message in a PR
name: Notify on Pull Request
on:
pull_request:
branches: [dev]
jobs:
send_notification:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0
ref: ${{github.event.after}}
- name: Get Commit Message
run: |
MSG=$(git log --format=%B -n 1 ${{github.event.after}})
echo "::set-env name=COMMIT_MESSAGE::${MSG}"
- name: Echo commit message
run: echo "Commit SHA: ${{github.event.after}}, commit message: ${{env.COMMIT_MESSAGE}} (or ${COMMIT_MESSAGE})"
@Ismoh
Copy link

Ismoh commented Mar 31, 2022

Just btw you can use
${{ github.event.head_commit.message }}
instead of
https://gist.github.com/ffflorian/71de2e72a3788fbc63fa5ead8e3b5fde#file-get-commit-yml-L19

@jerturowetz
Copy link

@Ismoh github.event.head_commit.message is not exposed in PRs.

@Ismoh
Copy link

Ismoh commented May 9, 2022

Ah yea makes sense. I used it on push. Thanks for pointing out. My bad!

@jerturowetz
Copy link

As ::set-env is now deprecated you can fiddle around with envs or define outputs to manage it.

@omertoptas
Copy link

As ::set-env is now deprecated you can fiddle around with envs or define outputs to manage it.

Thanks so much 👍

@neotan
Copy link

neotan commented Jan 11, 2023

In case someone landed here for a quick solution. The ${{ github.event.head_commit.message }} is still working fine. FYI.

@dsherret
Copy link

dsherret commented Jan 11, 2023

@neotan no, it doesn't work in PR events as mentioned above (only push). I came here because it doesn't work in PR events.

@neotan
Copy link

neotan commented Jan 11, 2023

@neotan no, it doesn't work in PR events as mentioned above (only push).

ah, my bad! Overlooked the mentions above, ya it works in pushing. Thanks for pointing out!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment